diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-15 10:10:41 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | 51548b31815c6f96f314ae96588a9adca150519d (patch) | |
tree | b3298447b7ac128823016fdec92d083e07d9432e /client/src/app/+admin/friends/friend-add | |
parent | 350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad (diff) | |
download | PeerTube-51548b31815c6f96f314ae96588a9adca150519d.tar.gz PeerTube-51548b31815c6f96f314ae96588a9adca150519d.tar.zst PeerTube-51548b31815c6f96f314ae96588a9adca150519d.zip |
Add follow tabs
Following
Follow
Followers
Diffstat (limited to 'client/src/app/+admin/friends/friend-add')
4 files changed, 0 insertions, 164 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 @@ | |||
1 | table { | ||
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 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { FormControl, FormGroup } from '@angular/forms' | ||
3 | import { Router } from '@angular/router' | ||
4 | |||
5 | import { NotificationsService } from 'angular2-notifications' | ||
6 | |||
7 | import { ConfirmService } from '../../../core' | ||
8 | import { validateHost } from '../../../shared' | ||
9 | import { FriendService } from '../shared' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-friend-add', | ||
13 | templateUrl: './friend-add.component.html', | ||
14 | styleUrls: [ './friend-add.component.scss' ] | ||
15 | }) | ||
16 | export 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 @@ | |||
1 | export * from './friend-add.component' | ||