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
15 private searchStream: Subject<string>
17 abstract getIdentifier (): string
25 const result = peertubeLocalStorage.getItem(this.getSortLocalStorageKey())
29 this.sort = JSON.parse(result)
31 console.error('Cannot load sort of local storage key ' + this.getSortLocalStorageKey(), err)
36 loadLazy (event: LazyLoadEvent) {
38 order: event.sortOrder,
39 field: event.sortField
44 count: this.rowsPerPage
52 peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort))
56 this.searchStream = new Subject()
61 distinctUntilChanged()
63 .subscribe(search => {
69 onSearch (event: Event) {
70 const target = event.target as HTMLInputElement
71 this.searchStream.next(target.value)
74 protected abstract loadData (): void
76 private getSortLocalStorageKey () {
77 return 'rest-table-sort-' + this.getIdentifier()