diff options
Diffstat (limited to 'client/src/app/+admin/friends/friend-list')
-rw-r--r-- | client/src/app/+admin/friends/friend-list/friend-list.component.html | 15 | ||||
-rw-r--r-- | client/src/app/+admin/friends/friend-list/friend-list.component.ts | 88 |
2 files changed, 42 insertions, 61 deletions
diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.html b/client/src/app/+admin/friends/friend-list/friend-list.component.html index 7b9fff304..7887bc5e3 100644 --- a/client/src/app/+admin/friends/friend-list/friend-list.component.html +++ b/client/src/app/+admin/friends/friend-list/friend-list.component.html | |||
@@ -2,13 +2,24 @@ | |||
2 | <div class="content-padding"> | 2 | <div class="content-padding"> |
3 | <h3>Friends list</h3> | 3 | <h3>Friends list</h3> |
4 | 4 | ||
5 | <ng2-smart-table [settings]="tableSettings" [source]="friendsSource" (delete)="removeFriend($event)"></ng2-smart-table> | 5 | <p-dataTable [value]="friends"> |
6 | <p-column field="id" header="ID"></p-column> | ||
7 | <p-column field="host" header="Host"></p-column> | ||
8 | <p-column field="email" header="Email"></p-column> | ||
9 | <p-column field="score" header="Score"></p-column> | ||
10 | <p-column field="createdAt" header="Created date"></p-column> | ||
11 | <p-column header="Delete" styleClass="action-cell"> | ||
12 | <ng-template pTemplate="body" let-pod="rowData"> | ||
13 | <span (click)="removeFriend(pod)" class="glyphicon glyphicon-remove glyphicon-black" title="Remove this pod"></span> | ||
14 | </ng-template> | ||
15 | </p-column> | ||
16 | </p-dataTable> | ||
6 | 17 | ||
7 | <a *ngIf="hasFriends()" class="btn btn-danger pull-left" (click)="quitFriends()"> | 18 | <a *ngIf="hasFriends()" class="btn btn-danger pull-left" (click)="quitFriends()"> |
8 | Quit friends | 19 | Quit friends |
9 | </a> | 20 | </a> |
10 | 21 | ||
11 | <a *ngIf="!hasFriends()" class="btn btn-success pull-right" [routerLink]="['/admin/friends/add']"> | 22 | <a *ngIf="!hasFriends()" class="btn btn-success pull-right" [routerLink]="[ '/admin/friends/add' ]"> |
12 | Make friends | 23 | Make friends |
13 | </a> | 24 | </a> |
14 | </div> | 25 | </div> |
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 @@ | |||
1 | import { Component } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | 2 | ||
3 | import { NotificationsService } from 'angular2-notifications' | 3 | import { NotificationsService } from 'angular2-notifications' |
4 | import { ServerDataSource } from 'ng2-smart-table' | ||
5 | 4 | ||
6 | import { ConfirmService } from '../../../core' | 5 | import { ConfirmService } from '../../../core' |
7 | import { Utils } from '../../../shared' | ||
8 | import { FriendService } from '../shared' | 6 | import { FriendService } from '../shared' |
9 | import { Pod } from '../../../../../../shared' | 7 | import { 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 | }) |
16 | export class FriendListComponent { | 14 | export 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 | } |