Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #125 from zooniverse/delete-rows
Browse files Browse the repository at this point in the history
Delete rows
  • Loading branch information
itsravenous authored Aug 24, 2016
2 parents e7482b7 + 02d66a4 commit 6bee11f
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 144 deletions.
97 changes: 65 additions & 32 deletions app/modules/annotation/scripts/annotations-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,56 @@
scope.$apply();
};

var storeAnnotations = function (e, data) {
var existing = _.find(scope.annotations, {_id: data._id});
if (angular.isUndefined(existing)) {
addAnnotation(data);
} else {
updateAnnotation(data, existing);
}
};

var tempCells = {};

var createCells = function (row) {
var headers = _.where(scope.annotations, {type: 'header'});
var rowId = _.uniqueId('row_'); // + new Date().getTime(); // use human-readable id for debugging --STI
_.each(headers, function (header, index) {
// If the row is below the header
if (row.y >= (header.y + header.height)) {
var obj = {
var annotation = {
height: row.height,
width: header.width,
x: header.x,
y: row.y,
rotation: header.rotation
rotation: header.rotation,
type: 'row_annotation' // actual row annotations need to be called something else for now --STI
};

var existing = _.find(scope.annotations, { _id: tempCells[index] });

if (angular.isUndefined(existing)) {
obj._id = _.uniqueId() + new Date().getTime();
addAnnotation(obj);
tempCells[index] = obj._id;
annotation._id = _.uniqueId('antn_'); //+ new Date().getTime(); // use human-readable id for debugging --STI
annotation._rowId = rowId;
addAnnotation(annotation);
tempCells[index] = annotation._id;
} else {
obj._id = existing._id;
updateAnnotation(obj, existing);
annotation._id = existing._id;
annotation._rowId = existing._rowId;
updateAnnotation(annotation, existing);
}

}
});
};

var storeAnnotations = function (e, data) {
// skip for row annotation: createCells() called separately
if (data.type === 'row') {
createCells(data);
}
else {
var existing = _.find(scope.annotations, {_id: data._id});
if (angular.isUndefined(existing)) {
addAnnotation(data);
} else {
updateAnnotation(data, existing);
}
}

};

var getAnnotations = function () {
scope.annotations = [];

Expand All @@ -78,18 +90,27 @@
};

var clearAnnotations = function () {
confirmationModalFactory.deployModal('Clear all annotations?', function(isConfirmed){
if(isConfirmed){
var params = {message: 'Clear all annotations?'};
confirmationModalFactory.setParams(params);
confirmationModalFactory.deployModal(function(deleteType){
if(deleteType){
scope.annotations = [];
annotationsFactory.clear(null, scope.$parent.subject);
}
});
};

scope.removeAnnotation = function (annotation) {
_.remove(scope.annotations, {_id: annotation._id});
annotationsFactory.remove(annotation._id, scope.$parent.subject);

scope.removeAnnotation = function (annotation, type) {
if(type === 'row' && annotation._rowId) { // remove all annotations in row
var annotationsToRemove = _.filter(scope.annotations, {_rowId: annotation._rowId});
for(var currAnnotation of annotationsToRemove) {
_.remove(scope.annotations, {_rowId: currAnnotation._rowId});
annotationsFactory.remove(currAnnotation._id, scope.$parent.subject);
}
} else {
_.remove(scope.annotations, {_id: annotation._id});
annotationsFactory.remove(annotation._id, scope.$parent.subject);
}
scope.$apply();
};

Expand All @@ -113,20 +134,20 @@
scope.$on('svgDrawing:update', storeAnnotations);

scope.$on('svgDrawing:update', function (e, rect, data) {
if (data.type === 'row') {
createCells(rect);
}
// if (data.type === 'row') {
// createCells(rect); // this doesn't seem necessary anymore
// }
});

scope.$on('svgDrawing:finish', function (e, rect, data) {
if (data.type === 'row') {
createCells(rect);
}
// if (data.type === 'row') {
// createCells(rect); // this doesn't seem necessary anymore
// }
tempCells = {};
});

getAnnotations();
}
} // end link
};
}]);

Expand All @@ -137,9 +158,21 @@
element.bind('mousedown', function (e) {
e.stopPropagation();
var annotation = $parse(attrs.annotation)(scope);
confirmationModalFactory.deployModal('Delete annotation?', function(isConfirmed){
if(isConfirmed){
scope.$parent.removeAnnotation(annotation);

var params = {
message: annotation.type === 'row_annotation' ? 'Delete annotation or entire row?' : 'Delete annotation?',
deleteType: annotation.type === 'row_annotation' ? 'row' : 'row_annotation'
};

confirmationModalFactory.setParams(params);
confirmationModalFactory.deployModal( function(deleteType) {
if(!deleteType) {
return; // no params passed, nothing to do
}
if(deleteType === 'row'){
scope.$parent.removeAnnotation(annotation, 'row');
} else if(deleteType === 'annotation') {
scope.$parent.removeAnnotation(annotation, 'annotation');
}
});
});
Expand Down
7 changes: 4 additions & 3 deletions app/modules/annotation/scripts/annotations-factory-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@
var classification = localStorageService.get(storageKey);

if (classification.annotations.length === 0) {

confirmationModalFactory.deployModal('You haven\'t added any annotations, are you sure you want to finish?', function(isConfirmed){
if(isConfirmed){
var params = {message: 'You haven\'t added any annotations, are you sure you want to finish?'};
confirmationModalFactory.setParams(params);
confirmationModalFactory.deployModal( function(deleteType) {
if(deleteType){
var subject_set_queue = localStorageService.get('subject_set_queue_' + $stateParams.subject_set_id);
_.remove(subject_set_queue, {id: id});
localStorageService.set('subject_set_queue_' + $stateParams.subject_set_id, subject_set_queue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@

module.controller('ConfirmationModalController', function(confirmationModalFactory, $scope){

$scope.msg = confirmationModalFactory.getMessage();
$scope.params = confirmationModalFactory.getParams();

$scope.deleteAnnotation = function() {
$scope.$close('annotation');
};

$scope.deleteRow = function() {
$scope.$close('row');
};

$scope.confirm = function() {
$scope.$close(true);
}
$scope.$close('annotation');
};

$scope.cancel = function() {
$scope.$close(false);
}
};

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@

module.factory('confirmationModalFactory', [ '$modal', '$controller', function($modal,$controller){

var message = 'Are you sure?'; // set default message
// set default parameters
var params = {
message: 'Are you sure?'
};

var setMessage = function(msg) {
message = msg;
}
var setParams = function(data) {
params = data;
};

var getMessage = function() {
return message;
}
var getParams = function() {
return params;
};

var deployModal = function(msg, callback) {
setMessage(msg);
var deployModal = function(callback) {

var modalInstance = $modal.open({
templateUrl: 'templates/confirmation-modal.html',
controller: 'ConfirmationModalController',
size: 'sm'
controller: 'ConfirmationModalController'
});

modalInstance.result.then(function(isConfirmed) {
callback(isConfirmed);
modalInstance.result.then( function(deleteType) {
callback(deleteType);
});
}
};

return {
deployModal: deployModal,
message: message,
setMessage: setMessage,
getMessage: getMessage
setParams: setParams,
getParams: getParams
};

}]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<div class="modal-header" ng-controller="ConfirmationModalController">
<div class="modal-title">
<h3>{{msg}}</h3>
<h3>{{params.message}}</h3>
</div>
</div>

<div class="modal-footer">
<button ng-click="confirm()" class="btn">Yes</button>
<button ng-click="cancel()" class="btn">No</button>
<button ng-show="{{params.deleteType !== 'row'}}" ng-click="confirm()" class="btn btn-teal small">Yes</button>
<button ng-show="{{params.deleteType === 'row'}}" ng-click="deleteAnnotation()" class="btn btn-teal small">Annotation</button>
<button ng-show="{{params.deleteType === 'row'}}" ng-click="deleteRow()" class="btn btn-teal small">Row</button>
<button ng-click="cancel()" class="btn btn-skeleton teal small">Cancel</button>
</div>
80 changes: 40 additions & 40 deletions app/modules/svg/scripts/svg-drawing-factory-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,31 @@
self.$viewport = $viewport;
};

var bindMouseEvents = function (data) {
if (angular.isDefined(data)) {
self.data = data;
} else {
self.data = null;
}

self.$viewport.on('mousedown', startDraw);
self.$viewport.on('mouseup', finishDraw);

self.eventsBound = true;
};

var unBindMouseEvents = function () {
self.data = null;

self.$viewport.off('mousedown');
self.$viewport.off('mouseup');

self.eventsBound = false;
};

var hasMouseEvents = function () {
return self.eventsBound;
var draw = function (event) {
var newPoint = svgService.createPoint(self.el, self.$viewport, event);
self.tempRect.x = (self.tempOrigin.x < newPoint.x) ? self.tempOrigin.x : newPoint.x;
self.tempRect.y = (self.tempOrigin.y < newPoint.y) ? self.tempOrigin.y : newPoint.y;
self.tempRect.width = Math.abs(newPoint.x - self.tempOrigin.x);
self.tempRect.height = Math.abs(newPoint.y - self.tempOrigin.y);
$rootScope.$broadcast('svgDrawing:update', self.tempRect, self.data);
};

var startDraw = function (event) {
// Only start drawing if panZoom is disabled, and it's a primary mouse click
if (!svgPanZoomFactory.status() && event.which === 1) {
event.preventDefault();

if (self.drawing) {
if (self.drawing) { // already drawing...
draw(event);
finishDraw(event);
// finishDraw(event); // not necessary?
} else {
self.tempOrigin = svgService.getPoint(self.el, self.$viewport, event);
self.tempOrigin = svgService.createPoint(self.el, self.$viewport, event);
self.drawing = true;
self.tempRect = angular.extend({}, self.tempOrigin, {
width: 0,
height: 0,
timestamp: new Date().getTime(),
_id: _.uniqueId() + new Date().getTime(),
_id: _.uniqueId('antn_'), //+ new Date().getTime(), // use human-readable id for debugging --STI
rotation: svgPanZoomFactory.getRotation()
}, self.data);
$rootScope.$broadcast('svgDrawing:add', self.tempRect, self.data);
Expand All @@ -69,29 +52,46 @@
}
};

var draw = function (event) {
var newPoint = svgService.getPoint(self.el, self.$viewport, event);
self.tempRect.x = (self.tempOrigin.x < newPoint.x) ? self.tempOrigin.x : newPoint.x;
self.tempRect.y = (self.tempOrigin.y < newPoint.y) ? self.tempOrigin.y : newPoint.y;
self.tempRect.width = Math.abs(newPoint.x - self.tempOrigin.x);
self.tempRect.height = Math.abs(newPoint.y - self.tempOrigin.y);
$rootScope.$broadcast('svgDrawing:update', self.tempRect, self.data);
};

var finishDraw = function (event) {
var newPoint = svgService.getPoint(self.el, self.$viewport, event);
var newPoint = svgService.createPoint(self.el, self.$viewport, event);
if (self.tempOrigin && !(newPoint.x === self.tempOrigin.x && newPoint.y === self.tempOrigin.y)) {
$rootScope.$broadcast('svgDrawing:finish', angular.extend({}, self.tempRect), self.data);
self.drawing = false;
self.tempRect = null;
self.tempOrigin = null;
} else {
} else { // zero-dimension rect created
// TODO: Add a marker here.
return;
}
self.$viewport.off('mousemove');
};

var bindMouseEvents = function (data) {
if (angular.isDefined(data)) {
self.data = data;
} else {
self.data = null;
}

self.$viewport.on('mousedown', startDraw);
self.$viewport.on('mouseup', finishDraw);

self.eventsBound = true;
};

var unBindMouseEvents = function () {
self.data = null;

self.$viewport.off('mousedown');
self.$viewport.off('mouseup');

self.eventsBound = false;
};

var hasMouseEvents = function () {
return self.eventsBound;
};

return {
init: init,
startDraw: startDraw,
Expand Down
Loading

0 comments on commit 6bee11f

Please sign in to comment.