Use typescript standard and lint all files
[oweals/peertube.git] / client / src / app / +admin / friends / friend-list / friend-list.component.ts
1 import { Component } from '@angular/core'
2
3 import { NotificationsService } from 'angular2-notifications'
4 import { ServerDataSource } from 'ng2-smart-table'
5
6 import { ConfirmService } from '../../../core'
7 import { Utils } from '../../../shared'
8 import { Friend, FriendService } from '../shared'
9
10 @Component({
11   selector: 'my-friend-list',
12   templateUrl: './friend-list.component.html',
13   styleUrls: [ './friend-list.component.scss' ]
14 })
15 export class FriendListComponent {
16   friendsSource = null
17   tableSettings = {
18     attr: {
19       class: 'table-hover'
20     },
21     hideSubHeader: true,
22     actions: {
23       position: 'right',
24       add: false,
25       edit: false,
26       delete: false
27     },
28     columns: {
29       id: {
30         title: 'ID',
31         sort: false,
32         sortDirection: 'asc'
33       },
34       host: {
35         title: 'Host',
36         sort: false
37       },
38       email: {
39         title: 'Email',
40         sort: false
41       },
42       score: {
43         title: 'Score',
44         sort: false
45       },
46       createdAt: {
47         title: 'Created Date',
48         sort: false,
49         valuePrepareFunction: Utils.dateToHuman
50       }
51     }
52   }
53
54   constructor (
55     private notificationsService: NotificationsService,
56     private confirmService: ConfirmService,
57     private friendService: FriendService
58   ) {
59     this.friendsSource = this.friendService.getDataSource()
60   }
61
62   hasFriends () {
63     return this.friendsSource.count() !== 0
64   }
65
66   quitFriends () {
67     const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'
68     this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
69       res => {
70         if (res === false) return
71
72         this.friendService.quitFriends().subscribe(
73           status => {
74             this.notificationsService.success('Sucess', 'Friends left!')
75
76             this.friendsSource.refresh()
77           },
78
79           err => this.notificationsService.error('Error', err.text)
80         )
81       }
82     )
83   }
84 }