]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/users/user-list/user-list.component.ts
Add ability to unfollow a server
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-list / user-list.component.ts
index 12826741c027969077442c7d5e0def949f45cf60..1e8e1af49ea88545d56b041ec25638242c7c09f8 100644 (file)
@@ -1,9 +1,10 @@
 import { Component } from '@angular/core'
+import { SortMeta } from 'primeng/components/common/sortmeta'
 
 import { NotificationsService } from 'angular2-notifications'
 
 import { ConfirmService } from '../../../core'
-import { RestDataSource, User, Utils } from '../../../shared'
+import { RestTable, RestPagination, User } from '../../../shared'
 import { UserService } from '../shared'
 
 @Component({
@@ -11,60 +12,22 @@ import { UserService } from '../shared'
   templateUrl: './user-list.component.html',
   styleUrls: [ './user-list.component.scss' ]
 })
-export class UserListComponent {
-  usersSource: RestDataSource = null
-  tableSettings = {
-    mode: 'external',
-    attr: {
-      class: 'table-hover'
-    },
-    hideSubHeader: true,
-    actions: {
-      position: 'right',
-      add: false,
-      edit: false,
-      delete: true
-    },
-    delete: {
-      deleteButtonContent: Utils.getRowDeleteButton()
-    },
-    pager: {
-      display: true,
-      perPage: 10
-    },
-    columns: {
-      id: {
-        title: 'ID',
-        sortDirection: 'asc'
-      },
-      username: {
-        title: 'Username'
-      },
-      email: {
-        title: 'Email'
-      },
-      role: {
-        title: 'Role',
-        sort: false
-      },
-      createdAt: {
-        title: 'Created Date',
-        valuePrepareFunction: Utils.dateToHuman
-      }
-    }
-  }
+export class UserListComponent extends RestTable {
+  users: User[] = []
+  totalRecords = 0
+  rowsPerPage = 10
+  sort: SortMeta = { field: 'id', order: 1 }
+  pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
 
   constructor (
     private notificationsService: NotificationsService,
     private confirmService: ConfirmService,
     private userService: UserService
   ) {
-    this.usersSource = this.userService.getDataSource()
+    super()
   }
 
-  removeUser ({ data }) {
-    const user: User = data
-
+  removeUser (user: User) {
     if (user.username === 'root') {
       this.notificationsService.error('Error', 'You cannot delete root.')
       return
@@ -77,12 +40,28 @@ export class UserListComponent {
         this.userService.removeUser(user).subscribe(
           () => {
             this.notificationsService.success('Success', `User ${user.username} deleted.`)
-            this.usersSource.refresh()
+            this.loadData()
           },
 
-          err => this.notificationsService.error('Error', err.text)
+          err => this.notificationsService.error('Error', err.message)
         )
       }
     )
   }
+
+  getRouterUserEditLink (user: User) {
+    return [ '/admin', 'users', user.id, 'update' ]
+  }
+
+  protected loadData () {
+    this.userService.getUsers(this.pagination, this.sort)
+                    .subscribe(
+                      resultList => {
+                        this.users = resultList.data
+                        this.totalRecords = resultList.total
+                      },
+
+                      err => this.notificationsService.error('Error', err.message)
+                    )
+  }
 }