X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Frest%2Frest-table.ts;h=7b765f7fc09e2fd3f6b7ab4a380309f1fd43f511;hb=87a0cac618c8ed4a09408273d0f5a468530e8062;hp=1b35ad47d171687d9691af4797bfa8c68476fbae;hpb=67ed6552b831df66713bac9e672738796128d33f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/rest/rest-table.ts b/client/src/app/core/rest/rest-table.ts index 1b35ad47d..7b765f7fc 100644 --- a/client/src/app/core/rest/rest-table.ts +++ b/client/src/app/core/rest/rest-table.ts @@ -1,8 +1,10 @@ -import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' +import * as debug from 'debug' import { LazyLoadEvent, SortMeta } from 'primeng/api' +import { ActivatedRoute, Router } from '@angular/router' +import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' import { RestPagination } from './rest-pagination' -import { Subject } from 'rxjs' -import { debounceTime, distinctUntilChanged } from 'rxjs/operators' + +const logger = debug('peertube:tables:RestTable') export abstract class RestTable { @@ -10,18 +12,19 @@ export abstract class RestTable { abstract sort: SortMeta abstract pagination: RestPagination - search: string rowsPerPageOptions = [ 10, 20, 50, 100 ] rowsPerPage = this.rowsPerPageOptions[0] expandedRows = {} - private searchStream: Subject + search: string + + protected route: ActivatedRoute + protected router: Router abstract getIdentifier (): string initialize () { this.loadSort() - this.initSearch() } loadSort () { @@ -36,68 +39,37 @@ export abstract class RestTable { } } + saveSort () { + peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort)) + } + loadLazy (event: LazyLoadEvent) { + logger('Load lazy %o.', event) + this.sort = { order: event.sortOrder, field: event.sortField } + this.rowsPerPage = event.rows + this.pagination = { start: event.first, count: this.rowsPerPage } - this.loadData() - this.saveSort() - } - - saveSort () { - peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort)) - } - - initSearch () { - this.searchStream = new Subject() - - this.searchStream - .pipe( - debounceTime(400), - distinctUntilChanged() - ) - .subscribe(search => { - this.search = search - this.loadData() - }) - } - - onSearch (event: Event) { - const target = event.target as HTMLInputElement - this.searchStream.next(target.value) - } - - onPage (event: { first: number, rows: number }) { - if (this.rowsPerPage !== event.rows) { - this.rowsPerPage = event.rows - this.pagination = { - start: event.first, - count: this.rowsPerPage - } - this.loadData() - } this.expandedRows = {} - } - setTableFilter (filter: string) { - // FIXME: cannot use ViewChild, so create a component for the filter input - const filterInput = document.getElementById('table-filter') as HTMLInputElement - if (filterInput) filterInput.value = filter + this.reloadData() + this.saveSort() } - resetSearch () { - this.searchStream.next('') - this.setTableFilter('') + onSearch (search: string) { + this.search = search + this.reloadData() } - protected abstract loadData (): void + protected abstract reloadData (): void private getSortLocalStorageKey () { return 'rest-table-sort-' + this.getIdentifier()