Skip to content

Commit 98159fd

Browse files
committed
adding isPaginated and removePagination
1 parent 049f858 commit 98159fd

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

can-query-logic-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,19 @@ QUnit.test("filterMembers with reverse sort", function(){
216216
QUnit.deepEqual(sortedMembers,
217217
[{id: 2, name:"z"}, {id: 4, name:"s"}, {id: 3, name:"f"}, {id: 1, name:"a"}]);
218218
});
219+
220+
QUnit.test("isPaginated, removePagination", function(assert){
221+
assert.equal( algebra.isPaginated({}), false, "universe is not paginated");
222+
assert.equal( algebra.isPaginated({filter: {foo: "bar"}}), false, "filter is not paginated");
223+
assert.equal( algebra.isPaginated({sort: "bar"}), false, "sort is not paginated");
224+
225+
assert.equal( algebra.isPaginated({page: {start: 1, end: 2}}), true, "page is paginated");
226+
227+
228+
assert.deepEqual( algebra.removePagination({}), {}, "removePagination universe");
229+
assert.deepEqual( algebra.removePagination({filter: {foo: "bar"}}), {filter: {foo: "bar"}}, "removePagination filter");
230+
assert.deepEqual( algebra.removePagination({sort: "bar"}), {sort: "bar"}, "removePagination sort");
231+
232+
assert.deepEqual( algebra.removePagination({page: {start: 1, end: 2}}), {}, "removePagination page");
233+
234+
});

can-query-logic.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,17 @@ canReflect.assign(QueryLogic.prototype,{
148148
copy.splice(index, 0, item);
149149

150150
return copy;
151-
}
151+
},
152+
153+
isPaginated: function(query) {
154+
var basicQuery = this.hydrate(query);
155+
return !set.isEqual(basicQuery.page, set.UNIVERSAL);
156+
},
157+
removePagination: function(query) {
158+
var basicQuery = this.hydrate(query);
159+
basicQuery.removePagination();
160+
return this.serialize( basicQuery );
161+
},
152162

153163
});
154164

src/types/basic-query.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ canReflect.assignMap(BasicQuery.prototype, {
122122
isMember: function(props) {
123123
// Use the AND type for it's isMember method
124124
return this.filter.isMember(props);
125+
},
126+
removePagination: function(){
127+
this.page = new RecordRange();
125128
}
126129
});
127130

@@ -378,4 +381,4 @@ set.defineComparison(BasicQuery, BasicQuery, {
378381
});
379382

380383

381-
module.exports = BasicQuery;
384+
module.exports = BasicQuery;

0 commit comments

Comments
 (0)