aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/friends
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-30 22:41:14 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-30 22:41:14 +0100
commit28798b5d949826551740fc893d06e6424b77aa6a (patch)
treee235a7f49164a06c4b76df49ca61b89998d4ed81 /client/src/app/+admin/friends
parent13fc89f4a4b91b3da10493517de556240fb65463 (diff)
downloadPeerTube-28798b5d949826551740fc893d06e6424b77aa6a.tar.gz
PeerTube-28798b5d949826551740fc893d06e6424b77aa6a.tar.zst
PeerTube-28798b5d949826551740fc893d06e6424b77aa6a.zip
Client: replace simple tables by ng2 smart table component
Diffstat (limited to 'client/src/app/+admin/friends')
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.html24
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.ts58
-rw-r--r--client/src/app/+admin/friends/shared/friend.service.ts18
3 files changed, 51 insertions, 49 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 06258f8c8..254d0c65e 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
@@ -1,29 +1,11 @@
1<h3>Friends list</h3> 1<h3>Friends list</h3>
2 2
3<table class="table table-hover"> 3<ng2-smart-table [settings]="tableSettings" [source]="friendsSource"></ng2-smart-table>
4 <thead>
5 <tr>
6 <th class="table-column-id">ID</th>
7 <th>Host</th>
8 <th>Score</th>
9 <th>Created Date</th>
10 </tr>
11 </thead>
12 4
13 <tbody> 5<a *ngIf="hasFriends()" class="add-user btn btn-danger pull-left" (click)="quitFriends()">
14 <tr *ngFor="let friend of friends">
15 <td>{{ friend.id }}</td>
16 <td>{{ friend.host }}</td>
17 <td>{{ friend.score }}</td>
18 <td>{{ friend.createdAt | date: 'medium' }}</td>
19 </tr>
20 </tbody>
21</table>
22
23<a *ngIf="friends && friends.length !== 0" class="add-user btn btn-danger pull-left" (click)="quitFriends()">
24 Quit friends 6 Quit friends
25</a> 7</a>
26 8
27<a *ngIf="friends?.length === 0" class="add-user btn btn-success pull-right" [routerLink]="['/admin/friends/add']"> 9<a *ngIf="!hasFriends()" class="add-user btn btn-success pull-right" [routerLink]="['/admin/friends/add']">
28 Make friends 10 Make friends
29</a> 11</a>
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 175ad9cba..f29427640 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,8 +1,10 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component } from '@angular/core';
2 2
3import { NotificationsService } from 'angular2-notifications'; 3import { NotificationsService } from 'angular2-notifications';
4import { ServerDataSource } from 'ng2-smart-table';
4 5
5import { ConfirmService } from '../../../core'; 6import { ConfirmService } from '../../../core';
7import { Utils } from '../../../shared';
6import { Friend, FriendService } from '../shared'; 8import { Friend, FriendService } from '../shared';
7 9
8@Component({ 10@Component({
@@ -10,17 +12,51 @@ import { Friend, FriendService } from '../shared';
10 templateUrl: './friend-list.component.html', 12 templateUrl: './friend-list.component.html',
11 styleUrls: [ './friend-list.component.scss' ] 13 styleUrls: [ './friend-list.component.scss' ]
12}) 14})
13export class FriendListComponent implements OnInit { 15export class FriendListComponent {
14 friends: Friend[]; 16 friendsSource = null;
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 },
38 score: {
39 title: 'Score',
40 sort: false
41 },
42 createdAt: {
43 title: 'Created Date',
44 sort: false,
45 valuePrepareFunction: Utils.dateToHuman
46 }
47 }
48 }
15 49
16 constructor( 50 constructor(
17 private notificationsService: NotificationsService, 51 private notificationsService: NotificationsService,
18 private confirmService: ConfirmService, 52 private confirmService: ConfirmService,
19 private friendService: FriendService 53 private friendService: FriendService
20 ) { } 54 ) {
55 this.friendsSource = this.friendService.getDataSource();
56 }
21 57
22 ngOnInit() { 58 hasFriends() {
23 this.getFriends(); 59 return this.friendsSource.count() != 0;
24 } 60 }
25 61
26 quitFriends() { 62 quitFriends() {
@@ -33,7 +69,7 @@ export class FriendListComponent implements OnInit {
33 status => { 69 status => {
34 this.notificationsService.success('Sucess', 'Friends left!'); 70 this.notificationsService.success('Sucess', 'Friends left!');
35 71
36 this.getFriends(); 72 this.friendsSource.refresh();
37 }, 73 },
38 74
39 err => this.notificationsService.error('Error', err.text) 75 err => this.notificationsService.error('Error', err.text)
@@ -41,12 +77,4 @@ export class FriendListComponent implements OnInit {
41 } 77 }
42 ); 78 );
43 } 79 }
44
45 private getFriends() {
46 this.friendService.getFriends().subscribe(
47 res => this.friends = res.friends,
48
49 err => this.notificationsService.error('Error', err.text)
50 );
51 }
52} 80}
diff --git a/client/src/app/+admin/friends/shared/friend.service.ts b/client/src/app/+admin/friends/shared/friend.service.ts
index e97459385..6cb84f5cd 100644
--- a/client/src/app/+admin/friends/shared/friend.service.ts
+++ b/client/src/app/+admin/friends/shared/friend.service.ts
@@ -3,8 +3,10 @@ import { Observable } from 'rxjs/Observable';
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';
7
6import { Friend } from './friend.model'; 8import { Friend } from './friend.model';
7import { AuthHttp, RestExtractor, ResultList } from '../../../shared'; 9import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared';
8 10
9@Injectable() 11@Injectable()
10export class FriendService { 12export class FriendService {
@@ -15,11 +17,8 @@ export class FriendService {
15 private restExtractor: RestExtractor 17 private restExtractor: RestExtractor
16 ) {} 18 ) {}
17 19
18 getFriends() { 20 getDataSource() {
19 return this.authHttp.get(FriendService.BASE_FRIEND_URL) 21 return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL);
20 .map(this.restExtractor.extractDataList)
21 .map(this.extractFriends)
22 .catch((res) => this.restExtractor.handleError(res));
23 } 22 }
24 23
25 makeFriends(notEmptyHosts) { 24 makeFriends(notEmptyHosts) {
@@ -37,11 +36,4 @@ export class FriendService {
37 .map(res => res.status) 36 .map(res => res.status)
38 .catch((res) => this.restExtractor.handleError(res)); 37 .catch((res) => this.restExtractor.handleError(res));
39 } 38 }
40
41 private extractFriends(result: ResultList) {
42 const friends: Friend[] = result.data;
43 const totalFriends = result.total;
44
45 return { friends, totalFriends };
46 }
47} 39}