diff options
Diffstat (limited to 'client/src/app/+admin/users/user-add')
-rw-r--r-- | client/src/app/+admin/users/user-add/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/+admin/users/user-add/user-add.component.ts | 50 |
2 files changed, 26 insertions, 26 deletions
diff --git a/client/src/app/+admin/users/user-add/index.ts b/client/src/app/+admin/users/user-add/index.ts index 66d5ca04f..3a4654101 100644 --- a/client/src/app/+admin/users/user-add/index.ts +++ b/client/src/app/+admin/users/user-add/index.ts | |||
@@ -1 +1 @@ | |||
export * from './user-add.component'; | export * from './user-add.component' | ||
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 index f1d2fde80..2d25ab469 100644 --- a/client/src/app/+admin/users/user-add/user-add.component.ts +++ b/client/src/app/+admin/users/user-add/user-add.component.ts | |||
@@ -1,71 +1,71 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { FormBuilder, FormGroup } from '@angular/forms'; | 2 | import { FormBuilder, FormGroup } from '@angular/forms' |
3 | import { Router } from '@angular/router'; | 3 | import { Router } from '@angular/router' |
4 | 4 | ||
5 | import { NotificationsService } from 'angular2-notifications'; | 5 | import { NotificationsService } from 'angular2-notifications' |
6 | 6 | ||
7 | import { UserService } from '../shared'; | 7 | import { UserService } from '../shared' |
8 | import { | 8 | import { |
9 | FormReactive, | 9 | FormReactive, |
10 | USER_USERNAME, | 10 | USER_USERNAME, |
11 | USER_EMAIL, | 11 | USER_EMAIL, |
12 | USER_PASSWORD | 12 | USER_PASSWORD |
13 | } from '../../../shared'; | 13 | } from '../../../shared' |
14 | 14 | ||
15 | @Component({ | 15 | @Component({ |
16 | selector: 'my-user-add', | 16 | selector: 'my-user-add', |
17 | templateUrl: './user-add.component.html' | 17 | templateUrl: './user-add.component.html' |
18 | }) | 18 | }) |
19 | export class UserAddComponent extends FormReactive implements OnInit { | 19 | export class UserAddComponent extends FormReactive implements OnInit { |
20 | error: string = null; | 20 | error: string = null |
21 | 21 | ||
22 | form: FormGroup; | 22 | form: FormGroup |
23 | formErrors = { | 23 | formErrors = { |
24 | 'username': '', | 24 | 'username': '', |
25 | 'email': '', | 25 | 'email': '', |
26 | 'password': '' | 26 | 'password': '' |
27 | }; | 27 | } |
28 | validationMessages = { | 28 | validationMessages = { |
29 | 'username': USER_USERNAME.MESSAGES, | 29 | 'username': USER_USERNAME.MESSAGES, |
30 | 'email': USER_EMAIL.MESSAGES, | 30 | 'email': USER_EMAIL.MESSAGES, |
31 | 'password': USER_PASSWORD.MESSAGES, | 31 | 'password': USER_PASSWORD.MESSAGES |
32 | }; | 32 | } |
33 | 33 | ||
34 | constructor( | 34 | constructor ( |
35 | private formBuilder: FormBuilder, | 35 | private formBuilder: FormBuilder, |
36 | private router: Router, | 36 | private router: Router, |
37 | private notificationsService: NotificationsService, | 37 | private notificationsService: NotificationsService, |
38 | private userService: UserService | 38 | private userService: UserService |
39 | ) { | 39 | ) { |
40 | super(); | 40 | super() |
41 | } | 41 | } |
42 | 42 | ||
43 | buildForm() { | 43 | buildForm () { |
44 | this.form = this.formBuilder.group({ | 44 | this.form = this.formBuilder.group({ |
45 | username: [ '', USER_USERNAME.VALIDATORS ], | 45 | username: [ '', USER_USERNAME.VALIDATORS ], |
46 | email: [ '', USER_EMAIL.VALIDATORS ], | 46 | email: [ '', USER_EMAIL.VALIDATORS ], |
47 | password: [ '', USER_PASSWORD.VALIDATORS ], | 47 | password: [ '', USER_PASSWORD.VALIDATORS ] |
48 | }); | 48 | }) |
49 | 49 | ||
50 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | 50 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) |
51 | } | 51 | } |
52 | 52 | ||
53 | ngOnInit() { | 53 | ngOnInit () { |
54 | this.buildForm(); | 54 | this.buildForm() |
55 | } | 55 | } |
56 | 56 | ||
57 | addUser() { | 57 | addUser () { |
58 | this.error = null; | 58 | this.error = null |
59 | 59 | ||
60 | const { username, password, email } = this.form.value; | 60 | const { username, password, email } = this.form.value |
61 | 61 | ||
62 | this.userService.addUser(username, password, email).subscribe( | 62 | this.userService.addUser(username, password, email).subscribe( |
63 | () => { | 63 | () => { |
64 | this.notificationsService.success('Success', `User ${username} created.`); | 64 | this.notificationsService.success('Success', `User ${username} created.`) |
65 | this.router.navigate([ '/admin/users/list' ]); | 65 | this.router.navigate([ '/admin/users/list' ]) |
66 | }, | 66 | }, |
67 | 67 | ||
68 | err => this.error = err.text | 68 | err => this.error = err.text |
69 | ); | 69 | ) |
70 | } | 70 | } |
71 | } | 71 | } |