Skip to content

Commit

Permalink
fix(visualization) Fixes #186, out of date paging API
Browse files Browse the repository at this point in the history
The server introduced support for disablng paging and deprecated support for massive paging_item sizes.

This update adds new functionality to the QueryBuilder, appropriate unit tests, and also updates the getRecordingsForVisulisation in the AudioRecording service to the new API.
  • Loading branch information
atruskie committed Mar 10, 2015
1 parent d3eccee commit 0034def
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/components/services/audioRecording.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ angular
resource.getRecordingsForVisulisation = function (siteIds) {
var query = QueryBuilder.create(function (q) {

// HACK: ask for a ridiculous amount of items since
// paging cap automatically is enabled at 500 items.
// TODO: add an option to disable paging
// track issue here: https://github.com/QutBioacoustics/baw-server/issues/160
// WARNING: potentially very large queries because paging is disabled
return q
.in("siteId", siteIds)
.project({include: ["id", "siteId", "durationSeconds", "recordedDate"]})
.page({items: 100000, page: 1});
.page.disable();
});

return $http.post(filterUrl, query.toJSON());
Expand Down
13 changes: 12 additions & 1 deletion src/components/services/queryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ angular
};

function Query(currentFieldKey, rootQuery) {
var currentField = currentFieldKey;
var currentField = currentFieldKey,
self = this;
this.root = rootQuery;

this.filter = {};
Expand Down Expand Up @@ -154,10 +155,20 @@ angular

this.root.paging.items = pageArguments.items;
this.root.paging.page = pageArguments.page;
delete this.root.paging.disablePaging;

return this;
};

this.page.disable = function() {
delete self.root.paging.items;
delete self.root.paging.page;

self.root.paging.disablePaging = true;

return self;
};

this.project = function projection(projectionArguments) {
if (!angular.isObject(projectionArguments)) {
throw new Error("The project function expects an object");
Expand Down
53 changes: 53 additions & 0 deletions src/components/services/queryBuilder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,43 @@ describe("The QueryBuilder", function () {
}).toThrowError(Error, "paging.items must be an integer");
});

it("should allow disablePaging to be set", function() {
var expected = {
paging: {
disablePaging: true
}
};

var actual = q.page.disable();
expect(actual.toJSON(spaces)).toBe(j(expected));
});


it("should ensure that setting disablePaging will overwrite previous calls to set paging (and vice versa)", function() {
var expected = {
paging: {
disablePaging: true
}
};

var actual = q.page({}).page.disable();
expect(actual.toJSON(spaces)).toBe(j(expected));
});

it("should should allow re-enabling of paging", function() {
var expected = {
paging: {
items: 10,
page: 0
}
};

// this essentially represents paging with the default options
actual = q.page.disable().page({});
expect(actual.toJSON(spaces)).toBe(j(expected));
});


it("should always update root with paging...even if on a subquery", function () {
var expected = {
filter: {
Expand All @@ -347,6 +384,22 @@ describe("The QueryBuilder", function () {
expect(actual.toJSON(spaces)).toBe(j(expected));
});

it("should always update root with paging...even if on a subquery (for disablePaging too)", function () {
var expected = {
filter: {
fieldA: {
eq: 30
}
},
paging: {
disablePaging: true
}
};

var actual = q.eq("fieldA", 30).page.disable().end();
expect(actual.toJSON(spaces)).toBe(j(expected));
});

it("should allow sorting to be set", function() {
var expected = {
sorting: {
Expand Down

0 comments on commit 0034def

Please sign in to comment.