Skip to content

Commit

Permalink
Moved functions into library controller
Browse files Browse the repository at this point in the history
Fixed loading gif showing in front of spectrograms on annotation library
page
Changed dev api root back to staging.
  • Loading branch information
Mark Cottman-Fields committed May 3, 2014
1 parent f44b6aa commit 184a188
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 121 deletions.
2 changes: 1 addition & 1 deletion build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
},
configFile: appConfigFile,
development: {
apiRoot: "http://localhost:3000",
apiRoot: "http://staging.ecosounds.org",
siteRoot: "http://localhost:8080",
siteDir: "/"
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/annotationLibrary/_annotationLibrary.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ $loadGifPath: $IMAGE_ASSET_PATH + 'assets/img/load.gif';
padding: 0 !important;
margin: 0;
border: 1px dotted #8c8c8c;
background: url(#{$loadGifPath}) center center no-repeat;

& img {

Expand All @@ -83,7 +84,6 @@ $loadGifPath: $IMAGE_ASSET_PATH + 'assets/img/load.gif';
width: 100%;
height: 100%;
z-index: 1;
background: url(#{$loadGifPath}) center center no-repeat;
}

& .library-spectrogram-bounds {
Expand Down
124 changes: 115 additions & 9 deletions src/app/annotationLibrary/annotationLibrary.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,114 @@
var baw = window.baw = window.baw || {};

baw.annotationLibrary = {};
baw.annotationLibrary.addCalculatedProperties = function addCalculatedProperties(audioEvent, $url) {

audioEvent.annotationDuration = audioEvent.endTimeSeconds - audioEvent.startTimeSeconds;
audioEvent.annotationDurationRounded = Math.round10(audioEvent.endTimeSeconds - audioEvent.startTimeSeconds, -3);
audioEvent.annotationFrequencyRange = audioEvent.highFrequencyHertz - audioEvent.lowFrequencyHertz;
audioEvent.calcOffsetStart = Math.floor(audioEvent.startTimeSeconds / 30) * 30;
audioEvent.calcOffsetEnd = (Math.floor(audioEvent.startTimeSeconds / 30) * 30) + 30;

audioEvent.urls = {
site: '/projects/' + audioEvent.projects[0].id +
'/sites/' + audioEvent.siteId,
user: '/user_accounts/' + audioEvent.ownerId,
tagSearch: '/library?' + $url.toKeyValue({tagsPartial: audioEvent.priorityTag.text}),
similar: '/library?' + $url.toKeyValue(
{
annotationDuration: Math.round10(audioEvent.annotationDuration, -3),
freqMin: Math.round(audioEvent.lowFrequencyHertz),
freqMax: Math.round(audioEvent.highFrequencyHertz)
}),
singleItem: '/library/' + audioEvent.audioRecordingId +
'/audio_events/' + audioEvent.audioEventId,
listen: '/listen/' + audioEvent.audioRecordingId +
'?start=' + audioEvent.calcOffsetStart +
'&end=' + audioEvent.calcOffsetEnd,
listenWithoutPadding: '/listen/' + audioEvent.audioRecordingId +
'?start=' + audioEvent.startTimeSeconds +
'&end=' + audioEvent.endTimeSeconds
};

return audioEvent;
};

baw.annotationLibrary.getBoundSettings = function getBoundSettings(audioEvent, constants, unitConverter, Media) {
var mediaItemParameters = {
recordingId: audioEvent.audioRecordingId,
start_offset: Math.floor(audioEvent.startTimeSeconds - constants.annotationLibrary.paddingSeconds),
end_offset: Math.ceil(audioEvent.endTimeSeconds + constants.annotationLibrary.paddingSeconds),
format: "json"
};

audioEvent.media = Media.get(
mediaItemParameters,
function mediaGetSuccess(mediaValue, responseHeaders) {

Media.formatPaths(mediaValue);
mediaValue = new baw.Media(mediaValue);

// create properties that depend on Media
audioEvent.converters = unitConverter.getConversions({
sampleRate: audioEvent.media.sampleRate,
spectrogramWindowSize: audioEvent.media.availableImageFormats.png.window,
endOffset: audioEvent.media.endOffset,
startOffset: audioEvent.media.startOffset,
imageElement: null
});

audioEvent.bounds = {
top: audioEvent.converters.toTop(audioEvent.highFrequencyHertz),
left: audioEvent.converters.toLeft(audioEvent.startTimeSeconds),
width: audioEvent.converters.toWidth(audioEvent.endTimeSeconds, audioEvent.startTimeSeconds),
height: audioEvent.converters.toHeight(audioEvent.highFrequencyHertz, audioEvent.lowFrequencyHertz)
};

// set common/sensible defaults, but hide the elements
audioEvent.gridConfig = {
y: {
showGrid: true,
showScale: true,
max: audioEvent.converters.conversions.nyquistFrequency,
min: 0,
step: 1000,
height: audioEvent.converters.conversions.enforcedImageHeight,
labelFormatter: function (value, index, min, max) {
return (value / 1000).toFixed(1);
},
title: "Frequency (KHz)"
},
x: {
showGrid: true,
showScale: true,
max: audioEvent.media.endOffset,
min: audioEvent.media.startOffset,
step: 1,
width: audioEvent.converters.conversions.enforcedImageWidth,
labelFormatter: function (value, index, min, max) {
// show 'absolute' time.... i.e. seconds of the minute
var offset = (value % 60);

return (offset).toFixed(0);
},
title: "Time offset (seconds)"
}
};


}, function mediaGetFailure(httpResponse) {
console.error("Failed to get Media.", httpResponse);
}
);

return audioEvent;
};

angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])
.controller('AnnotationLibraryCtrl', ['$scope', '$location', '$resource', '$routeParams', '$url',
'conf.paths', 'conf.constants', 'bawApp.unitConverter',
'AudioEvent', 'Tag',
function ($scope, $location, $resource, $routeParams, $url, paths, constants, unitConverter, AudioEvent, Tag) {
'AudioEvent', 'Tag', 'Media',
function ($scope, $location, $resource, $routeParams, $url, paths, constants, unitConverter, AudioEvent, Tag, Media) {

$scope.status = 'idle';

Expand Down Expand Up @@ -140,8 +246,8 @@ angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])
angular.forEach(value.entries, function (audioEventValue, key) {
var annotation = angular.extend({}, audioEventValue);
annotation.priorityTag = Tag.selectSinglePriorityTag(annotation.tags);
AudioEvent.addCalculatedProperties(annotation);
AudioEvent.getBoundSettings(annotation);
baw.annotationLibrary.addCalculatedProperties(annotation, $url);
baw.annotationLibrary.getBoundSettings(annotation, constants, unitConverter, Media);
this.push(annotation);
}, $scope.annotations);

Expand All @@ -153,9 +259,9 @@ angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])
}])
.controller('AnnotationItemCtrl',
['$scope', '$location', '$resource', '$routeParams', '$url',
'conf.paths', 'conf.constants',
'AudioEvent', 'Tag',
function ($scope, $location, $resource, $routeParams, $url, paths, constants, AudioEvent, Tag) {
'conf.paths', 'conf.constants', 'bawApp.unitConverter',
'AudioEvent', 'Tag', 'Media',
function ($scope, $location, $resource, $routeParams, $url, paths, constants, unitConverter, AudioEvent, Tag, Media) {

var parameters = {
audioEventId: $routeParams.audioEventId,
Expand All @@ -167,8 +273,8 @@ angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])

var annotation = angular.extend({}, audioEventValue);
annotation.priorityTag = Tag.selectSinglePriorityTag(annotation.tags);
AudioEvent.addCalculatedProperties(annotation);
AudioEvent.getBoundSettings(annotation);
baw.annotationLibrary.addCalculatedProperties(annotation, $url);
baw.annotationLibrary.getBoundSettings(annotation, constants, unitConverter, Media);

$scope.annotation = annotation;

Expand Down
120 changes: 10 additions & 110 deletions src/components/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
{projectId: "@projectId", siteId: "@siteId", recordingId: '@recordingId'});
}]);

bawss.factory('AudioEvent', [ '$resource', '$url', 'conf.paths', 'conf.constants', 'bawApp.unitConverter', 'Media',
function ($resource, $url, paths, constants, unitConverter, Media) {
bawss.factory('AudioEvent', [ '$resource', 'conf.paths',
function ($resource, paths) {
var baseCsvUri = paths.api.routes.audioEvent.csvAbsolute;

// TODO: move this to paths conf object
Expand Down Expand Up @@ -92,114 +92,12 @@
);
resource.csvLink = makeCsvLink;

resource.addCalculatedProperties = function addCalculatedProperties(audioEvent){

audioEvent.annotationDuration = audioEvent.endTimeSeconds - audioEvent.startTimeSeconds;
audioEvent.annotationDurationRounded = Math.round10(audioEvent.endTimeSeconds - audioEvent.startTimeSeconds, -3);
audioEvent.annotationFrequencyRange = audioEvent.highFrequencyHertz - audioEvent.lowFrequencyHertz;
audioEvent.calcOffsetStart = Math.floor(audioEvent.startTimeSeconds / 30) * 30;
audioEvent.calcOffsetEnd = (Math.floor(audioEvent.startTimeSeconds / 30) * 30) + 30;

audioEvent.urls = {
site: '/projects/' + audioEvent.projects[0].id +
'/sites/' + audioEvent.siteId,
user: '/user_accounts/' + audioEvent.ownerId,
tagSearch: '/library?' + $url.toKeyValue({tagsPartial: audioEvent.priorityTag.text}),
similar: '/library?' + $url.toKeyValue(
{
annotationDuration: Math.round10(audioEvent.annotationDuration, -3),
freqMin: Math.round(audioEvent.lowFrequencyHertz),
freqMax: Math.round(audioEvent.highFrequencyHertz)
}),
singleItem: '/library/' + audioEvent.audioRecordingId +
'/audio_events/' + audioEvent.audioEventId,
listen: '/listen/' + audioEvent.audioRecordingId +
'?start=' + audioEvent.calcOffsetStart +
'&end=' + audioEvent.calcOffsetEnd,
listenWithoutPadding: '/listen/' + audioEvent.audioRecordingId +
'?start=' + audioEvent.startTimeSeconds +
'&end=' + audioEvent.endTimeSeconds
};

return audioEvent;
};

resource.getBoundSettings = function getBoundSettings(audioEvent){
var mediaItemParameters = {
recordingId: audioEvent.audioRecordingId,
start_offset: Math.floor(audioEvent.startTimeSeconds - constants.annotationLibrary.paddingSeconds),
end_offset: Math.ceil(audioEvent.endTimeSeconds + constants.annotationLibrary.paddingSeconds),
format: "json"
};

audioEvent.media = Media.get(
mediaItemParameters,
function mediaGetSuccess(mediaValue, responseHeaders) {

Media.formatPaths(mediaValue);
mediaValue = new baw.Media(mediaValue);

// create properties that depend on Media
audioEvent.converters = unitConverter.getConversions({
sampleRate: audioEvent.media.sampleRate,
spectrogramWindowSize: audioEvent.media.availableImageFormats.png.window,
endOffset: audioEvent.media.endOffset,
startOffset: audioEvent.media.startOffset,
imageElement: null
});

audioEvent.bounds = {
top: audioEvent.converters.toTop(audioEvent.highFrequencyHertz),
left: audioEvent.converters.toLeft(audioEvent.startTimeSeconds),
width: audioEvent.converters.toWidth(audioEvent.endTimeSeconds, audioEvent.startTimeSeconds),
height: audioEvent.converters.toHeight(audioEvent.highFrequencyHertz, audioEvent.lowFrequencyHertz)
};

// set common/sensible defaults, but hide the elements
audioEvent.gridConfig = {
y: {
showGrid: true,
showScale: true,
max: audioEvent.converters.conversions.nyquistFrequency,
min: 0,
step: 1000,
height: audioEvent.converters.conversions.enforcedImageHeight,
labelFormatter: function (value, index, min, max) {
return (value / 1000).toFixed(1);
},
title: "Frequency (KHz)"
},
x: {
showGrid: true,
showScale: true,
max: audioEvent.media.endOffset,
min: audioEvent.media.startOffset,
step: 1,
width: audioEvent.converters.conversions.enforcedImageWidth,
labelFormatter: function (value, index, min, max) {
// show 'absolute' time.... i.e. seconds of the minute
var offset = (value % 60);

return (offset).toFixed(0);
},
title: "Time offset (seconds)"
}
};


}, function mediaGetFailure(httpResponse) {
console.error("Failed to get Media.", httpResponse);
}
);

return audioEvent;
};

return resource;
}]);


bawss.factory('Taggings', [ '$resource', 'conf.paths', function ($resource, paths) {
bawss.factory('Taggings', [ '$resource', 'conf.paths',
function ($resource, paths) {
var resource = resourcePut($resource, uriConvert(paths.api.routes.tagging.showAbsolute),
{
recordingId: '@recordingId',
Expand Down Expand Up @@ -233,7 +131,8 @@
*
* This service memoises requests for tags
*/
bawss.factory('Tag', [ '$resource', 'conf.paths', '$q', function ($resource, paths, $q) {
bawss.factory('Tag', [ '$resource', 'conf.paths',
function ($resource, paths) {
var resource = $resource(uriConvert(paths.api.routes.tag.showAbsolute), {tagId: '@tagId'}, {});

var tags = {};
Expand Down Expand Up @@ -330,8 +229,8 @@
return resource;
}]);

bawss.factory('Media', [ '$resource', '$url', 'conf.paths',
function ($resource, $url, paths) {
bawss.factory('Media', [ '$resource', 'conf.paths',
function ($resource, paths) {

// create resource for rest requests to media api
var mediaResource = $resource(uriConvert(paths.api.routes.media.showAbsolute),
Expand Down Expand Up @@ -373,7 +272,8 @@
return mediaResource;
}]);

bawss.factory('BirdWalkService', ['$rootScope', '$location', '$route', '$routeParams', '$http', function ($rootScope, $location, $route, $routeParams, $http) {
bawss.factory('BirdWalkService', ['$rootScope', '$location', '$route', '$routeParams', '$http',
function ($rootScope, $location, $route, $routeParams, $http) {

var birdWalkService = {};

Expand Down

0 comments on commit 184a188

Please sign in to comment.