Skip to content

Commit

Permalink
Small changes to token parsing and audio event saving
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Nov 6, 2013
1 parent a8af950 commit 596b0d5
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 62 deletions.
7 changes: 3 additions & 4 deletions src/app/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module('bawApp.listen', [])
* @param paths
* @param constants
*/
function ListenCtrl($scope, $resource, $routeParams, $route, paths, constants, $url, AudioRecording, Media, AudioEvent, Tag) {
function ListenCtrl($scope, $resource, $routeParams, $route, paths, constants, $url, AudioRecording, Media, AudioEvent, Tag) {
var CHUNK_DURATION_SECONDS = constants.listen.chunkDurationSeconds;

function getMediaParameters(format) {
Expand All @@ -45,7 +45,7 @@ angular.module('bawApp.listen', [])
else {

// the core resource used in this controller
var recordingId = $scope.recordingId = baw.parseInt($routeParams.recordingId);
var recordingId = $scope.recordingId = baw.parseInt($routeParams.recordingId);

// parse the start and end offsets
$routeParams.start = parseFloat($routeParams.start) || 0.0;
Expand All @@ -62,7 +62,6 @@ angular.module('bawApp.listen', [])
}



// set up some dummy objects for use later
$scope.model = {
audioElement: {}
Expand Down Expand Up @@ -349,7 +348,7 @@ angular.module('bawApp.listen', [])
throw "The audioRecordingId should have been set way earlier!";
}

AudioEvent.save({audioEventId: null}, a,
AudioEvent.save({audioEventId: null, recordingId: a.audioRecordingId}, a.create(),
function createAnnotationSuccess(response, getResponseHeaders) {
console.log("Annotation creation successful");

Expand Down
129 changes: 74 additions & 55 deletions src/components/models/annotation.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,89 @@
var baw = window.baw = window.baw || {};
var baw = window.baw = window.baw || {};

/**
*
* @param localIdOrResource
* @param {*=} audioRecordingId
* @constructor
*/
baw.Annotation = function Annotation(localIdOrResource, audioRecordingId) {
/**
*
* @param localIdOrResource
* @param {*=} audioRecordingId
* @constructor
*/
baw.Annotation = function Annotation(localIdOrResource, audioRecordingId) {

var localId = typeof(localIdOrResource) === "number" ? localIdOrResource : undefined;
var resource;
if (localIdOrResource instanceof Object && localIdOrResource.constructor.name == "Resource") {
resource = localIdOrResource;
}
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");
}
if (!(this instanceof Annotation)) {
throw new Error("Constructor called as a function");
}

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

if (localId) {
var now = new Date();
if (localId) {
var now = new Date();

this.audioRecordingId = audioRecordingId;
this.audioRecordingId = audioRecordingId;

this.createdAt = now;
this.updatedAt = now;
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;
this.endTimeSeconds = 0.0;
this.highFrequencyHertz = 0.0;
this.isReference = false;
this.lowFrequencyHertz = 0.0;
this.startTimeSeconds = 0.0;

}
}

// ensure JSON values taken from a resource have nicely formatted values
if (resource) {
angular.extend(this, resource);
// ensure JSON values taken from a resource have nicely formatted values
if (resource) {
angular.extend(this, resource);

this.createdAt = new Date(this.createdAt);
this.updatedAt = new Date(this.updatedAt);
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);
this.endTimeSeconds = parseFloat(this.endTimeSeconds);
this.highFrequencyHertz = parseFloat(this.highFrequencyHertz);
this.lowFrequencyHertz = parseFloat(this.lowFrequencyHertz);
this.startTimeSeconds = parseFloat(this.startTimeSeconds);

this.audioEventTags = {};
angular.forEach(this.audioEventTags, function(value, key) {
this.audioEventTags[key] = new baw.AudioEventTag(value);
}, this);
}
this.audioEventTags = {};
angular.forEach(this.audioEventTags, function (value, key) {
this.audioEventTags[key] = new baw.AudioEventTag(value);
}, this);
}

// strip out unnecessary values;
this.create = function() {
// NO-OP
return this;
};
//
// this.toJSON = function() {
// return {
//
// }
// };
// strip out unnecessary values;
this.create = function () {
return {
// TODO:
taggings: [],
audioRecordingId: this.audioRecordingId,
createdAt: this.createdAt,
endTimeSeconds: this.endTimeSeconds,
highFrequencyHertz: this.highFrequencyHertz,
isReference: this.isReference,
lowFrequencyHertz: this.lowFrequencyHertz,
startTimeSeconds: this.startTimeSeconds,
updatedAt: this.updatedAt
}
};

// this.toJSON = function () {
// return {
// // TODO:
// taggings: [],
// audioRecordingId: this.audioRecordingId,
// createdAt: this.createdAt,
// endTimeSeconds: this.endTimeSeconds,
// highFrequencyHertz: this.highFrequencyHertz,
// isReference: this.isReference,
// lowFrequencyHertz: this.lowFrequencyHertz,
// startTimeSeconds: this.startTimeSeconds,
// updatedAt: this.updatedAt
// }
// };
};
9 changes: 6 additions & 3 deletions src/components/services/angularjs-rails-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@
};
})
// GIANT HACK!
.factory('railsCsrfToken', ['$q', '$rootScope', function ($q, $rootScope) {
.factory('railsCsrfToken', ['$q', '$rootScope', '$location', function ($q, $rootScope, $location) {
return {
request: function(config) {
if (!$rootScope.csrfToken) {
var token = "";
while (!token) {
token = prompt("Enter temporary CSRF token:");

token = $location.search().csrf;

if (!token) {
console.error("No temporary CSRF token has been found!");
}
$rootScope.csrfToken = token;
}
Expand Down

0 comments on commit 596b0d5

Please sign in to comment.