From b99290b1d5d736083513fb8f66e91f61bfe07e0b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 23 Jan 2017 22:32:43 +0100 Subject: Client: lazy load admin area --- 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 | 57 ---------------------- client/src/app/admin/users/user-list/index.ts | 1 - .../admin/users/user-list/user-list.component.html | 28 ----------- .../admin/users/user-list/user-list.component.scss | 7 --- .../admin/users/user-list/user-list.component.ts | 42 ---------------- client/src/app/admin/users/users.component.ts | 8 --- client/src/app/admin/users/users.routes.ts | 37 -------------- 12 files changed, 265 deletions(-) delete mode 100644 client/src/app/admin/users/index.ts delete mode 100644 client/src/app/admin/users/shared/index.ts delete mode 100644 client/src/app/admin/users/shared/user.service.ts delete mode 100644 client/src/app/admin/users/user-add/index.ts delete mode 100644 client/src/app/admin/users/user-add/user-add.component.html delete mode 100644 client/src/app/admin/users/user-add/user-add.component.ts delete mode 100644 client/src/app/admin/users/user-list/index.ts delete mode 100644 client/src/app/admin/users/user-list/user-list.component.html delete mode 100644 client/src/app/admin/users/user-list/user-list.component.scss delete mode 100644 client/src/app/admin/users/user-list/user-list.component.ts delete mode 100644 client/src/app/admin/users/users.component.ts delete 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 deleted file mode 100644 index e98a81f62..000000000 --- a/client/src/app/admin/users/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index e17ee5c7a..000000000 --- a/client/src/app/admin/users/shared/index.ts +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index d9005b213..000000000 --- a/client/src/app/admin/users/shared/user.service.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Injectable } from '@angular/core'; -import 'rxjs/add/operator/catch'; -import 'rxjs/add/operator/map'; - -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, - private restExtractor: RestExtractor - ) {} - - addUser(username: string, password: string) { - const body = { - username, - password - }; - - return this.authHttp.post(UserService.BASE_USERS_URL, body) - .map(this.restExtractor.extractDataBool) - .catch(this.restExtractor.handleError); - } - - getUsers() { - return this.authHttp.get(UserService.BASE_USERS_URL) - .map(this.restExtractor.extractDataList) - .map(this.extractUsers) - .catch((res) => this.restExtractor.handleError(res)); - } - - removeUser(user: User) { - return this.authHttp.delete(UserService.BASE_USERS_URL + user.id); - } - - private extractUsers(result: ResultList) { - const usersJson = result.data; - const totalUsers = result.total; - const users = []; - for (const userJson of usersJson) { - users.push(new User(userJson)); - } - - return { users, totalUsers }; - } -} 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 66d5ca04f..000000000 --- a/client/src/app/admin/users/user-add/index.ts +++ /dev/null @@ -1 +0,0 @@ -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 9b76c7c1b..000000000 --- a/client/src/app/admin/users/user-add/user-add.component.html +++ /dev/null @@ -1,29 +0,0 @@ -

Add user

- -
{{ error }}
- -
-
- - -
- {{ formErrors.username }} -
-
- -
- - -
- {{ 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 deleted file mode 100644 index ab96fb01d..000000000 --- a/client/src/app/admin/users/user-add/user-add.component.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -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', - templateUrl: './user-add.component.html' -}) -export class UserAddComponent extends FormReactive implements OnInit { - error: string = null; - - form: FormGroup; - formErrors = { - 'username': '', - 'password': '' - }; - validationMessages = { - 'username': USER_USERNAME.MESSAGES, - 'password': USER_PASSWORD.MESSAGES, - }; - - 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; - - const { username, password } = this.form.value; - - this.userService.addUser(username, password).subscribe( - ok => this.router.navigate([ '/admin/users/list' ]), - - err => this.error = err.text - ); - } -} diff --git a/client/src/app/admin/users/user-list/index.ts b/client/src/app/admin/users/user-list/index.ts deleted file mode 100644 index 51fbefa80..000000000 --- a/client/src/app/admin/users/user-list/index.ts +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 36193d119..000000000 --- a/client/src/app/admin/users/user-list/user-list.component.html +++ /dev/null @@ -1,28 +0,0 @@ -

Users list

- - - - - - - - - - - - - - - - - - - -
IDUsernameCreated DateRemove
{{ user.id }}{{ user.username }}{{ user.createdAt | date: 'medium' }} - -
- - - - 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 deleted file mode 100644 index e9f61e900..000000000 --- a/client/src/app/admin/users/user-list/user-list.component.scss +++ /dev/null @@ -1,7 +0,0 @@ -.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 deleted file mode 100644 index 03f4e5c0a..000000000 --- a/client/src/app/admin/users/user-list/user-list.component.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Component, OnInit } from '@angular/core'; - -import { User } from '../../../shared'; -import { UserService } from '../shared'; - -@Component({ - selector: 'my-user-list', - templateUrl: './user-list.component.html', - styleUrls: [ './user-list.component.scss' ] -}) -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.text) - ); - } - - - removeUser(user: User) { - if (confirm('Are you sure?')) { - this.userService.removeUser(user).subscribe( - () => this.getUsers(), - - err => alert(err.text) - ); - } - } -} diff --git a/client/src/app/admin/users/users.component.ts b/client/src/app/admin/users/users.component.ts deleted file mode 100644 index 37e3b158d..000000000 --- a/client/src/app/admin/users/users.component.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - template: '' -}) - -export class UsersComponent { -} diff --git a/client/src/app/admin/users/users.routes.ts b/client/src/app/admin/users/users.routes.ts deleted file mode 100644 index 92e3e43e3..000000000 --- a/client/src/app/admin/users/users.routes.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Routes } from '@angular/router'; - -import { UsersComponent } from './users.component'; -import { UserAddComponent } from './user-add'; -import { UserListComponent } from './user-list'; - -export const UsersRoutes: Routes = [ - { - path: 'users', - component: UsersComponent, - children: [ - { - path: '', - redirectTo: 'list', - pathMatch: 'full' - }, - { - path: 'list', - component: UserListComponent, - data: { - meta: { - titleSuffix: ' - Users list' - } - } - }, - { - path: 'add', - component: UserAddComponent, - data: { - meta: { - titleSuffix: ' - Add a user' - } - } - } - ] - } -]; -- cgit v1.2.3