aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/friends
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin/friends')
-rw-r--r--client/src/app/+admin/friends/friend-add/friend-add.component.ts5
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.html15
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.ts88
-rw-r--r--client/src/app/+admin/friends/shared/friend.service.ts24
4 files changed, 57 insertions, 75 deletions
diff --git a/client/src/app/+admin/friends/friend-add/friend-add.component.ts b/client/src/app/+admin/friends/friend-add/friend-add.component.ts
index 0449d26a9..02543d393 100644
--- a/client/src/app/+admin/friends/friend-add/friend-add.component.ts
+++ b/client/src/app/+admin/friends/friend-add/friend-add.component.ts
@@ -93,8 +93,9 @@ export class FriendAddComponent implements OnInit {
93 93
94 this.friendService.makeFriends(notEmptyHosts).subscribe( 94 this.friendService.makeFriends(notEmptyHosts).subscribe(
95 status => { 95 status => {
96 this.notificationsService.success('Sucess', 'Make friends request sent!') 96 this.notificationsService.success('Success', 'Make friends request sent!')
97 this.router.navigate([ '/admin/friends/list' ]) 97 // Wait requests between pods
98 setTimeout(() => this.router.navigate([ '/admin/friends/list' ]), 1000)
98 }, 99 },
99 100
100 err => this.notificationsService.error('Error', err.text) 101 err => this.notificationsService.error('Error', err.text)
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 @@
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}
diff --git a/client/src/app/+admin/friends/shared/friend.service.ts b/client/src/app/+admin/friends/shared/friend.service.ts
index 9b3ff04b1..45607e28d 100644
--- a/client/src/app/+admin/friends/shared/friend.service.ts
+++ b/client/src/app/+admin/friends/shared/friend.service.ts
@@ -1,24 +1,24 @@
1import { Injectable } from '@angular/core' 1import { Injectable } from '@angular/core'
2import { Observable } from 'rxjs/Observable' 2import { HttpClient } from '@angular/common/http'
3import 'rxjs/add/operator/catch' 3import 'rxjs/add/operator/catch'
4import 'rxjs/add/operator/map' 4import 'rxjs/add/operator/map'
5 5
6import { ServerDataSource } from 'ng2-smart-table' 6import { RestExtractor, } from '../../../shared'
7 7import { Pod, ResultList } from '../../../../../../shared'
8import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared'
9import { Pod } from '../../../../../../shared'
10 8
11@Injectable() 9@Injectable()
12export class FriendService { 10export class FriendService {
13 private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/' 11 private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/'
14 12
15 constructor ( 13 constructor (
16 private authHttp: AuthHttp, 14 private authHttp: HttpClient,
17 private restExtractor: RestExtractor 15 private restExtractor: RestExtractor
18 ) {} 16 ) {}
19 17
20 getDataSource () { 18 getFriends () {
21 return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL) 19 return this.authHttp.get<ResultList<Pod>>(FriendService.BASE_FRIEND_URL)
20 .map(res => this.restExtractor.convertResultListDateToHuman(res))
21 .catch(res => this.restExtractor.handleError(res))
22 } 22 }
23 23
24 makeFriends (notEmptyHosts: String[]) { 24 makeFriends (notEmptyHosts: String[]) {
@@ -28,18 +28,18 @@ export class FriendService {
28 28
29 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'make-friends', body) 29 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'make-friends', body)
30 .map(this.restExtractor.extractDataBool) 30 .map(this.restExtractor.extractDataBool)
31 .catch((res) => this.restExtractor.handleError(res)) 31 .catch(res => this.restExtractor.handleError(res))
32 } 32 }
33 33
34 quitFriends () { 34 quitFriends () {
35 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quit-friends') 35 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quit-friends')
36 .map(res => res.status) 36 .map(this.restExtractor.extractDataBool)
37 .catch((res) => this.restExtractor.handleError(res)) 37 .catch(res => this.restExtractor.handleError(res))
38 } 38 }
39 39
40 removeFriend (friend: Pod) { 40 removeFriend (friend: Pod) {
41 return this.authHttp.delete(FriendService.BASE_FRIEND_URL + friend.id) 41 return this.authHttp.delete(FriendService.BASE_FRIEND_URL + friend.id)
42 .map(this.restExtractor.extractDataBool) 42 .map(this.restExtractor.extractDataBool)
43 .catch((res) => this.restExtractor.handleError(res)) 43 .catch(res => this.restExtractor.handleError(res))
44 } 44 }
45} 45}