diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-23 22:32:43 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-23 22:32:43 +0100 |
commit | b99290b1d5d736083513fb8f66e91f61bfe07e0b (patch) | |
tree | e0e7fa738ee661a267f5330db35bc46d295f945f /client/src/app/admin/friends/friend-add | |
parent | 11ac88de40215783835cf6e6259ff0f6cee258dd (diff) | |
download | PeerTube-b99290b1d5d736083513fb8f66e91f61bfe07e0b.tar.gz PeerTube-b99290b1d5d736083513fb8f66e91f61bfe07e0b.tar.zst PeerTube-b99290b1d5d736083513fb8f66e91f61bfe07e0b.zip |
Client: lazy load admin area
Diffstat (limited to 'client/src/app/admin/friends/friend-add')
4 files changed, 0 insertions, 145 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 eebe033f9..000000000 --- a/client/src/app/admin/friends/friend-add/friend-add.component.html +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | <h3>Make friends</h3> | ||
2 | |||
3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | ||
4 | |||
5 | <form (ngSubmit)="makeFriends()" [formGroup]="form"> | ||
6 | <div class="form-group" *ngFor="let host of hosts; let id = index; trackBy:customTrackBy"> | ||
7 | <label for="username">Host</label> | ||
8 | |||
9 | <div class="input-group"> | ||
10 | <input | ||
11 | type="text" class="form-control" placeholder="domain.tld" | ||
12 | [id]="'host-' + id" [formControlName]="'host-' + id" | ||
13 | /> | ||
14 | <span class="input-group-btn"> | ||
15 | <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button> | ||
16 | <button *ngIf="displayRemoveField(id)" (click)="removeField(id)" class="btn btn-default" type="button">-</button> | ||
17 | </span> | ||
18 | </div> | ||
19 | |||
20 | <div [hidden]="form.controls['host-' + id].valid || form.controls['host-' + id].pristine" class="alert alert-warning"> | ||
21 | It should be a valid host. | ||
22 | </div> | ||
23 | </div> | ||
24 | |||
25 | <div *ngIf="canMakeFriends() === false" class="alert alert-warning"> | ||
26 | It seems that you are not on a HTTPS pod. Your webserver need to have TLS activated in order to make friends. | ||
27 | </div> | ||
28 | |||
29 | <input type="submit" value="Make friends" class="btn btn-default" [disabled]="!isFormValid()"> | ||
30 | </form> | ||
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 014252011..000000000 --- a/client/src/app/admin/friends/friend-add/friend-add.component.ts +++ /dev/null | |||
@@ -1,107 +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 { validateHost } from '../../../shared'; | ||
6 | import { FriendService } from '../shared'; | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-friend-add', | ||
10 | templateUrl: './friend-add.component.html', | ||
11 | styleUrls: [ './friend-add.component.scss' ] | ||
12 | }) | ||
13 | export class FriendAddComponent implements OnInit { | ||
14 | form: FormGroup; | ||
15 | hosts = [ ]; | ||
16 | error: string = null; | ||
17 | |||
18 | constructor(private router: Router, private friendService: FriendService) {} | ||
19 | |||
20 | ngOnInit() { | ||
21 | this.form = new FormGroup({}); | ||
22 | this.addField(); | ||
23 | } | ||
24 | |||
25 | addField() { | ||
26 | this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ])); | ||
27 | this.hosts.push(''); | ||
28 | } | ||
29 | |||
30 | canMakeFriends() { | ||
31 | return window.location.protocol === 'https:'; | ||
32 | } | ||
33 | |||
34 | customTrackBy(index: number, obj: any): any { | ||
35 | return index; | ||
36 | } | ||
37 | |||
38 | displayAddField(index: number) { | ||
39 | return index === (this.hosts.length - 1); | ||
40 | } | ||
41 | |||
42 | displayRemoveField(index: number) { | ||
43 | return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1); | ||
44 | } | ||
45 | |||
46 | isFormValid() { | ||
47 | // Do not check the last input | ||
48 | for (let i = 0; i < this.hosts.length - 1; i++) { | ||
49 | if (!this.form.controls[`host-${i}`].valid) return false; | ||
50 | } | ||
51 | |||
52 | const lastIndex = this.hosts.length - 1; | ||
53 | // If the last input (which is not the first) is empty, it's ok | ||
54 | if (this.hosts[lastIndex] === '' && lastIndex !== 0) { | ||
55 | return true; | ||
56 | } else { | ||
57 | return this.form.controls[`host-${lastIndex}`].valid; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | removeField(index: number) { | ||
62 | // Remove the last control | ||
63 | this.form.removeControl(`host-${this.hosts.length - 1}`); | ||
64 | this.hosts.splice(index, 1); | ||
65 | } | ||
66 | |||
67 | makeFriends() { | ||
68 | this.error = ''; | ||
69 | |||
70 | const notEmptyHosts = this.getNotEmptyHosts(); | ||
71 | if (notEmptyHosts.length === 0) { | ||
72 | this.error = 'You need to specify at least 1 host.'; | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | if (!this.isHostsUnique(notEmptyHosts)) { | ||
77 | this.error = 'Hosts need to be unique.'; | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyHosts.join('\n - '); | ||
82 | if (!confirm(confirmMessage)) return; | ||
83 | |||
84 | this.friendService.makeFriends(notEmptyHosts).subscribe( | ||
85 | status => { | ||
86 | alert('Make friends request sent!'); | ||
87 | this.router.navigate([ '/admin/friends/list' ]); | ||
88 | }, | ||
89 | error => alert(error.text) | ||
90 | ); | ||
91 | } | ||
92 | |||
93 | private getNotEmptyHosts() { | ||
94 | const notEmptyHosts = []; | ||
95 | |||
96 | Object.keys(this.form.value).forEach((hostKey) => { | ||
97 | const host = this.form.value[hostKey]; | ||
98 | if (host !== '') notEmptyHosts.push(host); | ||
99 | }); | ||
100 | |||
101 | return notEmptyHosts; | ||
102 | } | ||
103 | |||
104 | private isHostsUnique(hosts: string[]) { | ||
105 | return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host)); | ||
106 | } | ||
107 | } | ||
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 a101b3be5..000000000 --- a/client/src/app/admin/friends/friend-add/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './friend-add.component'; | ||