]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-create.component.ts
Fix user create daily quota component
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-create.component.ts
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'
11
12 @Component({
13 selector: 'my-user-create',
14 templateUrl: './user-edit.component.html',
15 styleUrls: [ './user-edit.component.scss' ]
16 })
17 export class UserCreateComponent extends UserEdit implements OnInit {
18 error: string
19
20 constructor (
21 protected serverService: ServerService,
22 protected formValidatorService: FormValidatorService,
23 private userValidatorsService: UserValidatorsService,
24 private router: Router,
25 private notificationsService: NotificationsService,
26 private userService: UserService,
27 private i18n: I18n
28 ) {
29 super()
30 }
31
32 ngOnInit () {
33 const defaultValues = {
34 role: UserRole.USER.toString(),
35 videoQuota: '-1',
36 videoQuotaDaily: '-1'
37 }
38
39 this.buildForm({
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
46 }, defaultValues)
47 }
48
49 formValidated () {
50 this.error = undefined
51
52 const userCreate: UserCreate = this.form.value
53
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)
56
57 this.userService.addUser(userCreate).subscribe(
58 () => {
59 this.notificationsService.success(
60 this.i18n('Success'),
61 this.i18n('User {{username}} created.', { username: userCreate.username })
62 )
63 this.router.navigate([ '/admin/users/list' ])
64 },
65
66 err => this.error = err.message
67 )
68 }
69
70 isCreation () {
71 return true
72 }
73
74 getFormButtonTitle () {
75 return this.i18n('Create user')
76 }
77 }