aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/users
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
commitdf98563e2104b82b119c00a3cd83cd0dc1242d25 (patch)
treea9720bf01bac9ad5646bd3d3c9bc7653617afdad /client/src/app/+admin/users
parent46757b477c1adb5f98060d15998a3852e18902a6 (diff)
downloadPeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.gz
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.zst
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.zip
Use typescript standard and lint all files
Diffstat (limited to 'client/src/app/+admin/users')
-rw-r--r--client/src/app/+admin/users/index.ts10
-rw-r--r--client/src/app/+admin/users/shared/index.ts2
-rw-r--r--client/src/app/+admin/users/shared/user.service.ts26
-rw-r--r--client/src/app/+admin/users/user-add/index.ts2
-rw-r--r--client/src/app/+admin/users/user-add/user-add.component.ts50
-rw-r--r--client/src/app/+admin/users/user-list/index.ts2
-rw-r--r--client/src/app/+admin/users/user-list/user-list.component.ts36
-rw-r--r--client/src/app/+admin/users/users.component.ts5
-rw-r--r--client/src/app/+admin/users/users.routes.ts10
9 files changed, 71 insertions, 72 deletions
diff --git a/client/src/app/+admin/users/index.ts b/client/src/app/+admin/users/index.ts
index e98a81f62..cef2c282c 100644
--- a/client/src/app/+admin/users/index.ts
+++ b/client/src/app/+admin/users/index.ts
@@ -1,5 +1,5 @@
1export * from './shared'; 1export * from './shared'
2export * from './user-add'; 2export * from './user-add'
3export * from './user-list'; 3export * from './user-list'
4export * from './users.component'; 4export * from './users.component'
5export * from './users.routes'; 5export * from './users.routes'
diff --git a/client/src/app/+admin/users/shared/index.ts b/client/src/app/+admin/users/shared/index.ts
index e17ee5c7a..1f1302dc5 100644
--- a/client/src/app/+admin/users/shared/index.ts
+++ b/client/src/app/+admin/users/shared/index.ts
@@ -1 +1 @@
export * from './user.service'; 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
index 9c7176d39..d52993a29 100644
--- a/client/src/app/+admin/users/shared/user.service.ts
+++ b/client/src/app/+admin/users/shared/user.service.ts
@@ -1,35 +1,35 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import 'rxjs/add/operator/catch'; 2import 'rxjs/add/operator/catch'
3import 'rxjs/add/operator/map'; 3import 'rxjs/add/operator/map'
4 4
5import { AuthHttp, RestExtractor, RestDataSource, User } from '../../../shared'; 5import { AuthHttp, RestExtractor, RestDataSource, User } from '../../../shared'
6 6
7@Injectable() 7@Injectable()
8export class UserService { 8export class UserService {
9 private static BASE_USERS_URL = API_URL + '/api/v1/users/'; 9 private static BASE_USERS_URL = API_URL + '/api/v1/users/'
10 10
11 constructor( 11 constructor (
12 private authHttp: AuthHttp, 12 private authHttp: AuthHttp,
13 private restExtractor: RestExtractor 13 private restExtractor: RestExtractor
14 ) {} 14 ) {}
15 15
16 addUser(username: string, password: string, email: string) { 16 addUser (username: string, password: string, email: string) {
17 const body = { 17 const body = {
18 username, 18 username,
19 email, 19 email,
20 password 20 password
21 }; 21 }
22 22
23 return this.authHttp.post(UserService.BASE_USERS_URL, body) 23 return this.authHttp.post(UserService.BASE_USERS_URL, body)
24 .map(this.restExtractor.extractDataBool) 24 .map(this.restExtractor.extractDataBool)
25 .catch(this.restExtractor.handleError); 25 .catch(this.restExtractor.handleError)
26 } 26 }
27 27
28 getDataSource() { 28 getDataSource () {
29 return new RestDataSource(this.authHttp, UserService.BASE_USERS_URL); 29 return new RestDataSource(this.authHttp, UserService.BASE_USERS_URL)
30 } 30 }
31 31
32 removeUser(user: User) { 32 removeUser (user: User) {
33 return this.authHttp.delete(UserService.BASE_USERS_URL + user.id); 33 return this.authHttp.delete(UserService.BASE_USERS_URL + user.id)
34 } 34 }
35} 35}
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 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'; 2import { FormBuilder, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router'; 3import { Router } from '@angular/router'
4 4
5import { NotificationsService } from 'angular2-notifications'; 5import { NotificationsService } from 'angular2-notifications'
6 6
7import { UserService } from '../shared'; 7import { UserService } from '../shared'
8import { 8import {
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})
19export class UserAddComponent extends FormReactive implements OnInit { 19export 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}
diff --git a/client/src/app/+admin/users/user-list/index.ts b/client/src/app/+admin/users/user-list/index.ts
index 51fbefa80..1826a4abe 100644
--- a/client/src/app/+admin/users/user-list/index.ts
+++ b/client/src/app/+admin/users/user-list/index.ts
@@ -1 +1 @@
export * from './user-list.component'; export * from './user-list.component'
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 69ae4353d..b6fb0ed99 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,10 +1,10 @@
1import { Component } from '@angular/core'; 1import { Component } from '@angular/core'
2 2
3import { NotificationsService } from 'angular2-notifications'; 3import { NotificationsService } from 'angular2-notifications'
4 4
5import { ConfirmService } from '../../../core'; 5import { ConfirmService } from '../../../core'
6import { User, Utils } from '../../../shared'; 6import { User, Utils } from '../../../shared'
7import { UserService } from '../shared'; 7import { UserService } from '../shared'
8 8
9@Component({ 9@Component({
10 selector: 'my-user-list', 10 selector: 'my-user-list',
@@ -12,7 +12,7 @@ import { UserService } from '../shared';
12 styleUrls: [ './user-list.component.scss' ] 12 styleUrls: [ './user-list.component.scss' ]
13}) 13})
14export class UserListComponent { 14export class UserListComponent {
15 usersSource = null; 15 usersSource = null
16 tableSettings = { 16 tableSettings = {
17 mode: 'external', 17 mode: 'external',
18 attr: { 18 attr: {
@@ -52,37 +52,37 @@ export class UserListComponent {
52 valuePrepareFunction: Utils.dateToHuman 52 valuePrepareFunction: Utils.dateToHuman
53 } 53 }
54 } 54 }
55 }; 55 }
56 56
57 constructor( 57 constructor (
58 private notificationsService: NotificationsService, 58 private notificationsService: NotificationsService,
59 private confirmService: ConfirmService, 59 private confirmService: ConfirmService,
60 private userService: UserService 60 private userService: UserService
61 ) { 61 ) {
62 this.usersSource = this.userService.getDataSource(); 62 this.usersSource = this.userService.getDataSource()
63 } 63 }
64 64
65 removeUser({ data }) { 65 removeUser ({ data }) {
66 const user: User = data; 66 const user: User = data
67 67
68 if (user.username === 'root') { 68 if (user.username === 'root') {
69 this.notificationsService.error('Error', 'You cannot delete root.'); 69 this.notificationsService.error('Error', 'You cannot delete root.')
70 return; 70 return
71 } 71 }
72 72
73 this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe( 73 this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
74 res => { 74 res => {
75 if (res === false) return; 75 if (res === false) return
76 76
77 this.userService.removeUser(user).subscribe( 77 this.userService.removeUser(user).subscribe(
78 () => { 78 () => {
79 this.notificationsService.success('Success', `User ${user.username} deleted.`); 79 this.notificationsService.success('Success', `User ${user.username} deleted.`)
80 this.usersSource.refresh(); 80 this.usersSource.refresh()
81 }, 81 },
82 82
83 err => this.notificationsService.error('Error', err.text) 83 err => this.notificationsService.error('Error', err.text)
84 ); 84 )
85 } 85 }
86 ); 86 )
87 } 87 }
88} 88}
diff --git a/client/src/app/+admin/users/users.component.ts b/client/src/app/+admin/users/users.component.ts
index 91af6c320..e9c8f6b0d 100644
--- a/client/src/app/+admin/users/users.component.ts
+++ b/client/src/app/+admin/users/users.component.ts
@@ -1,8 +1,7 @@
1import { Component } from '@angular/core'; 1import { Component } from '@angular/core'
2 2
3@Component({ 3@Component({
4 template: '<router-outlet></router-outlet>' 4 template: '<router-outlet></router-outlet>'
5}) 5})
6
7export class UsersComponent { 6export class UsersComponent {
8} 7}
diff --git a/client/src/app/+admin/users/users.routes.ts b/client/src/app/+admin/users/users.routes.ts
index 21fb192e0..723c5715d 100644
--- a/client/src/app/+admin/users/users.routes.ts
+++ b/client/src/app/+admin/users/users.routes.ts
@@ -1,8 +1,8 @@
1import { Routes } from '@angular/router'; 1import { Routes } from '@angular/router'
2 2
3import { UsersComponent } from './users.component'; 3import { UsersComponent } from './users.component'
4import { UserAddComponent } from './user-add'; 4import { UserAddComponent } from './user-add'
5import { UserListComponent } from './user-list'; 5import { UserListComponent } from './user-list'
6 6
7export const UsersRoutes: Routes = [ 7export const UsersRoutes: Routes = [
8 { 8 {
@@ -34,4 +34,4 @@ export const UsersRoutes: Routes = [
34 } 34 }
35 ] 35 ]
36 } 36 }
37]; 37]