]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/friends/friend-list/friend-list.component.ts
Client: replace simple tables by ng2 smart table component
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / friends / friend-list / friend-list.component.ts
1 import { Component } from '@angular/core';
2
3 import { NotificationsService } from 'angular2-notifications';
4 import { ServerDataSource } from 'ng2-smart-table';
5
6 import { ConfirmService } from '../../../core';
7 import { Utils } from '../../../shared';
8 import { Friend, FriendService } from '../shared';
9
10 @Component({
11 selector: 'my-friend-list',
12 templateUrl: './friend-list.component.html',
13 styleUrls: [ './friend-list.component.scss' ]
14 })
15 export class FriendListComponent {
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 }
49
50 constructor(
51 private notificationsService: NotificationsService,
52 private confirmService: ConfirmService,
53 private friendService: FriendService
54 ) {
55 this.friendsSource = this.friendService.getDataSource();
56 }
57
58 hasFriends() {
59 return this.friendsSource.count() != 0;
60 }
61
62 quitFriends() {
63 const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.';
64 this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
65 res => {
66 if (res === false) return;
67
68 this.friendService.quitFriends().subscribe(
69 status => {
70 this.notificationsService.success('Sucess', 'Friends left!');
71
72 this.friendsSource.refresh();
73 },
74
75 err => this.notificationsService.error('Error', err.text)
76 );
77 }
78 );
79 }
80 }