1 import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
2 import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'
3 import { SortMeta } from 'primeng/components/common/sortmeta'
4 import { RestPagination } from './rest-pagination'
5 import { Subject } from 'rxjs'
6 import { debounceTime, distinctUntilChanged } from 'rxjs/operators'
8 export abstract class RestTable {
10 abstract totalRecords: number
11 abstract rowsPerPage: number
12 abstract sort: SortMeta
13 abstract pagination: RestPagination
15 protected search: string
16 private searchStream: Subject<string>
17 private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name
25 const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey)
29 this.sort = JSON.parse(result)
31 console.error('Cannot load sort of local storage key ' + this.sortLocalStorageKey, err)
36 loadLazy (event: LazyLoadEvent) {
38 order: event.sortOrder,
39 field: event.sortField
44 count: this.rowsPerPage
52 peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort))
56 this.searchStream = new Subject()
61 distinctUntilChanged()
63 .subscribe(search => {
69 onSearch (search: string) {
70 this.searchStream.next(search)
73 protected abstract loadData (): void