Commit 1eb68f0b authored by adietmue's avatar adietmue
Browse files

Frontend: Add method to request all entries

parent 3e1bcd3c
...@@ -7,7 +7,7 @@ function isSelectedOrReserved(course) { ...@@ -7,7 +7,7 @@ function isSelectedOrReserved(course) {
} }
export default class CourseList { export default class CourseList {
static oninit() { courses.get(); } static oninit() { courses.getAll(); }
static view() { static view() {
return m('table', [ return m('table', [
......
...@@ -74,19 +74,37 @@ class Resource { ...@@ -74,19 +74,37 @@ class Resource {
return [...currentItems, ...this._items_new]; return [...currentItems, ...this._items_new];
} }
get() { get(page = 1) {
// Build query with pagination
const query = Object.assign({}, this.query, { page });
return request({ return request({
resource: this.name, resource: this.name,
query: this.query, query,
}).then((data) => { }).then((data) => {
// Fill own list // Fill own list
this._items = {};
data._items.forEach((item) => { this._items[item._id] = item; }); data._items.forEach((item) => { this._items[item._id] = item; });
// Pass on data // Pass on data
return data; return data;
}); });
} }
getAll() {
this._items = {};
// Get first page to know number of results, then request others
return this.get(1).then((response) => {
const userCount = response._meta.total;
const pageSize = response._meta.max_results;
const pages = Math.ceil(userCount / pageSize);
for (let p = 2; p <= pages; p += 1) {
this.get(p);
}
return response;
});
}
getItem(id) { getItem(id) {
return request({ return request({
resource: this.name, resource: this.name,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment