1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { AuthService, Notifier, ServerService } from '@app/core'
4 import { UserCreate, UserRole } from '../../../../../../shared'
5 import { UserEdit } from './user-edit'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
9 import { ConfigService } from '@app/+admin/config/shared/config.service'
10 import { UserService } from '@app/shared'
13 selector: 'my-user-create',
14 templateUrl: './user-edit.component.html',
15 styleUrls: [ './user-edit.component.scss' ]
17 export class UserCreateComponent extends UserEdit implements OnInit {
21 protected serverService: ServerService,
22 protected formValidatorService: FormValidatorService,
23 protected configService: ConfigService,
24 protected auth: AuthService,
25 private userValidatorsService: UserValidatorsService,
26 private router: Router,
27 private notifier: Notifier,
28 private userService: UserService,
33 this.buildQuotaOptions()
39 const defaultValues = {
40 role: UserRole.USER.toString(),
46 username: this.userValidatorsService.USER_USERNAME,
47 email: this.userValidatorsService.USER_EMAIL,
48 password: this.userValidatorsService.USER_PASSWORD,
49 role: this.userValidatorsService.USER_ROLE,
50 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
51 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY,
52 byPassAutoBlacklist: null
57 this.error = undefined
59 const userCreate: UserCreate = this.form.value
61 userCreate.adminFlags = this.buildAdminFlags(this.form.value)
63 // A select in HTML is always mapped as a string, we convert it to number
64 userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
65 userCreate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10)
67 this.userService.addUser(userCreate).subscribe(
69 this.notifier.success(this.i18n('User {{username}} created.', { username: userCreate.username }))
70 this.router.navigate([ '/admin/users/list' ])
73 err => this.error = err.message
81 getFormButtonTitle () {
82 return this.i18n('Create user')