Fixed comparison of shapes (#1000)

main
Boris Sekachev 6 years ago committed by Nikita Manovich
parent 63d5326b51
commit c407874a52

@ -102,12 +102,18 @@
}, },
}; };
const keys = ['id', 'label_id', 'group', 'frame',
'occluded', 'z_order', 'points', 'type', 'shapes',
'attributes', 'value', 'spec_id', 'outside'];
// Find created and updated objects // Find created and updated objects
for (const type of Object.keys(exported)) { for (const type of Object.keys(exported)) {
for (const object of exported[type]) { for (const object of exported[type]) {
if (object.id in this.initialObjects[type]) { if (object.id in this.initialObjects[type]) {
const exportedHash = JSON.stringify(object); const exportedHash = JSON.stringify(object, keys);
const initialHash = JSON.stringify(this.initialObjects[type][object.id]); const initialHash = JSON.stringify(
this.initialObjects[type][object.id], keys,
);
if (exportedHash !== initialHash) { if (exportedHash !== initialHash) {
splitted.updated[type].push(object); splitted.updated[type].push(object);
} }

@ -151,14 +151,18 @@ class AnnotationSaverModel extends Listener {
tags: [], tags: [],
}; };
const keys = ['id', 'label_id', 'group', 'frame',
'occluded', 'z_order', 'points', 'type', 'shapes',
'attributes', 'value', 'spec_id', 'outside'];
// Compare initial state objects and export state objects // Compare initial state objects and export state objects
// in order to get updated and created objects // in order to get updated and created objects
for (const type of Object.keys(this._initialObjects)) { for (const type of Object.keys(this._initialObjects)) {
for (const obj of exported[type]) { for (const obj of exported[type]) {
if (obj.id in this._initialObjects[type]) { if (obj.id in this._initialObjects[type]) {
const exportedHash = JSON.stringify(obj); const exportedHash = JSON.stringify(obj, keys);
const initialSash = JSON.stringify(this._initialObjects[type][obj.id]); const initialHash = JSON.stringify(this._initialObjects[type][obj.id], keys);
if (exportedHash !== initialSash) { if (exportedHash !== initialHash) {
updated[type].push(obj); updated[type].push(obj);
} }
} else if (typeof obj.id === 'undefined') { } else if (typeof obj.id === 'undefined') {
@ -241,11 +245,18 @@ class AnnotationSaverModel extends Listener {
this._shapeCollection.flush = false; this._shapeCollection.flush = false;
this._version = savedObjects.version; this._version = savedObjects.version;
this._resetState(); this._resetState();
for (const type of Object.keys(this._initialObjects)) { for (const type of Object.keys(this._initialObjects)) {
for (const object of savedObjects[type]) { for (const object of savedObjects[type]) {
if (object.shapes) {
for (const shape of object.shapes) {
delete shape.id;
}
}
this._initialObjects[type][object.id] = object; this._initialObjects[type][object.id] = object;
} }
} }
this._version = savedObjects.version; this._version = savedObjects.version;
} else { } else {
const [created, updated, deleted] = this._split(exported); const [created, updated, deleted] = this._split(exported);
@ -253,8 +264,14 @@ class AnnotationSaverModel extends Listener {
const savedCreated = await this._create(created); const savedCreated = await this._create(created);
this._updateCreatedObjects(created, savedCreated, mapping); this._updateCreatedObjects(created, savedCreated, mapping);
this._version = savedCreated.version; this._version = savedCreated.version;
for (const type of Object.keys(this._initialObjects)) { for (const type of Object.keys(this._initialObjects)) {
for (const object of savedCreated[type]) { for (const object of savedCreated[type]) {
if (object.shapes) {
for (const shape of object.shapes) {
delete shape.id;
}
}
this._initialObjects[type][object.id] = object; this._initialObjects[type][object.id] = object;
} }
} }
@ -264,6 +281,11 @@ class AnnotationSaverModel extends Listener {
this._version = savedUpdated.version; this._version = savedUpdated.version;
for (const type of Object.keys(this._initialObjects)) { for (const type of Object.keys(this._initialObjects)) {
for (const object of savedUpdated[type]) { for (const object of savedUpdated[type]) {
if (object.shapes) {
for (const shape of object.shapes) {
delete shape.id;
}
}
this._initialObjects[type][object.id] = object; this._initialObjects[type][object.id] = object;
} }
} }
@ -375,7 +397,7 @@ class AnnotationSaverView {
}); });
window.onbeforeunload = (e) => { window.onbeforeunload = (e) => {
if (this._controller.hasUnsavedChanges()) { // eslint-disable-line react/no-this-in-sfc if (this._controller.hasUnsavedChanges()) {
const message = 'You have unsaved changes. Leave this page?'; const message = 'You have unsaved changes. Leave this page?';
e.returnValue = message; e.returnValue = message;
return message; return message;

Loading…
Cancel
Save