aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/users/user-edit/user-create.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-09 15:30:37 +0200
committerChocobozzz <me@florianbigard.com>2018-05-11 08:48:20 +0200
commit4c200caae63b3f5602dcd93e94b52c39e01857fe (patch)
tree11840ce5759cd2a903fdce1ad4aba8ae851e551e /client/src/app/+admin/users/user-edit/user-create.component.ts
parent169310b288ea4ecfd0a664bc0829b404e1cc7bc2 (diff)
downloadPeerTube-4c200caae63b3f5602dcd93e94b52c39e01857fe.tar.gz
PeerTube-4c200caae63b3f5602dcd93e94b52c39e01857fe.tar.zst
PeerTube-4c200caae63b3f5602dcd93e94b52c39e01857fe.zip
User add -> User create
Diffstat (limited to 'client/src/app/+admin/users/user-edit/user-create.component.ts')
-rw-r--r--client/src/app/+admin/users/user-edit/user-create.component.ts94
1 files changed, 94 insertions, 0 deletions
diff --git a/client/src/app/+admin/users/user-edit/user-create.component.ts b/client/src/app/+admin/users/user-edit/user-create.component.ts
new file mode 100644
index 000000000..2a9882cde
--- /dev/null
+++ b/client/src/app/+admin/users/user-edit/user-create.component.ts
@@ -0,0 +1,94 @@
1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router'
4
5import { NotificationsService } from 'angular2-notifications'
6
7import { UserService } from '../shared'
8import {
9 USER_USERNAME,
10 USER_EMAIL,
11 USER_PASSWORD,
12 USER_VIDEO_QUOTA,
13 USER_ROLE
14} from '../../../shared'
15import { ServerService } from '../../../core'
16import { UserCreate, UserRole } from '../../../../../../shared'
17import { UserEdit } from './user-edit'
18
19@Component({
20 selector: 'my-user-create',
21 templateUrl: './user-edit.component.html',
22 styleUrls: [ './user-edit.component.scss' ]
23})
24export class UserCreateComponent extends UserEdit implements OnInit {
25 error: string
26
27 form: FormGroup
28 formErrors = {
29 'username': '',
30 'email': '',
31 'password': '',
32 'role': '',
33 'videoQuota': ''
34 }
35 validationMessages = {
36 'username': USER_USERNAME.MESSAGES,
37 'email': USER_EMAIL.MESSAGES,
38 'password': USER_PASSWORD.MESSAGES,
39 'role': USER_ROLE.MESSAGES,
40 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
41 }
42
43 constructor (
44 protected serverService: ServerService,
45 private formBuilder: FormBuilder,
46 private router: Router,
47 private notificationsService: NotificationsService,
48 private userService: UserService
49 ) {
50 super()
51 }
52
53 buildForm () {
54 this.form = this.formBuilder.group({
55 username: [ '', USER_USERNAME.VALIDATORS ],
56 email: [ '', USER_EMAIL.VALIDATORS ],
57 password: [ '', USER_PASSWORD.VALIDATORS ],
58 role: [ UserRole.USER, USER_ROLE.VALIDATORS ],
59 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
60 })
61
62 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
63 }
64
65 ngOnInit () {
66 this.buildForm()
67 }
68
69 formValidated () {
70 this.error = undefined
71
72 const userCreate: UserCreate = this.form.value
73
74 // A select in HTML is always mapped as a string, we convert it to number
75 userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
76
77 this.userService.addUser(userCreate).subscribe(
78 () => {
79 this.notificationsService.success('Success', `User ${userCreate.username} created.`)
80 this.router.navigate([ '/admin/users/list' ])
81 },
82
83 err => this.error = err.message
84 )
85 }
86
87 isCreation () {
88 return true
89 }
90
91 getFormButtonTitle () {
92 return 'Create user'
93 }
94}