]>
Commit | Line | Data |
---|---|---|
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 { FriendService } from '../shared' | |
9 | import { Pod } from '../../../../../../shared' | |
10 | ||
11 | @Component({ | |
12 | selector: 'my-friend-list', | |
13 | templateUrl: './friend-list.component.html', | |
14 | styleUrls: [ './friend-list.component.scss' ] | |
15 | }) | |
16 | export class FriendListComponent { | |
17 | friendsSource = null | |
18 | tableSettings = { | |
19 | mode: 'external', | |
20 | attr: { | |
21 | class: 'table-hover' | |
22 | }, | |
23 | hideSubHeader: true, | |
24 | actions: { | |
25 | position: 'right', | |
26 | add: false, | |
27 | edit: false, | |
28 | delete: true | |
29 | }, | |
30 | delete: { | |
31 | deleteButtonContent: Utils.getRowDeleteButton() | |
32 | }, | |
33 | columns: { | |
34 | id: { | |
35 | title: 'ID', | |
36 | sort: false, | |
37 | sortDirection: 'asc' | |
38 | }, | |
39 | host: { | |
40 | title: 'Host', | |
41 | sort: false | |
42 | }, | |
43 | email: { | |
44 | title: 'Email', | |
45 | sort: false | |
46 | }, | |
47 | score: { | |
48 | title: 'Score', | |
49 | sort: false | |
50 | }, | |
51 | createdAt: { | |
52 | title: 'Created Date', | |
53 | sort: false, | |
54 | valuePrepareFunction: Utils.dateToHuman | |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | constructor ( | |
60 | private notificationsService: NotificationsService, | |
61 | private confirmService: ConfirmService, | |
62 | private friendService: FriendService | |
63 | ) { | |
64 | this.friendsSource = this.friendService.getDataSource() | |
65 | } | |
66 | ||
67 | hasFriends () { | |
68 | return this.friendsSource.count() !== 0 | |
69 | } | |
70 | ||
71 | quitFriends () { | |
72 | const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.' | |
73 | this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe( | |
74 | res => { | |
75 | if (res === false) return | |
76 | ||
77 | this.friendService.quitFriends().subscribe( | |
78 | status => { | |
79 | this.notificationsService.success('Success', 'Friends left!') | |
80 | this.friendsSource.refresh() | |
81 | }, | |
82 | ||
83 | err => this.notificationsService.error('Error', err.text) | |
84 | ) | |
85 | } | |
86 | ) | |
87 | } | |
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 | } | |
108 | } |