1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { NotificationsService } from 'angular2-notifications'
4 import { UserService } from '../shared'
5 import { ServerService } from '../../../core'
6 import { UserCreate, UserRole } from '../../../../../../shared'
7 import { UserEdit } from './user-edit'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
10 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
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 private userValidatorsService: UserValidatorsService,
24 private router: Router,
25 private notificationsService: NotificationsService,
26 private userService: UserService,
33 const defaultValues = {
34 role: UserRole.USER.toString(),
40 username: this.userValidatorsService.USER_USERNAME,
41 email: this.userValidatorsService.USER_EMAIL,
42 password: this.userValidatorsService.USER_PASSWORD,
43 role: this.userValidatorsService.USER_ROLE,
44 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
45 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
50 this.error = undefined
52 const userCreate: UserCreate = this.form.value
54 // A select in HTML is always mapped as a string, we convert it to number
55 userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
57 this.userService.addUser(userCreate).subscribe(
59 this.notificationsService.success(
61 this.i18n('User {{username}} created.', { username: userCreate.username })
63 this.router.navigate([ '/admin/users/list' ])
66 err => this.error = err.message
74 getFormButtonTitle () {
75 return this.i18n('Create user')