From 7da18e4420c4b71a8ecfda07f39324fbfec081c3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Aug 2016 21:45:21 +0200 Subject: Client: add user management --- client/src/app/admin/users/index.ts | 5 +++ client/src/app/admin/users/shared/index.ts | 1 + client/src/app/admin/users/shared/user.service.ts | 49 ++++++++++++++++++++++ client/src/app/admin/users/user-add/index.ts | 1 + .../admin/users/user-add/user-add.component.html | 29 +++++++++++++ .../app/admin/users/user-add/user-add.component.ts | 33 +++++++++++++++ client/src/app/admin/users/user-list/index.ts | 1 + .../admin/users/user-list/user-list.component.html | 24 +++++++++++ .../admin/users/user-list/user-list.component.scss | 7 ++++ .../admin/users/user-list/user-list.component.ts | 44 +++++++++++++++++++ client/src/app/admin/users/users.component.ts | 13 ++++++ client/src/app/admin/users/users.routes.ts | 27 ++++++++++++ 12 files changed, 234 insertions(+) create mode 100644 client/src/app/admin/users/index.ts create mode 100644 client/src/app/admin/users/shared/index.ts create mode 100644 client/src/app/admin/users/shared/user.service.ts create mode 100644 client/src/app/admin/users/user-add/index.ts create mode 100644 client/src/app/admin/users/user-add/user-add.component.html create mode 100644 client/src/app/admin/users/user-add/user-add.component.ts create mode 100644 client/src/app/admin/users/user-list/index.ts create mode 100644 client/src/app/admin/users/user-list/user-list.component.html create mode 100644 client/src/app/admin/users/user-list/user-list.component.scss create mode 100644 client/src/app/admin/users/user-list/user-list.component.ts create mode 100644 client/src/app/admin/users/users.component.ts create mode 100644 client/src/app/admin/users/users.routes.ts (limited to 'client/src/app/admin/users') 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 @@ +export * from './shared'; +export * from './user-add'; +export * from './user-list'; +export * from './users.component'; +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..be433f0a1 --- /dev/null +++ b/client/src/app/admin/users/shared/user.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@angular/core'; +import { Response } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; + +import { AuthHttp, User } from '../../../shared'; + +@Injectable() +export class UserService { + // TODO: merge this constant with account + private static BASE_USERS_URL = '/api/v1/users/'; + + constructor(private authHttp: AuthHttp) {} + + addUser(username: string, password: string) { + const body = { + username, + password + }; + + return this.authHttp.post(UserService.BASE_USERS_URL, body); + } + + getUsers() { + return this.authHttp.get(UserService.BASE_USERS_URL) + .map(res => res.json()) + .map(this.extractUsers) + .catch(this.handleError); + } + + removeUser(user: User) { + return this.authHttp.delete(UserService.BASE_USERS_URL + user.id); + } + + private extractUsers(body: any) { + const usersJson = body.data; + const totalUsers = body.total; + const users = []; + for (const userJson of usersJson) { + users.push(new User(userJson)); + } + + return { users, totalUsers }; + } + + private handleError(error: Response) { + console.error(error); + return Observable.throw(error.json().error || 'Server error'); + } +} 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..aa102358a --- /dev/null +++ b/client/src/app/admin/users/user-add/user-add.component.html @@ -0,0 +1,29 @@ +

Add user

+ +
{{ error }}
+ +
+
+ + +
+ Username is required with a length >= 3 and <= 20 +
+
+ +
+ + +
+ Password is required with a length >= 6 +
+
+ + +
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..30ca947a0 --- /dev/null +++ b/client/src/app/admin/users/user-add/user-add.component.ts @@ -0,0 +1,33 @@ +import { Control, ControlGroup, Validators } from '@angular/common'; +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { UserService } from '../shared'; + +@Component({ + selector: 'my-user-add', + template: require('./user-add.component.html'), +}) +export class UserAddComponent implements OnInit { + userAddForm: ControlGroup; + error: string = null; + + constructor(private router: Router, private userService: UserService) {} + + ngOnInit() { + this.userAddForm = new ControlGroup({ + username: new Control('', Validators.compose([ Validators.required, Validators.minLength(3), Validators.maxLength(20) ])), + password: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), + }); + } + + addUser(username: string, password: string) { + this.error = null; + + this.userService.addUser(username, password).subscribe( + ok => this.router.navigate([ '/admin/users/list' ]), + + err => this.error = err + ); + } +} 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..2aca05f2b --- /dev/null +++ b/client/src/app/admin/users/user-list/user-list.component.html @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + +
IdUsernameRemove
{{ user.id }}{{ user.username }} + +
+ + + + Add user + 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 @@ +.glyphicon-remove { + cursor: pointer; +} + +.add-user { + margin-top: 10px; +} 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..598daa42a --- /dev/null +++ b/client/src/app/admin/users/user-list/user-list.component.ts @@ -0,0 +1,44 @@ +import { Component, OnInit } from '@angular/core'; +import { ROUTER_DIRECTIVES } from '@angular/router'; + +import { User } from '../../../shared'; +import { UserService } from '../shared'; + +@Component({ + selector: 'my-user-list', + template: require('./user-list.component.html'), + styles: [ require('./user-list.component.scss') ], + directives: [ ROUTER_DIRECTIVES ] +}) +export class UserListComponent implements OnInit { + totalUsers: number; + users: User[]; + + constructor(private userService: UserService) {} + + ngOnInit() { + this.getUsers(); + } + + getUsers() { + this.userService.getUsers().subscribe( + ({ users, totalUsers }) => { + this.users = users; + this.totalUsers = totalUsers; + }, + + err => alert(err) + ); + } + + + removeUser(user: User) { + if (confirm('Are you sure?')) { + this.userService.removeUser(user).subscribe( + () => this.getUsers(), + + err => alert(err) + ); + } + } +} 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..46aa0862f --- /dev/null +++ b/client/src/app/admin/users/users.component.ts @@ -0,0 +1,13 @@ +import { Component } from '@angular/core'; +import { ROUTER_DIRECTIVES } from '@angular/router'; + +import { UserService } from './shared'; + +@Component({ + template: '', + directives: [ ROUTER_DIRECTIVES ], + providers: [ UserService ] +}) + +export class UsersComponent { +} 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..0457c3843 --- /dev/null +++ b/client/src/app/admin/users/users.routes.ts @@ -0,0 +1,27 @@ +import { RouterConfig } from '@angular/router'; + +import { UsersComponent } from './users.component'; +import { UserAddComponent } from './user-add'; +import { UserListComponent } from './user-list'; + +export const UsersRoutes: RouterConfig = [ + { + path: 'users', + component: UsersComponent, + children: [ + { + path: '', + redirectTo: 'list', + pathMatch: 'full' + }, + { + path: 'list', + component: UserListComponent + }, + { + path: 'add', + component: UserAddComponent + } + ] + } +]; -- cgit v1.2.3 From dfe3ec6bf66dfc5e2878f1df24f6a55b66812f46 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Aug 2016 18:24:24 +0200 Subject: Client: add users list/friends list titles --- client/src/app/admin/users/user-list/user-list.component.html | 2 ++ 1 file changed, 2 insertions(+) (limited to 'client/src/app/admin/users') 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 2aca05f2b..fa7f71864 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 @@ -1,3 +1,5 @@ +

Users list

+ -- cgit v1.2.3 From 0f6da32b148c0f4146b2ae9ad1add9a9f00cc339 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 14:37:49 +0200 Subject: Client: update to new form api --- .../app/admin/users/user-add/user-add.component.html | 16 ++++++++-------- .../src/app/admin/users/user-add/user-add.component.ts | 18 +++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'client/src/app/admin/users') 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 index aa102358a..09219893b 100644 --- a/client/src/app/admin/users/user-add/user-add.component.html +++ b/client/src/app/admin/users/user-add/user-add.component.html @@ -2,14 +2,14 @@
{{ error }}
-
+
-
+
Username is required with a length >= 3 and <= 20
@@ -17,13 +17,13 @@
-
+
Password is required with a length >= 6
- + 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 30ca947a0..b7efd3a80 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,5 +1,6 @@ -import { Control, ControlGroup, Validators } from '@angular/common'; +import { Validators } from '@angular/common'; import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormControl, REACTIVE_FORM_DIRECTIVES } from '@angular/forms'; import { Router } from '@angular/router'; import { UserService } from '../shared'; @@ -7,24 +8,27 @@ import { UserService } from '../shared'; @Component({ selector: 'my-user-add', template: require('./user-add.component.html'), + directives: [ REACTIVE_FORM_DIRECTIVES ] }) export class UserAddComponent implements OnInit { - userAddForm: ControlGroup; + userAddForm: FormGroup; error: string = null; + username = ''; + password = ''; constructor(private router: Router, private userService: UserService) {} ngOnInit() { - this.userAddForm = new ControlGroup({ - username: new Control('', Validators.compose([ Validators.required, Validators.minLength(3), Validators.maxLength(20) ])), - password: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), + this.userAddForm = new FormGroup({ + username: new FormControl('', [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ]), + password: new FormControl('', [ Validators.required, Validators.minLength(6) ]), }); } - addUser(username: string, password: string) { + addUser() { this.error = null; - this.userService.addUser(username, password).subscribe( + this.userService.addUser(this.username, this.password).subscribe( ok => this.router.navigate([ '/admin/users/list' ]), err => this.error = err -- cgit v1.2.3 From de59c48f5f317018e3f746bbe4a7b7efe00109f2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 16:54:21 +0200 Subject: Client: centralize http res extraction in a service --- client/src/app/admin/users/shared/user.service.ts | 28 +++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'client/src/app/admin/users') diff --git a/client/src/app/admin/users/shared/user.service.ts b/client/src/app/admin/users/shared/user.service.ts index be433f0a1..d96db4575 100644 --- a/client/src/app/admin/users/shared/user.service.ts +++ b/client/src/app/admin/users/shared/user.service.ts @@ -1,15 +1,16 @@ import { Injectable } from '@angular/core'; -import { Response } from '@angular/http'; -import { Observable } from 'rxjs/Observable'; -import { AuthHttp, User } from '../../../shared'; +import { AuthHttp, RestExtractor, ResultList, User } from '../../../shared'; @Injectable() export class UserService { // TODO: merge this constant with account private static BASE_USERS_URL = '/api/v1/users/'; - constructor(private authHttp: AuthHttp) {} + constructor( + private authHttp: AuthHttp, + private restExtractor: RestExtractor + ) {} addUser(username: string, password: string) { const body = { @@ -17,23 +18,25 @@ export class UserService { password }; - return this.authHttp.post(UserService.BASE_USERS_URL, body); + return this.authHttp.post(UserService.BASE_USERS_URL, body) + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)); } getUsers() { return this.authHttp.get(UserService.BASE_USERS_URL) - .map(res => res.json()) + .map(this.restExtractor.extractDataList) .map(this.extractUsers) - .catch(this.handleError); + .catch((res) => this.restExtractor.handleError(res)); } removeUser(user: User) { return this.authHttp.delete(UserService.BASE_USERS_URL + user.id); } - private extractUsers(body: any) { - const usersJson = body.data; - const totalUsers = body.total; + private extractUsers(result: ResultList) { + const usersJson = result.data; + const totalUsers = result.total; const users = []; for (const userJson of usersJson) { users.push(new User(userJson)); @@ -41,9 +44,4 @@ export class UserService { return { users, totalUsers }; } - - private handleError(error: Response) { - console.error(error); - return Observable.throw(error.json().error || 'Server error'); - } } -- cgit v1.2.3 From bf68dd752d6e3d5fce791dd8e0df9debb9d96902 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 17:42:56 +0200 Subject: Client: fix error display for component --- client/src/app/admin/users/shared/user.service.ts | 2 +- client/src/app/admin/users/user-add/user-add.component.ts | 2 +- client/src/app/admin/users/user-list/user-list.component.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'client/src/app/admin/users') diff --git a/client/src/app/admin/users/shared/user.service.ts b/client/src/app/admin/users/shared/user.service.ts index d96db4575..13be553c0 100644 --- a/client/src/app/admin/users/shared/user.service.ts +++ b/client/src/app/admin/users/shared/user.service.ts @@ -20,7 +20,7 @@ export class UserService { return this.authHttp.post(UserService.BASE_USERS_URL, body) .map(this.restExtractor.extractDataBool) - .catch((res) => this.restExtractor.handleError(res)); + .catch(this.restExtractor.handleError); } getUsers() { 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 b7efd3a80..8dd98cc5c 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 @@ -31,7 +31,7 @@ export class UserAddComponent implements OnInit { this.userService.addUser(this.username, this.password).subscribe( ok => this.router.navigate([ '/admin/users/list' ]), - err => this.error = err + err => this.error = err.text ); } } 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 598daa42a..c89a61bca 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 @@ -27,7 +27,7 @@ export class UserListComponent implements OnInit { this.totalUsers = totalUsers; }, - err => alert(err) + err => alert(err.text) ); } @@ -37,7 +37,7 @@ export class UserListComponent implements OnInit { this.userService.removeUser(user).subscribe( () => this.getUsers(), - err => alert(err) + err => alert(err.text) ); } } -- cgit v1.2.3 From 21496304370d6e84329091ccf5388c57bad67785 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Aug 2016 19:02:43 +0200 Subject: Client: ID column smaller --- client/src/app/admin/users/user-list/user-list.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'client/src/app/admin/users') 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 fa7f71864..2ef9ea0e0 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 @@ -3,7 +3,7 @@
- + -- cgit v1.2.3 From ab32b0fc805b92c5a1d7ac5901cb1a38e94622ca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Sep 2016 22:40:57 +0200 Subject: Dirty update to Angular RC6 --- client/src/app/admin/users/user-add/user-add.component.ts | 6 ++---- client/src/app/admin/users/user-list/user-list.component.ts | 4 +--- client/src/app/admin/users/users.component.ts | 7 +------ client/src/app/admin/users/users.routes.ts | 4 ++-- 4 files changed, 6 insertions(+), 15 deletions(-) (limited to 'client/src/app/admin/users') 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 8dd98cc5c..e3f4b2e1a 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,14 +1,12 @@ -import { Validators } from '@angular/common'; import { Component, OnInit } from '@angular/core'; -import { FormGroup, FormControl, REACTIVE_FORM_DIRECTIVES } from '@angular/forms'; +import { FormGroup, FormControl, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { UserService } from '../shared'; @Component({ selector: 'my-user-add', - template: require('./user-add.component.html'), - directives: [ REACTIVE_FORM_DIRECTIVES ] + template: require('./user-add.component.html') }) export class UserAddComponent implements OnInit { userAddForm: FormGroup; 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 c89a61bca..d3827eb28 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 @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; -import { ROUTER_DIRECTIVES } from '@angular/router'; import { User } from '../../../shared'; import { UserService } from '../shared'; @@ -7,8 +6,7 @@ import { UserService } from '../shared'; @Component({ selector: 'my-user-list', template: require('./user-list.component.html'), - styles: [ require('./user-list.component.scss') ], - directives: [ ROUTER_DIRECTIVES ] + styles: [ require('./user-list.component.scss') ] }) export class UserListComponent implements OnInit { totalUsers: number; diff --git a/client/src/app/admin/users/users.component.ts b/client/src/app/admin/users/users.component.ts index 46aa0862f..37e3b158d 100644 --- a/client/src/app/admin/users/users.component.ts +++ b/client/src/app/admin/users/users.component.ts @@ -1,12 +1,7 @@ import { Component } from '@angular/core'; -import { ROUTER_DIRECTIVES } from '@angular/router'; - -import { UserService } from './shared'; @Component({ - template: '', - directives: [ ROUTER_DIRECTIVES ], - providers: [ UserService ] + template: '' }) export class UsersComponent { diff --git a/client/src/app/admin/users/users.routes.ts b/client/src/app/admin/users/users.routes.ts index 0457c3843..eb71bd0ae 100644 --- a/client/src/app/admin/users/users.routes.ts +++ b/client/src/app/admin/users/users.routes.ts @@ -1,10 +1,10 @@ -import { RouterConfig } from '@angular/router'; +import { Routes } from '@angular/router'; import { UsersComponent } from './users.component'; import { UserAddComponent } from './user-add'; import { UserListComponent } from './user-list'; -export const UsersRoutes: RouterConfig = [ +export const UsersRoutes: Routes = [ { path: 'users', component: UsersComponent, -- cgit v1.2.3 From 4b2f33f3c6d109365090b08244d7f99ad4e69025 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Sep 2016 22:16:51 +0200 Subject: Client: reactive forms --- .../admin/users/user-add/user-add.component.html | 20 +++++----- .../app/admin/users/user-add/user-add.component.ts | 44 ++++++++++++++++------ 2 files changed, 43 insertions(+), 21 deletions(-) (limited to 'client/src/app/admin/users') 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 index 09219893b..9b76c7c1b 100644 --- a/client/src/app/admin/users/user-add/user-add.component.html +++ b/client/src/app/admin/users/user-add/user-add.component.html @@ -2,28 +2,28 @@
{{ error }}
-
+
-
- Username is required with a length >= 3 and <= 20 +
+ {{ formErrors.username }}
-
- Password is required with a length >= 6 +
+ {{ formErrors.password }}
- + 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 e3f4b2e1a..b79437795 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,32 +1,54 @@ import { Component, OnInit } from '@angular/core'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { FormBuilder, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { UserService } from '../shared'; +import { FormReactive, USER_USERNAME, USER_PASSWORD } from '../../../shared'; @Component({ selector: 'my-user-add', template: require('./user-add.component.html') }) -export class UserAddComponent implements OnInit { - userAddForm: FormGroup; +export class UserAddComponent extends FormReactive implements OnInit { error: string = null; - username = ''; - password = ''; - constructor(private router: Router, private userService: UserService) {} + form: FormGroup; + formErrors = { + 'username': '', + 'password': '' + }; + validationMessages = { + 'username': USER_USERNAME.MESSAGES, + 'password': USER_PASSWORD.MESSAGES, + }; - ngOnInit() { - this.userAddForm = new FormGroup({ - username: new FormControl('', [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ]), - password: new FormControl('', [ Validators.required, Validators.minLength(6) ]), + constructor( + private formBuilder: FormBuilder, + private router: Router, + private userService: UserService + ) { + super(); + } + + buildForm() { + this.form = this.formBuilder.group({ + username: [ '', USER_USERNAME.VALIDATORS ], + password: [ '', USER_PASSWORD.VALIDATORS ], }); + + this.form.valueChanges.subscribe(data => this.onValueChanged(data)); + } + + ngOnInit() { + this.buildForm(); } addUser() { this.error = null; - this.userService.addUser(this.username, this.password).subscribe( + const { username, password } = this.form.value; + + this.userService.addUser(username, password).subscribe( ok => this.router.navigate([ '/admin/users/list' ]), err => this.error = err.text -- cgit v1.2.3 From ec8d8440a893ba64075da2e57ea04c7976e0b303 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 19 Sep 2016 22:49:31 +0200 Subject: Client: use templateUrl/styleUrls instead of require --- client/src/app/admin/users/user-add/user-add.component.ts | 2 +- client/src/app/admin/users/user-list/user-list.component.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'client/src/app/admin/users') 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 b79437795..ab96fb01d 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 @@ -7,7 +7,7 @@ import { FormReactive, USER_USERNAME, USER_PASSWORD } from '../../../shared'; @Component({ selector: 'my-user-add', - template: require('./user-add.component.html') + templateUrl: './user-add.component.html' }) export class UserAddComponent extends FormReactive implements OnInit { error: string = null; 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 d3827eb28..03f4e5c0a 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,8 +5,8 @@ import { UserService } from '../shared'; @Component({ selector: 'my-user-list', - template: require('./user-list.component.html'), - styles: [ require('./user-list.component.scss') ] + templateUrl: './user-list.component.html', + styleUrls: [ './user-list.component.scss' ] }) export class UserListComponent implements OnInit { totalUsers: number; -- cgit v1.2.3 From b539c9b34c246eb7bfc4afea92ae095cb1c38e59 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 23 Sep 2016 17:20:15 +0200 Subject: Client: display created user date --- client/src/app/admin/users/user-list/user-list.component.html | 2 ++ 1 file changed, 2 insertions(+) (limited to 'client/src/app/admin/users') 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 2ef9ea0e0..328b1be77 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,6 +5,7 @@
+ @@ -13,6 +14,7 @@ + -- cgit v1.2.3
IdID Username Remove
ID UsernameCreated Date Remove
{{ user.id }} {{ user.username }}{{ user.createdDate | date: 'medium' }}