diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-16 14:47:05 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-16 14:47:05 +0100 |
commit | 5ed46c1bce29affbe101f126d58657ab484bffe7 (patch) | |
tree | 019b1649facdefea85eb2cb490a485a5fbf83c64 /client/src/app/core | |
parent | 7706b3703aeb2bea686b12089959b963a7dd89f4 (diff) | |
download | PeerTube-5ed46c1bce29affbe101f126d58657ab484bffe7.tar.gz PeerTube-5ed46c1bce29affbe101f126d58657ab484bffe7.tar.zst PeerTube-5ed46c1bce29affbe101f126d58657ab484bffe7.zip |
Refactor rest table search filter
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/rest/rest-table.ts | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/client/src/app/core/rest/rest-table.ts b/client/src/app/core/rest/rest-table.ts index 7e7e6f4f7..50f6bf39d 100644 --- a/client/src/app/core/rest/rest-table.ts +++ b/client/src/app/core/rest/rest-table.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | 1 | import * as debug from 'debug' |
2 | import { LazyLoadEvent, SortMeta } from 'primeng/api' | 2 | import { LazyLoadEvent, SortMeta } from 'primeng/api' |
3 | import { RestPagination } from './rest-pagination' | ||
4 | import { Subject } from 'rxjs' | 3 | import { Subject } from 'rxjs' |
5 | import { debounceTime, distinctUntilChanged } from 'rxjs/operators' | 4 | import { debounceTime, distinctUntilChanged } from 'rxjs/operators' |
6 | import * as debug from 'debug' | 5 | import { ActivatedRoute, Params, Router } from '@angular/router' |
6 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | ||
7 | import { RestPagination } from './rest-pagination' | ||
7 | 8 | ||
8 | const logger = debug('peertube:tables:RestTable') | 9 | const logger = debug('peertube:tables:RestTable') |
9 | 10 | ||
@@ -18,8 +19,13 @@ export abstract class RestTable { | |||
18 | rowsPerPage = this.rowsPerPageOptions[0] | 19 | rowsPerPage = this.rowsPerPageOptions[0] |
19 | expandedRows = {} | 20 | expandedRows = {} |
20 | 21 | ||
22 | baseRoute: string | ||
23 | |||
21 | protected searchStream: Subject<string> | 24 | protected searchStream: Subject<string> |
22 | 25 | ||
26 | protected route: ActivatedRoute | ||
27 | protected router: Router | ||
28 | |||
23 | abstract getIdentifier (): string | 29 | abstract getIdentifier (): string |
24 | 30 | ||
25 | initialize () { | 31 | initialize () { |
@@ -80,6 +86,33 @@ export abstract class RestTable { | |||
80 | onSearch (event: Event) { | 86 | onSearch (event: Event) { |
81 | const target = event.target as HTMLInputElement | 87 | const target = event.target as HTMLInputElement |
82 | this.searchStream.next(target.value) | 88 | this.searchStream.next(target.value) |
89 | |||
90 | this.setQueryParams((event.target as HTMLInputElement).value) | ||
91 | } | ||
92 | |||
93 | setQueryParams (search: string) { | ||
94 | if (!this.baseRoute) return | ||
95 | |||
96 | const queryParams: Params = {} | ||
97 | |||
98 | if (search) Object.assign(queryParams, { search }) | ||
99 | this.router.navigate([ this.baseRoute ], { queryParams }) | ||
100 | } | ||
101 | |||
102 | resetTableFilter () { | ||
103 | this.setTableFilter('') | ||
104 | this.setQueryParams('') | ||
105 | this.resetSearch() | ||
106 | } | ||
107 | |||
108 | listenToSearchChange () { | ||
109 | this.route.queryParams | ||
110 | .subscribe(params => { | ||
111 | this.search = params.search || '' | ||
112 | |||
113 | this.setTableFilter(this.search) | ||
114 | this.loadData() | ||
115 | }) | ||
83 | } | 116 | } |
84 | 117 | ||
85 | onPage (event: { first: number, rows: number }) { | 118 | onPage (event: { first: number, rows: number }) { |