diff options
Diffstat (limited to 'client/src/app/+admin')
-rw-r--r-- | client/src/app/+admin/admin.module.ts | 3 | ||||
-rw-r--r-- | client/src/app/+admin/users/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/+admin/users/shared/user.service.ts | 14 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-add/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-edit/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-edit/user-add.component.ts (renamed from client/src/app/+admin/users/user-add/user-add.component.ts) | 20 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-edit/user-edit.component.html (renamed from client/src/app/+admin/users/user-add/user-add.component.html) | 21 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-edit/user-edit.ts | 16 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-edit/user-update.component.ts | 106 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-list/user-list.component.html | 2 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-list/user-list.component.ts | 17 | ||||
-rw-r--r-- | client/src/app/+admin/users/users.routes.ts | 11 |
12 files changed, 187 insertions, 28 deletions
diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index e4ba8e5b7..853085a83 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts | |||
@@ -4,7 +4,7 @@ import { AdminComponent } from './admin.component' | |||
4 | import { AdminRoutingModule } from './admin-routing.module' | 4 | import { AdminRoutingModule } from './admin-routing.module' |
5 | import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendService } from './friends' | 5 | import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendService } from './friends' |
6 | import { RequestSchedulersComponent, RequestSchedulersStatsComponent, RequestSchedulersService } from './request-schedulers' | 6 | import { RequestSchedulersComponent, RequestSchedulersStatsComponent, RequestSchedulersService } from './request-schedulers' |
7 | import { UsersComponent, UserAddComponent, UserListComponent, UserService } from './users' | 7 | import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users' |
8 | import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses' | 8 | import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses' |
9 | import { SharedModule } from '../shared' | 9 | import { SharedModule } from '../shared' |
10 | 10 | ||
@@ -26,6 +26,7 @@ import { SharedModule } from '../shared' | |||
26 | 26 | ||
27 | UsersComponent, | 27 | UsersComponent, |
28 | UserAddComponent, | 28 | UserAddComponent, |
29 | UserUpdateComponent, | ||
29 | UserListComponent, | 30 | UserListComponent, |
30 | 31 | ||
31 | VideoAbusesComponent, | 32 | VideoAbusesComponent, |
diff --git a/client/src/app/+admin/users/index.ts b/client/src/app/+admin/users/index.ts index cef2c282c..efcd0d9cb 100644 --- a/client/src/app/+admin/users/index.ts +++ b/client/src/app/+admin/users/index.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | export * from './shared' | 1 | export * from './shared' |
2 | export * from './user-add' | 2 | export * from './user-edit' |
3 | export * from './user-list' | 3 | export * from './user-list' |
4 | export * from './users.component' | 4 | export * from './users.component' |
5 | export * from './users.routes' | 5 | export * from './users.routes' |
diff --git a/client/src/app/+admin/users/shared/user.service.ts b/client/src/app/+admin/users/shared/user.service.ts index ffd7ba7da..999013bcc 100644 --- a/client/src/app/+admin/users/shared/user.service.ts +++ b/client/src/app/+admin/users/shared/user.service.ts | |||
@@ -5,7 +5,7 @@ import 'rxjs/add/operator/map' | |||
5 | import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe' | 5 | import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe' |
6 | 6 | ||
7 | import { AuthHttp, RestExtractor, RestDataSource, User } from '../../../shared' | 7 | import { AuthHttp, RestExtractor, RestDataSource, User } from '../../../shared' |
8 | import { UserCreate } from '../../../../../../shared' | 8 | import { UserCreate, UserUpdate } from '../../../../../../shared' |
9 | 9 | ||
10 | @Injectable() | 10 | @Injectable() |
11 | export class UserService { | 11 | export class UserService { |
@@ -23,6 +23,18 @@ export class UserService { | |||
23 | .catch(this.restExtractor.handleError) | 23 | .catch(this.restExtractor.handleError) |
24 | } | 24 | } |
25 | 25 | ||
26 | updateUser (userId: number, userUpdate: UserUpdate) { | ||
27 | return this.authHttp.put(UserService.BASE_USERS_URL + userId, userUpdate) | ||
28 | .map(this.restExtractor.extractDataBool) | ||
29 | .catch(this.restExtractor.handleError) | ||
30 | } | ||
31 | |||
32 | getUser (userId: number) { | ||
33 | return this.authHttp.get(UserService.BASE_USERS_URL + userId) | ||
34 | .map(this.restExtractor.extractDataGet) | ||
35 | .catch(this.restExtractor.handleError) | ||
36 | } | ||
37 | |||
26 | getDataSource () { | 38 | getDataSource () { |
27 | return new RestDataSource(this.authHttp, UserService.BASE_USERS_URL, this.formatDataSource.bind(this)) | 39 | return new RestDataSource(this.authHttp, UserService.BASE_USERS_URL, this.formatDataSource.bind(this)) |
28 | } | 40 | } |
diff --git a/client/src/app/+admin/users/user-add/index.ts b/client/src/app/+admin/users/user-add/index.ts deleted file mode 100644 index 3a4654101..000000000 --- a/client/src/app/+admin/users/user-add/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './user-add.component' | ||
diff --git a/client/src/app/+admin/users/user-edit/index.ts b/client/src/app/+admin/users/user-edit/index.ts new file mode 100644 index 000000000..edec02fbb --- /dev/null +++ b/client/src/app/+admin/users/user-edit/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './user-add.component' | ||
2 | export * from './user-update.component' | ||
diff --git a/client/src/app/+admin/users/user-add/user-add.component.ts b/client/src/app/+admin/users/user-edit/user-add.component.ts index 91377a933..40f649cff 100644 --- a/client/src/app/+admin/users/user-add/user-add.component.ts +++ b/client/src/app/+admin/users/user-edit/user-add.component.ts | |||
@@ -6,20 +6,20 @@ import { NotificationsService } from 'angular2-notifications' | |||
6 | 6 | ||
7 | import { UserService } from '../shared' | 7 | import { UserService } from '../shared' |
8 | import { | 8 | import { |
9 | FormReactive, | ||
10 | USER_USERNAME, | 9 | USER_USERNAME, |
11 | USER_EMAIL, | 10 | USER_EMAIL, |
12 | USER_PASSWORD, | 11 | USER_PASSWORD, |
13 | USER_VIDEO_QUOTA | 12 | USER_VIDEO_QUOTA |
14 | } from '../../../shared' | 13 | } from '../../../shared' |
15 | import { UserCreate } from '../../../../../../shared' | 14 | import { UserCreate } from '../../../../../../shared' |
15 | import { UserEdit } from './user-edit' | ||
16 | 16 | ||
17 | @Component({ | 17 | @Component({ |
18 | selector: 'my-user-add', | 18 | selector: 'my-user-add', |
19 | templateUrl: './user-add.component.html' | 19 | templateUrl: './user-edit.component.html' |
20 | }) | 20 | }) |
21 | export class UserAddComponent extends FormReactive implements OnInit { | 21 | export class UserAddComponent extends UserEdit implements OnInit { |
22 | error: string = null | 22 | error: string |
23 | 23 | ||
24 | form: FormGroup | 24 | form: FormGroup |
25 | formErrors = { | 25 | formErrors = { |
@@ -59,8 +59,8 @@ export class UserAddComponent extends FormReactive implements OnInit { | |||
59 | this.buildForm() | 59 | this.buildForm() |
60 | } | 60 | } |
61 | 61 | ||
62 | addUser () { | 62 | formValidated () { |
63 | this.error = null | 63 | this.error = undefined |
64 | 64 | ||
65 | const userCreate: UserCreate = this.form.value | 65 | const userCreate: UserCreate = this.form.value |
66 | 66 | ||
@@ -76,4 +76,12 @@ export class UserAddComponent extends FormReactive implements OnInit { | |||
76 | err => this.error = err.text | 76 | err => this.error = err.text |
77 | ) | 77 | ) |
78 | } | 78 | } |
79 | |||
80 | isCreation () { | ||
81 | return true | ||
82 | } | ||
83 | |||
84 | getFormButtonTitle () { | ||
85 | return 'Add user' | ||
86 | } | ||
79 | } | 87 | } |
diff --git a/client/src/app/+admin/users/user-add/user-add.component.html b/client/src/app/+admin/users/user-edit/user-edit.component.html index f84d72c7c..0e23cb731 100644 --- a/client/src/app/+admin/users/user-add/user-add.component.html +++ b/client/src/app/+admin/users/user-edit/user-edit.component.html | |||
@@ -1,12 +1,13 @@ | |||
1 | <div class="row"> | 1 | <div class="row"> |
2 | <div class="content-padding"> | 2 | <div class="content-padding"> |
3 | 3 | ||
4 | <h3>Add user</h3> | 4 | <h3 *ngIf="isCreation() === true">Add user</h3> |
5 | <h3 *ngIf="isCreation() === false">Edit user {{ username }}</h3> | ||
5 | 6 | ||
6 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | 7 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> |
7 | 8 | ||
8 | <form role="form" (ngSubmit)="addUser()" [formGroup]="form"> | 9 | <form role="form" (ngSubmit)="formValidated()" [formGroup]="form"> |
9 | <div class="form-group"> | 10 | <div class="form-group" *ngIf="isCreation()"> |
10 | <label for="username">Username</label> | 11 | <label for="username">Username</label> |
11 | <input | 12 | <input |
12 | type="text" class="form-control" id="username" placeholder="john" | 13 | type="text" class="form-control" id="username" placeholder="john" |
@@ -28,7 +29,7 @@ | |||
28 | </div> | 29 | </div> |
29 | </div> | 30 | </div> |
30 | 31 | ||
31 | <div class="form-group"> | 32 | <div class="form-group" *ngIf="isCreation()"> |
32 | <label for="password">Password</label> | 33 | <label for="password">Password</label> |
33 | <input | 34 | <input |
34 | type="password" class="form-control" id="password" | 35 | type="password" class="form-control" id="password" |
@@ -42,17 +43,13 @@ | |||
42 | <div class="form-group"> | 43 | <div class="form-group"> |
43 | <label for="videoQuota">Video quota</label> | 44 | <label for="videoQuota">Video quota</label> |
44 | <select class="form-control" id="videoQuota" formControlName="videoQuota"> | 45 | <select class="form-control" id="videoQuota" formControlName="videoQuota"> |
45 | <option value="-1">Unlimited</option> | 46 | <option *ngFor="let videoQuotaOption of videoQuotaOptions" [value]="videoQuotaOption.value"> |
46 | <option value="100000000">100MB</option> | 47 | {{ videoQuotaOption.label }} |
47 | <option value="500000000">500MB</option> | 48 | </option> |
48 | <option value="1000000000">1GB</option> | ||
49 | <option value="5000000000">5GB</option> | ||
50 | <option value="20000000000">20GB</option> | ||
51 | <option value="50000000000">50GB</option> | ||
52 | </select> | 49 | </select> |
53 | </div> | 50 | </div> |
54 | 51 | ||
55 | <input type="submit" value="Add user" class="btn btn-default" [disabled]="!form.valid"> | 52 | <input type="submit" value="{{ getFormButtonTitle() }}" class="btn btn-default" [disabled]="!form.valid"> |
56 | </form> | 53 | </form> |
57 | </div> | 54 | </div> |
58 | </div> | 55 | </div> |
diff --git a/client/src/app/+admin/users/user-edit/user-edit.ts b/client/src/app/+admin/users/user-edit/user-edit.ts new file mode 100644 index 000000000..61db8a906 --- /dev/null +++ b/client/src/app/+admin/users/user-edit/user-edit.ts | |||
@@ -0,0 +1,16 @@ | |||
1 | import { FormReactive } from '../../../shared' | ||
2 | |||
3 | export abstract class UserEdit extends FormReactive { | ||
4 | videoQuotaOptions = [ | ||
5 | { value: -1, label: 'Unlimited' }, | ||
6 | { value: 100 * 1024 * 1024, label: '100MB' }, | ||
7 | { value: 5 * 1024 * 1024, label: '500MB' }, | ||
8 | { value: 1024 * 1024 * 1024, label: '1GB' }, | ||
9 | { value: 5 * 1024 * 1024 * 1024, label: '5GB' }, | ||
10 | { value: 20 * 1024 * 1024 * 1024, label: '20GB' }, | ||
11 | { value: 50 * 1024 * 1024 * 1024, label: '50GB' } | ||
12 | ] | ||
13 | |||
14 | abstract isCreation (): boolean | ||
15 | abstract getFormButtonTitle (): string | ||
16 | } | ||
diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.ts new file mode 100644 index 000000000..dbac5f974 --- /dev/null +++ b/client/src/app/+admin/users/user-edit/user-update.component.ts | |||
@@ -0,0 +1,106 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
3 | import { ActivatedRoute, Router } from '@angular/router' | ||
4 | import { Subscription } from 'rxjs/Subscription' | ||
5 | |||
6 | import { NotificationsService } from 'angular2-notifications' | ||
7 | |||
8 | import { UserService } from '../shared' | ||
9 | import { USER_EMAIL, USER_VIDEO_QUOTA } from '../../../shared' | ||
10 | import { UserUpdate } from '../../../../../../shared/models/users/user-update.model' | ||
11 | import { User } from '../../../shared/users/user.model' | ||
12 | import { UserEdit } from './user-edit' | ||
13 | |||
14 | @Component({ | ||
15 | selector: 'my-user-update', | ||
16 | templateUrl: './user-edit.component.html' | ||
17 | }) | ||
18 | export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { | ||
19 | error: string | ||
20 | userId: number | ||
21 | username: string | ||
22 | |||
23 | form: FormGroup | ||
24 | formErrors = { | ||
25 | 'email': '', | ||
26 | 'videoQuota': '' | ||
27 | } | ||
28 | validationMessages = { | ||
29 | 'email': USER_EMAIL.MESSAGES, | ||
30 | 'videoQuota': USER_VIDEO_QUOTA.MESSAGES | ||
31 | } | ||
32 | |||
33 | private paramsSub: Subscription | ||
34 | |||
35 | constructor ( | ||
36 | private formBuilder: FormBuilder, | ||
37 | private route: ActivatedRoute, | ||
38 | private router: Router, | ||
39 | private notificationsService: NotificationsService, | ||
40 | private userService: UserService | ||
41 | ) { | ||
42 | super() | ||
43 | } | ||
44 | |||
45 | buildForm () { | ||
46 | this.form = this.formBuilder.group({ | ||
47 | email: [ '', USER_EMAIL.VALIDATORS ], | ||
48 | videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ] | ||
49 | }) | ||
50 | |||
51 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
52 | } | ||
53 | |||
54 | ngOnInit () { | ||
55 | this.buildForm() | ||
56 | |||
57 | this.paramsSub = this.route.params.subscribe(routeParams => { | ||
58 | const userId = routeParams['id'] | ||
59 | this.userService.getUser(userId).subscribe( | ||
60 | user => this.onUserFetched(user), | ||
61 | |||
62 | err => this.error = err.text | ||
63 | ) | ||
64 | }) | ||
65 | } | ||
66 | |||
67 | ngOnDestroy () { | ||
68 | this.paramsSub.unsubscribe() | ||
69 | } | ||
70 | |||
71 | formValidated () { | ||
72 | this.error = undefined | ||
73 | |||
74 | const userUpdate: UserUpdate = this.form.value | ||
75 | |||
76 | // A select in HTML is always mapped as a string, we convert it to number | ||
77 | userUpdate.videoQuota = parseInt(this.form.value['videoQuota'], 10) | ||
78 | |||
79 | this.userService.updateUser(this.userId, userUpdate).subscribe( | ||
80 | () => { | ||
81 | this.notificationsService.success('Success', `User ${this.username} updated.`) | ||
82 | this.router.navigate([ '/admin/users/list' ]) | ||
83 | }, | ||
84 | |||
85 | err => this.error = err.text | ||
86 | ) | ||
87 | } | ||
88 | |||
89 | isCreation () { | ||
90 | return false | ||
91 | } | ||
92 | |||
93 | getFormButtonTitle () { | ||
94 | return 'Update user' | ||
95 | } | ||
96 | |||
97 | private onUserFetched (userJson: User) { | ||
98 | this.userId = userJson.id | ||
99 | this.username = userJson.username | ||
100 | |||
101 | this.form.patchValue({ | ||
102 | email: userJson.email, | ||
103 | videoQuota: userJson.videoQuota | ||
104 | }) | ||
105 | } | ||
106 | } | ||
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 index bb4c99a3f..eb5bc9d4a 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.html +++ b/client/src/app/+admin/users/user-list/user-list.component.html | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | <ng2-smart-table | 6 | <ng2-smart-table |
7 | [settings]="tableSettings" [source]="usersSource" | 7 | [settings]="tableSettings" [source]="usersSource" |
8 | (delete)="removeUser($event)" | 8 | (delete)="removeUser($event)" (edit)="editUser($event)" |
9 | ></ng2-smart-table> | 9 | ></ng2-smart-table> |
10 | 10 | ||
11 | <a class="add-user btn btn-success pull-right" [routerLink]="['/admin/users/add']"> | 11 | <a class="add-user btn btn-success pull-right" [routerLink]="['/admin/users/add']"> |
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 index dbb85cedd..7187a2008 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.ts +++ b/client/src/app/+admin/users/user-list/user-list.component.ts | |||
@@ -5,6 +5,7 @@ import { NotificationsService } from 'angular2-notifications' | |||
5 | import { ConfirmService } from '../../../core' | 5 | import { ConfirmService } from '../../../core' |
6 | import { RestDataSource, User, Utils } from '../../../shared' | 6 | import { RestDataSource, User, Utils } from '../../../shared' |
7 | import { UserService } from '../shared' | 7 | import { UserService } from '../shared' |
8 | import { Router } from '@angular/router' | ||
8 | 9 | ||
9 | @Component({ | 10 | @Component({ |
10 | selector: 'my-user-list', | 11 | selector: 'my-user-list', |
@@ -22,15 +23,18 @@ export class UserListComponent { | |||
22 | actions: { | 23 | actions: { |
23 | position: 'right', | 24 | position: 'right', |
24 | add: false, | 25 | add: false, |
25 | edit: false, | 26 | edit: true, |
26 | delete: true | 27 | delete: true |
27 | }, | 28 | }, |
28 | delete: { | 29 | delete: { |
29 | deleteButtonContent: Utils.getRowDeleteButton() | 30 | deleteButtonContent: Utils.getRowDeleteButton() |
30 | }, | 31 | }, |
32 | edit: { | ||
33 | editButtonContent: Utils.getRowEditButton() | ||
34 | }, | ||
31 | pager: { | 35 | pager: { |
32 | display: true, | 36 | display: true, |
33 | perPage: 1 | 37 | perPage: 10 |
34 | }, | 38 | }, |
35 | columns: { | 39 | columns: { |
36 | id: { | 40 | id: { |
@@ -58,6 +62,7 @@ export class UserListComponent { | |||
58 | } | 62 | } |
59 | 63 | ||
60 | constructor ( | 64 | constructor ( |
65 | private router: Router, | ||
61 | private notificationsService: NotificationsService, | 66 | private notificationsService: NotificationsService, |
62 | private confirmService: ConfirmService, | 67 | private confirmService: ConfirmService, |
63 | private userService: UserService | 68 | private userService: UserService |
@@ -65,8 +70,12 @@ export class UserListComponent { | |||
65 | this.usersSource = this.userService.getDataSource() | 70 | this.usersSource = this.userService.getDataSource() |
66 | } | 71 | } |
67 | 72 | ||
68 | removeUser ({ data }) { | 73 | editUser ({ data }: { data: User }) { |
69 | const user: User = data | 74 | this.router.navigate([ '/admin', 'users', data.id, 'update' ]) |
75 | } | ||
76 | |||
77 | removeUser ({ data }: { data: User }) { | ||
78 | const user = data | ||
70 | 79 | ||
71 | if (user.username === 'root') { | 80 | if (user.username === 'root') { |
72 | this.notificationsService.error('Error', 'You cannot delete root.') | 81 | this.notificationsService.error('Error', 'You cannot delete root.') |
diff --git a/client/src/app/+admin/users/users.routes.ts b/client/src/app/+admin/users/users.routes.ts index 723c5715d..a6a9c4c19 100644 --- a/client/src/app/+admin/users/users.routes.ts +++ b/client/src/app/+admin/users/users.routes.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Routes } from '@angular/router' | 1 | import { Routes } from '@angular/router' |
2 | 2 | ||
3 | import { UsersComponent } from './users.component' | 3 | import { UsersComponent } from './users.component' |
4 | import { UserAddComponent } from './user-add' | 4 | import { UserAddComponent, UserUpdateComponent } from './user-edit' |
5 | import { UserListComponent } from './user-list' | 5 | import { UserListComponent } from './user-list' |
6 | 6 | ||
7 | export const UsersRoutes: Routes = [ | 7 | export const UsersRoutes: Routes = [ |
@@ -31,6 +31,15 @@ export const UsersRoutes: Routes = [ | |||
31 | title: 'Add a user' | 31 | title: 'Add a user' |
32 | } | 32 | } |
33 | } | 33 | } |
34 | }, | ||
35 | { | ||
36 | path: ':id/update', | ||
37 | component: UserUpdateComponent, | ||
38 | data: { | ||
39 | meta: { | ||
40 | title: 'Update a user' | ||
41 | } | ||
42 | } | ||
34 | } | 43 | } |
35 | ] | 44 | ] |
36 | } | 45 | } |