]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/friends/friend-list/friend-list.component.ts
Remove one pod (#76)
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / friends / friend-list / friend-list.component.ts
index 9783adf16afe556d21384763dd469aa64f829431..822a112ccc05ebf9c405a46b7c097d36a6440424 100644 (file)
@@ -1,11 +1,12 @@
-import { Component } from '@angular/core';
+import { Component } from '@angular/core'
 
-import { NotificationsService } from 'angular2-notifications';
-import { ServerDataSource } from 'ng2-smart-table';
+import { NotificationsService } from 'angular2-notifications'
+import { ServerDataSource } from 'ng2-smart-table'
 
-import { ConfirmService } from '../../../core';
-import { Utils } from '../../../shared';
-import { Friend, FriendService } from '../shared';
+import { ConfirmService } from '../../../core'
+import { Utils } from '../../../shared'
+import { FriendService } from '../shared'
+import { Pod } from '../../../../../../shared'
 
 @Component({
   selector: 'my-friend-list',
@@ -13,8 +14,9 @@ import { Friend, FriendService } from '../shared';
   styleUrls: [ './friend-list.component.scss' ]
 })
 export class FriendListComponent {
-  friendsSource = null;
+  friendsSource = null
   tableSettings = {
+    mode: 'external',
     attr: {
       class: 'table-hover'
     },
@@ -23,7 +25,10 @@ export class FriendListComponent {
       position: 'right',
       add: false,
       edit: false,
-      delete: false
+      delete: true
+    },
+    delete: {
+      deleteButtonContent: Utils.getRowDeleteButton()
     },
     columns: {
       id: {
@@ -35,6 +40,10 @@ export class FriendListComponent {
         title: 'Host',
         sort: false
       },
+      email: {
+        title: 'Email',
+        sort: false
+      },
       score: {
         title: 'Score',
         sort: false
@@ -45,36 +54,55 @@ export class FriendListComponent {
         valuePrepareFunction: Utils.dateToHuman
       }
     }
-  };
+  }
 
-  constructor(
+  constructor (
     private notificationsService: NotificationsService,
     private confirmService: ConfirmService,
     private friendService: FriendService
   ) {
-    this.friendsSource = this.friendService.getDataSource();
+    this.friendsSource = this.friendService.getDataSource()
   }
 
-  hasFriends() {
-    return this.friendsSource.count() !== 0;
+  hasFriends () {
+    return this.friendsSource.count() !== 0
   }
 
-  quitFriends() {
-    const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.';
+  quitFriends () {
+    const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'
     this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
       res => {
-        if (res === false) return;
+        if (res === false) return
 
         this.friendService.quitFriends().subscribe(
           status => {
-            this.notificationsService.success('Sucess', 'Friends left!');
-
-            this.friendsSource.refresh();
+            this.notificationsService.success('Success', 'Friends left!')
+            this.friendsSource.refresh()
           },
 
           err => this.notificationsService.error('Error', err.text)
-        );
+        )
+      }
+    )
+  }
+
+  removeFriend ({ data }) {
+    const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.'
+    const friend: Pod = data
+
+    this.confirmService.confirm(confirmMessage, 'Remove').subscribe(
+      res => {
+        if (res === false) return
+
+        this.friendService.removeFriend(friend).subscribe(
+         status => {
+           this.notificationsService.success('Success', 'Friend removed')
+           this.friendsSource.refresh()
+         },
+
+         err => this.notificationsService.error('Error', err.text)
+       )
       }
-    );
+    )
   }
 }