]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Component } from '@angular/core' |
e2f555ca | 2 | |
df98563e C |
3 | import { NotificationsService } from 'angular2-notifications' |
4 | import { ServerDataSource } from 'ng2-smart-table' | |
7ddd02c9 | 5 | |
df98563e C |
6 | import { ConfirmService } from '../../../core' |
7 | import { Utils } from '../../../shared' | |
8 | import { Friend, FriendService } from '../shared' | |
e2f555ca C |
9 | |
10 | @Component({ | |
11 | selector: 'my-friend-list', | |
ec8d8440 C |
12 | templateUrl: './friend-list.component.html', |
13 | styleUrls: [ './friend-list.component.scss' ] | |
e2f555ca | 14 | }) |
28798b5d | 15 | export class FriendListComponent { |
df98563e | 16 | friendsSource = null |
28798b5d C |
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 | }, | |
4793c343 C |
38 | email: { |
39 | title: 'Email', | |
40 | sort: false | |
41 | }, | |
28798b5d C |
42 | score: { |
43 | title: 'Score', | |
44 | sort: false | |
45 | }, | |
46 | createdAt: { | |
47 | title: 'Created Date', | |
48 | sort: false, | |
49 | valuePrepareFunction: Utils.dateToHuman | |
50 | } | |
51 | } | |
df98563e | 52 | } |
e2f555ca | 53 | |
df98563e | 54 | constructor ( |
7ddd02c9 | 55 | private notificationsService: NotificationsService, |
5769e1db | 56 | private confirmService: ConfirmService, |
7ddd02c9 | 57 | private friendService: FriendService |
28798b5d | 58 | ) { |
df98563e | 59 | this.friendsSource = this.friendService.getDataSource() |
28798b5d | 60 | } |
e2f555ca | 61 | |
df98563e C |
62 | hasFriends () { |
63 | return this.friendsSource.count() !== 0 | |
e2f555ca C |
64 | } |
65 | ||
df98563e C |
66 | quitFriends () { |
67 | const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.' | |
5769e1db C |
68 | this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe( |
69 | res => { | |
df98563e | 70 | if (res === false) return |
e2f555ca | 71 | |
5769e1db C |
72 | this.friendService.quitFriends().subscribe( |
73 | status => { | |
df98563e | 74 | this.notificationsService.success('Sucess', 'Friends left!') |
7ddd02c9 | 75 | |
df98563e | 76 | this.friendsSource.refresh() |
5769e1db | 77 | }, |
7ddd02c9 | 78 | |
5769e1db | 79 | err => this.notificationsService.error('Error', err.text) |
df98563e | 80 | ) |
5769e1db | 81 | } |
df98563e | 82 | ) |
e2f555ca C |
83 | } |
84 | } |