1 import * as debug from 'debug'
2 import { LazyLoadEvent, SortMeta } from 'primeng/api'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
5 import { RestPagination } from './rest-pagination'
7 const logger = debug('peertube:tables:RestTable')
9 export abstract class RestTable {
11 abstract totalRecords: number
12 abstract sort: SortMeta
13 abstract pagination: RestPagination
15 rowsPerPageOptions = [ 10, 20, 50, 100 ]
16 rowsPerPage = this.rowsPerPageOptions[0]
21 protected route: ActivatedRoute
22 protected router: Router
24 abstract getIdentifier (): string
31 const result = peertubeLocalStorage.getItem(this.getSortLocalStorageKey())
35 this.sort = JSON.parse(result)
37 console.error('Cannot load sort of local storage key ' + this.getSortLocalStorageKey(), err)
42 loadLazy (event: LazyLoadEvent) {
43 logger('Load lazy %o.', event)
46 order: event.sortOrder,
47 field: event.sortField
50 this.rowsPerPage = event.rows
54 count: this.rowsPerPage
57 this.expandedRows = {}
64 peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort))
67 onSearch (search: string) {
72 protected abstract reloadData (): void
74 private getSortLocalStorageKey () {
75 return 'rest-table-sort-' + this.getIdentifier()