|
|
|
@ -1,20 +1,5 @@
|
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
// Sanity-check the conversion and remove this comment.
|
|
|
|
|
/*
|
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
* DS104: Avoid inline assignments
|
|
|
|
|
* DS202: Simplify dynamic range loops
|
|
|
|
|
* DS206: Consider reworking classes to avoid initClass
|
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
|
|
|
*/
|
|
|
|
|
(function () {
|
|
|
|
|
let PER_PAGE = undefined;
|
|
|
|
|
app.views.PaginatedList = class PaginatedList extends app.View {
|
|
|
|
|
static initClass() {
|
|
|
|
|
PER_PAGE = app.config.max_results;
|
|
|
|
|
}
|
|
|
|
|
app.views.PaginatedList = class PaginatedList extends app.View {
|
|
|
|
|
static PER_PAGE = app.config.max_results;
|
|
|
|
|
|
|
|
|
|
constructor(data) {
|
|
|
|
|
super();
|
|
|
|
@ -43,7 +28,10 @@
|
|
|
|
|
|
|
|
|
|
renderPage(page) {
|
|
|
|
|
return this.render(
|
|
|
|
|
this.data.slice((page - 1) * PER_PAGE, page * PER_PAGE),
|
|
|
|
|
this.data.slice(
|
|
|
|
|
(page - 1) * PaginatedList.PER_PAGE,
|
|
|
|
|
page * PaginatedList.PER_PAGE,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -52,15 +40,17 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPrevLink(page) {
|
|
|
|
|
return this.renderPageLink((page - 1) * PER_PAGE);
|
|
|
|
|
return this.renderPageLink((page - 1) * PaginatedList.PER_PAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderNextLink(page) {
|
|
|
|
|
return this.renderPageLink(this.data.length - page * PER_PAGE);
|
|
|
|
|
return this.renderPageLink(
|
|
|
|
|
this.data.length - page * PaginatedList.PER_PAGE,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalPages() {
|
|
|
|
|
return Math.ceil(this.data.length / PER_PAGE);
|
|
|
|
|
return Math.ceil(this.data.length / PaginatedList.PER_PAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paginate(link) {
|
|
|
|
@ -101,11 +91,11 @@
|
|
|
|
|
|
|
|
|
|
paginateTo(object) {
|
|
|
|
|
const index = this.data.indexOf(object);
|
|
|
|
|
if (index >= PER_PAGE) {
|
|
|
|
|
if (index >= PaginatedList.PER_PAGE) {
|
|
|
|
|
for (
|
|
|
|
|
let i = 0, end = Math.floor(index / PER_PAGE), asc = 0 <= end;
|
|
|
|
|
asc ? i < end : i > end;
|
|
|
|
|
asc ? i++ : i--
|
|
|
|
|
let i = 0, end = Math.floor(index / PaginatedList.PER_PAGE);
|
|
|
|
|
i < end;
|
|
|
|
|
i++
|
|
|
|
|
) {
|
|
|
|
|
this.paginateNext();
|
|
|
|
|
}
|
|
|
|
@ -113,12 +103,9 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideTopPage() {
|
|
|
|
|
const n = this.page <= 2 ? PER_PAGE : PER_PAGE + 1; // remove link
|
|
|
|
|
for (
|
|
|
|
|
let i = 0, end = n, asc = 0 <= end;
|
|
|
|
|
asc ? i < end : i > end;
|
|
|
|
|
asc ? i++ : i--
|
|
|
|
|
) {
|
|
|
|
|
const n =
|
|
|
|
|
this.page <= 2 ? PaginatedList.PER_PAGE : PaginatedList.PER_PAGE + 1; // remove link
|
|
|
|
|
for (let i = 0, end = n; i < end; i++) {
|
|
|
|
|
this.remove(this.el.firstChild);
|
|
|
|
|
}
|
|
|
|
|
this.prepend(this.renderPrevLink(this.page));
|
|
|
|
@ -127,13 +114,9 @@
|
|
|
|
|
hideBottomPage() {
|
|
|
|
|
const n =
|
|
|
|
|
this.page === this.totalPages()
|
|
|
|
|
? this.data.length % PER_PAGE || PER_PAGE
|
|
|
|
|
: PER_PAGE + 1; // remove link
|
|
|
|
|
for (
|
|
|
|
|
let i = 0, end = n, asc = 0 <= end;
|
|
|
|
|
asc ? i < end : i > end;
|
|
|
|
|
asc ? i++ : i--
|
|
|
|
|
) {
|
|
|
|
|
? this.data.length % PaginatedList.PER_PAGE || PaginatedList.PER_PAGE
|
|
|
|
|
: PaginatedList.PER_PAGE + 1; // remove link
|
|
|
|
|
for (let i = 0, end = n; i < end; i++) {
|
|
|
|
|
this.remove(this.el.lastChild);
|
|
|
|
|
}
|
|
|
|
|
this.append(this.renderNextLink(this.page - 1));
|
|
|
|
@ -147,7 +130,4 @@
|
|
|
|
|
this.paginate(target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
app.views.PaginatedList.initClass();
|
|
|
|
|
return app.views.PaginatedList;
|
|
|
|
|
})();
|
|
|
|
|
};
|
|
|
|
|