]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/rest/rest-table.ts
Remove unnecessary onPage event on admin tables
[github/Chocobozzz/PeerTube.git] / client / src / app / core / rest / rest-table.ts
index e6328eddc1bc99f5441186c5ea91ed6ad7fb8c56..d8b0391876cf63ed53cccfdbb9233d823454c611 100644 (file)
@@ -1,9 +1,8 @@
-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'
-import * as debug from 'debug'
 
 const logger = debug('peertube:tables:RestTable')
 
@@ -13,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 = {}
 
-  protected searchStream: Subject<string>
+  search: string
+
+  protected route: ActivatedRoute
+  protected router: Router
 
   abstract getIdentifier (): string
 
   initialize () {
     this.loadSort()
-    this.initSearch()
   }
 
   loadSort () {
@@ -47,12 +47,16 @@ export abstract class RestTable {
       field: event.sortField
     }
 
+    this.rowsPerPage = event.rows
+
     this.pagination = {
       start: event.first,
       count: this.rowsPerPage
     }
 
-    this.loadData()
+    this.expandedRows = {}
+
+    this.reloadData()
     this.saveSort()
   }
 
@@ -60,56 +64,12 @@ export abstract class RestTable {
     peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort))
   }
 
-  initSearch () {
-    this.searchStream = new Subject()
-
-    this.searchStream
-      .pipe(
-        debounceTime(400),
-        distinctUntilChanged()
-      )
-      .subscribe(search => {
-        this.search = search
-
-        logger('On search %s.', this.search)
-
-        this.loadData()
-      })
-  }
-
-  onSearch (event: Event) {
-    const target = event.target as HTMLInputElement
-    this.searchStream.next(target.value)
-  }
-
-  onPage (event: { first: number, rows: number }) {
-    logger('On page %o.', event)
-
-    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
-  }
-
-  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()