]>
Commit | Line | Data |
---|---|---|
1 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | |
2 | import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent' | |
3 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
4 | ||
5 | import { RestPagination } from './rest-pagination' | |
6 | ||
7 | export abstract class RestTable { | |
8 | ||
9 | abstract totalRecords: number | |
10 | abstract rowsPerPage: number | |
11 | abstract sort: SortMeta | |
12 | abstract pagination: RestPagination | |
13 | ||
14 | private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name | |
15 | ||
16 | protected abstract loadData (): void | |
17 | ||
18 | loadSort () { | |
19 | const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey) | |
20 | ||
21 | if (result) { | |
22 | try { | |
23 | this.sort = JSON.parse(result) | |
24 | } catch (err) { | |
25 | console.error('Cannot load sort of local storage key ' + this.sortLocalStorageKey, err) | |
26 | } | |
27 | } | |
28 | } | |
29 | ||
30 | loadLazy (event: LazyLoadEvent) { | |
31 | this.sort = { | |
32 | order: event.sortOrder, | |
33 | field: event.sortField | |
34 | } | |
35 | ||
36 | this.pagination = { | |
37 | start: event.first, | |
38 | count: this.rowsPerPage | |
39 | } | |
40 | ||
41 | this.loadData() | |
42 | this.saveSort() | |
43 | } | |
44 | ||
45 | saveSort () { | |
46 | peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) | |
47 | } | |
48 | ||
49 | } |