]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/rest/rest-table.ts
Prevent edition with 0 task
[github/Chocobozzz/PeerTube.git] / client / src / app / core / rest / rest-table.ts
index d8b0391876cf63ed53cccfdbb9233d823454c611..707110d7f7f404aeacaea73f3e8647fae0202360 100644 (file)
@@ -1,12 +1,13 @@
-import * as debug from 'debug'
+import debug from 'debug'
 import { LazyLoadEvent, SortMeta } from 'primeng/api'
 import { ActivatedRoute, Router } from '@angular/router'
+import { logger } from '@root-helpers/logger'
 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
 import { RestPagination } from './rest-pagination'
 
-const logger = debug('peertube:tables:RestTable')
+const debugLogger = debug('peertube:tables:RestTable')
 
-export abstract class RestTable {
+export abstract class RestTable <T = unknown> {
 
   abstract totalRecords: number
   abstract sort: SortMeta
@@ -16,6 +17,8 @@ export abstract class RestTable {
   rowsPerPage = this.rowsPerPageOptions[0]
   expandedRows = {}
 
+  selectedRows: T[] = []
+
   search: string
 
   protected route: ActivatedRoute
@@ -34,13 +37,17 @@ export abstract class RestTable {
       try {
         this.sort = JSON.parse(result)
       } catch (err) {
-        console.error('Cannot load sort of local storage key ' + this.getSortLocalStorageKey(), err)
+        logger.error('Cannot load sort of local storage key ' + this.getSortLocalStorageKey(), err)
       }
     }
   }
 
+  saveSort () {
+    peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort))
+  }
+
   loadLazy (event: LazyLoadEvent) {
-    logger('Load lazy %o.', event)
+    debugLogger('Load lazy %o.', event)
 
     this.sort = {
       order: event.sortOrder,
@@ -60,16 +67,27 @@ export abstract class RestTable {
     this.saveSort()
   }
 
-  saveSort () {
-    peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort))
-  }
-
   onSearch (search: string) {
+    this.pagination = {
+      start: 0,
+      count: this.rowsPerPage
+    }
+
     this.search = search
     this.reloadData()
   }
 
-  protected abstract reloadData (): void
+  isInSelectionMode () {
+    return this.selectedRows.length !== 0
+  }
+
+  protected abstract reloadDataInternal (): void
+
+  protected reloadData () {
+    this.selectedRows = []
+
+    this.reloadDataInternal()
+  }
 
   private getSortLocalStorageKey () {
     return 'rest-table-sort-' + this.getIdentifier()