Skip to content

Commit

Permalink
now detecting concurrent commits
Browse files Browse the repository at this point in the history
  • Loading branch information
siegel-his committed Mar 17, 2017
1 parent 87a4a42 commit 0ff712f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class AppComponent implements OnInit {
if ( this.rows.length > 0 && this.currentConfig.sameAs( this.rows[0].config ) )
alert( "Not saved. Configuration is already active." );
else if ( confirm( "Save new configuration?" ) ) {

let newestInLast: number = ( this.rows.length > 0 ) ? this.rows[0].timestamp : 42;
let ths = this;
let added = this.currentConfig.clone();
this.configurationsService.saveConfig( added ).then(
Expand All @@ -66,6 +68,9 @@ export class AppComponent implements OnInit {
}
).then( rows => {
ths.setRows( rows );
let newestInThis: number = ( this.rows.length > 1 ) ? this.rows[1].timestamp : 42;
if ( newestInThis != newestInLast )
alert( "Changes have been submitted concurrently. Please revisit the configuration." );
},
function( data ) {
alert( "Could not save configuration.\n\nMessage returned by server: '" + data + "'" );
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/app/configurations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ function formatDate( str: string ) {
return dateToStr( new Date( str ) );
}

const MOCK = [
/*const MOCK = [
new Submission( new Configuration( "conftext1", "confcomment1" ), "Karl-Heinz", formatDate( "2017-01-13" ) ),
new Submission( new Configuration( "conftext2", "confcomment2" ), "Hans-Horst", formatDate( "2017-01-14" ) ),
new Submission( new Configuration( "conftext3", "confcomment3" ), "Rüdiger-Maria", formatDate( "2017-01-15" ) )
];

*/

@Injectable()
export class ConfigurationsService {
Expand All @@ -37,12 +37,7 @@ export class ConfigurationsService {


getConfigurations(): Promise<Submission[]> {
let mock = false;
if ( mock )
return Promise.resolve( MOCK ).then( x => x );


let confs = this.http.get( this.configurationsUrl )
let confs = this.http.get( this.configurationsUrl )
.toPromise()
.then( response =>
this.translate( response.json() )
Expand All @@ -56,7 +51,9 @@ export class ConfigurationsService {
let submissions = [];
for ( var i = 0; i < o.length; i++ ) {
var row = o[i];
let sumi = new Submission( new Configuration( row[0], row[2] ), row[1], dateToStr( new Date( row[3] ) ) );
let conf = new Configuration( row[0], row[2] );
let date = new Date(row[3]);
let sumi = new Submission(conf , row[1], dateToStr( date ), date.getTime() );
submissions.push( sumi );
}
return submissions
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/app/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ export class Submission {
config: Configuration;
username: string;
changetime: string;
timestamp : number;


constructor( config: Configuration, user: string, time: string ) {
constructor( config: Configuration, user: string, time: string, timestamp:number ) {
this.config = config;
this.username = user;
this.changetime = time;
this.timestamp = timestamp;
}

toString() {
Expand Down

0 comments on commit 0ff712f

Please sign in to comment.