import { Component, OnInit } from '@angular/core'
-import { FormBuilder, FormGroup } from '@angular/forms'
import { Router } from '@angular/router'
-import { NotificationsService } from 'angular2-notifications'
-import { UserService } from '../shared'
-import { USER_EMAIL, USER_PASSWORD, USER_ROLE, USER_USERNAME, USER_VIDEO_QUOTA } from '../../../shared'
-import { ServerService } from '../../../core'
+import { Notifier, ServerService } from '@app/core'
import { UserCreate, UserRole } from '../../../../../../shared'
import { UserEdit } from './user-edit'
import { I18n } from '@ngx-translate/i18n-polyfill'
+import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
+import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
+import { ConfigService } from '@app/+admin/config/shared/config.service'
+import { UserService } from '@app/shared'
@Component({
selector: 'my-user-create',
export class UserCreateComponent extends UserEdit implements OnInit {
error: string
- form: FormGroup
- formErrors = {
- 'username': '',
- 'email': '',
- 'password': '',
- 'role': '',
- 'videoQuota': ''
- }
- validationMessages = {
- 'username': USER_USERNAME.MESSAGES,
- 'email': USER_EMAIL.MESSAGES,
- 'password': USER_PASSWORD.MESSAGES,
- 'role': USER_ROLE.MESSAGES,
- 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
- }
-
constructor (
protected serverService: ServerService,
- private formBuilder: FormBuilder,
+ protected formValidatorService: FormValidatorService,
+ protected configService: ConfigService,
+ private userValidatorsService: UserValidatorsService,
private router: Router,
- private notificationsService: NotificationsService,
+ private notifier: Notifier,
private userService: UserService,
private i18n: I18n
) {
super()
- }
-
- buildForm () {
- this.form = this.formBuilder.group({
- username: [ '', USER_USERNAME.VALIDATORS ],
- email: [ '', USER_EMAIL.VALIDATORS ],
- password: [ '', USER_PASSWORD.VALIDATORS ],
- role: [ UserRole.USER, USER_ROLE.VALIDATORS ],
- videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
- })
- this.form.valueChanges.subscribe(data => this.onValueChanged(data))
+ this.buildQuotaOptions()
}
ngOnInit () {
- this.buildForm()
+ const defaultValues = {
+ role: UserRole.USER.toString(),
+ videoQuota: '-1',
+ videoQuotaDaily: '-1'
+ }
+
+ this.buildForm({
+ username: this.userValidatorsService.USER_USERNAME,
+ email: this.userValidatorsService.USER_EMAIL,
+ password: this.userValidatorsService.USER_PASSWORD,
+ role: this.userValidatorsService.USER_ROLE,
+ videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
+ videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
+ }, defaultValues)
}
formValidated () {
this.userService.addUser(userCreate).subscribe(
() => {
- this.notificationsService.success(
- this.i18n('Success'),
- this.i18n('User {{ username }} created.', { username: userCreate.username })
- )
+ this.notifier.success(this.i18n('User {{username}} created.', { username: userCreate.username }))
this.router.navigate([ '/admin/users/list' ])
},