]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-create.component.ts
add shortcuts icon in menu
[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'
df98563e 4import { UserService } from '../shared'
6a84aafd 5import { ServerService } from '../../../core'
954605a8 6import { UserCreate, UserRole } from '../../../../../../shared'
8094a898 7import { UserEdit } from './user-edit'
b1d40cff 8import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 9import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e309822b 10import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
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,
e309822b 23 private userValidatorsService: UserValidatorsService,
4b2f33f3 24 private router: Router,
7ddd02c9 25 private notificationsService: NotificationsService,
b1d40cff
C
26 private userService: UserService,
27 private i18n: I18n
4b2f33f3 28 ) {
df98563e 29 super()
4b2f33f3
C
30 }
31
df98563e 32 ngOnInit () {
d18d6478
C
33 const defaultValues = {
34 role: UserRole.USER.toString(),
d6ca951b
C
35 videoQuota: '-1',
36 videoQuotaDaily: '-1'
d18d6478
C
37 }
38
39 this.buildForm({
e309822b
C
40 username: this.userValidatorsService.USER_USERNAME,
41 email: this.userValidatorsService.USER_EMAIL,
42 password: this.userValidatorsService.USER_PASSWORD,
43 role: this.userValidatorsService.USER_ROLE,
d6ca951b
C
44 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
45 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
d18d6478 46 }, defaultValues)
7da18e44
C
47 }
48
8094a898
C
49 formValidated () {
50 this.error = undefined
7da18e44 51
4771e000 52 const userCreate: UserCreate = this.form.value
4b2f33f3 53
b0f9f39e
C
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
4771e000 57 this.userService.addUser(userCreate).subscribe(
7ddd02c9 58 () => {
b1d40cff
C
59 this.notificationsService.success(
60 this.i18n('Success'),
25acef90 61 this.i18n('User {{username}} created.', { username: userCreate.username })
b1d40cff 62 )
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}