diff options
Diffstat (limited to 'client/src/app/admin/friends')
5 files changed, 39 insertions, 39 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 index 788f3b44d..621822860 100644 --- a/client/src/app/admin/friends/friend-add/friend-add.component.html +++ b/client/src/app/admin/friends/friend-add/friend-add.component.html | |||
@@ -3,13 +3,13 @@ | |||
3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | 3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> |
4 | 4 | ||
5 | <form (ngSubmit)="makeFriends()" [formGroup]="form"> | 5 | <form (ngSubmit)="makeFriends()" [formGroup]="form"> |
6 | <div class="form-group" *ngFor="let url of urls; let id = index; trackBy:customTrackBy"> | 6 | <div class="form-group" *ngFor="let host of hosts; let id = index; trackBy:customTrackBy"> |
7 | <label for="username">Url</label> | 7 | <label for="username">Host</label> |
8 | 8 | ||
9 | <div class="input-group"> | 9 | <div class="input-group"> |
10 | <input | 10 | <input |
11 | type="text" class="form-control" placeholder="http://domain.com" | 11 | type="text" class="form-control" placeholder="domain.tld" |
12 | [id]="'url-' + id" [formControlName]="'url-' + id" | 12 | [id]="'host-' + id" [formControlName]="'host-' + id" |
13 | /> | 13 | /> |
14 | <span class="input-group-btn"> | 14 | <span class="input-group-btn"> |
15 | <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button> | 15 | <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button> |
@@ -17,8 +17,8 @@ | |||
17 | </span> | 17 | </span> |
18 | </div> | 18 | </div> |
19 | 19 | ||
20 | <div [hidden]="form.controls['url-' + id].valid || form.controls['url-' + id].pristine" class="alert alert-warning"> | 20 | <div [hidden]="form.controls['host-' + id].valid || form.controls['host-' + id].pristine" class="alert alert-warning"> |
21 | It should be a valid url. | 21 | It should be a valid host. |
22 | </div> | 22 | </div> |
23 | </div> | 23 | </div> |
24 | 24 | ||
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 index 64165a9a5..86b018de2 100644 --- a/client/src/app/admin/friends/friend-add/friend-add.component.ts +++ b/client/src/app/admin/friends/friend-add/friend-add.component.ts | |||
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; | |||
2 | import { FormControl, FormGroup } from '@angular/forms'; | 2 | import { FormControl, FormGroup } from '@angular/forms'; |
3 | import { Router } from '@angular/router'; | 3 | import { Router } from '@angular/router'; |
4 | 4 | ||
5 | import { validateUrl } from '../../../shared'; | 5 | import { validateHost } from '../../../shared'; |
6 | import { FriendService } from '../shared'; | 6 | import { FriendService } from '../shared'; |
7 | 7 | ||
8 | @Component({ | 8 | @Component({ |
@@ -12,7 +12,7 @@ import { FriendService } from '../shared'; | |||
12 | }) | 12 | }) |
13 | export class FriendAddComponent implements OnInit { | 13 | export class FriendAddComponent implements OnInit { |
14 | form: FormGroup; | 14 | form: FormGroup; |
15 | urls = [ ]; | 15 | hosts = [ ]; |
16 | error: string = null; | 16 | error: string = null; |
17 | 17 | ||
18 | constructor(private router: Router, private friendService: FriendService) {} | 18 | constructor(private router: Router, private friendService: FriendService) {} |
@@ -23,8 +23,8 @@ export class FriendAddComponent implements OnInit { | |||
23 | } | 23 | } |
24 | 24 | ||
25 | addField() { | 25 | addField() { |
26 | this.form.addControl(`url-${this.urls.length}`, new FormControl('', [ validateUrl ])); | 26 | this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ])); |
27 | this.urls.push(''); | 27 | this.hosts.push(''); |
28 | } | 28 | } |
29 | 29 | ||
30 | customTrackBy(index: number, obj: any): any { | 30 | customTrackBy(index: number, obj: any): any { |
@@ -32,52 +32,52 @@ export class FriendAddComponent implements OnInit { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | displayAddField(index: number) { | 34 | displayAddField(index: number) { |
35 | return index === (this.urls.length - 1); | 35 | return index === (this.hosts.length - 1); |
36 | } | 36 | } |
37 | 37 | ||
38 | displayRemoveField(index: number) { | 38 | displayRemoveField(index: number) { |
39 | return (index !== 0 || this.urls.length > 1) && index !== (this.urls.length - 1); | 39 | return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1); |
40 | } | 40 | } |
41 | 41 | ||
42 | isFormValid() { | 42 | isFormValid() { |
43 | // Do not check the last input | 43 | // Do not check the last input |
44 | for (let i = 0; i < this.urls.length - 1; i++) { | 44 | for (let i = 0; i < this.hosts.length - 1; i++) { |
45 | if (!this.form.controls[`url-${i}`].valid) return false; | 45 | if (!this.form.controls[`host-${i}`].valid) return false; |
46 | } | 46 | } |
47 | 47 | ||
48 | const lastIndex = this.urls.length - 1; | 48 | const lastIndex = this.hosts.length - 1; |
49 | // If the last input (which is not the first) is empty, it's ok | 49 | // If the last input (which is not the first) is empty, it's ok |
50 | if (this.urls[lastIndex] === '' && lastIndex !== 0) { | 50 | if (this.hosts[lastIndex] === '' && lastIndex !== 0) { |
51 | return true; | 51 | return true; |
52 | } else { | 52 | } else { |
53 | return this.form.controls[`url-${lastIndex}`].valid; | 53 | return this.form.controls[`host-${lastIndex}`].valid; |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | removeField(index: number) { | 57 | removeField(index: number) { |
58 | // Remove the last control | 58 | // Remove the last control |
59 | this.form.removeControl(`url-${this.urls.length - 1}`); | 59 | this.form.removeControl(`host-${this.hosts.length - 1}`); |
60 | this.urls.splice(index, 1); | 60 | this.hosts.splice(index, 1); |
61 | } | 61 | } |
62 | 62 | ||
63 | makeFriends() { | 63 | makeFriends() { |
64 | this.error = ''; | 64 | this.error = ''; |
65 | 65 | ||
66 | const notEmptyUrls = this.getNotEmptyUrls(); | 66 | const notEmptyHosts = this.getNotEmptyHosts(); |
67 | if (notEmptyUrls.length === 0) { | 67 | if (notEmptyHosts.length === 0) { |
68 | this.error = 'You need to specify at less 1 url.'; | 68 | this.error = 'You need to specify at least 1 host.'; |
69 | return; | 69 | return; |
70 | } | 70 | } |
71 | 71 | ||
72 | if (!this.isUrlsUnique(notEmptyUrls)) { | 72 | if (!this.isHostsUnique(notEmptyHosts)) { |
73 | this.error = 'Urls need to be unique.'; | 73 | this.error = 'Hosts need to be unique.'; |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | 76 | ||
77 | const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyUrls.join('\n - '); | 77 | const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyHosts.join('\n - '); |
78 | if (!confirm(confirmMessage)) return; | 78 | if (!confirm(confirmMessage)) return; |
79 | 79 | ||
80 | this.friendService.makeFriends(notEmptyUrls).subscribe( | 80 | this.friendService.makeFriends(notEmptyHosts).subscribe( |
81 | status => { | 81 | status => { |
82 | // TODO: extractdatastatus | 82 | // TODO: extractdatastatus |
83 | // if (status === 409) { | 83 | // if (status === 409) { |
@@ -91,18 +91,18 @@ export class FriendAddComponent implements OnInit { | |||
91 | ); | 91 | ); |
92 | } | 92 | } |
93 | 93 | ||
94 | private getNotEmptyUrls() { | 94 | private getNotEmptyHosts() { |
95 | const notEmptyUrls = []; | 95 | const notEmptyHosts = []; |
96 | 96 | ||
97 | Object.keys(this.form.value).forEach((urlKey) => { | 97 | Object.keys(this.form.value).forEach((hostKey) => { |
98 | const url = this.form.value[urlKey]; | 98 | const host = this.form.value[hostKey]; |
99 | if (url !== '') notEmptyUrls.push(url); | 99 | if (host !== '') notEmptyHosts.push(host); |
100 | }); | 100 | }); |
101 | 101 | ||
102 | return notEmptyUrls; | 102 | return notEmptyHosts; |
103 | } | 103 | } |
104 | 104 | ||
105 | private isUrlsUnique(urls: string[]) { | 105 | private isHostsUnique(hosts: string[]) { |
106 | return urls.every(url => urls.indexOf(url) === urls.lastIndexOf(url)); | 106 | return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host)); |
107 | } | 107 | } |
108 | } | 108 | } |
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 index 20b4d12db..4236fc5f6 100644 --- a/client/src/app/admin/friends/friend-list/friend-list.component.html +++ b/client/src/app/admin/friends/friend-list/friend-list.component.html | |||
@@ -4,7 +4,7 @@ | |||
4 | <thead> | 4 | <thead> |
5 | <tr> | 5 | <tr> |
6 | <th class="table-column-id">ID</th> | 6 | <th class="table-column-id">ID</th> |
7 | <th>Url</th> | 7 | <th>Host</th> |
8 | <th>Score</th> | 8 | <th>Score</th> |
9 | <th>Created Date</th> | 9 | <th>Created Date</th> |
10 | </tr> | 10 | </tr> |
@@ -13,7 +13,7 @@ | |||
13 | <tbody> | 13 | <tbody> |
14 | <tr *ngFor="let friend of friends"> | 14 | <tr *ngFor="let friend of friends"> |
15 | <td>{{ friend.id }}</td> | 15 | <td>{{ friend.id }}</td> |
16 | <td>{{ friend.url }}</td> | 16 | <td>{{ friend.host }}</td> |
17 | <td>{{ friend.score }}</td> | 17 | <td>{{ friend.score }}</td> |
18 | <td>{{ friend.createdDate | date: 'medium' }}</td> | 18 | <td>{{ friend.createdDate | date: 'medium' }}</td> |
19 | </tr> | 19 | </tr> |
diff --git a/client/src/app/admin/friends/shared/friend.model.ts b/client/src/app/admin/friends/shared/friend.model.ts index 7cb28f440..3c23feebc 100644 --- a/client/src/app/admin/friends/shared/friend.model.ts +++ b/client/src/app/admin/friends/shared/friend.model.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | export interface Friend { | 1 | export interface Friend { |
2 | id: string; | 2 | id: string; |
3 | url: string; | 3 | host: string; |
4 | score: number; | 4 | score: number; |
5 | createdDate: Date; | 5 | createdDate: Date; |
6 | } | 6 | } |
diff --git a/client/src/app/admin/friends/shared/friend.service.ts b/client/src/app/admin/friends/shared/friend.service.ts index 75826fc17..8a1ba6b02 100644 --- a/client/src/app/admin/friends/shared/friend.service.ts +++ b/client/src/app/admin/friends/shared/friend.service.ts | |||
@@ -21,9 +21,9 @@ export class FriendService { | |||
21 | .catch((res) => this.restExtractor.handleError(res)); | 21 | .catch((res) => this.restExtractor.handleError(res)); |
22 | } | 22 | } |
23 | 23 | ||
24 | makeFriends(notEmptyUrls) { | 24 | makeFriends(notEmptyHosts) { |
25 | const body = { | 25 | const body = { |
26 | urls: notEmptyUrls | 26 | hosts: notEmptyHosts |
27 | }; | 27 | }; |
28 | 28 | ||
29 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) | 29 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) |