To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 1eb68f0b authored by Alexander Dietmüller's avatar Alexander Dietmüller
Browse files

Frontend: Add method to request all entries

parent 3e1bcd3c
......@@ -7,7 +7,7 @@ function isSelectedOrReserved(course) {
}
export default class CourseList {
static oninit() { courses.get(); }
static oninit() { courses.getAll(); }
static view() {
return m('table', [
......
......@@ -74,19 +74,37 @@ class Resource {
return [...currentItems, ...this._items_new];
}
get() {
get(page = 1) {
// Build query with pagination
const query = Object.assign({}, this.query, { page });
return request({
resource: this.name,
query: this.query,
query,
}).then((data) => {
// Fill own list
this._items = {};
data._items.forEach((item) => { this._items[item._id] = item; });
// Pass on 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) {
return request({
resource: this.name,
......
Markdown is supported
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