Skip to content

Commit

Permalink
More work on viewing tags in the annotator.
Browse files Browse the repository at this point in the history
Also created started transferring objects into closures (rather than declaring controllers in the global namespace)

Closes #79

modified:   app/assets/javascripts/angular/controllers/annotation_viewer.js
	-- refactored out Annotation model, and wrapped class in proper angular module configuration

modified:   app/assets/javascripts/angular/controllers/listen.js
	-- added formatting and parsing options for select2 dropdown in annotation editor

modified:   app/assets/javascripts/angular/directives/directives.js
	-- wrote the baw inject transformer (for generalised injection of parsers and formatters to ngModel bindings)

new file:   app/assets/javascripts/angular/models/annotation.js
new file:   app/assets/javascripts/angular/models/audio_event_tag.js
	-- broke models out into their own folders and files for better code structure

modified:   app/assets/javascripts/angular/services/services.js
	-- renamed module to be more consistent with naming elsewhere

modified:   app/assets/javascripts/app.js
	-- changed controller references in routes to strings because controllers should no longer be declared in global namespaces

new file:   app/assets/javascripts/angular/controllers/controller_module.js
modified:   app/assets/javascripts/application.js
	-- since controllers are declared inside a module, and they are multifile, they need a module creation declaration that happens before all the others (else they overwrite each other)

modified:   app/assets/templates/listen.html

modified:   lib/assets/javascripts/functions.js
	-- changed the way objects are exported to global scope

modified:   vendor/assets/javascripts/angular-ui-ieshiv.js
modified:   vendor/assets/javascripts/angular-ui.js
	-- updated angular-ui to version 0.4.0
	-- WARNING MAJOR HACK. edited VENDOR FILE TO GET SOLUTION TO WORK. WILL SEND PATCH / SUBMODULE A FORK LATER
  • Loading branch information
atruskie committed Feb 15, 2013
1 parent 19421c8 commit 0bbe53e
Show file tree
Hide file tree
Showing 13 changed files with 852 additions and 629 deletions.
104 changes: 33 additions & 71 deletions app/assets/javascripts/angular/controllers/annotation_viewer.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,45 @@
"use strict";

/**
* The listen controller. Show a spectrogram, listen to audio, annotate the spectrogram.
* @param $scope
* @param $element
* @param $attrs
* @param $transclude
* @constructor
* @param Tag
*/
function AnnotationViewerCtrl($scope, $element, $attrs, $transclude, Tag) {
;
(function (undefined) {
var app = angular.module('bawApp.controllers');

$scope.getTag = function getTag(id) {
var tagObject = Tag.resolve(id);
if (tagObject) {
return tagObject.text;
}
else {
return "<unknown>";
}
};
app.controller('AnnotationViewerCtrl', ['$scope', '$element', '$attrs', '$transclude', 'Tag',
/**
* The AnnotationViewer controller
* @param $scope
* @param $element
* @param $attrs
* @param $transclude
* @constructor
* @param Tag
*/
function AnnotationViewerCtrl($scope, $element, $attrs, $transclude, Tag) {
$scope.getTag = function getTag(id) {
var tagObject = Tag.resolve(id);
if (tagObject) {
return tagObject.text;
}
else {
return "<unknown>";
}
};

$scope.positionLabel = function (audioEvent) {
return $scope.model.converters.secondsToPixels(audioEvent.startTimeSeconds);
};
$scope.positionLabel = function (audioEvent) {
return $scope.model.converters.secondsToPixels(audioEvent.startTimeSeconds);
};

$scope.positionLine = function () {
return $scope.model.converters.secondsToPixels($scope.model.audioElement.position);
};
$scope.positionLine = function () {
return $scope.model.converters.secondsToPixels($scope.model.audioElement.position);
};


// updated in directive
$scope.model.converters = $scope.model.converters || {};
// updated in directive
$scope.model.converters = $scope.model.converters || {};
}]);
})();


}

function Annotation(localIdOrResource, audioRecordingId) {

var localId = typeof(localIdOrResource) === "number" ? localIdOrResource : undefined;
var resource;
if (localIdOrResource instanceof Object && localIdOrResource.constructor.name == "Resource") {
resource = localIdOrResource;
}

if (!(this instanceof Annotation))
throw new Error("Constructor called as a function");

var now = new Date();

this.__temporaryId__ = localId || Number.Unique();
this._selected = false;
this.audioEventTags = [];

if (localId) {
this.audioRecordingId = audioRecordingId;

this.createdAt = now;
this.updatedAt = now;

this.endTimeSeconds = 0.0;
this.highFrequencyHertz = 0.0;
this.isReference = false;
this.lowFrequencyHertz = 0.0;
this.startTimeSeconds = 0.0;

}

if (resource) {
angular.extend(this, resource);

this.createdAt = new Date(this.createdAt);
this.updatedAt = new Date(this.updatedAt);

this.endTimeSeconds = parseFloat(this.endTimeSeconds);
this.highFrequencyHertz = parseFloat(this.highFrequencyHertz);
this.lowFrequencyHertz = parseFloat(this.lowFrequencyHertz);
this.startTimeSeconds = parseFloat(this.startTimeSeconds);
}
}

AnnotationViewerCtrl.$inject = ['$scope', '$element', '$attrs', '$transclude', 'Tag'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
;
(function (undefined) {
/**
* Creates the angular module for all other controllers, this has to run first!
* @type {*}
*/
var app = angular.module('bawApp.controllers', []);

})();
Loading

0 comments on commit 0bbe53e

Please sign in to comment.