diff options
Diffstat (limited to 'client/src/app/+admin/users/user-add')
3 files changed, 0 insertions, 138 deletions
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-add/user-add.component.html b/client/src/app/+admin/users/user-add/user-add.component.html deleted file mode 100644 index f84d72c7c..000000000 --- a/client/src/app/+admin/users/user-add/user-add.component.html +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | <div class="row"> | ||
2 | <div class="content-padding"> | ||
3 | |||
4 | <h3>Add user</h3> | ||
5 | |||
6 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | ||
7 | |||
8 | <form role="form" (ngSubmit)="addUser()" [formGroup]="form"> | ||
9 | <div class="form-group"> | ||
10 | <label for="username">Username</label> | ||
11 | <input | ||
12 | type="text" class="form-control" id="username" placeholder="john" | ||
13 | formControlName="username" | ||
14 | > | ||
15 | <div *ngIf="formErrors.username" class="alert alert-danger"> | ||
16 | {{ formErrors.username }} | ||
17 | </div> | ||
18 | </div> | ||
19 | |||
20 | <div class="form-group"> | ||
21 | <label for="email">Email</label> | ||
22 | <input | ||
23 | type="text" class="form-control" id="email" placeholder="mail@example.com" | ||
24 | formControlName="email" | ||
25 | > | ||
26 | <div *ngIf="formErrors.email" class="alert alert-danger"> | ||
27 | {{ formErrors.email }} | ||
28 | </div> | ||
29 | </div> | ||
30 | |||
31 | <div class="form-group"> | ||
32 | <label for="password">Password</label> | ||
33 | <input | ||
34 | type="password" class="form-control" id="password" | ||
35 | formControlName="password" | ||
36 | > | ||
37 | <div *ngIf="formErrors.password" class="alert alert-danger"> | ||
38 | {{ formErrors.password }} | ||
39 | </div> | ||
40 | </div> | ||
41 | |||
42 | <div class="form-group"> | ||
43 | <label for="videoQuota">Video quota</label> | ||
44 | <select class="form-control" id="videoQuota" formControlName="videoQuota"> | ||
45 | <option value="-1">Unlimited</option> | ||
46 | <option value="100000000">100MB</option> | ||
47 | <option value="500000000">500MB</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> | ||
53 | </div> | ||
54 | |||
55 | <input type="submit" value="Add user" class="btn btn-default" [disabled]="!form.valid"> | ||
56 | </form> | ||
57 | </div> | ||
58 | </div> | ||
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 deleted file mode 100644 index 91377a933..000000000 --- a/client/src/app/+admin/users/user-add/user-add.component.ts +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
3 | import { Router } from '@angular/router' | ||
4 | |||
5 | import { NotificationsService } from 'angular2-notifications' | ||
6 | |||
7 | import { UserService } from '../shared' | ||
8 | import { | ||
9 | FormReactive, | ||
10 | USER_USERNAME, | ||
11 | USER_EMAIL, | ||
12 | USER_PASSWORD, | ||
13 | USER_VIDEO_QUOTA | ||
14 | } from '../../../shared' | ||
15 | import { UserCreate } from '../../../../../../shared' | ||
16 | |||
17 | @Component({ | ||
18 | selector: 'my-user-add', | ||
19 | templateUrl: './user-add.component.html' | ||
20 | }) | ||
21 | export class UserAddComponent extends FormReactive implements OnInit { | ||
22 | error: string = null | ||
23 | |||
24 | form: FormGroup | ||
25 | formErrors = { | ||
26 | 'username': '', | ||
27 | 'email': '', | ||
28 | 'password': '', | ||
29 | 'videoQuota': '' | ||
30 | } | ||
31 | validationMessages = { | ||
32 | 'username': USER_USERNAME.MESSAGES, | ||
33 | 'email': USER_EMAIL.MESSAGES, | ||
34 | 'password': USER_PASSWORD.MESSAGES, | ||
35 | 'videoQuota': USER_VIDEO_QUOTA.MESSAGES | ||
36 | } | ||
37 | |||
38 | constructor ( | ||
39 | private formBuilder: FormBuilder, | ||
40 | private router: Router, | ||
41 | private notificationsService: NotificationsService, | ||
42 | private userService: UserService | ||
43 | ) { | ||
44 | super() | ||
45 | } | ||
46 | |||
47 | buildForm () { | ||
48 | this.form = this.formBuilder.group({ | ||
49 | username: [ '', USER_USERNAME.VALIDATORS ], | ||
50 | email: [ '', USER_EMAIL.VALIDATORS ], | ||
51 | password: [ '', USER_PASSWORD.VALIDATORS ], | ||
52 | videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ] | ||
53 | }) | ||
54 | |||
55 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
56 | } | ||
57 | |||
58 | ngOnInit () { | ||
59 | this.buildForm() | ||
60 | } | ||
61 | |||
62 | addUser () { | ||
63 | this.error = null | ||
64 | |||
65 | const userCreate: UserCreate = this.form.value | ||
66 | |||
67 | // A select in HTML is always mapped as a string, we convert it to number | ||
68 | userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10) | ||
69 | |||
70 | this.userService.addUser(userCreate).subscribe( | ||
71 | () => { | ||
72 | this.notificationsService.success('Success', `User ${userCreate.username} created.`) | ||
73 | this.router.navigate([ '/admin/users/list' ]) | ||
74 | }, | ||
75 | |||
76 | err => this.error = err.text | ||
77 | ) | ||
78 | } | ||
79 | } | ||