aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/friends
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 10:10:41 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit51548b31815c6f96f314ae96588a9adca150519d (patch)
treeb3298447b7ac128823016fdec92d083e07d9432e /client/src/app/+admin/friends
parent350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad (diff)
downloadPeerTube-51548b31815c6f96f314ae96588a9adca150519d.tar.gz
PeerTube-51548b31815c6f96f314ae96588a9adca150519d.tar.zst
PeerTube-51548b31815c6f96f314ae96588a9adca150519d.zip
Add follow tabs
Following Follow Followers
Diffstat (limited to 'client/src/app/+admin/friends')
-rw-r--r--client/src/app/+admin/friends/friend-add/friend-add.component.html35
-rw-r--r--client/src/app/+admin/friends/friend-add/friend-add.component.scss7
-rw-r--r--client/src/app/+admin/friends/friend-add/friend-add.component.ts121
-rw-r--r--client/src/app/+admin/friends/friend-add/index.ts1
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.html29
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.scss3
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.ts87
-rw-r--r--client/src/app/+admin/friends/friend-list/index.ts1
-rw-r--r--client/src/app/+admin/friends/friends.component.ts7
-rw-r--r--client/src/app/+admin/friends/friends.routes.ts43
-rw-r--r--client/src/app/+admin/friends/index.ts5
-rw-r--r--client/src/app/+admin/friends/shared/friend.service.ts52
-rw-r--r--client/src/app/+admin/friends/shared/index.ts1
13 files changed, 0 insertions, 392 deletions
diff --git a/client/src/app/+admin/friends/friend-add/friend-add.component.html b/client/src/app/+admin/friends/friend-add/friend-add.component.html
deleted file mode 100644
index 81d8291cd..000000000
--- a/client/src/app/+admin/friends/friend-add/friend-add.component.html
+++ /dev/null
@@ -1,35 +0,0 @@
1<div class="row">
2 <div class="content-padding">
3
4 <h3>Make friends</h3>
5
6 <div *ngIf="error" class="alert alert-danger">{{ error }}</div>
7
8 <form (ngSubmit)="makeFriends()" [formGroup]="form">
9 <div class="form-group" *ngFor="let host of hosts; let id = index; trackBy:customTrackBy">
10 <label [for]="'host-' + id">Host (so without "http://")</label>
11
12 <div class="input-group">
13 <input
14 type="text" class="form-control" placeholder="example.com"
15 [id]="'host-' + id" [formControlName]="'host-' + id"
16 />
17 <span class="input-group-btn">
18 <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button>
19 <button *ngIf="displayRemoveField(id)" (click)="removeField(id)" class="btn btn-default" type="button">-</button>
20 </span>
21 </div>
22
23 <div [hidden]="form.controls['host-' + id].valid || form.controls['host-' + id].pristine" class="alert alert-warning">
24 It should be a valid host.
25 </div>
26 </div>
27
28 <div *ngIf="canMakeFriends() === false" class="alert alert-warning">
29 It seems that you are not on a HTTPS pod. Your webserver need to have TLS activated in order to make friends.
30 </div>
31
32 <input type="submit" value="Make friends" class="btn btn-default" [disabled]="!isFormValid()">
33 </form>
34 </div>
35</div>
diff --git a/client/src/app/+admin/friends/friend-add/friend-add.component.scss b/client/src/app/+admin/friends/friend-add/friend-add.component.scss
deleted file mode 100644
index 5fde51636..000000000
--- a/client/src/app/+admin/friends/friend-add/friend-add.component.scss
+++ /dev/null
@@ -1,7 +0,0 @@
1table {
2 margin-bottom: 40px;
3}
4
5.input-group-btn button {
6 width: 35px;
7}
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
deleted file mode 100644
index 29ed23e0c..000000000
--- a/client/src/app/+admin/friends/friend-add/friend-add.component.ts
+++ /dev/null
@@ -1,121 +0,0 @@
1import { Component, OnInit } from '@angular/core'
2import { FormControl, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router'
4
5import { NotificationsService } from 'angular2-notifications'
6
7import { ConfirmService } from '../../../core'
8import { validateHost } from '../../../shared'
9import { FriendService } from '../shared'
10
11@Component({
12 selector: 'my-friend-add',
13 templateUrl: './friend-add.component.html',
14 styleUrls: [ './friend-add.component.scss' ]
15})
16export class FriendAddComponent implements OnInit {
17 form: FormGroup
18 hosts: string[] = [ ]
19 error: string = null
20
21 constructor (
22 private router: Router,
23 private notificationsService: NotificationsService,
24 private confirmService: ConfirmService,
25 private friendService: FriendService
26 ) {}
27
28 ngOnInit () {
29 this.form = new FormGroup({})
30 this.addField()
31 }
32
33 addField () {
34 this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ]))
35 this.hosts.push('')
36 }
37
38 canMakeFriends () {
39 return window.location.protocol === 'https:'
40 }
41
42 customTrackBy (index: number, obj: any): any {
43 return index
44 }
45
46 displayAddField (index: number) {
47 return index === (this.hosts.length - 1)
48 }
49
50 displayRemoveField (index: number) {
51 return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1)
52 }
53
54 isFormValid () {
55 // Do not check the last input
56 for (let i = 0; i < this.hosts.length - 1; i++) {
57 if (!this.form.controls[`host-${i}`].valid) return false
58 }
59
60 const lastIndex = this.hosts.length - 1
61 // If the last input (which is not the first) is empty, it's ok
62 if (this.hosts[lastIndex] === '' && lastIndex !== 0) {
63 return true
64 } else {
65 return this.form.controls[`host-${lastIndex}`].valid
66 }
67 }
68
69 removeField (index: number) {
70 // Remove the last control
71 this.form.removeControl(`host-${this.hosts.length - 1}`)
72 this.hosts.splice(index, 1)
73 }
74
75 makeFriends () {
76 this.error = ''
77
78 const notEmptyHosts = this.getNotEmptyHosts()
79 if (notEmptyHosts.length === 0) {
80 this.error = 'You need to specify at least 1 host.'
81 return
82 }
83
84 if (!this.isHostsUnique(notEmptyHosts)) {
85 this.error = 'Hosts need to be unique.'
86 return
87 }
88
89 const confirmMessage = 'Are you sure to make friends with:<br /> - ' + notEmptyHosts.join('<br /> - ')
90 this.confirmService.confirm(confirmMessage, 'Make friends').subscribe(
91 res => {
92 if (res === false) return
93
94 this.friendService.follow(notEmptyHosts).subscribe(
95 status => {
96 this.notificationsService.success('Success', 'Make friends request sent!')
97 // Wait requests between pods
98 setTimeout(() => this.router.navigate([ '/admin/friends/list' ]), 1000)
99 },
100
101 err => this.notificationsService.error('Error', err.message)
102 )
103 }
104 )
105 }
106
107 private getNotEmptyHosts () {
108 const notEmptyHosts = []
109
110 Object.keys(this.form.value).forEach((hostKey) => {
111 const host = this.form.value[hostKey]
112 if (host !== '') notEmptyHosts.push(host)
113 })
114
115 return notEmptyHosts
116 }
117
118 private isHostsUnique (hosts: string[]) {
119 return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host))
120 }
121}
diff --git a/client/src/app/+admin/friends/friend-add/index.ts b/client/src/app/+admin/friends/friend-add/index.ts
deleted file mode 100644
index 978ab3d46..000000000
--- a/client/src/app/+admin/friends/friend-add/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './friend-add.component'
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
deleted file mode 100644
index df5a570fd..000000000
--- a/client/src/app/+admin/friends/friend-list/friend-list.component.html
+++ /dev/null
@@ -1,29 +0,0 @@
1<div class="row">
2 <div class="content-padding">
3 <h3>Friends list</h3>
4
5 <p-dataTable
6 [value]="friends" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
7 sortField="createdAt" (onLazyLoad)="loadLazy($event)"
8 >
9 <p-column field="id" header="ID"></p-column>
10 <p-column field="host" header="Host"></p-column>
11 <p-column field="email" header="Email"></p-column>
12 <p-column field="score" header="Score"></p-column>
13 <p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
14 <p-column header="Delete" styleClass="action-cell">
15 <ng-template pTemplate="body" let-pod="rowData">
16 <span (click)="removeFriend(pod)" class="glyphicon glyphicon-remove glyphicon-black" title="Remove this pod"></span>
17 </ng-template>
18 </p-column>
19 </p-dataTable>
20
21 <a *ngIf="hasFriends()" class="btn btn-danger pull-left" (click)="quitFriends()">
22 Quit friends
23 </a>
24
25 <a *ngIf="!hasFriends()" class="btn btn-success pull-right" [routerLink]="[ '/admin/friends/add' ]">
26 Make friends
27 </a>
28 </div>
29</div>
diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.scss b/client/src/app/+admin/friends/friend-list/friend-list.component.scss
deleted file mode 100644
index 0a0f621c6..000000000
--- a/client/src/app/+admin/friends/friend-list/friend-list.component.scss
+++ /dev/null
@@ -1,3 +0,0 @@
1.btn {
2 margin-top: 10px;
3}
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
deleted file mode 100644
index 3fa8ef19f..000000000
--- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts
+++ /dev/null
@@ -1,87 +0,0 @@
1import { Component, OnInit } from '@angular/core'
2
3import { NotificationsService } from 'angular2-notifications'
4import { SortMeta } from 'primeng/primeng'
5
6import { ConfirmService } from '../../../core'
7import { RestTable, RestPagination } from '../../../shared'
8import { Pod } from '../../../../../../shared'
9import { FriendService } from '../shared'
10
11@Component({
12 selector: 'my-friend-list',
13 templateUrl: './friend-list.component.html',
14 styleUrls: ['./friend-list.component.scss']
15})
16export class FriendListComponent extends RestTable implements OnInit {
17 friends: Pod[] = []
18 totalRecords = 0
19 rowsPerPage = 10
20 sort: SortMeta = { field: 'createdAt', order: 1 }
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22
23 constructor (
24 private notificationsService: NotificationsService,
25 private confirmService: ConfirmService,
26 private friendService: FriendService
27 ) {
28 super()
29 }
30
31 ngOnInit () {
32 this.loadData()
33 }
34
35 hasFriends () {
36 return this.friends.length !== 0
37 }
38
39 quitFriends () {
40 const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'
41 this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
42 res => {
43 if (res === false) return
44
45 this.friendService.quitFriends().subscribe(
46 status => {
47 this.notificationsService.success('Success', 'Friends left!')
48 this.loadData()
49 },
50
51 err => this.notificationsService.error('Error', err.message)
52 )
53 }
54 )
55 }
56
57 removeFriend (friend: Pod) {
58 const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.'
59
60 this.confirmService.confirm(confirmMessage, 'Remove').subscribe(
61 res => {
62 if (res === false) return
63
64 this.friendService.removeFriend(friend).subscribe(
65 status => {
66 this.notificationsService.success('Success', 'Friend removed')
67 this.loadData()
68 },
69
70 err => this.notificationsService.error('Error', err.message)
71 )
72 }
73 )
74 }
75
76 protected loadData () {
77 this.friendService.getFollowing(this.pagination, this.sort)
78 .subscribe(
79 resultList => {
80 this.friends = resultList.data
81 this.totalRecords = resultList.total
82 },
83
84 err => this.notificationsService.error('Error', err.message)
85 )
86 }
87}
diff --git a/client/src/app/+admin/friends/friend-list/index.ts b/client/src/app/+admin/friends/friend-list/index.ts
deleted file mode 100644
index c9cbd2800..000000000
--- a/client/src/app/+admin/friends/friend-list/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './friend-list.component'
diff --git a/client/src/app/+admin/friends/friends.component.ts b/client/src/app/+admin/friends/friends.component.ts
deleted file mode 100644
index 5ef0aaa03..000000000
--- a/client/src/app/+admin/friends/friends.component.ts
+++ /dev/null
@@ -1,7 +0,0 @@
1import { Component } from '@angular/core'
2
3@Component({
4 template: '<router-outlet></router-outlet>'
5})
6export class FriendsComponent {
7}
diff --git a/client/src/app/+admin/friends/friends.routes.ts b/client/src/app/+admin/friends/friends.routes.ts
deleted file mode 100644
index e2cb953b3..000000000
--- a/client/src/app/+admin/friends/friends.routes.ts
+++ /dev/null
@@ -1,43 +0,0 @@
1import { Routes } from '@angular/router'
2
3import { UserRightGuard } from '../../core'
4import { FriendsComponent } from './friends.component'
5import { FriendAddComponent } from './friend-add'
6import { FriendListComponent } from './friend-list'
7import { UserRight } from '../../../../../shared'
8
9export const FriendsRoutes: Routes = [
10 {
11 path: 'friends',
12 component: FriendsComponent,
13 canActivate: [ UserRightGuard ],
14 data: {
15 userRight: UserRight.MANAGE_PEERTUBE_FOLLOW
16 },
17 children: [
18 {
19 path: '',
20 redirectTo: 'list',
21 pathMatch: 'full'
22 },
23 {
24 path: 'list',
25 component: FriendListComponent,
26 data: {
27 meta: {
28 title: 'Friends list'
29 }
30 }
31 },
32 {
33 path: 'add',
34 component: FriendAddComponent,
35 data: {
36 meta: {
37 title: 'Add friends'
38 }
39 }
40 }
41 ]
42 }
43]
diff --git a/client/src/app/+admin/friends/index.ts b/client/src/app/+admin/friends/index.ts
deleted file mode 100644
index 356dee8e9..000000000
--- a/client/src/app/+admin/friends/index.ts
+++ /dev/null
@@ -1,5 +0,0 @@
1export * from './friend-add'
2export * from './friend-list'
3export * from './shared'
4export * from './friends.component'
5export * from './friends.routes'
diff --git a/client/src/app/+admin/friends/shared/friend.service.ts b/client/src/app/+admin/friends/shared/friend.service.ts
deleted file mode 100644
index 867656a53..000000000
--- a/client/src/app/+admin/friends/shared/friend.service.ts
+++ /dev/null
@@ -1,52 +0,0 @@
1import { Injectable } from '@angular/core'
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Observable } from 'rxjs/Observable'
4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'
6
7import { SortMeta } from 'primeng/primeng'
8
9import { RestExtractor, RestPagination, RestService } from '../../../shared'
10import { Pod, ResultList } from '../../../../../../shared'
11
12@Injectable()
13export class FriendService {
14 private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/'
15
16 constructor (
17 private authHttp: HttpClient,
18 private restService: RestService,
19 private restExtractor: RestExtractor
20 ) {}
21
22 getFollowing (pagination: RestPagination, sort: SortMeta): Observable<ResultList<Pod>> {
23 let params = new HttpParams()
24 params = this.restService.addRestGetParams(params, pagination, sort)
25
26 return this.authHttp.get<ResultList<Account>>(API_URL + '/api/v1/pods/followers', { params })
27 .map(res => this.restExtractor.convertResultListDateToHuman(res))
28 .catch(res => this.restExtractor.handleError(res))
29 }
30
31 follow (notEmptyHosts: String[]) {
32 const body = {
33 hosts: notEmptyHosts
34 }
35
36 return this.authHttp.post(API_URL + '/api/v1/pods/follow', body)
37 .map(this.restExtractor.extractDataBool)
38 .catch(res => this.restExtractor.handleError(res))
39 }
40
41 quitFriends () {
42 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quit-friends')
43 .map(this.restExtractor.extractDataBool)
44 .catch(res => this.restExtractor.handleError(res))
45 }
46
47 removeFriend (friend: Pod) {
48 return this.authHttp.delete(FriendService.BASE_FRIEND_URL + friend.id)
49 .map(this.restExtractor.extractDataBool)
50 .catch(res => this.restExtractor.handleError(res))
51 }
52}
diff --git a/client/src/app/+admin/friends/shared/index.ts b/client/src/app/+admin/friends/shared/index.ts
deleted file mode 100644
index 65ab9fb46..000000000
--- a/client/src/app/+admin/friends/shared/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './friend.service'