]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-create.component.ts
Fix client build
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-create.component.ts
CommitLineData
df98563e 1import { Component, OnInit } from '@angular/core'
df98563e 2import { Router } from '@angular/router'
df98563e 3import { NotificationsService } from 'angular2-notifications'
df98563e 4import { UserService } from '../shared'
6a84aafd 5import { ServerService } from '../../../core'
954605a8 6import { UserCreate, UserRole } from '../../../../../../shared'
8094a898 7import { UserEdit } from './user-edit'
b1d40cff 8import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 9import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e309822b 10import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
7da18e44
C
11
12@Component({
4c200caa 13 selector: 'my-user-create',
6a84aafd
C
14 templateUrl: './user-edit.component.html',
15 styleUrls: [ './user-edit.component.scss' ]
7da18e44 16})
4c200caa 17export class UserCreateComponent extends UserEdit implements OnInit {
8094a898 18 error: string
7da18e44 19
df98563e 20 constructor (
6a84aafd 21 protected serverService: ServerService,
d18d6478 22 protected formValidatorService: FormValidatorService,
e309822b 23 private userValidatorsService: UserValidatorsService,
4b2f33f3 24 private router: Router,
7ddd02c9 25 private notificationsService: NotificationsService,
b1d40cff
C
26 private userService: UserService,
27 private i18n: I18n
4b2f33f3 28 ) {
df98563e 29 super()
4b2f33f3
C
30 }
31
df98563e 32 ngOnInit () {
d18d6478
C
33 const defaultValues = {
34 role: UserRole.USER.toString(),
35 videoQuota: '-1'
36 }
37
38 this.buildForm({
e309822b
C
39 username: this.userValidatorsService.USER_USERNAME,
40 email: this.userValidatorsService.USER_EMAIL,
41 password: this.userValidatorsService.USER_PASSWORD,
42 role: this.userValidatorsService.USER_ROLE,
43 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA
d18d6478 44 }, defaultValues)
7da18e44
C
45 }
46
8094a898
C
47 formValidated () {
48 this.error = undefined
7da18e44 49
4771e000 50 const userCreate: UserCreate = this.form.value
4b2f33f3 51
b0f9f39e
C
52 // A select in HTML is always mapped as a string, we convert it to number
53 userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
54
4771e000 55 this.userService.addUser(userCreate).subscribe(
7ddd02c9 56 () => {
b1d40cff
C
57 this.notificationsService.success(
58 this.i18n('Success'),
25acef90 59 this.i18n('User {{username}} created.', { username: userCreate.username })
b1d40cff 60 )
df98563e 61 this.router.navigate([ '/admin/users/list' ])
7ddd02c9 62 },
7da18e44 63
f7354483 64 err => this.error = err.message
df98563e 65 )
7da18e44 66 }
8094a898
C
67
68 isCreation () {
69 return true
70 }
71
72 getFormButtonTitle () {
b1d40cff 73 return this.i18n('Create user')
8094a898 74 }
7da18e44 75}