]>
Commit | Line | Data |
---|---|---|
d592e0a9 | 1 | import { Component, OnInit } from '@angular/core' |
e2f555ca | 2 | |
df98563e | 3 | import { NotificationsService } from 'angular2-notifications' |
8a02bd04 | 4 | import { SortMeta } from 'primeng/primeng' |
7ddd02c9 | 5 | |
df98563e | 6 | import { ConfirmService } from '../../../core' |
8a02bd04 | 7 | import { RestTable, RestPagination } from '../../../shared' |
d5f5a670 | 8 | import { Pod } from '../../../../../../shared' |
8a02bd04 | 9 | import { FriendService } from '../shared' |
e2f555ca C |
10 | |
11 | @Component({ | |
12 | selector: 'my-friend-list', | |
ec8d8440 | 13 | templateUrl: './friend-list.component.html', |
d592e0a9 | 14 | styleUrls: ['./friend-list.component.scss'] |
e2f555ca | 15 | }) |
8a02bd04 | 16 | export class FriendListComponent extends RestTable implements OnInit { |
d592e0a9 | 17 | friends: Pod[] = [] |
8a02bd04 C |
18 | totalRecords = 0 |
19 | rowsPerPage = 10 | |
20 | sort: SortMeta = { field: 'id', order: 1 } | |
21 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
e2f555ca | 22 | |
df98563e | 23 | constructor ( |
7ddd02c9 | 24 | private notificationsService: NotificationsService, |
5769e1db | 25 | private confirmService: ConfirmService, |
7ddd02c9 | 26 | private friendService: FriendService |
8a02bd04 C |
27 | ) { |
28 | super() | |
29 | } | |
d592e0a9 C |
30 | |
31 | ngOnInit () { | |
32 | this.loadData() | |
28798b5d | 33 | } |
e2f555ca | 34 | |
df98563e | 35 | hasFriends () { |
d592e0a9 | 36 | return this.friends.length !== 0 |
e2f555ca C |
37 | } |
38 | ||
df98563e C |
39 | quitFriends () { |
40 | const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.' | |
5769e1db C |
41 | this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe( |
42 | res => { | |
df98563e | 43 | if (res === false) return |
e2f555ca | 44 | |
5769e1db C |
45 | this.friendService.quitFriends().subscribe( |
46 | status => { | |
d5f5a670 | 47 | this.notificationsService.success('Success', 'Friends left!') |
d592e0a9 | 48 | this.loadData() |
5769e1db | 49 | }, |
7ddd02c9 | 50 | |
bfb3a98f | 51 | err => this.notificationsService.error('Error', err.message) |
df98563e | 52 | ) |
5769e1db | 53 | } |
df98563e | 54 | ) |
e2f555ca | 55 | } |
d5f5a670 | 56 | |
d592e0a9 | 57 | removeFriend (friend: Pod) { |
d5f5a670 | 58 | const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.' |
d5f5a670 GS |
59 | |
60 | this.confirmService.confirm(confirmMessage, 'Remove').subscribe( | |
61 | res => { | |
62 | if (res === false) return | |
63 | ||
64 | this.friendService.removeFriend(friend).subscribe( | |
d592e0a9 C |
65 | status => { |
66 | this.notificationsService.success('Success', 'Friend removed') | |
67 | this.loadData() | |
68 | }, | |
d5f5a670 | 69 | |
bfb3a98f | 70 | err => this.notificationsService.error('Error', err.message) |
d592e0a9 | 71 | ) |
d5f5a670 GS |
72 | } |
73 | ) | |
74 | } | |
d592e0a9 | 75 | |
8a02bd04 C |
76 | protected loadData () { |
77 | this.friendService.getFriends(this.pagination, this.sort) | |
d592e0a9 C |
78 | .subscribe( |
79 | resultList => { | |
80 | this.friends = resultList.data | |
8a02bd04 | 81 | this.totalRecords = resultList.total |
d592e0a9 C |
82 | }, |
83 | ||
bfb3a98f | 84 | err => this.notificationsService.error('Error', err.message) |
d592e0a9 C |
85 | ) |
86 | } | |
e2f555ca | 87 | } |