aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin')
-rw-r--r--client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts78
-rw-r--r--client/src/app/+admin/users/user-edit/user-create.component.ts45
-rw-r--r--client/src/app/+admin/users/user-edit/user-edit.ts4
-rw-r--r--client/src/app/+admin/users/user-edit/user-update.component.ts33
4 files changed, 48 insertions, 112 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
index 73ff4b7bb..f2a3464cb 100644
--- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
+++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
@@ -17,6 +17,7 @@ import {
17import { NotificationsService } from 'angular2-notifications' 17import { NotificationsService } from 'angular2-notifications'
18import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' 18import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model'
19import { I18n } from '@ngx-translate/i18n-polyfill' 19import { I18n } from '@ngx-translate/i18n-polyfill'
20import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
20 21
21@Component({ 22@Component({
22 selector: 'my-edit-custom-config', 23 selector: 'my-edit-custom-config',
@@ -44,38 +45,11 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
44 { value: 8, label: '8' } 45 { value: 8, label: '8' }
45 ] 46 ]
46 47
47 form: FormGroup
48 formErrors = {
49 instanceName: '',
50 instanceShortDescription: '',
51 instanceDescription: '',
52 instanceTerms: '',
53 instanceDefaultClientRoute: '',
54 instanceDefaultNSFWPolicy: '',
55 servicesTwitterUsername: '',
56 cachePreviewsSize: '',
57 signupLimit: '',
58 adminEmail: '',
59 userVideoQuota: '',
60 transcodingThreads: '',
61 customizationJavascript: '',
62 customizationCSS: ''
63 }
64 validationMessages = {
65 instanceShortDescription: INSTANCE_SHORT_DESCRIPTION.MESSAGES,
66 instanceName: INSTANCE_NAME.MESSAGES,
67 servicesTwitterUsername: SERVICES_TWITTER_USERNAME,
68 cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES,
69 signupLimit: SIGNUP_LIMIT.MESSAGES,
70 adminEmail: ADMIN_EMAIL.MESSAGES,
71 userVideoQuota: USER_VIDEO_QUOTA.MESSAGES
72 }
73
74 private oldCustomJavascript: string 48 private oldCustomJavascript: string
75 private oldCustomCSS: string 49 private oldCustomCSS: string
76 50
77 constructor ( 51 constructor (
78 private formBuilder: FormBuilder, 52 protected formValidatorService: FormValidatorService,
79 private router: Router, 53 private router: Router,
80 private notificationsService: NotificationsService, 54 private notificationsService: NotificationsService,
81 private configService: ConfigService, 55 private configService: ConfigService,
@@ -90,39 +64,35 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
90 return 'transcodingResolution' + resolution 64 return 'transcodingResolution' + resolution
91 } 65 }
92 66
93 buildForm () { 67 ngOnInit () {
94 const formGroupData = { 68 const formGroupData = {
95 instanceName: [ '', INSTANCE_NAME.VALIDATORS ], 69 instanceName: INSTANCE_NAME,
96 instanceShortDescription: [ '', INSTANCE_SHORT_DESCRIPTION.VALIDATORS ], 70 instanceShortDescription: INSTANCE_SHORT_DESCRIPTION,
97 instanceDescription: [ '' ], 71 instanceDescription: null,
98 instanceTerms: [ '' ], 72 instanceTerms: null,
99 instanceDefaultClientRoute: [ '' ], 73 instanceDefaultClientRoute: null,
100 instanceDefaultNSFWPolicy: [ '' ], 74 instanceDefaultNSFWPolicy: null,
101 servicesTwitterUsername: [ '', SERVICES_TWITTER_USERNAME.VALIDATORS ], 75 servicesTwitterUsername: SERVICES_TWITTER_USERNAME,
102 servicesTwitterWhitelisted: [ ], 76 servicesTwitterWhitelisted: null,
103 cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ], 77 cachePreviewsSize: CACHE_PREVIEWS_SIZE,
104 signupEnabled: [ ], 78 signupEnabled: null,
105 signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ], 79 signupLimit: SIGNUP_LIMIT,
106 adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ], 80 adminEmail: ADMIN_EMAIL,
107 userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ], 81 userVideoQuota: USER_VIDEO_QUOTA,
108 transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ], 82 transcodingThreads: TRANSCODING_THREADS,
109 transcodingEnabled: [ ], 83 transcodingEnabled: null,
110 customizationJavascript: [ '' ], 84 customizationJavascript: null,
111 customizationCSS: [ '' ] 85 customizationCSS: null
112 } 86 }
113 87
88 const defaultValues: BuildFormDefaultValues = {}
114 for (const resolution of this.resolutions) { 89 for (const resolution of this.resolutions) {
115 const key = this.getResolutionKey(resolution) 90 const key = this.getResolutionKey(resolution)
116 formGroupData[key] = [ false ] 91 defaultValues[key] = 'false'
92 formGroupData[key] = null
117 } 93 }
118 94
119 this.form = this.formBuilder.group(formGroupData) 95 this.buildForm(formGroupData)
120
121 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
122 }
123
124 ngOnInit () {
125 this.buildForm()
126 96
127 this.configService.getCustomConfig() 97 this.configService.getCustomConfig()
128 .subscribe( 98 .subscribe(
diff --git a/client/src/app/+admin/users/user-edit/user-create.component.ts b/client/src/app/+admin/users/user-edit/user-create.component.ts
index 8478a7692..e5f0903b6 100644
--- a/client/src/app/+admin/users/user-edit/user-create.component.ts
+++ b/client/src/app/+admin/users/user-edit/user-create.component.ts
@@ -1,5 +1,4 @@
1import { Component, OnInit } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router' 2import { Router } from '@angular/router'
4import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
5import { UserService } from '../shared' 4import { UserService } from '../shared'
@@ -8,6 +7,7 @@ import { ServerService } from '../../../core'
8import { UserCreate, UserRole } from '../../../../../../shared' 7import { UserCreate, UserRole } from '../../../../../../shared'
9import { UserEdit } from './user-edit' 8import { UserEdit } from './user-edit'
10import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
10import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
11 11
12@Component({ 12@Component({
13 selector: 'my-user-create', 13 selector: 'my-user-create',
@@ -17,25 +17,9 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
17export class UserCreateComponent extends UserEdit implements OnInit { 17export class UserCreateComponent extends UserEdit implements OnInit {
18 error: string 18 error: string
19 19
20 form: FormGroup
21 formErrors = {
22 'username': '',
23 'email': '',
24 'password': '',
25 'role': '',
26 'videoQuota': ''
27 }
28 validationMessages = {
29 'username': USER_USERNAME.MESSAGES,
30 'email': USER_EMAIL.MESSAGES,
31 'password': USER_PASSWORD.MESSAGES,
32 'role': USER_ROLE.MESSAGES,
33 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
34 }
35
36 constructor ( 20 constructor (
37 protected serverService: ServerService, 21 protected serverService: ServerService,
38 private formBuilder: FormBuilder, 22 protected formValidatorService: FormValidatorService,
39 private router: Router, 23 private router: Router,
40 private notificationsService: NotificationsService, 24 private notificationsService: NotificationsService,
41 private userService: UserService, 25 private userService: UserService,
@@ -44,20 +28,19 @@ export class UserCreateComponent extends UserEdit implements OnInit {
44 super() 28 super()
45 } 29 }
46 30
47 buildForm () {
48 this.form = this.formBuilder.group({
49 username: [ '', USER_USERNAME.VALIDATORS ],
50 email: [ '', USER_EMAIL.VALIDATORS ],
51 password: [ '', USER_PASSWORD.VALIDATORS ],
52 role: [ UserRole.USER, USER_ROLE.VALIDATORS ],
53 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
54 })
55
56 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
57 }
58
59 ngOnInit () { 31 ngOnInit () {
60 this.buildForm() 32 const defaultValues = {
33 role: UserRole.USER.toString(),
34 videoQuota: '-1'
35 }
36
37 this.buildForm({
38 username: USER_USERNAME,
39 email: USER_EMAIL,
40 password: USER_PASSWORD,
41 role: USER_ROLE,
42 videoQuota: USER_VIDEO_QUOTA
43 }, defaultValues)
61 } 44 }
62 45
63 formValidated () { 46 formValidated () {
diff --git a/client/src/app/+admin/users/user-edit/user-edit.ts b/client/src/app/+admin/users/user-edit/user-edit.ts
index 2b47c685c..ea8c733c3 100644
--- a/client/src/app/+admin/users/user-edit/user-edit.ts
+++ b/client/src/app/+admin/users/user-edit/user-edit.ts
@@ -12,9 +12,9 @@ export abstract class UserEdit extends FormReactive {
12 { value: 5 * 1024 * 1024 * 1024, label: '5GB' }, 12 { value: 5 * 1024 * 1024 * 1024, label: '5GB' },
13 { value: 20 * 1024 * 1024 * 1024, label: '20GB' }, 13 { value: 20 * 1024 * 1024 * 1024, label: '20GB' },
14 { value: 50 * 1024 * 1024 * 1024, label: '50GB' } 14 { value: 50 * 1024 * 1024 * 1024, label: '50GB' }
15 ] 15 ].map(q => ({ value: q.value.toString(), label: q.label })) // Used by a HTML select, so convert key into strings
16 16
17 roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key, label: USER_ROLE_LABELS[key] })) 17 roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
18 18
19 protected abstract serverService: ServerService 19 protected abstract serverService: ServerService
20 abstract isCreation (): boolean 20 abstract isCreation (): boolean
diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.ts
index 5689aab2f..f8073c928 100644
--- a/client/src/app/+admin/users/user-edit/user-update.component.ts
+++ b/client/src/app/+admin/users/user-edit/user-update.component.ts
@@ -1,5 +1,4 @@
1import { Component, OnDestroy, OnInit } from '@angular/core' 1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { ActivatedRoute, Router } from '@angular/router' 2import { ActivatedRoute, Router } from '@angular/router'
4import { Subscription } from 'rxjs' 3import { Subscription } from 'rxjs'
5import { NotificationsService } from 'angular2-notifications' 4import { NotificationsService } from 'angular2-notifications'
@@ -9,6 +8,7 @@ import { ServerService } from '../../../core'
9import { UserEdit } from './user-edit' 8import { UserEdit } from './user-edit'
10import { UserUpdate } from '../../../../../../shared' 9import { UserUpdate } from '../../../../../../shared'
11import { I18n } from '@ngx-translate/i18n-polyfill' 10import { I18n } from '@ngx-translate/i18n-polyfill'
11import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
12 12
13@Component({ 13@Component({
14 selector: 'my-user-update', 14 selector: 'my-user-update',
@@ -20,44 +20,27 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
20 userId: number 20 userId: number
21 username: string 21 username: string
22 22
23 form: FormGroup
24 formErrors = {
25 'email': '',
26 'role': '',
27 'videoQuota': ''
28 }
29 validationMessages = {
30 'email': USER_EMAIL.MESSAGES,
31 'role': USER_ROLE.MESSAGES,
32 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
33 }
34
35 private paramsSub: Subscription 23 private paramsSub: Subscription
36 24
37 constructor ( 25 constructor (
26 protected formValidatorService: FormValidatorService,
38 protected serverService: ServerService, 27 protected serverService: ServerService,
39 private route: ActivatedRoute, 28 private route: ActivatedRoute,
40 private router: Router, 29 private router: Router,
41 private notificationsService: NotificationsService, 30 private notificationsService: NotificationsService,
42 private formBuilder: FormBuilder,
43 private userService: UserService, 31 private userService: UserService,
44 private i18n: I18n 32 private i18n: I18n
45 ) { 33 ) {
46 super() 34 super()
47 } 35 }
48 36
49 buildForm () {
50 this.form = this.formBuilder.group({
51 email: [ '', USER_EMAIL.VALIDATORS ],
52 role: [ '', USER_ROLE.VALIDATORS ],
53 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
54 })
55
56 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
57 }
58
59 ngOnInit () { 37 ngOnInit () {
60 this.buildForm() 38 const defaultValues = { videoQuota: '-1' }
39 this.buildForm({
40 email: USER_EMAIL,
41 role: USER_ROLE,
42 videoQuota: USER_VIDEO_QUOTA
43 }, defaultValues)
61 44
62 this.paramsSub = this.route.params.subscribe(routeParams => { 45 this.paramsSub = this.route.params.subscribe(routeParams => {
63 const userId = routeParams['id'] 46 const userId = routeParams['id']