aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/admin/admin.routes.ts5
-rw-r--r--client/src/app/admin/friends/friend-add/friend-add.component.html18
-rw-r--r--client/src/app/admin/friends/friend-add/friend-add.component.scss3
-rw-r--r--client/src/app/admin/friends/friend-add/friend-add.component.ts99
-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.html2
-rw-r--r--client/src/app/admin/friends/friend-list/friend-list.component.ts4
-rw-r--r--client/src/app/admin/friends/friends.routes.ts5
-rw-r--r--client/src/app/admin/friends/index.ts3
-rw-r--r--client/src/app/admin/friends/shared/friend.service.ts8
-rw-r--r--client/src/app/admin/menu-admin.component.html4
-rw-r--r--client/src/app/menu.component.html2
12 files changed, 146 insertions, 8 deletions
diff --git a/client/src/app/admin/admin.routes.ts b/client/src/app/admin/admin.routes.ts
index f57deef62..80b3ecbc1 100644
--- a/client/src/app/admin/admin.routes.ts
+++ b/client/src/app/admin/admin.routes.ts
@@ -9,6 +9,11 @@ export const AdminRoutes: RouterConfig = [
9 path: 'admin', 9 path: 'admin',
10 component: AdminComponent, 10 component: AdminComponent,
11 children: [ 11 children: [
12 {
13 path: '',
14 redirectTo: 'users',
15 pathMatch: 'full'
16 },
12 ...FriendsRoutes, 17 ...FriendsRoutes,
13 ...UsersRoutes 18 ...UsersRoutes
14 ] 19 ]
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
new file mode 100644
index 000000000..a52965e8f
--- /dev/null
+++ b/client/src/app/admin/friends/friend-add/friend-add.component.html
@@ -0,0 +1,18 @@
1<h3>Make friends</h3>
2
3<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
4
5<form role="form" (ngSubmit)="makeFriends()">
6 <div class="form-group" *ngFor="let url of urls; let id = index; trackBy:customTrackBy">
7 <label for="username">Url</label>
8 <div class="input-group">
9 <input type="text" class="form-control" name="url" id="url" placeholder="http://domain.com" [(ngModel)]="urls[id]" />
10 <span class="input-group-btn">
11 <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button>
12 <button *ngIf="displayRemoveField(id)" (click)="removeField(index)" class="btn btn-default" type="button">-</button>
13 </span>
14 </div>
15 </div>
16
17 <input type="submit" value="Make friends" class="btn btn-default">
18</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
new file mode 100644
index 000000000..cb597e12b
--- /dev/null
+++ b/client/src/app/admin/friends/friend-add/friend-add.component.scss
@@ -0,0 +1,3 @@
1table {
2 margin-bottom: 40px;
3}
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
new file mode 100644
index 000000000..30dbf4d36
--- /dev/null
+++ b/client/src/app/admin/friends/friend-add/friend-add.component.ts
@@ -0,0 +1,99 @@
1import { Component } from '@angular/core';
2import { Router } from '@angular/router';
3
4import { FriendService } from '../shared';
5
6@Component({
7 selector: 'my-friend-add',
8 template: require('./friend-add.component.html'),
9 styles: [ require('./friend-add.component.scss') ]
10})
11export class FriendAddComponent {
12 urls = [ '' ];
13 error: string = null;
14
15 constructor(private router: Router, private friendService: FriendService) {}
16
17 addField() {
18 this.urls.push('');
19 }
20
21 customTrackBy(index: number, obj: any): any {
22 return index;
23 }
24
25 displayAddField(index: number) {
26 return index === (this.urls.length - 1);
27 }
28
29 displayRemoveField(index: number) {
30 return (index !== 0 || this.urls.length > 1) && index !== (this.urls.length - 1);
31 }
32
33 removeField(index: number) {
34 this.urls.splice(index, 1);
35 }
36
37 makeFriends() {
38 this.error = '';
39
40 const notEmptyUrls = this.getNotEmptyUrls();
41 if (notEmptyUrls.length === 0) {
42 this.error = 'You need to specify at less 1 url.';
43 return;
44 }
45
46 if (!this.isUrlsRegexValid(notEmptyUrls)) {
47 this.error = 'Some url(s) are not valid.';
48 return;
49 }
50
51 if (!this.isUrlsUnique(notEmptyUrls)) {
52 this.error = 'Urls need to be unique.';
53 return;
54 }
55
56 const confirmMessage = 'Are you sure to make friends with:\n - ' + this.urls.join('\n - ');
57 if (!confirm(confirmMessage)) return;
58
59 this.friendService.makeFriends(notEmptyUrls).subscribe(
60 status => {
61 if (status === 409) {
62 alert('Already made friends!');
63 } else {
64 alert('Made friends!');
65 }
66 },
67 error => alert(error)
68 );
69 }
70
71 private getNotEmptyUrls() {
72 const notEmptyUrls = [];
73
74 this.urls.forEach((url) => {
75 if (url !== '') notEmptyUrls.push(url);
76 });
77
78 return notEmptyUrls;
79 }
80
81 // Temporary
82 // Use HTML validators
83 private isUrlsRegexValid(urls: string[]) {
84 let res = true;
85
86 const urlRegex = new RegExp('^https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$');
87 urls.forEach((url) => {
88 if (urlRegex.test(url) === false) {
89 res = false;
90 }
91 });
92
93 return res;
94 }
95
96 private isUrlsUnique(urls: string[]) {
97 return urls.every(url => urls.indexOf(url) === urls.lastIndexOf(url));
98 }
99}
diff --git a/client/src/app/admin/friends/friend-add/index.ts b/client/src/app/admin/friends/friend-add/index.ts
new file mode 100644
index 000000000..a101b3be5
--- /dev/null
+++ b/client/src/app/admin/friends/friend-add/index.ts
@@ -0,0 +1 @@
export * 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
index f4d14293e..4be3d364f 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
@@ -18,6 +18,6 @@
18 Quit friends 18 Quit friends
19</a> 19</a>
20 20
21<a class="add-user btn btn-success pull-right" (click)="makeFriends()"> 21<a class="add-user btn btn-success pull-right" [routerLink]="['/admin/friends/add']">
22 Make friends 22 Make friends
23</a> 23</a>
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
index bf66d3ff1..aa92c1b1e 100644
--- a/client/src/app/admin/friends/friend-list/friend-list.component.ts
+++ b/client/src/app/admin/friends/friend-list/friend-list.component.ts
@@ -1,11 +1,13 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core';
2import { ROUTER_DIRECTIVES } from '@angular/router';
2 3
3import { Friend, FriendService } from '../shared'; 4import { Friend, FriendService } from '../shared';
4 5
5@Component({ 6@Component({
6 selector: 'my-friend-list', 7 selector: 'my-friend-list',
7 template: require('./friend-list.component.html'), 8 template: require('./friend-list.component.html'),
8 styles: [ require('./friend-list.component.scss') ] 9 styles: [ require('./friend-list.component.scss') ],
10 directives: [ ROUTER_DIRECTIVES ]
9}) 11})
10export class FriendListComponent implements OnInit { 12export class FriendListComponent implements OnInit {
11 friends: Friend[]; 13 friends: Friend[];
diff --git a/client/src/app/admin/friends/friends.routes.ts b/client/src/app/admin/friends/friends.routes.ts
index 1e3646395..42b4a6c14 100644
--- a/client/src/app/admin/friends/friends.routes.ts
+++ b/client/src/app/admin/friends/friends.routes.ts
@@ -1,6 +1,7 @@
1import { RouterConfig } from '@angular/router'; 1import { RouterConfig } from '@angular/router';
2 2
3import { FriendsComponent } from './friends.component'; 3import { FriendsComponent } from './friends.component';
4import { FriendAddComponent } from './friend-add';
4import { FriendListComponent } from './friend-list'; 5import { FriendListComponent } from './friend-list';
5 6
6export const FriendsRoutes: RouterConfig = [ 7export const FriendsRoutes: RouterConfig = [
@@ -16,6 +17,10 @@ export const FriendsRoutes: RouterConfig = [
16 { 17 {
17 path: 'list', 18 path: 'list',
18 component: FriendListComponent 19 component: FriendListComponent
20 },
21 {
22 path: 'add',
23 component: FriendAddComponent
19 } 24 }
20 ] 25 ]
21 } 26 }
diff --git a/client/src/app/admin/friends/index.ts b/client/src/app/admin/friends/index.ts
index 01aeedeee..f3110e31d 100644
--- a/client/src/app/admin/friends/index.ts
+++ b/client/src/app/admin/friends/index.ts
@@ -1,3 +1,4 @@
1export * from './shared'; 1export * from './friend-add';
2export * from './friend-list'; 2export * from './friend-list';
3export * from './shared';
3export * from './friends.routes'; 4export * 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
index da4d64611..e4e680c29 100644
--- a/client/src/app/admin/friends/shared/friend.service.ts
+++ b/client/src/app/admin/friends/shared/friend.service.ts
@@ -20,8 +20,12 @@ export class FriendService {
20 .catch(this.handleError); 20 .catch(this.handleError);
21 } 21 }
22 22
23 makeFriends() { 23 makeFriends(notEmptyUrls) {
24 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'makefriends') 24 const body = {
25 urls: notEmptyUrls
26 };
27
28 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
25 .map(res => res.status) 29 .map(res => res.status)
26 .catch(this.handleError); 30 .catch(this.handleError);
27 } 31 }
diff --git a/client/src/app/admin/menu-admin.component.html b/client/src/app/admin/menu-admin.component.html
index 092ab6081..26a3f3492 100644
--- a/client/src/app/admin/menu-admin.component.html
+++ b/client/src/app/admin/menu-admin.component.html
@@ -8,14 +8,14 @@
8 8
9 <div id="panel-friends" class="panel-button"> 9 <div id="panel-friends" class="panel-button">
10 <span class="hidden-xs glyphicon glyphicon-cloud"></span> 10 <span class="hidden-xs glyphicon glyphicon-cloud"></span>
11 <a [routerLink]="['/admin/friends/list']">Friends</a> 11 <a [routerLink]="['/admin/friends/list']">List friends</a>
12 </div> 12 </div>
13 </div> 13 </div>
14 14
15 <div class="panel-block"> 15 <div class="panel-block">
16 <div id="panel-quit-administration" class="panel-button"> 16 <div id="panel-quit-administration" class="panel-button">
17 <span class="hidden-xs glyphicon glyphicon-cog"></span> 17 <span class="hidden-xs glyphicon glyphicon-cog"></span>
18 <a (click)="quitAdmin()">Quit admin.</a> 18 <a [routerLink]="['/videos/list']" (click)="quitAdmin()">Quit admin.</a>
19 </div> 19 </div>
20 </div> 20 </div>
21</menu> 21</menu>
diff --git a/client/src/app/menu.component.html b/client/src/app/menu.component.html
index 922375395..8ea99138d 100644
--- a/client/src/app/menu.component.html
+++ b/client/src/app/menu.component.html
@@ -33,7 +33,7 @@
33 <div class="panel-block" *ngIf="isUserAdmin()"> 33 <div class="panel-block" *ngIf="isUserAdmin()">
34 <div id="panel-get-videos" class="panel-button"> 34 <div id="panel-get-videos" class="panel-button">
35 <span class="hidden-xs glyphicon glyphicon-cog"></span> 35 <span class="hidden-xs glyphicon glyphicon-cog"></span>
36 <a (click)="enterInAdmin()">Administration</a> 36 <a [routerLink]="['/admin']" (click)="enterInAdmin()">Administration</a>
37 </div> 37 </div>
38 </div> 38 </div>
39</menu> 39</menu>