]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
df98563e 1import { Component } from '@angular/core'
e2f555ca 2
df98563e
C
3import { NotificationsService } from 'angular2-notifications'
4import { ServerDataSource } from 'ng2-smart-table'
7ddd02c9 5
df98563e
C
6import { ConfirmService } from '../../../core'
7import { Utils } from '../../../shared'
154898b0 8import { FriendService } from '../shared'
d5f5a670 9import { Pod } from '../../../../../../shared'
e2f555ca
C
10
11@Component({
12 selector: 'my-friend-list',
ec8d8440
C
13 templateUrl: './friend-list.component.html',
14 styleUrls: [ './friend-list.component.scss' ]
e2f555ca 15})
28798b5d 16export class FriendListComponent {
df98563e 17 friendsSource = null
28798b5d 18 tableSettings = {
d5f5a670 19 mode: 'external',
28798b5d
C
20 attr: {
21 class: 'table-hover'
22 },
23 hideSubHeader: true,
24 actions: {
25 position: 'right',
26 add: false,
27 edit: false,
d5f5a670
GS
28 delete: true
29 },
30 delete: {
31 deleteButtonContent: Utils.getRowDeleteButton()
28798b5d
C
32 },
33 columns: {
34 id: {
35 title: 'ID',
36 sort: false,
37 sortDirection: 'asc'
38 },
39 host: {
40 title: 'Host',
41 sort: false
42 },
4793c343
C
43 email: {
44 title: 'Email',
45 sort: false
46 },
28798b5d
C
47 score: {
48 title: 'Score',
49 sort: false
50 },
51 createdAt: {
52 title: 'Created Date',
53 sort: false,
54 valuePrepareFunction: Utils.dateToHuman
55 }
56 }
df98563e 57 }
e2f555ca 58
df98563e 59 constructor (
7ddd02c9 60 private notificationsService: NotificationsService,
5769e1db 61 private confirmService: ConfirmService,
7ddd02c9 62 private friendService: FriendService
28798b5d 63 ) {
df98563e 64 this.friendsSource = this.friendService.getDataSource()
28798b5d 65 }
e2f555ca 66
df98563e
C
67 hasFriends () {
68 return this.friendsSource.count() !== 0
e2f555ca
C
69 }
70
df98563e
C
71 quitFriends () {
72 const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'
5769e1db
C
73 this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
74 res => {
df98563e 75 if (res === false) return
e2f555ca 76
5769e1db
C
77 this.friendService.quitFriends().subscribe(
78 status => {
d5f5a670 79 this.notificationsService.success('Success', 'Friends left!')
df98563e 80 this.friendsSource.refresh()
5769e1db 81 },
7ddd02c9 82
5769e1db 83 err => this.notificationsService.error('Error', err.text)
df98563e 84 )
5769e1db 85 }
df98563e 86 )
e2f555ca 87 }
d5f5a670
GS
88
89 removeFriend ({ data }) {
90 const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.'
91 const friend: Pod = data
92
93 this.confirmService.confirm(confirmMessage, 'Remove').subscribe(
94 res => {
95 if (res === false) return
96
97 this.friendService.removeFriend(friend).subscribe(
98 status => {
99 this.notificationsService.success('Success', 'Friend removed')
100 this.friendsSource.refresh()
101 },
102
103 err => this.notificationsService.error('Error', err.text)
104 )
105 }
106 )
107 }
e2f555ca 108}