Skip to content

Commit

Permalink
Copy URL, Frame URL and object URL functionality in a context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Sekachev committed Oct 4, 2018
1 parent 79dcefc commit 8061236
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 21 deletions.
22 changes: 10 additions & 12 deletions cvat/apps/engine/static/engine/js/annotationUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
*/

/* exported callAnnotationUI translateSVGPos blurAllElements drawBoxSize */
/* exported callAnnotationUI translateSVGPos blurAllElements drawBoxSize copyToClipboard */
"use strict";

function callAnnotationUI(jid) {
Expand Down Expand Up @@ -221,20 +221,18 @@ function buildAnnotationUI(job, shapeData, loadJobEvent) {
blurAllElements();
}
});
}

$('#copyLinkButton').on('click', (e) => {
let tempInput = $("<input>");
$("body").append(tempInput);
tempInput.prop('value', window.cvat.search.toString()).select();
document.execCommand("copy");
tempInput.remove();
e.target.innerText = '\u2714';
setTimeout(() => {
e.target.innerText = '\u270e';
}, 1000);
});

function copyToClipboard(text) {
let tempInput = $("<input>");
$("body").append(tempInput);
tempInput.prop('value', text).select();
document.execCommand("copy");
tempInput.remove();
}


function setupFrameFilters() {
let brightnessRange = $('#playerBrightnessRange');
let contrastRange = $('#playerContrastRange');
Expand Down
33 changes: 33 additions & 0 deletions cvat/apps/engine/static/engine/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ class PlayerView {
this._frameNumber = $('#frameNumber');
this._playerGridPattern = $('#playerGridPattern');
this._playerGridPath = $('#playerGridPath');
this._contextMenuUI = $('#playerContextMenu');

$('*').on('mouseup', () => this._controller.frameMouseUp());
this._playerUI.on('wheel', (e) => this._controller.zoom(e));
Expand Down Expand Up @@ -763,6 +764,38 @@ class PlayerView {
this._multiplePrevButtonUI.find('polygon').append($(document.createElementNS('http://www.w3.org/2000/svg', 'title'))
.html(`${shortkeys['backward_frame'].view_value} - ${shortkeys['backward_frame'].description}`));


this._contextMenuUI.click((e) => {
$('.custom-menu').hide(100);
switch($(e.target).attr("action")) {
case "job_url": {
window.cvat.search.set('frame', null);
window.cvat.search.set('filter', null);
copyToClipboard(window.cvat.search.toString());
break;
}
case "frame_url":
window.cvat.search.set('frame', window.cvat.player.frames.current);
window.cvat.search.set('filter', null);
copyToClipboard(window.cvat.search.toString());
window.cvat.search.set('frame', null);
break;
}
});

this._playerContentUI.on('contextmenu.playerContextMenu', (e) => {
$('.custom-menu').hide(100);
this._contextMenuUI.finish().show(100).offset({
top: e.pageY - 10,
left: e.pageX - 10,
});
e.preventDefault();
});

this._playerContentUI.on('mousedown.playerContextMenu', () => {
$('.custom-menu').hide(100);
});

playerModel.subscribe(this);
}

Expand Down
19 changes: 17 additions & 2 deletions cvat/apps/engine/static/engine/js/shapeCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,10 @@ class ShapeCollectionController {
get filterController() {
return this._filterController;
}

get activeShape() {
return this._model.activeShape;
}
}

class ShapeCollectionView {
Expand Down Expand Up @@ -1117,9 +1121,20 @@ class ShapeCollectionView {

$('#shapeContextMenu li').click((e) => {
let menu = $('#shapeContextMenu');
menu.hide(100);
$('.custom-menu').hide(100);

switch($(e.target).attr("action")) {
case "object_url": {
let active = this._controller.activeShape;
if (active) {
window.cvat.search.set('frame', window.cvat.player.frames.current);
window.cvat.search.set('filter', `*[id="${active.id}"]`);
copyToClipboard(window.cvat.search.toString());
window.cvat.search.set('frame', null);
window.cvat.search.set('filter', null);
}
break;
}
case "change_color":
this._controller.switchActiveColor();
break;
Expand Down Expand Up @@ -1162,7 +1177,7 @@ class ShapeCollectionView {
$('#pointContextMenu li').click((e) => {
let menu = $('#pointContextMenu');
let idx = +menu.attr('point_idx');
menu.hide(100);
$('.custom-menu').hide(100);

switch($(e.target).attr("action")) {
case "remove_point":
Expand Down
10 changes: 4 additions & 6 deletions cvat/apps/engine/static/engine/js/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,16 +1492,15 @@ class ShapeView extends Listener {
// Setup context menu
this._uis.shape.on('mousedown.contextMenu', (e) => {
if (e.which === 1) {
this._shapeContextMenu.hide(100);
this._pointContextMenu.hide(100);
$('.custom-menu').hide(100);
}
if (e.which === 3) {
e.stopPropagation();
}
});

this._uis.shape.on('contextmenu.contextMenu', (e) => {
this._pointContextMenu.hide(100);
$('.custom-menu').hide(100);
let type = this._controller.type.split('_');
if (type[0] === 'interpolation') {
this._shapeContextMenu.find('.interpolationItem').removeClass('hidden');
Expand Down Expand Up @@ -1553,8 +1552,7 @@ class ShapeView extends Listener {
this._flags.editable = false;
}

this._pointContextMenu.hide(100);
this._shapeContextMenu.hide(100);
$('.custom-menu').hide(100);
}


Expand Down Expand Up @@ -2829,7 +2827,7 @@ class PolyShapeView extends ShapeView {
point = $(point);

point.on('contextmenu.contextMenu', (e) => {
this._shapeContextMenu.hide(100);
$('.custom-menu').hide(100);
this._pointContextMenu.attr('point_idx', point.index());
this._pointContextMenu.attr('dom_point_id', point.attr('id'));

Expand Down
8 changes: 7 additions & 1 deletion cvat/apps/engine/templates/engine/annotation.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
</defs>
<rect width="100%" height="100%" fill="url(#playerGridPattern)" />
</svg>

<ul id="shapeContextMenu" class='custom-menu' oncontextmenu="return false;">
<li action="object_url"> Copy Object URL </li>
<li action="change_color"> Change Color </li>
<li action="remove_shape"> Remove Shape </li>
<li action="switch_occluded"> Switch Occluded </li>
Expand All @@ -86,6 +88,11 @@
<li class="polygonItem" action="drag_polygon"> Enable Dragging </li>
</ul>

<ul id="playerContextMenu" class='custom-menu' oncontextmenu="return false;">
<li action="job_url"> Copy Job URL </li>
<li action="frame_url"> Copy Frame URL </li>
</ul>

<ul id="pointContextMenu" class='custom-menu' oncontextmenu="return false;">
<li action="remove_point"> Remove </li>
</ul>
Expand Down Expand Up @@ -135,7 +142,6 @@
<option id="lastRedoText" title="Redo Action"> None </option>
</select>
<button class="regular h1" id="redoButton" disabled> &#10227; </button>
<button class="regular h1" title="Copy detailed URL to buffer. It contains frame and filter values" id="copyLinkButton"> &#x270e; </button>
<div style="float: right;">
<label class="regular h1"> Frame </label>
<input class="regular h2" style="width: 3.5em;" type="number" id="frameNumber">
Expand Down
1 change: 1 addition & 0 deletions tests/eslintrc.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
'translateSVGPos': true,
'blurAllElements': true,
'drawBoxSize': true,
'copyToClipboard': true,
// from base.js
'showMessage': true,
'showOverlay': true,
Expand Down

0 comments on commit 8061236

Please sign in to comment.