diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-30 22:41:14 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-30 22:41:14 +0100 |
commit | 28798b5d949826551740fc893d06e6424b77aa6a (patch) | |
tree | e235a7f49164a06c4b76df49ca61b89998d4ed81 /client/src/app/+admin/friends/friend-list/friend-list.component.ts | |
parent | 13fc89f4a4b91b3da10493517de556240fb65463 (diff) | |
download | PeerTube-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/friend-list/friend-list.component.ts')
-rw-r--r-- | client/src/app/+admin/friends/friend-list/friend-list.component.ts | 58 |
1 files changed, 43 insertions, 15 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 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 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component } from '@angular/core'; |
2 | 2 | ||
3 | import { NotificationsService } from 'angular2-notifications'; | 3 | import { NotificationsService } from 'angular2-notifications'; |
4 | import { ServerDataSource } from 'ng2-smart-table'; | ||
4 | 5 | ||
5 | import { ConfirmService } from '../../../core'; | 6 | import { ConfirmService } from '../../../core'; |
7 | import { Utils } from '../../../shared'; | ||
6 | import { Friend, FriendService } from '../shared'; | 8 | import { 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 | }) |
13 | export class FriendListComponent implements OnInit { | 15 | export 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 | } |