mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
feat: add pagination to evaluations.index
This commit is contained in:
@@ -3,12 +3,41 @@ import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
|
||||
export default class EvaluationsController extends Controller {
|
||||
queryParams = ['pageSize'];
|
||||
queryParams = ['nextToken', 'pageSize'];
|
||||
|
||||
get shouldDisableNext() {
|
||||
return !this.model.meta?.nextToken;
|
||||
}
|
||||
|
||||
get shouldDisablePrev() {
|
||||
return !this.previousTokens.length;
|
||||
}
|
||||
|
||||
@tracked pageSize = 25;
|
||||
@tracked nextToken = null;
|
||||
@tracked previousTokens = [];
|
||||
|
||||
@action
|
||||
onChange(newPageSize) {
|
||||
this.pageSize = newPageSize;
|
||||
}
|
||||
|
||||
@action
|
||||
onNext(nextToken) {
|
||||
this.previousTokens = [...this.previousTokens, this.nextToken];
|
||||
this.nextToken = nextToken;
|
||||
}
|
||||
|
||||
@action
|
||||
onPrev(lastToken) {
|
||||
this.previousTokens.pop();
|
||||
this.previousTokens = [...this.previousTokens];
|
||||
this.nextToken = lastToken;
|
||||
}
|
||||
|
||||
@action
|
||||
refresh() {
|
||||
this.nextToken = null;
|
||||
this.previousTokens = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,16 @@ export default class EvaluationsIndexRoute extends Route {
|
||||
pageSize: {
|
||||
refreshModel: true,
|
||||
},
|
||||
nextToken: {
|
||||
refreshModel: true,
|
||||
},
|
||||
};
|
||||
|
||||
model({ pageSize }) {
|
||||
model({ pageSize, nextToken }) {
|
||||
return this.store.query('evaluation', {
|
||||
namespace: ALL_NAMESPACE_WILDCARD,
|
||||
per_page: pageSize,
|
||||
next_token: nextToken,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,5 +58,22 @@
|
||||
</ListTable>
|
||||
<div class="table-foot">
|
||||
<PageSizeSelect @onChange={{this.onChange}} />
|
||||
<button type="button" {{on "click" this.refresh}}>
|
||||
Refresh
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={{this.shouldDisablePrev}}
|
||||
{{on "click" (fn this.onPrev this.lastToken)}}
|
||||
>
|
||||
Prev
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={{this.shouldDisableNext}}
|
||||
{{on "click" (fn this.onNext @model.meta.nextToken)}}
|
||||
>
|
||||
Next >
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user