From 42d79b550c031d5b4af774540c58b81ddb733193 Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov <41117609+azhavoro@users.noreply.github.com> Date: Thu, 18 Oct 2018 16:30:20 +0300 Subject: [PATCH] Fixed bug for save functionality (#141) In case of any changes during save request the state of exported shapes can be inconsistent. That leads to errors for future saves. --- cvat/apps/engine/static/engine/js/annotationUI.js | 9 +++++---- cvat/apps/engine/static/engine/js/shapeCollection.js | 10 ++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cvat/apps/engine/static/engine/js/annotationUI.js b/cvat/apps/engine/static/engine/js/annotationUI.js index 9f0ca3acb5e1..9a80c51cd3ca 100644 --- a/cvat/apps/engine/static/engine/js/annotationUI.js +++ b/cvat/apps/engine/static/engine/js/annotationUI.js @@ -100,7 +100,8 @@ function buildAnnotationUI(job, shapeData, loadJobEvent) { // Setup components let annotationParser = new AnnotationParser(job, window.cvat.labelsInfo); - let shapeCollectionModel = new ShapeCollectionModel().import(shapeData).updateHash(); + let shapeCollectionModel = new ShapeCollectionModel().import(shapeData).updateExportedState(); + shapeCollectionModel.confirmExportedState(); let shapeCollectionController = new ShapeCollectionController(shapeCollectionModel); let shapeCollectionView = new ShapeCollectionView(shapeCollectionModel, shapeCollectionController); @@ -690,6 +691,7 @@ function saveAnnotation(shapeCollectionModel, job) { }); const exportedData = shapeCollectionModel.export(); + shapeCollectionModel.updateExportedState(); const annotationLogs = Logger.getLogs(); const data = { @@ -702,8 +704,7 @@ function saveAnnotation(shapeCollectionModel, job) { saveJobRequest(job.jobid, data, () => { // success - shapeCollectionModel.reset_state(); - shapeCollectionModel.updateHash(); + shapeCollectionModel.confirmExportedState(); saveButton.text('Success!'); setTimeout(() => { saveButton.prop('disabled', false); @@ -741,4 +742,4 @@ function translateSVGPos(svgCanvas, clientX, clientY) { function blurAllElements() { document.activeElement.blur(); -} \ No newline at end of file +} diff --git a/cvat/apps/engine/static/engine/js/shapeCollection.js b/cvat/apps/engine/static/engine/js/shapeCollection.js index 7f6416f866d9..7567fa7d53f1 100644 --- a/cvat/apps/engine/static/engine/js/shapeCollection.js +++ b/cvat/apps/engine/static/engine/js/shapeCollection.js @@ -53,6 +53,7 @@ class ShapeCollectionModel extends Listener { this._splitter = new ShapeSplitter(); this._erased = false; this._initialShapes = {}; + this._exportedShapes = {}; } _nextIdx() { @@ -239,8 +240,9 @@ class ShapeCollectionModel extends Listener { return this; } - reset_state() { + confirmExportedState() { this._erased = false; + this._initialShapes = this._exportedShapes; } export() { @@ -349,8 +351,8 @@ class ShapeCollectionModel extends Listener { return exportData.pre_erase; } - updateHash() { - this._initialShapes = {}; + updateExportedState() { + this._exportedShapes = {}; if (this._erased) { return this; @@ -358,7 +360,7 @@ class ShapeCollectionModel extends Listener { for (const shape of this._shapes) { if (!shape.removed) { - this._initialShapes[shape.id] = shape.export(); + this._exportedShapes[shape.id] = shape.export(); } } return this;