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