diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
commit | a6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (patch) | |
tree | 03204a408d56311692c3528bedcf95d2455e94f2 /client/src/app/admin | |
parent | 052937db8a8d282eccdbdf38d487ed8d85d3c0a7 (diff) | |
parent | c4403b29ad4db097af528a7f04eea07e0ed320d0 (diff) | |
download | PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.gz PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.zst PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.zip |
Merge branch 'master' into webseed-merged
Diffstat (limited to 'client/src/app/admin')
41 files changed, 794 insertions, 0 deletions
diff --git a/client/src/app/admin/admin.component.ts b/client/src/app/admin/admin.component.ts new file mode 100644 index 000000000..64a7400e7 --- /dev/null +++ b/client/src/app/admin/admin.component.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | |||
3 | @Component({ | ||
4 | template: '<router-outlet></router-outlet>' | ||
5 | }) | ||
6 | |||
7 | export class AdminComponent { | ||
8 | } | ||
diff --git a/client/src/app/admin/admin.routes.ts b/client/src/app/admin/admin.routes.ts new file mode 100644 index 000000000..edb8ba49f --- /dev/null +++ b/client/src/app/admin/admin.routes.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import { Routes } from '@angular/router'; | ||
2 | |||
3 | import { AdminComponent } from './admin.component'; | ||
4 | import { FriendsRoutes } from './friends'; | ||
5 | import { RequestsRoutes } from './requests'; | ||
6 | import { UsersRoutes } from './users'; | ||
7 | |||
8 | export const AdminRoutes: Routes = [ | ||
9 | { | ||
10 | path: 'admin', | ||
11 | component: AdminComponent, | ||
12 | children: [ | ||
13 | { | ||
14 | path: '', | ||
15 | redirectTo: 'users', | ||
16 | pathMatch: 'full' | ||
17 | }, | ||
18 | ...FriendsRoutes, | ||
19 | ...RequestsRoutes, | ||
20 | ...UsersRoutes | ||
21 | ] | ||
22 | } | ||
23 | ]; | ||
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..788f3b44d --- /dev/null +++ b/client/src/app/admin/friends/friend-add/friend-add.component.html | |||
@@ -0,0 +1,26 @@ | |||
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 url of urls; let id = index; trackBy:customTrackBy"> | ||
7 | <label for="username">Url</label> | ||
8 | |||
9 | <div class="input-group"> | ||
10 | <input | ||
11 | type="text" class="form-control" placeholder="http://domain.com" | ||
12 | [id]="'url-' + id" [formControlName]="'url-' + 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['url-' + id].valid || form.controls['url-' + id].pristine" class="alert alert-warning"> | ||
21 | It should be a valid url. | ||
22 | </div> | ||
23 | </div> | ||
24 | |||
25 | <input type="submit" value="Make friends" class="btn btn-default" [disabled]="!isFormValid()"> | ||
26 | </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..5fde51636 --- /dev/null +++ b/client/src/app/admin/friends/friend-add/friend-add.component.scss | |||
@@ -0,0 +1,7 @@ | |||
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 new file mode 100644 index 000000000..64165a9a5 --- /dev/null +++ b/client/src/app/admin/friends/friend-add/friend-add.component.ts | |||
@@ -0,0 +1,108 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | ||
2 | import { FormControl, FormGroup } from '@angular/forms'; | ||
3 | import { Router } from '@angular/router'; | ||
4 | |||
5 | import { validateUrl } 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 | urls = [ ]; | ||
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(`url-${this.urls.length}`, new FormControl('', [ validateUrl ])); | ||
27 | this.urls.push(''); | ||
28 | } | ||
29 | |||
30 | customTrackBy(index: number, obj: any): any { | ||
31 | return index; | ||
32 | } | ||
33 | |||
34 | displayAddField(index: number) { | ||
35 | return index === (this.urls.length - 1); | ||
36 | } | ||
37 | |||
38 | displayRemoveField(index: number) { | ||
39 | return (index !== 0 || this.urls.length > 1) && index !== (this.urls.length - 1); | ||
40 | } | ||
41 | |||
42 | isFormValid() { | ||
43 | // Do not check the last input | ||
44 | for (let i = 0; i < this.urls.length - 1; i++) { | ||
45 | if (!this.form.controls[`url-${i}`].valid) return false; | ||
46 | } | ||
47 | |||
48 | const lastIndex = this.urls.length - 1; | ||
49 | // If the last input (which is not the first) is empty, it's ok | ||
50 | if (this.urls[lastIndex] === '' && lastIndex !== 0) { | ||
51 | return true; | ||
52 | } else { | ||
53 | return this.form.controls[`url-${lastIndex}`].valid; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | removeField(index: number) { | ||
58 | // Remove the last control | ||
59 | this.form.removeControl(`url-${this.urls.length - 1}`); | ||
60 | this.urls.splice(index, 1); | ||
61 | } | ||
62 | |||
63 | makeFriends() { | ||
64 | this.error = ''; | ||
65 | |||
66 | const notEmptyUrls = this.getNotEmptyUrls(); | ||
67 | if (notEmptyUrls.length === 0) { | ||
68 | this.error = 'You need to specify at less 1 url.'; | ||
69 | return; | ||
70 | } | ||
71 | |||
72 | if (!this.isUrlsUnique(notEmptyUrls)) { | ||
73 | this.error = 'Urls need to be unique.'; | ||
74 | return; | ||
75 | } | ||
76 | |||
77 | const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyUrls.join('\n - '); | ||
78 | if (!confirm(confirmMessage)) return; | ||
79 | |||
80 | this.friendService.makeFriends(notEmptyUrls).subscribe( | ||
81 | status => { | ||
82 | // TODO: extractdatastatus | ||
83 | // if (status === 409) { | ||
84 | // alert('Already made friends!'); | ||
85 | // } else { | ||
86 | alert('Make friends request sent!'); | ||
87 | this.router.navigate([ '/admin/friends/list' ]); | ||
88 | // } | ||
89 | }, | ||
90 | error => alert(error.text) | ||
91 | ); | ||
92 | } | ||
93 | |||
94 | private getNotEmptyUrls() { | ||
95 | const notEmptyUrls = []; | ||
96 | |||
97 | Object.keys(this.form.value).forEach((urlKey) => { | ||
98 | const url = this.form.value[urlKey]; | ||
99 | if (url !== '') notEmptyUrls.push(url); | ||
100 | }); | ||
101 | |||
102 | return notEmptyUrls; | ||
103 | } | ||
104 | |||
105 | private isUrlsUnique(urls: string[]) { | ||
106 | return urls.every(url => urls.indexOf(url) === urls.lastIndexOf(url)); | ||
107 | } | ||
108 | } | ||
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 new file mode 100644 index 000000000..d786a7846 --- /dev/null +++ b/client/src/app/admin/friends/friend-list/friend-list.component.html | |||
@@ -0,0 +1,29 @@ | |||
1 | <h3>Friends list</h3> | ||
2 | |||
3 | <table class="table table-hover"> | ||
4 | <thead> | ||
5 | <tr> | ||
6 | <th class="table-column-id">ID</th> | ||
7 | <th>Url</th> | ||
8 | <th>Score</th> | ||
9 | <th>Created Date</th> | ||
10 | </tr> | ||
11 | </thead> | ||
12 | |||
13 | <tbody> | ||
14 | <tr *ngFor="let friend of friends"> | ||
15 | <td>{{ friend.id }}</td> | ||
16 | <td>{{ friend.url }}</td> | ||
17 | <td>{{ friend.score }}</td> | ||
18 | <td>{{ friend.createdDate | date: 'medium' }}</td> | ||
19 | </tr> | ||
20 | </tbody> | ||
21 | </table> | ||
22 | |||
23 | <a *ngIf="friends?.length !== 0" class="add-user btn btn-danger pull-left" (click)="quitFriends()"> | ||
24 | Quit friends | ||
25 | </a> | ||
26 | |||
27 | <a *ngIf="friends?.length === 0" class="add-user btn btn-success pull-right" [routerLink]="['/admin/friends/add']"> | ||
28 | Make friends | ||
29 | </a> | ||
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 new file mode 100644 index 000000000..cb597e12b --- /dev/null +++ b/client/src/app/admin/friends/friend-list/friend-list.component.scss | |||
@@ -0,0 +1,3 @@ | |||
1 | table { | ||
2 | margin-bottom: 40px; | ||
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 new file mode 100644 index 000000000..88c4800ee --- /dev/null +++ b/client/src/app/admin/friends/friend-list/friend-list.component.ts | |||
@@ -0,0 +1,38 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | ||
2 | |||
3 | import { Friend, FriendService } from '../shared'; | ||
4 | |||
5 | @Component({ | ||
6 | selector: 'my-friend-list', | ||
7 | templateUrl: './friend-list.component.html', | ||
8 | styleUrls: [ './friend-list.component.scss' ] | ||
9 | }) | ||
10 | export class FriendListComponent implements OnInit { | ||
11 | friends: Friend[]; | ||
12 | |||
13 | constructor(private friendService: FriendService) { } | ||
14 | |||
15 | ngOnInit() { | ||
16 | this.getFriends(); | ||
17 | } | ||
18 | |||
19 | quitFriends() { | ||
20 | if (!confirm('Are you sure?')) return; | ||
21 | |||
22 | this.friendService.quitFriends().subscribe( | ||
23 | status => { | ||
24 | alert('Quit friends!'); | ||
25 | this.getFriends(); | ||
26 | }, | ||
27 | error => alert(error.text) | ||
28 | ); | ||
29 | } | ||
30 | |||
31 | private getFriends() { | ||
32 | this.friendService.getFriends().subscribe( | ||
33 | friends => this.friends = friends, | ||
34 | |||
35 | err => alert(err.text) | ||
36 | ); | ||
37 | } | ||
38 | } | ||
diff --git a/client/src/app/admin/friends/friend-list/index.ts b/client/src/app/admin/friends/friend-list/index.ts new file mode 100644 index 000000000..354c978a4 --- /dev/null +++ b/client/src/app/admin/friends/friend-list/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './friend-list.component'; | |||
diff --git a/client/src/app/admin/friends/friends.component.ts b/client/src/app/admin/friends/friends.component.ts new file mode 100644 index 000000000..bc3f54158 --- /dev/null +++ b/client/src/app/admin/friends/friends.component.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | |||
3 | @Component({ | ||
4 | template: '<router-outlet></router-outlet>' | ||
5 | }) | ||
6 | |||
7 | export class FriendsComponent { | ||
8 | } | ||
diff --git a/client/src/app/admin/friends/friends.routes.ts b/client/src/app/admin/friends/friends.routes.ts new file mode 100644 index 000000000..7fdef68f9 --- /dev/null +++ b/client/src/app/admin/friends/friends.routes.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import { Routes } from '@angular/router'; | ||
2 | |||
3 | import { FriendsComponent } from './friends.component'; | ||
4 | import { FriendAddComponent } from './friend-add'; | ||
5 | import { FriendListComponent } from './friend-list'; | ||
6 | |||
7 | export const FriendsRoutes: Routes = [ | ||
8 | { | ||
9 | path: 'friends', | ||
10 | component: FriendsComponent, | ||
11 | children: [ | ||
12 | { | ||
13 | path: '', | ||
14 | redirectTo: 'list', | ||
15 | pathMatch: 'full' | ||
16 | }, | ||
17 | { | ||
18 | path: 'list', | ||
19 | component: FriendListComponent | ||
20 | }, | ||
21 | { | ||
22 | path: 'add', | ||
23 | component: FriendAddComponent | ||
24 | } | ||
25 | ] | ||
26 | } | ||
27 | ]; | ||
diff --git a/client/src/app/admin/friends/index.ts b/client/src/app/admin/friends/index.ts new file mode 100644 index 000000000..dd4df2538 --- /dev/null +++ b/client/src/app/admin/friends/index.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export * from './friend-add'; | ||
2 | export * from './friend-list'; | ||
3 | export * from './shared'; | ||
4 | export * from './friends.component'; | ||
5 | export * from './friends.routes'; | ||
diff --git a/client/src/app/admin/friends/shared/friend.model.ts b/client/src/app/admin/friends/shared/friend.model.ts new file mode 100644 index 000000000..7cb28f440 --- /dev/null +++ b/client/src/app/admin/friends/shared/friend.model.ts | |||
@@ -0,0 +1,6 @@ | |||
1 | export interface Friend { | ||
2 | id: string; | ||
3 | url: string; | ||
4 | score: number; | ||
5 | createdDate: Date; | ||
6 | } | ||
diff --git a/client/src/app/admin/friends/shared/friend.service.ts b/client/src/app/admin/friends/shared/friend.service.ts new file mode 100644 index 000000000..75826fc17 --- /dev/null +++ b/client/src/app/admin/friends/shared/friend.service.ts | |||
@@ -0,0 +1,39 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Observable } from 'rxjs/Observable'; | ||
3 | |||
4 | import { Friend } from './friend.model'; | ||
5 | import { AuthHttp, RestExtractor } from '../../../shared'; | ||
6 | |||
7 | @Injectable() | ||
8 | export class FriendService { | ||
9 | private static BASE_FRIEND_URL: string = '/api/v1/pods/'; | ||
10 | |||
11 | constructor ( | ||
12 | private authHttp: AuthHttp, | ||
13 | private restExtractor: RestExtractor | ||
14 | ) {} | ||
15 | |||
16 | getFriends(): Observable<Friend[]> { | ||
17 | return this.authHttp.get(FriendService.BASE_FRIEND_URL) | ||
18 | // Not implemented as a data list by the server yet | ||
19 | // .map(this.restExtractor.extractDataList) | ||
20 | .map((res) => res.json()) | ||
21 | .catch((res) => this.restExtractor.handleError(res)); | ||
22 | } | ||
23 | |||
24 | makeFriends(notEmptyUrls) { | ||
25 | const body = { | ||
26 | urls: notEmptyUrls | ||
27 | }; | ||
28 | |||
29 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) | ||
30 | .map(this.restExtractor.extractDataBool) | ||
31 | .catch((res) => this.restExtractor.handleError(res)); | ||
32 | } | ||
33 | |||
34 | quitFriends() { | ||
35 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') | ||
36 | .map(res => res.status) | ||
37 | .catch((res) => this.restExtractor.handleError(res)); | ||
38 | } | ||
39 | } | ||
diff --git a/client/src/app/admin/friends/shared/index.ts b/client/src/app/admin/friends/shared/index.ts new file mode 100644 index 000000000..0d671637d --- /dev/null +++ b/client/src/app/admin/friends/shared/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './friend.model'; | ||
2 | export * from './friend.service'; | ||
diff --git a/client/src/app/admin/index.ts b/client/src/app/admin/index.ts new file mode 100644 index 000000000..493caed15 --- /dev/null +++ b/client/src/app/admin/index.ts | |||
@@ -0,0 +1,6 @@ | |||
1 | export * from './friends'; | ||
2 | export * from './requests'; | ||
3 | export * from './users'; | ||
4 | export * from './admin.component'; | ||
5 | export * from './admin.routes'; | ||
6 | export * from './menu-admin.component'; | ||
diff --git a/client/src/app/admin/menu-admin.component.html b/client/src/app/admin/menu-admin.component.html new file mode 100644 index 000000000..e250615aa --- /dev/null +++ b/client/src/app/admin/menu-admin.component.html | |||
@@ -0,0 +1,26 @@ | |||
1 | <menu class="col-md-2 col-sm-3 col-xs-3"> | ||
2 | |||
3 | <div class="panel-block"> | ||
4 | <div id="panel-users" class="panel-button"> | ||
5 | <span class="hidden-xs glyphicon glyphicon-user"></span> | ||
6 | <a [routerLink]="['/admin/users/list']">List users</a> | ||
7 | </div> | ||
8 | |||
9 | <div id="panel-friends" class="panel-button"> | ||
10 | <span class="hidden-xs glyphicon glyphicon-cloud"></span> | ||
11 | <a [routerLink]="['/admin/friends/list']">List friends</a> | ||
12 | </div> | ||
13 | |||
14 | <div id="panel-request-stats" class="panel-button"> | ||
15 | <span class="hidden-xs glyphicon glyphicon-stats"></span> | ||
16 | <a [routerLink]="['/admin/requests/stats']">Request stats</a> | ||
17 | </div> | ||
18 | </div> | ||
19 | |||
20 | <div class="panel-block"> | ||
21 | <div id="panel-quit-administration" class="panel-button"> | ||
22 | <span class="hidden-xs glyphicon glyphicon-cog"></span> | ||
23 | <a [routerLink]="['/videos/list']">Quit admin.</a> | ||
24 | </div> | ||
25 | </div> | ||
26 | </menu> | ||
diff --git a/client/src/app/admin/menu-admin.component.ts b/client/src/app/admin/menu-admin.component.ts new file mode 100644 index 000000000..59ffccf9f --- /dev/null +++ b/client/src/app/admin/menu-admin.component.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | |||
3 | @Component({ | ||
4 | selector: 'my-menu-admin', | ||
5 | templateUrl: './menu-admin.component.html' | ||
6 | }) | ||
7 | export class MenuAdminComponent { } | ||
diff --git a/client/src/app/admin/requests/index.ts b/client/src/app/admin/requests/index.ts new file mode 100644 index 000000000..236a9ee8f --- /dev/null +++ b/client/src/app/admin/requests/index.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export * from './request-stats'; | ||
2 | export * from './shared'; | ||
3 | export * from './requests.component'; | ||
4 | export * from './requests.routes'; | ||
diff --git a/client/src/app/admin/requests/request-stats/index.ts b/client/src/app/admin/requests/request-stats/index.ts new file mode 100644 index 000000000..be3a66f77 --- /dev/null +++ b/client/src/app/admin/requests/request-stats/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './request-stats.component'; | |||
diff --git a/client/src/app/admin/requests/request-stats/request-stats.component.html b/client/src/app/admin/requests/request-stats/request-stats.component.html new file mode 100644 index 000000000..b5ac59a9a --- /dev/null +++ b/client/src/app/admin/requests/request-stats/request-stats.component.html | |||
@@ -0,0 +1,23 @@ | |||
1 | <h3>Requests stats</h3> | ||
2 | |||
3 | <div *ngIf="stats !== null"> | ||
4 | <div> | ||
5 | <span class="label-description">Interval seconds between requests:</span> | ||
6 | {{ stats.secondsInterval }} | ||
7 | </div> | ||
8 | |||
9 | <div> | ||
10 | <span class="label-description">Remaining time before the scheduled request:</span> | ||
11 | {{ stats.remainingSeconds }} | ||
12 | </div> | ||
13 | |||
14 | <div> | ||
15 | <span class="label-description">Maximum number of requests per interval:</span> | ||
16 | {{ stats.maxRequestsInParallel }} | ||
17 | </div> | ||
18 | |||
19 | <div> | ||
20 | <span class="label-description">Remaining requests:</span> | ||
21 | {{ stats.requests.length }} | ||
22 | </div> | ||
23 | </div> | ||
diff --git a/client/src/app/admin/requests/request-stats/request-stats.component.scss b/client/src/app/admin/requests/request-stats/request-stats.component.scss new file mode 100644 index 000000000..92c28dc99 --- /dev/null +++ b/client/src/app/admin/requests/request-stats/request-stats.component.scss | |||
@@ -0,0 +1,6 @@ | |||
1 | .label-description { | ||
2 | display: inline-block; | ||
3 | width: 350px; | ||
4 | font-weight: bold; | ||
5 | color: black; | ||
6 | } | ||
diff --git a/client/src/app/admin/requests/request-stats/request-stats.component.ts b/client/src/app/admin/requests/request-stats/request-stats.component.ts new file mode 100644 index 000000000..4b0844574 --- /dev/null +++ b/client/src/app/admin/requests/request-stats/request-stats.component.ts | |||
@@ -0,0 +1,51 @@ | |||
1 | import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
2 | |||
3 | import { RequestService, RequestStats } from '../shared'; | ||
4 | |||
5 | @Component({ | ||
6 | selector: 'my-request-stats', | ||
7 | templateUrl: './request-stats.component.html', | ||
8 | styleUrls: [ './request-stats.component.scss' ] | ||
9 | }) | ||
10 | export class RequestStatsComponent implements OnInit, OnDestroy { | ||
11 | stats: RequestStats = null; | ||
12 | |||
13 | private interval: NodeJS.Timer = null; | ||
14 | |||
15 | constructor(private requestService: RequestService) { } | ||
16 | |||
17 | ngOnInit() { | ||
18 | this.getStats(); | ||
19 | } | ||
20 | |||
21 | ngOnDestroy() { | ||
22 | if (this.stats.secondsInterval !== null) { | ||
23 | clearInterval(this.interval); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | getStats() { | ||
28 | this.requestService.getStats().subscribe( | ||
29 | stats => { | ||
30 | console.log(stats); | ||
31 | this.stats = stats; | ||
32 | this.runInterval(); | ||
33 | }, | ||
34 | |||
35 | err => alert(err.text) | ||
36 | ); | ||
37 | } | ||
38 | |||
39 | private runInterval() { | ||
40 | this.interval = setInterval(() => { | ||
41 | this.stats.remainingMilliSeconds -= 1000; | ||
42 | |||
43 | if (this.stats.remainingMilliSeconds <= 0) { | ||
44 | setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100); | ||
45 | clearInterval(this.interval); | ||
46 | } | ||
47 | }, 1000); | ||
48 | } | ||
49 | |||
50 | |||
51 | } | ||
diff --git a/client/src/app/admin/requests/requests.component.ts b/client/src/app/admin/requests/requests.component.ts new file mode 100644 index 000000000..471112b45 --- /dev/null +++ b/client/src/app/admin/requests/requests.component.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | |||
3 | @Component({ | ||
4 | template: '<router-outlet></router-outlet>' | ||
5 | }) | ||
6 | |||
7 | export class RequestsComponent { | ||
8 | } | ||
diff --git a/client/src/app/admin/requests/requests.routes.ts b/client/src/app/admin/requests/requests.routes.ts new file mode 100644 index 000000000..78221a9ff --- /dev/null +++ b/client/src/app/admin/requests/requests.routes.ts | |||
@@ -0,0 +1,22 @@ | |||
1 | import { Routes } from '@angular/router'; | ||
2 | |||
3 | import { RequestsComponent } from './requests.component'; | ||
4 | import { RequestStatsComponent } from './request-stats'; | ||
5 | |||
6 | export const RequestsRoutes: Routes = [ | ||
7 | { | ||
8 | path: 'requests', | ||
9 | component: RequestsComponent, | ||
10 | children: [ | ||
11 | { | ||
12 | path: '', | ||
13 | redirectTo: 'stats', | ||
14 | pathMatch: 'full' | ||
15 | }, | ||
16 | { | ||
17 | path: 'stats', | ||
18 | component: RequestStatsComponent | ||
19 | } | ||
20 | ] | ||
21 | } | ||
22 | ]; | ||
diff --git a/client/src/app/admin/requests/shared/index.ts b/client/src/app/admin/requests/shared/index.ts new file mode 100644 index 000000000..32ab5767b --- /dev/null +++ b/client/src/app/admin/requests/shared/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './request-stats.model'; | ||
2 | export * from './request.service'; | ||
diff --git a/client/src/app/admin/requests/shared/request-stats.model.ts b/client/src/app/admin/requests/shared/request-stats.model.ts new file mode 100644 index 000000000..766e80836 --- /dev/null +++ b/client/src/app/admin/requests/shared/request-stats.model.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | export interface Request { | ||
2 | request: any; | ||
3 | to: any; | ||
4 | } | ||
5 | |||
6 | export class RequestStats { | ||
7 | maxRequestsInParallel: number; | ||
8 | milliSecondsInterval: number; | ||
9 | remainingMilliSeconds: number; | ||
10 | requests: Request[]; | ||
11 | |||
12 | constructor(hash: { | ||
13 | maxRequestsInParallel: number, | ||
14 | milliSecondsInterval: number, | ||
15 | remainingMilliSeconds: number, | ||
16 | requests: Request[]; | ||
17 | }) { | ||
18 | this.maxRequestsInParallel = hash.maxRequestsInParallel; | ||
19 | this.milliSecondsInterval = hash.milliSecondsInterval; | ||
20 | this.remainingMilliSeconds = hash.remainingMilliSeconds; | ||
21 | this.requests = hash.requests; | ||
22 | } | ||
23 | |||
24 | get remainingSeconds() { | ||
25 | return Math.floor(this.remainingMilliSeconds / 1000); | ||
26 | } | ||
27 | |||
28 | get secondsInterval() { | ||
29 | return Math.floor(this.milliSecondsInterval / 1000); | ||
30 | } | ||
31 | |||
32 | } | ||
diff --git a/client/src/app/admin/requests/shared/request.service.ts b/client/src/app/admin/requests/shared/request.service.ts new file mode 100644 index 000000000..aeec37448 --- /dev/null +++ b/client/src/app/admin/requests/shared/request.service.ts | |||
@@ -0,0 +1,22 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Observable } from 'rxjs/Observable'; | ||
3 | |||
4 | import { RequestStats } from './request-stats.model'; | ||
5 | import { AuthHttp, RestExtractor } from '../../../shared'; | ||
6 | |||
7 | @Injectable() | ||
8 | export class RequestService { | ||
9 | private static BASE_REQUEST_URL: string = '/api/v1/requests/'; | ||
10 | |||
11 | constructor ( | ||
12 | private authHttp: AuthHttp, | ||
13 | private restExtractor: RestExtractor | ||
14 | ) {} | ||
15 | |||
16 | getStats(): Observable<RequestStats> { | ||
17 | return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats') | ||
18 | .map(this.restExtractor.extractDataGet) | ||
19 | .map((data) => new RequestStats(data)) | ||
20 | .catch((res) => this.restExtractor.handleError(res)); | ||
21 | } | ||
22 | } | ||
diff --git a/client/src/app/admin/users/index.ts b/client/src/app/admin/users/index.ts new file mode 100644 index 000000000..e98a81f62 --- /dev/null +++ b/client/src/app/admin/users/index.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export * from './shared'; | ||
2 | export * from './user-add'; | ||
3 | export * from './user-list'; | ||
4 | export * from './users.component'; | ||
5 | export * from './users.routes'; | ||
diff --git a/client/src/app/admin/users/shared/index.ts b/client/src/app/admin/users/shared/index.ts new file mode 100644 index 000000000..e17ee5c7a --- /dev/null +++ b/client/src/app/admin/users/shared/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './user.service'; | |||
diff --git a/client/src/app/admin/users/shared/user.service.ts b/client/src/app/admin/users/shared/user.service.ts new file mode 100644 index 000000000..13be553c0 --- /dev/null +++ b/client/src/app/admin/users/shared/user.service.ts | |||
@@ -0,0 +1,47 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | |||
3 | import { AuthHttp, RestExtractor, ResultList, User } from '../../../shared'; | ||
4 | |||
5 | @Injectable() | ||
6 | export class UserService { | ||
7 | // TODO: merge this constant with account | ||
8 | private static BASE_USERS_URL = '/api/v1/users/'; | ||
9 | |||
10 | constructor( | ||
11 | private authHttp: AuthHttp, | ||
12 | private restExtractor: RestExtractor | ||
13 | ) {} | ||
14 | |||
15 | addUser(username: string, password: string) { | ||
16 | const body = { | ||
17 | username, | ||
18 | password | ||
19 | }; | ||
20 | |||
21 | return this.authHttp.post(UserService.BASE_USERS_URL, body) | ||
22 | .map(this.restExtractor.extractDataBool) | ||
23 | .catch(this.restExtractor.handleError); | ||
24 | } | ||
25 | |||
26 | getUsers() { | ||
27 | return this.authHttp.get(UserService.BASE_USERS_URL) | ||
28 | .map(this.restExtractor.extractDataList) | ||
29 | .map(this.extractUsers) | ||
30 | .catch((res) => this.restExtractor.handleError(res)); | ||
31 | } | ||
32 | |||
33 | removeUser(user: User) { | ||
34 | return this.authHttp.delete(UserService.BASE_USERS_URL + user.id); | ||
35 | } | ||
36 | |||
37 | private extractUsers(result: ResultList) { | ||
38 | const usersJson = result.data; | ||
39 | const totalUsers = result.total; | ||
40 | const users = []; | ||
41 | for (const userJson of usersJson) { | ||
42 | users.push(new User(userJson)); | ||
43 | } | ||
44 | |||
45 | return { users, totalUsers }; | ||
46 | } | ||
47 | } | ||
diff --git a/client/src/app/admin/users/user-add/index.ts b/client/src/app/admin/users/user-add/index.ts new file mode 100644 index 000000000..66d5ca04f --- /dev/null +++ b/client/src/app/admin/users/user-add/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './user-add.component'; | |||
diff --git a/client/src/app/admin/users/user-add/user-add.component.html b/client/src/app/admin/users/user-add/user-add.component.html new file mode 100644 index 000000000..9b76c7c1b --- /dev/null +++ b/client/src/app/admin/users/user-add/user-add.component.html | |||
@@ -0,0 +1,29 @@ | |||
1 | <h3>Add user</h3> | ||
2 | |||
3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | ||
4 | |||
5 | <form role="form" (ngSubmit)="addUser()" [formGroup]="form"> | ||
6 | <div class="form-group"> | ||
7 | <label for="username">Username</label> | ||
8 | <input | ||
9 | type="text" class="form-control" id="username" placeholder="Username" | ||
10 | formControlName="username" | ||
11 | > | ||
12 | <div *ngIf="formErrors.username" class="alert alert-danger"> | ||
13 | {{ formErrors.username }} | ||
14 | </div> | ||
15 | </div> | ||
16 | |||
17 | <div class="form-group"> | ||
18 | <label for="password">Password</label> | ||
19 | <input | ||
20 | type="password" class="form-control" id="password" placeholder="Password" | ||
21 | formControlName="password" | ||
22 | > | ||
23 | <div *ngIf="formErrors.password" class="alert alert-danger"> | ||
24 | {{ formErrors.password }} | ||
25 | </div> | ||
26 | </div> | ||
27 | |||
28 | <input type="submit" value="Add user" class="btn btn-default" [disabled]="!form.valid"> | ||
29 | </form> | ||
diff --git a/client/src/app/admin/users/user-add/user-add.component.ts b/client/src/app/admin/users/user-add/user-add.component.ts new file mode 100644 index 000000000..ab96fb01d --- /dev/null +++ b/client/src/app/admin/users/user-add/user-add.component.ts | |||
@@ -0,0 +1,57 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms'; | ||
3 | import { Router } from '@angular/router'; | ||
4 | |||
5 | import { UserService } from '../shared'; | ||
6 | import { FormReactive, USER_USERNAME, USER_PASSWORD } from '../../../shared'; | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-user-add', | ||
10 | templateUrl: './user-add.component.html' | ||
11 | }) | ||
12 | export class UserAddComponent extends FormReactive implements OnInit { | ||
13 | error: string = null; | ||
14 | |||
15 | form: FormGroup; | ||
16 | formErrors = { | ||
17 | 'username': '', | ||
18 | 'password': '' | ||
19 | }; | ||
20 | validationMessages = { | ||
21 | 'username': USER_USERNAME.MESSAGES, | ||
22 | 'password': USER_PASSWORD.MESSAGES, | ||
23 | }; | ||
24 | |||
25 | constructor( | ||
26 | private formBuilder: FormBuilder, | ||
27 | private router: Router, | ||
28 | private userService: UserService | ||
29 | ) { | ||
30 | super(); | ||
31 | } | ||
32 | |||
33 | buildForm() { | ||
34 | this.form = this.formBuilder.group({ | ||
35 | username: [ '', USER_USERNAME.VALIDATORS ], | ||
36 | password: [ '', USER_PASSWORD.VALIDATORS ], | ||
37 | }); | ||
38 | |||
39 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | ||
40 | } | ||
41 | |||
42 | ngOnInit() { | ||
43 | this.buildForm(); | ||
44 | } | ||
45 | |||
46 | addUser() { | ||
47 | this.error = null; | ||
48 | |||
49 | const { username, password } = this.form.value; | ||
50 | |||
51 | this.userService.addUser(username, password).subscribe( | ||
52 | ok => this.router.navigate([ '/admin/users/list' ]), | ||
53 | |||
54 | err => this.error = err.text | ||
55 | ); | ||
56 | } | ||
57 | } | ||
diff --git a/client/src/app/admin/users/user-list/index.ts b/client/src/app/admin/users/user-list/index.ts new file mode 100644 index 000000000..51fbefa80 --- /dev/null +++ b/client/src/app/admin/users/user-list/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './user-list.component'; | |||
diff --git a/client/src/app/admin/users/user-list/user-list.component.html b/client/src/app/admin/users/user-list/user-list.component.html new file mode 100644 index 000000000..328b1be77 --- /dev/null +++ b/client/src/app/admin/users/user-list/user-list.component.html | |||
@@ -0,0 +1,28 @@ | |||
1 | <h3>Users list</h3> | ||
2 | |||
3 | <table class="table table-hover"> | ||
4 | <thead> | ||
5 | <tr> | ||
6 | <th class="table-column-id">ID</th> | ||
7 | <th>Username</th> | ||
8 | <th>Created Date</th> | ||
9 | <th class="text-right">Remove</th> | ||
10 | </tr> | ||
11 | </thead> | ||
12 | |||
13 | <tbody> | ||
14 | <tr *ngFor="let user of users"> | ||
15 | <td>{{ user.id }}</td> | ||
16 | <td>{{ user.username }}</td> | ||
17 | <td>{{ user.createdDate | date: 'medium' }}</td> | ||
18 | <td class="text-right"> | ||
19 | <span class="glyphicon glyphicon-remove" *ngIf="!user.isAdmin()" (click)="removeUser(user)"></span> | ||
20 | </td> | ||
21 | </tr> | ||
22 | </tbody> | ||
23 | </table> | ||
24 | |||
25 | <a class="add-user btn btn-success pull-right" [routerLink]="['/admin/users/add']"> | ||
26 | <span class="glyphicon glyphicon-plus"></span> | ||
27 | Add user | ||
28 | </a> | ||
diff --git a/client/src/app/admin/users/user-list/user-list.component.scss b/client/src/app/admin/users/user-list/user-list.component.scss new file mode 100644 index 000000000..e9f61e900 --- /dev/null +++ b/client/src/app/admin/users/user-list/user-list.component.scss | |||
@@ -0,0 +1,7 @@ | |||
1 | .glyphicon-remove { | ||
2 | cursor: pointer; | ||
3 | } | ||
4 | |||
5 | .add-user { | ||
6 | margin-top: 10px; | ||
7 | } | ||
diff --git a/client/src/app/admin/users/user-list/user-list.component.ts b/client/src/app/admin/users/user-list/user-list.component.ts new file mode 100644 index 000000000..03f4e5c0a --- /dev/null +++ b/client/src/app/admin/users/user-list/user-list.component.ts | |||
@@ -0,0 +1,42 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | ||
2 | |||
3 | import { User } from '../../../shared'; | ||
4 | import { UserService } from '../shared'; | ||
5 | |||
6 | @Component({ | ||
7 | selector: 'my-user-list', | ||
8 | templateUrl: './user-list.component.html', | ||
9 | styleUrls: [ './user-list.component.scss' ] | ||
10 | }) | ||
11 | export class UserListComponent implements OnInit { | ||
12 | totalUsers: number; | ||
13 | users: User[]; | ||
14 | |||
15 | constructor(private userService: UserService) {} | ||
16 | |||
17 | ngOnInit() { | ||
18 | this.getUsers(); | ||
19 | } | ||
20 | |||
21 | getUsers() { | ||
22 | this.userService.getUsers().subscribe( | ||
23 | ({ users, totalUsers }) => { | ||
24 | this.users = users; | ||
25 | this.totalUsers = totalUsers; | ||
26 | }, | ||
27 | |||
28 | err => alert(err.text) | ||
29 | ); | ||
30 | } | ||
31 | |||
32 | |||
33 | removeUser(user: User) { | ||
34 | if (confirm('Are you sure?')) { | ||
35 | this.userService.removeUser(user).subscribe( | ||
36 | () => this.getUsers(), | ||
37 | |||
38 | err => alert(err.text) | ||
39 | ); | ||
40 | } | ||
41 | } | ||
42 | } | ||
diff --git a/client/src/app/admin/users/users.component.ts b/client/src/app/admin/users/users.component.ts new file mode 100644 index 000000000..37e3b158d --- /dev/null +++ b/client/src/app/admin/users/users.component.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | |||
3 | @Component({ | ||
4 | template: '<router-outlet></router-outlet>' | ||
5 | }) | ||
6 | |||
7 | export class UsersComponent { | ||
8 | } | ||
diff --git a/client/src/app/admin/users/users.routes.ts b/client/src/app/admin/users/users.routes.ts new file mode 100644 index 000000000..eb71bd0ae --- /dev/null +++ b/client/src/app/admin/users/users.routes.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import { Routes } from '@angular/router'; | ||
2 | |||
3 | import { UsersComponent } from './users.component'; | ||
4 | import { UserAddComponent } from './user-add'; | ||
5 | import { UserListComponent } from './user-list'; | ||
6 | |||
7 | export const UsersRoutes: Routes = [ | ||
8 | { | ||
9 | path: 'users', | ||
10 | component: UsersComponent, | ||
11 | children: [ | ||
12 | { | ||
13 | path: '', | ||
14 | redirectTo: 'list', | ||
15 | pathMatch: 'full' | ||
16 | }, | ||
17 | { | ||
18 | path: 'list', | ||
19 | component: UserListComponent | ||
20 | }, | ||
21 | { | ||
22 | path: 'add', | ||
23 | component: UserAddComponent | ||
24 | } | ||
25 | ] | ||
26 | } | ||
27 | ]; | ||