@@ -151,14 +151,18 @@ class AnnotationSaverModel extends Listener {
151
151
tags : [ ] ,
152
152
} ;
153
153
154
+ const keys = [ 'id' , 'label_id' , 'group' , 'frame' ,
155
+ 'occluded' , 'z_order' , 'points' , 'type' , 'shapes' ,
156
+ 'attributes' , 'value' , 'spec_id' , 'outside' ] ;
157
+
154
158
// Compare initial state objects and export state objects
155
159
// in order to get updated and created objects
156
160
for ( const type of Object . keys ( this . _initialObjects ) ) {
157
161
for ( const obj of exported [ type ] ) {
158
162
if ( obj . id in this . _initialObjects [ type ] ) {
159
- const exportedHash = JSON . stringify ( obj ) ;
160
- const initialSash = JSON . stringify ( this . _initialObjects [ type ] [ obj . id ] ) ;
161
- if ( exportedHash !== initialSash ) {
163
+ const exportedHash = JSON . stringify ( obj , keys ) ;
164
+ const initialHash = JSON . stringify ( this . _initialObjects [ type ] [ obj . id ] , keys ) ;
165
+ if ( exportedHash !== initialHash ) {
162
166
updated [ type ] . push ( obj ) ;
163
167
}
164
168
} else if ( typeof obj . id === 'undefined' ) {
@@ -241,20 +245,33 @@ class AnnotationSaverModel extends Listener {
241
245
this . _shapeCollection . flush = false ;
242
246
this . _version = savedObjects . version ;
243
247
this . _resetState ( ) ;
248
+
244
249
for ( const type of Object . keys ( this . _initialObjects ) ) {
245
250
for ( const object of savedObjects [ type ] ) {
251
+ if ( object . shapes ) {
252
+ for ( const shape of object . shapes ) {
253
+ delete shape . id ;
254
+ }
255
+ }
246
256
this . _initialObjects [ type ] [ object . id ] = object ;
247
257
}
248
258
}
259
+
249
260
this . _version = savedObjects . version ;
250
261
} else {
251
262
const [ created , updated , deleted ] = this . _split ( exported ) ;
252
263
this . notify ( 'saveCreated' ) ;
253
264
const savedCreated = await this . _create ( created ) ;
254
265
this . _updateCreatedObjects ( created , savedCreated , mapping ) ;
255
266
this . _version = savedCreated . version ;
267
+
256
268
for ( const type of Object . keys ( this . _initialObjects ) ) {
257
269
for ( const object of savedCreated [ type ] ) {
270
+ if ( object . shapes ) {
271
+ for ( const shape of object . shapes ) {
272
+ delete shape . id ;
273
+ }
274
+ }
258
275
this . _initialObjects [ type ] [ object . id ] = object ;
259
276
}
260
277
}
@@ -264,6 +281,11 @@ class AnnotationSaverModel extends Listener {
264
281
this . _version = savedUpdated . version ;
265
282
for ( const type of Object . keys ( this . _initialObjects ) ) {
266
283
for ( const object of savedUpdated [ type ] ) {
284
+ if ( object . shapes ) {
285
+ for ( const shape of object . shapes ) {
286
+ delete shape . id ;
287
+ }
288
+ }
267
289
this . _initialObjects [ type ] [ object . id ] = object ;
268
290
}
269
291
}
@@ -375,7 +397,7 @@ class AnnotationSaverView {
375
397
} ) ;
376
398
377
399
window . onbeforeunload = ( e ) => {
378
- if ( this . _controller . hasUnsavedChanges ( ) ) { // eslint-disable-line react/no-this-in-sfc
400
+ if ( this . _controller . hasUnsavedChanges ( ) ) {
379
401
const message = 'You have unsaved changes. Leave this page?' ;
380
402
e . returnValue = message ;
381
403
return message ;
0 commit comments