Skip to content

Commit

Permalink
Fixed bug with previous checkin. Annotation drawing now stable.
Browse files Browse the repository at this point in the history
- Minor change to listen template
- Fixed bug in drawabox where new boxes were not created with top/left statistics (drawn correctly, but the numbers were not included in the newBoc callback)
- Bug fixes for create/update/deleting annotations
- Added support for null dates in Annotation (rather than setting null's to Date.Min)
- No longer send an id field in the export object of an annotation if it is not defined
- Changed the preficate that determine the value for the isNew function to something more reasonable.
  • Loading branch information
atruskie committed Nov 19, 2013
1 parent c5572df commit e615c20
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/app/listen/listen.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ <h3>Annotations</h3>
<thead>
<tr>
<th>Selected</th>
<th>Unsaved</th>
<th>Saved</th>
<th>Jump to</th>
<th>Annotation ID</th>
<th>Audio Recording</th>
Expand All @@ -157,7 +157,7 @@ <h3>Annotations</h3>
<td>
<!--<input type="radio" ng-checked="ae.selected" ng-model="ae.selected" name="selectionRadioGroup" >-->
<input type="radio" baw-checked="ae.selected" name="selectionRadioGroup">
{{ae.selected && '' || ''}}
{{ae.selected && '' || ''}}
</td>
<td>
{{ae.isDirty && '✓' || '✗'}}
Expand Down
6 changes: 2 additions & 4 deletions src/common/jquery.drawabox.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@
// raise moved event
dataMouseUp.options.boxResized($box);
};
var dataIdKey = 'data-id';



var dataIdKey = 'data-id';

function createBox($parent, contextData, width, height, top, left, uniqueId, silent) {

Expand Down Expand Up @@ -246,7 +244,7 @@

// no box created yet. Only create box once dragged for 10 pixels
if (distance > 10) {
var $newBox = createBox($thisMouseMove, dataMouseMove, xdiff, ydiff);
var $newBox = createBox($thisMouseMove, dataMouseMove, xdiff, ydiff, startClickPos.y, startClickPos.x);
setBoxBoxPosition($newBox, startClickPos, currentPos);
}
} else {
Expand Down
43 changes: 24 additions & 19 deletions src/components/directives/bawAnnotationViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ bawds.directive('bawAnnotationViewer', [ 'conf.paths', 'AudioEvent', function (p
annotation.startTimeSeconds = scope.model.converters.pixelsToSeconds(box.left || 0.0);
annotation.endTimeSeconds = annotation.startTimeSeconds + scope.model.converters.pixelsToSeconds(box.width || 0.0);
annotation.lowFrequencyHertz = annotation.highFrequencyHertz - scope.model.converters.pixelsToHertz(box.height || 0.0);

if (!annotation.$intermediateEvent) {
// funny bug. resized does not trigger a model updated... although moved does.
// so force an update for resized events
annotation.forceDodgyUpdate = (annotation.forceDodgyUpdate || 0) + 1;
}
}

// delete
Expand Down Expand Up @@ -280,25 +286,19 @@ bawds.directive('bawAnnotationViewer', [ 'conf.paths', 'AudioEvent', function (p
};
var defaultQueueItem = {
create: {
current: {

}
current: null
},
update: {
current: {

},
pending: {}
current: null,
pending: null
},
remove: {
current: {

}
current: null
},
count: function () {
return (this.create.current && 1 || 0) +
(this.update.current && 1 || 0) +
(this.pending.current && 1 || 0) +
(this.update.pending && 1 || 0) +
(this.remove.current && 1 || 0);
},
executeNext: function () {
Expand Down Expand Up @@ -342,7 +342,11 @@ bawds.directive('bawAnnotationViewer', [ 'conf.paths', 'AudioEvent', function (p
if (annotation.isNew()) {
if (currentQueue.create.current != null) {
// convert to update instead
// no-op, catch all update will pick it up
// enqueue update
console.assert(currentQueue.update.current == null);
currentQueue.update.current = makeExecute("update", serverAction.update);
return;

}
else {
// enqueue create
Expand Down Expand Up @@ -394,7 +398,7 @@ bawds.directive('bawAnnotationViewer', [ 'conf.paths', 'AudioEvent', function (p


// action complete - clear it
queuedAnnotation[action] = null;
queuedAnnotation[action].current = null;

// should reset dirty flag for create/update
if (action === serverAction.create || action === serverAction.update) {
Expand All @@ -414,7 +418,7 @@ bawds.directive('bawAnnotationViewer', [ 'conf.paths', 'AudioEvent', function (p
}
else {
// should clean up resources for delete
console.assert(action === serverAction.deleteAction, "The remaining case must be a delete server action");
console.assert(action === serverAction.remove, "The remaining case must be a delete server action");
console.assert(count == 1, "There should be no more actions enqueued after a delete");

// find the correct Annotation and kill it!
Expand Down Expand Up @@ -454,8 +458,7 @@ bawds.directive('bawAnnotationViewer', [ 'conf.paths', 'AudioEvent', function (p
*/
function modelUpdated(changedAnnotation, oldAnnotation, scope) {
if (!changedAnnotation) {
console.debug("AnnotationEditor:modelUpdated: Falsy annotation, skip update.",
changedAnnotation.__localId__);
console.debug("AnnotationEditor:modelUpdated: Falsy annotation, skip update.");
return;
}

Expand Down Expand Up @@ -516,11 +519,13 @@ bawds.directive('bawAnnotationViewer', [ 'conf.paths', 'AudioEvent', function (p
element.annotationViewerIndex = index;

// register for reverse binding
watchSingleAnnotation(scope, scope.model.audioEvents, index,
scope.$drawaboxElement);
watchSingleAnnotation(scope, scope.model.audioEvents, index);
}
else {
throw "Array and elements on drawabox out of sync, shit fucked up";
// reset the index - this should only happen after a delete
console.debug("AnnotationEditor:modelCollectionUpdated: resetting element index", element.annotationViewerIndex, index);
element.annotationViewerIndex = index;
//throw "Array and elements on drawabox out of sync, shit fucked up";
}
});
}
Expand Down
17 changes: 12 additions & 5 deletions src/components/models/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ baw.Annotation = (function () {

pt.isNew = function() {

return this.__localId__ !== this.id;
return this.id === undefined || this.id === null;
};

pt.mergeResource = function mergeResource(resource, ignoreClientFields) {
this.id = resource.id;
this.audioRecordingId = resource.audioRecordingId;
this.createdAt = new Date(resource.createdAt);
this.createdAt = resource.createdAt ? new Date(resource.createdAt) : null;
this.creatorId = resource.creatorId;
this.updatedAt = new Date(resource.updatedAt);
this.updatedAt = resource.updatedAt ? new Date(resource.updatedAt) : null;
this.updaterId = resource.updaterId;
this.deletedAt = new Date(resource.deletedAt);
this.deletedAt = resource.deletedAt ? new Date(resource.deletedAt) : null;
this.deleterId = resource.deleterId;

if (!ignoreClientFields) {
Expand All @@ -128,7 +128,7 @@ baw.Annotation = (function () {
};

pt.exportObj = function exportObj() {
return {
var result = {
// TODO:
taggings: [],
audioRecordingId: this.audioRecordingId,
Expand All @@ -141,6 +141,13 @@ baw.Annotation = (function () {
updatedAt: this.updatedAt,
id: this.id
};

// don't send a null id back
if(!this.isNew()) {
result.id = this.id;
}

return result;
};

pt.toJSON = function toJSON() {
Expand Down

0 comments on commit e615c20

Please sign in to comment.