Skip to content

Commit

Permalink
Bug has been fixed: label UIs don't update after changelabel (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored and nmanovic committed Oct 4, 2018
1 parent b8e0683 commit f3c406a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 20 deletions.
52 changes: 37 additions & 15 deletions cvat/apps/engine/static/engine/js/shapeCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,15 @@ class ShapeCollectionView {
});
}

onCollectionUpdate(collection) {
_updateLabelUIs() {
this._labelsContent.find('.labelContentElement').addClass('hidden');
let labels = new Set(this._currentModels.map((el) => el.label));
for (let label of labels) {
this._labelsContent.find(`.labelContentElement[label_id="${label}"]`).removeClass('hidden');
}
}

onCollectionUpdate(collection) {
// Save parents and detach elements from DOM
// in order to increase performance in the buildShapeView function
let parents = {
Expand Down Expand Up @@ -1268,7 +1274,6 @@ class ShapeCollectionView {
else {
this._currentViews.push(oldViews[oldIdx]);
this._currentModels.push(oldModels[oldIdx]);
this._labelsContent.find(`.labelContentElement[label_id="${oldModels[oldIdx].label}"]`).removeClass('hidden');
}
}

Expand All @@ -1284,10 +1289,9 @@ class ShapeCollectionView {
parents.uis.prepend(this._UIContent);
}


ShapeCollectionView.sortByZOrder();
this._frameMarker = window.cvat.player.frames.current;

this._updateLabelUIs();

function drawView(shape, model) {
let view = buildShapeView(model, buildShapeController(model), this._frameContent, this._UIContent);
Expand All @@ -1297,7 +1301,6 @@ class ShapeCollectionView {
view.subscribe(this);
this._currentViews.push(view);
this._currentModels.push(model);
this._labelsContent.find(`.labelContentElement[label_id="${model.label}"]`).removeClass('hidden');
}
}

Expand Down Expand Up @@ -1327,18 +1330,37 @@ class ShapeCollectionView {
}

onShapeViewUpdate(view) {
if (view.dragging) {
window.cvat.mode = 'drag';
}
else if (window.cvat.mode === 'drag') {
window.cvat.mode = null;
switch (view.updateReason) {
case 'drag':
if (view.dragging) {
window.cvat.mode = 'drag';
}
else if (window.cvat.mode === 'drag') {
window.cvat.mode = null;
}
break;
case 'resize':
if (view.resize) {
window.cvat.mode = 'resize';
}
else if (window.cvat.mode === 'resize') {
window.cvat.mode = null;
}
break;
case 'remove': {
let idx = this._currentViews.indexOf(view);
view.unsubscribe(this);
view.controller().model().unsubscribe(view);
view.erase();
this._currentViews.splice(idx, 1);
this._currentModels.splice(idx, 1);
this._updateLabelUIs();
break;
}

if (view.resize) {
window.cvat.mode = 'resize';
case 'changelabel': {
this._updateLabelUIs();
break;
}
else if (window.cvat.mode === 'resize') {
window.cvat.mode = null;
}
}

Expand Down
29 changes: 24 additions & 5 deletions cvat/apps/engine/static/engine/js/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ShapeModel extends Listener {
this._label = +labelId;
this._importAttributes([], []);
this._setupKeyFrames();
this.notify('attributes');
this.notify('changelabel');
}
else {
throw Error(`Unknown label id value found: ${labelId}`);
Expand Down Expand Up @@ -1403,6 +1403,7 @@ class ShapeView extends Listener {
};

this._controller = shapeController;
this._updateReason = null;

this._shapeContextMenu = $('#shapeContextMenu');
this._pointContextMenu = $('#pointContextMenu');
Expand All @@ -1426,7 +1427,7 @@ class ShapeView extends Listener {
this._flags.dragging = true;
blurAllElements();
this._hideShapeText();
this.notify();
this.notify('drag');
}).on('dragend', (e) => {
let p1 = e.detail.handler.startPoints.point;
let p2 = e.detail.p;
Expand All @@ -1438,7 +1439,7 @@ class ShapeView extends Listener {
events.drag = null;
this._flags.dragging = false;
this._showShapeText();
this.notify();
this.notify('drag');
});

// Setup resize events
Expand All @@ -1456,7 +1457,7 @@ class ShapeView extends Listener {
events.resize = Logger.addContinuedEvent(Logger.EventType.resizeObject);
blurAllElements();
this._hideShapeText();
this.notify();
this.notify('resize');
}).on('resizing', () => {
objWasResized = true;
}).on('resizedone', () => {
Expand All @@ -1469,7 +1470,7 @@ class ShapeView extends Listener {
events.resize = null;
this._flags.resizing = false;
this._showShapeText();
this.notify();
this.notify('resize');
});


Expand Down Expand Up @@ -2353,6 +2354,18 @@ class ShapeView extends Listener {
}


notify(newReason) {
let oldReason = this._updateReason;
this._updateReason = newReason;
try {
Listener.prototype.notify.call(this);
}
finally {
this._updateReason = oldReason;
}
}


// Inteface methods
draw(interpolation) {
let outside = interpolation.position.outside;
Expand Down Expand Up @@ -2473,6 +2486,7 @@ class ShapeView extends Listener {
case 'remove':
if (model.removed) {
this.erase();
this.notify('remove');
}
break;
case 'position':
Expand All @@ -2494,6 +2508,7 @@ class ShapeView extends Listener {
if (colorByLabel.prop('checked')) {
colorByLabel.trigger('change');
}
this.notify('changelabel');
break;
}
case 'attributeFocus': {
Expand Down Expand Up @@ -2663,6 +2678,10 @@ class ShapeView extends Listener {
return this._flags.resizing;
}

get updateReason() {
return this._updateReason;
}

// Used in shapeGrouper in order to get model via controller and set group id
controller() {
return this._controller;
Expand Down

0 comments on commit f3c406a

Please sign in to comment.