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