Skip to content

Commit

Permalink
fix(listen, library): Fixed various API compat bugs
Browse files Browse the repository at this point in the history
Updated the site to work with the latest staging API changes.
- AudioRecording service updated (`getRecordingsForLibrary` now includes `recordedDate` in projection)
- AudioEvents service updated
  - `getAudioEventsWithinRange` method added as old style QSPs were deprecated
  - $resource's query function corrected to not expect an array
- bawAnnotationViewer changed to correctly unwrap response
- Tag service updated $resource's array expectations
- Listen:
  - Controller renamed
  - Various moment date warnings cleaned up and fixed
  - Unwrapped responses correctly for AudioRecordings and Tags
  - Changed which audio event method for downloading events
  - other API fixes
  • Loading branch information
atruskie committed Jan 14, 2016
1 parent 7552dc0 commit f8683c2
Show file tree
Hide file tree
Showing 8 changed files with 998 additions and 1,041 deletions.
2 changes: 1 addition & 1 deletion src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ angular.module("baw",
when("/listen", {templateUrl: paths.site.files.recordings.recentRecordings, controller: "RecentRecordingsCtrl", title: "Listen"}).
when("/listen/:recordingId", {templateUrl: paths.site.files.listen, controller: "ListenCtrl", title: ":recordingId", fullWidth: true}).

//when('/listen/:recordingId/start=:start/end=:end', {templateUrl: paths.site.files.listen, controller: 'ListenCtrl'}).
//when('/listen/:recordingId/start=:start/end=:end', {templateUrl: paths.site.files.listen, controller: 'ListenController'}).

when("/accounts", {templateUrl: "/assets/accounts_sign_in.html", controller: "AccountsCtrl"}).
when("/accounts/:action",
Expand Down
1,146 changes: 571 additions & 575 deletions src/app/listen/listen.js

Large diffs are not rendered by default.

472 changes: 211 additions & 261 deletions src/app/listen/listen.tpl.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/directives/bawAnnotationViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ bawds.directive("bawAnnotationViewer",
AudioEvent[method](parameters, postData,
function success(value, headers) {
console.debug("AnnotationEditor:modelUpdatesServer: " + action + " success", value);
serverUpdatesModel(scope, action, value, annotation);
serverUpdatesModel(scope, action, value.data, annotation);
},
function error(response) {
console.error("AnnotationEditor:modelUpdatesServer: " + action + " FAILURE", response);
Expand Down
2 changes: 2 additions & 0 deletions src/components/models/AudioRecording.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ angular
class AudioRecording extends AudioRecordingCore {
constructor(resource) {
super(resource);

this.recordedEndDate = new Date(this.recordedEndDateMilliSeconds);
}
}

Expand Down
208 changes: 108 additions & 100 deletions src/components/services/audioEvent.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,112 @@
angular
.module("bawApp.services.audioEvent", [])
.factory(
"AudioEvent",
[
"$resource", "$http", "bawResource", "$url", "conf.paths", "QueryBuilder",
"baw.models.AudioEvent",
function ($resource, $http, bawResource, $url, paths, QueryBuilder, AudioEventModel) {
var baseCsvUri = paths.api.routes.audioEvent.csvAbsolute;

var csvOptions = {
format: "csv", // "csv", "xml", "json"
projectId: null,
siteId: null,
recordingId: null,
startOffset: null,
endOffset: null

};
// TODO: move this to paths conf object

function makeCsvLink(options) {
var query = angular.extend(csvOptions, options);
return $url.formatUri(baseCsvUri, query);
}

var resource = bawResource(
paths.api.routes.audioEvent.showAbsolute,
{recordingId: "@recordingId", audioEventId: "@audioEventId"},
{
query: {
method: "GET",
isArray: true
}
});

resource.getLibraryItems = function getLibraryItems(query) {
var url = paths.api.routes.audioEvent.filterAbsolute;

var qb = QueryBuilder.create(function (baseQuery) {
let q = baseQuery;
if (query.tagsPartial) {
q = q.contains("tags.text", query.tagsPartial);
}

if (query.reference !== undefined && query.reference !== "all") {
q = q.eq("isReference", query.reference === "reference");
}

if (query.userId) {
q = q.or(
baseQuery.eq("creatorId", query.userId),
// hack
baseQuery.lt("creatorId", 0)
// disabled as updater_id not whitelisted on server :-/
/*,
baseQuery.eq("taggings.creatorId", query.userId)
baseQuery.eq("updaterId", query.userId) */
"AudioEvent",
[
"$resource", "$http", "bawResource", "$url", "conf.paths", "QueryBuilder",
"baw.models.AudioEvent",
function ($resource, $http, bawResource, $url, paths, QueryBuilder, AudioEventModel) {
var baseCsvUri = paths.api.routes.audioEvent.csvAbsolute;

var csvOptions = {
format: "csv", // "csv", "xml", "json"
projectId: null,
siteId: null,
recordingId: null,
startOffset: null,
endOffset: null

};
// TODO: move this to paths conf object

function makeCsvLink(options) {
var query = angular.extend(csvOptions, options);
return $url.formatUri(baseCsvUri, query);
}

var resource = bawResource(
paths.api.routes.audioEvent.showAbsolute,
{recordingId: "@recordingId", audioEventId: "@audioEventId"},
{});

resource.getLibraryItems = function getLibraryItems(query) {
var url = paths.api.routes.audioEvent.filterAbsolute;

var qb = QueryBuilder.create(function (baseQuery) {
let q = baseQuery;
if (query.tagsPartial) {
q = q.contains("tags.text", query.tagsPartial);
}

if (query.reference !== undefined && query.reference !== "all") {
q = q.eq("isReference", query.reference === "reference");
}

if (query.userId) {
q = q.or(
baseQuery.eq("creatorId", query.userId),
// hack
baseQuery.lt("creatorId", 0)
// disabled as updater_id not whitelisted on server :-/
/*,
baseQuery.eq("taggings.creatorId", query.userId)
baseQuery.eq("updaterId", query.userId) */
);
}

if (query.audioRecordingId) {
q = q.eq("audioRecordingId", query.audioRecordingId);
}

q = q.range("durationSeconds", {from: query.minDuration, to: query.maxDuration});

if (query.lowFrequency) {
q = q.gteq("lowFrequencyHertz", query.lowFrequency);
}

if (query.highFrequency) {
q = q.lt("highFrequencyHertz", query.highFrequency);
}

q = q.page(query);
if (query.sortBy && query.sortByType) {
q = q.sort({orderBy: query.sortBy, direction: query.sortByType});
}

return q;
});

return $http.post(url, qb.toJSON());
};

const filterUrl = paths.api.routes.audioEvent.filterAbsolute;
resource.getAudioEventsByIds = function (audioEventIds) {
var query = QueryBuilder.create(function (q) {
return q.in("id", audioEventIds);
});

return $http
.post(filterUrl, query.toJSON())
.then(x => AudioEventModel.makeFromApi(x));
};

resource.getAudioEventsWithinRange = function (audioRecordingId, offsets) {
var query = QueryBuilder.create(function (q) {
return q.and(
q.eq("audioRecordingId", audioRecordingId),
q.gteq("startTimeSeconds", offsets[0]),
q.lt("endTimeSeconds", offsets[1])
);
}

if (query.audioRecordingId) {
q = q.eq("audioRecordingId", query.audioRecordingId);
}

q = q.range("durationSeconds", {from: query.minDuration, to: query.maxDuration});

if (query.lowFrequency) {
q = q.gteq("lowFrequencyHertz", query.lowFrequency);
}

if (query.highFrequency) {
q = q.lt("highFrequencyHertz", query.highFrequency);
}

q = q.page(query);
if (query.sortBy && query.sortByType) {
q = q.sort({orderBy: query.sortBy, direction: query.sortByType});
}

return q;
});

return $http.post(url, qb.toJSON());
};

const filterUrl = paths.api.routes.audioEvent.filterAbsolute;
resource.getAudioEventsByIds = function(audioEventIds) {
var query = QueryBuilder.create(function (q) {
return q.in("id", audioEventIds);
});

return $http
.post(filterUrl, query.toJSON())
.then( x => AudioEventModel.makeFromApi(x));
};

resource.csvLink = makeCsvLink;

return resource;
}
]
);
});

return $http.post(filterUrl, query.toJSON())
.then(x => AudioEventModel.makeFromApi(x));
};

resource.csvLink = makeCsvLink;

return resource;
}
]
);
2 changes: 1 addition & 1 deletion src/components/services/audioRecording.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ angular
resource.getRecordingsForLibrary = function (audioRecordingIds) {
var query = QueryBuilder.create(q => q
.in("id", audioRecordingIds)
.project({include: ["id", "siteId", "durationSeconds"]}));
.project({include: ["id", "siteId", "durationSeconds", "recordedDate"]}));

return $http
.post(filterUrl, query.toJSON())
Expand Down
Loading

0 comments on commit f8683c2

Please sign in to comment.