aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/friends/friend-list/friend-list.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin/friends/friend-list/friend-list.component.ts')
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.ts88
1 files changed, 29 insertions, 59 deletions
diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.ts b/client/src/app/+admin/friends/friend-list/friend-list.component.ts
index 822a112cc..6a8bd492c 100644
--- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts
+++ b/client/src/app/+admin/friends/friend-list/friend-list.component.ts
@@ -1,71 +1,31 @@
1import { Component } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
2 2
3import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
4import { ServerDataSource } from 'ng2-smart-table'
5 4
6import { ConfirmService } from '../../../core' 5import { ConfirmService } from '../../../core'
7import { Utils } from '../../../shared'
8import { FriendService } from '../shared' 6import { FriendService } from '../shared'
9import { Pod } from '../../../../../../shared' 7import { Pod } from '../../../../../../shared'
10 8
11@Component({ 9@Component({
12 selector: 'my-friend-list', 10 selector: 'my-friend-list',
13 templateUrl: './friend-list.component.html', 11 templateUrl: './friend-list.component.html',
14 styleUrls: [ './friend-list.component.scss' ] 12 styleUrls: ['./friend-list.component.scss']
15}) 13})
16export class FriendListComponent { 14export class FriendListComponent implements OnInit {
17 friendsSource = null 15 friends: Pod[] = []
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 16
59 constructor ( 17 constructor (
60 private notificationsService: NotificationsService, 18 private notificationsService: NotificationsService,
61 private confirmService: ConfirmService, 19 private confirmService: ConfirmService,
62 private friendService: FriendService 20 private friendService: FriendService
63 ) { 21 ) {}
64 this.friendsSource = this.friendService.getDataSource() 22
23 ngOnInit () {
24 this.loadData()
65 } 25 }
66 26
67 hasFriends () { 27 hasFriends () {
68 return this.friendsSource.count() !== 0 28 return this.friends.length !== 0
69 } 29 }
70 30
71 quitFriends () { 31 quitFriends () {
@@ -77,32 +37,42 @@ export class FriendListComponent {
77 this.friendService.quitFriends().subscribe( 37 this.friendService.quitFriends().subscribe(
78 status => { 38 status => {
79 this.notificationsService.success('Success', 'Friends left!') 39 this.notificationsService.success('Success', 'Friends left!')
80 this.friendsSource.refresh() 40 this.loadData()
81 }, 41 },
82 42
83 err => this.notificationsService.error('Error', err.text) 43 err => this.notificationsService.error('Error', err)
84 ) 44 )
85 } 45 }
86 ) 46 )
87 } 47 }
88 48
89 removeFriend ({ data }) { 49 removeFriend (friend: Pod) {
90 const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.' 50 const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.'
91 const friend: Pod = data
92 51
93 this.confirmService.confirm(confirmMessage, 'Remove').subscribe( 52 this.confirmService.confirm(confirmMessage, 'Remove').subscribe(
94 res => { 53 res => {
95 if (res === false) return 54 if (res === false) return
96 55
97 this.friendService.removeFriend(friend).subscribe( 56 this.friendService.removeFriend(friend).subscribe(
98 status => { 57 status => {
99 this.notificationsService.success('Success', 'Friend removed') 58 this.notificationsService.success('Success', 'Friend removed')
100 this.friendsSource.refresh() 59 this.loadData()
101 }, 60 },
102 61
103 err => this.notificationsService.error('Error', err.text) 62 err => this.notificationsService.error('Error', err)
104 ) 63 )
105 } 64 }
106 ) 65 )
107 } 66 }
67
68 private loadData () {
69 this.friendService.getFriends()
70 .subscribe(
71 resultList => {
72 this.friends = resultList.data
73 },
74
75 err => this.notificationsService.error('Error', err)
76 )
77 }
108} 78}