1 import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
2 import { LazyLoadEvent, SortMeta } from 'primeng/api'
3 import { RestPagination } from './rest-pagination'
4 import { Subject } from 'rxjs'
5 import { debounceTime, distinctUntilChanged } from 'rxjs/operators'
7 export abstract class RestTable {
9 abstract totalRecords: number
10 abstract rowsPerPage: number
11 abstract sort: SortMeta
12 abstract pagination: RestPagination
14 protected search: string
15 private searchStream: Subject<string>
16 private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name
24 const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey)
28 this.sort = JSON.parse(result)
30 console.error('Cannot load sort of local storage key ' + this.sortLocalStorageKey, err)
35 loadLazy (event: LazyLoadEvent) {
37 order: event.sortOrder,
38 field: event.sortField
43 count: this.rowsPerPage
51 peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort))
55 this.searchStream = new Subject()
60 distinctUntilChanged()
62 .subscribe(search => {
68 onSearch (event: Event) {
69 const target = event.target as HTMLInputElement
70 this.searchStream.next(target.value)
73 protected abstract loadData (): void