]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
Fix misplaced i18n tag in admin system config
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-custom-config.component.ts
index d8eb55da7f613d5f5b53046481460e7e6c48ce38..3fda0851efa9da12e0807788f120251cf6e8427d 100644 (file)
@@ -5,7 +5,10 @@ import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } fr
 import { Notifier } from '@app/core'
 import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model'
 import { I18n } from '@ngx-translate/i18n-polyfill'
-import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
+import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
+import { SelectItem } from 'primeng/api'
+import { forkJoin } from 'rxjs'
+import { ServerConfig } from '@shared/models'
 
 @Component({
   selector: 'my-edit-custom-config',
@@ -15,9 +18,14 @@ import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/
 export class EditCustomConfigComponent extends FormReactive implements OnInit {
   customConfig: CustomConfig
 
-  resolutions: string[] = []
+  resolutions: { id: string, label: string, description?: string }[] = []
   transcodingThreadOptions: { label: string, value: number }[] = []
 
+  languageItems: SelectItem[] = []
+  categoryItems: SelectItem[] = []
+
+  private serverConfig: ServerConfig
+
   constructor (
     protected formValidatorService: FormValidatorService,
     private customConfigValidatorsService: CustomConfigValidatorsService,
@@ -30,11 +38,35 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
     super()
 
     this.resolutions = [
-      this.i18n('240p'),
-      this.i18n('360p'),
-      this.i18n('480p'),
-      this.i18n('720p'),
-      this.i18n('1080p')
+      {
+        id: '0p',
+        label: this.i18n('Audio-only'),
+        description: this.i18n('A <code>.mp4</code> that keeps the original audio track, with no video')
+      },
+      {
+        id: '240p',
+        label: this.i18n('240p')
+      },
+      {
+        id: '360p',
+        label: this.i18n('360p')
+      },
+      {
+        id: '480p',
+        label: this.i18n('480p')
+      },
+      {
+        id: '720p',
+        label: this.i18n('720p')
+      },
+      {
+        id: '1080p',
+        label: this.i18n('1080p')
+      },
+      {
+        id: '2160p',
+        label: this.i18n('2160p')
+      }
     ]
 
     this.transcodingThreadOptions = [
@@ -54,25 +86,53 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
     return this.configService.videoQuotaDailyOptions
   }
 
+  get availableThemes () {
+    return this.serverConfig.theme.registered
+      .map(t => t.name)
+  }
+
   getResolutionKey (resolution: string) {
     return 'transcoding.resolutions.' + resolution
   }
 
   ngOnInit () {
+    this.serverConfig = this.serverService.getTmpConfig()
+    this.serverService.getConfig()
+        .subscribe(config => this.serverConfig = config)
+
     const formGroupData: { [key in keyof CustomConfig ]: any } = {
       instance: {
         name: this.customConfigValidatorsService.INSTANCE_NAME,
         shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
         description: null,
-        terms: null,
-        defaultClientRoute: null,
+
         isNSFW: false,
         defaultNSFWPolicy: null,
+
+        terms: null,
+        codeOfConduct: null,
+
+        creationReason: null,
+        moderationInformation: null,
+        administrator: null,
+        maintenanceLifetime: null,
+        businessModel: null,
+
+        hardwareInformation: null,
+
+        categories: null,
+        languages: null,
+
+        defaultClientRoute: null,
+
         customizations: {
           javascript: null,
           css: null
         }
       },
+      theme: {
+        default: null
+      },
       services: {
         twitter: {
           username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
@@ -116,7 +176,14 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
         enabled: null,
         threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
         allowAdditionalExtensions: null,
-        resolutions: {}
+        allowAudioFiles: null,
+        resolutions: {},
+        hls: {
+          enabled: null
+        },
+        webtorrent: {
+          enabled: null
+        }
       },
       autoBlacklist: {
         videos: {
@@ -124,6 +191,23 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
             enabled: null
           }
         }
+      },
+      followers: {
+        instance: {
+          enabled: null,
+          manualApproval: null
+        }
+      },
+      followings: {
+        instance: {
+          autoFollowBack: {
+            enabled: null
+          },
+          autoFollowIndex: {
+            enabled: null,
+            indexUrl: this.customConfigValidatorsService.INDEX_URL
+          }
+        }
       }
     }
 
@@ -133,24 +217,30 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
       }
     }
     for (const resolution of this.resolutions) {
-      defaultValues.transcoding.resolutions[resolution] = 'false'
-      formGroupData.transcoding.resolutions[resolution] = null
+      defaultValues.transcoding.resolutions[resolution.id] = 'false'
+      formGroupData.transcoding.resolutions[resolution.id] = null
     }
 
     this.buildForm(formGroupData)
 
-    this.configService.getCustomConfig()
-      .subscribe(
-        res => {
-          this.customConfig = res
+    forkJoin([
+      this.configService.getCustomConfig(),
+      this.serverService.getVideoLanguages(),
+      this.serverService.getVideoCategories()
+    ]).subscribe(
+      ([ config, languages, categories ]) => {
+        this.customConfig = config
 
-          this.updateForm()
-          // Force form validation
-          this.forceCheck()
-        },
+        this.languageItems = languages.map(l => ({ label: l.label, value: l.id }))
+        this.categoryItems = categories.map(l => ({ label: l.label, value: l.id }))
 
-        err => this.notifier.error(err.message)
-      )
+        this.updateForm()
+        // Force form validation
+        this.forceCheck()
+      },
+
+      err => this.notifier.error(err.message)
+    )
   }
 
   isTranscodingEnabled () {
@@ -163,12 +253,14 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
 
   async formValidated () {
     this.configService.updateCustomConfig(this.form.value)
+      .pipe(
+      )
       .subscribe(
         res => {
           this.customConfig = res
 
           // Reload general configuration
-          this.serverService.loadConfig()
+          this.serverService.resetConfig()
 
           this.updateForm()
 
@@ -179,8 +271,23 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
       )
   }
 
+  getSelectedLanguageLabel () {
+    return this.i18n('{{\'{0} languages selected')
+  }
+
+  getDefaultLanguageLabel () {
+    return this.i18n('No language')
+  }
+
+  getSelectedCategoryLabel () {
+    return this.i18n('{{\'{0} categories selected')
+  }
+
+  getDefaultCategoryLabel () {
+    return this.i18n('No category')
+  }
+
   private updateForm () {
     this.form.patchValue(this.customConfig)
   }
-
 }