-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(listen, library): Fixed various API compat bugs
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
Showing
8 changed files
with
998 additions
and
1,041 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.