]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts
Add channel hooks
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / plugins / plugin-show-installed / plugin-show-installed.component.ts
index ca9ad9922b3beb5e8f371e442813cb38fe12edf4..ec02cfcd9a344b89afe9e7efa08d7d3266879f16 100644 (file)
@@ -2,7 +2,7 @@ import { Subscription } from 'rxjs'
 import { map, switchMap } from 'rxjs/operators'
 import { Component, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute } from '@angular/router'
-import { Notifier, PluginService } from '@app/core'
+import { HooksService, Notifier, PluginService } from '@app/core'
 import { BuildFormArgument } from '@app/shared/form-validators'
 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
 import { PeerTubePlugin, RegisterServerSettingOptions } from '@shared/models'
@@ -26,6 +26,7 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
     private pluginService: PluginService,
     private pluginAPIService: PluginApiService,
     private notifier: Notifier,
+    private hooks: HooksService,
     private route: ActivatedRoute
   ) {
     super()
@@ -49,13 +50,13 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
     const settings = this.form.value
 
     this.pluginAPIService.updatePluginSettings(this.plugin.name, this.plugin.type, settings)
-        .subscribe(
-          () => {
+        .subscribe({
+          next: () => {
             this.notifier.success($localize`Settings updated.`)
           },
 
-          err => this.notifier.error(err.message)
-        )
+          error: err => this.notifier.error(err.message)
+        })
   }
 
   hasRegisteredSettings () {
@@ -70,14 +71,20 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
     return script.isSettingHidden({ setting, formValues: this.form.value })
   }
 
+  getWrapperId (setting: RegisterServerSettingOptions) {
+    if (!setting.name) return
+
+    return setting.name + '-wrapper'
+  }
+
   private loadPlugin (npmName: string) {
     this.pluginAPIService.getPlugin(npmName)
         .pipe(switchMap(plugin => {
           return this.pluginAPIService.getPluginRegisteredSettings(plugin.name, plugin.type)
             .pipe(map(data => ({ plugin, registeredSettings: data.registeredSettings })))
         }))
-        .subscribe(
-          async ({ plugin, registeredSettings }) => {
+        .subscribe({
+          next: async ({ plugin, registeredSettings }) => {
             this.plugin = plugin
 
             this.registeredSettings = await this.translateSettings(registeredSettings)
@@ -87,8 +94,8 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
             this.buildSettingsForm()
           },
 
-          err => this.notifier.error(err.message)
-        )
+          error: err => this.notifier.error(err.message)
+        })
   }
 
   private buildSettingsForm () {
@@ -96,19 +103,21 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
     const settingsValues: any = {}
 
     for (const setting of this.registeredSettings) {
-      buildOptions[ setting.name ] = null
-      settingsValues[ setting.name ] = this.getSetting(setting.name)
+      buildOptions[setting.name] = null
+      settingsValues[setting.name] = this.getSetting(setting.name)
     }
 
     this.buildForm(buildOptions)
 
     this.form.patchValue(settingsValues)
+
+    this.hooks.runAction('action:admin-plugin-settings.init', 'admin-plugin', { npmName: this.npmName })
   }
 
   private getSetting (name: string) {
     const settings = this.plugin.settings
 
-    if (settings && settings[name] !== undefined) return settings[name]
+    if (settings?.[name] !== undefined) return settings[name]
 
     const registered = this.registeredSettings.find(r => r.name === name)
 
@@ -117,25 +126,9 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
 
   private async translateSettings (settings: RegisterServerSettingOptions[]) {
     for (const setting of settings) {
-      for (const key of [ 'label', 'html', 'descriptionHTML' ]) {
-        if (setting[key]) setting[key] = await this.pluginService.translateBy(this.npmName, setting[key])
-      }
-
-      if (Array.isArray(setting.options)) {
-        const newOptions = []
-
-        for (const o of setting.options) {
-          newOptions.push({
-            value: o.value,
-            label: await this.pluginService.translateBy(this.npmName, o.label)
-          })
-        }
-
-        setting.options = newOptions
-      }
+      await this.pluginService.translateSetting(this.npmName, setting)
     }
 
     return settings
   }
-
 }