From 3c47fa3bc0e3f2362bb17976057287a7e9aba46b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Apr 2021 13:50:31 +0200 Subject: Add ability to hide plugin settings --- .../plugin-show-installed.component.ts | 18 +++++++++++------- client/src/app/core/plugins/plugin.service.ts | 7 +++++++ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'client/src/app') diff --git a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts index 2c5dbea95..ca9ad9922 100644 --- a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts @@ -19,6 +19,7 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit pluginTypeLabel: string private sub: Subscription + private npmName: string constructor ( protected formValidatorService: FormValidatorService, @@ -33,9 +34,9 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit ngOnInit () { this.sub = this.route.params.subscribe( routeParams => { - const npmName = routeParams['npmName'] + this.npmName = routeParams['npmName'] - this.loadPlugin(npmName) + this.loadPlugin(this.npmName) } ) } @@ -62,7 +63,11 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit } isSettingHidden (setting: RegisterServerSettingOptions) { - return false + const script = this.pluginService.getRegisteredSettingsScript(this.npmName) + + if (!script?.isSettingHidden) return false + + return script.isSettingHidden({ setting, formValues: this.form.value }) } private loadPlugin (npmName: string) { @@ -74,6 +79,7 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit .subscribe( async ({ plugin, registeredSettings }) => { this.plugin = plugin + this.registeredSettings = await this.translateSettings(registeredSettings) this.pluginTypeLabel = this.pluginAPIService.getPluginTypeLabel(this.plugin.type) @@ -110,11 +116,9 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit } private async translateSettings (settings: RegisterServerSettingOptions[]) { - const npmName = this.pluginService.nameToNpmName(this.plugin.name, this.plugin.type) - for (const setting of settings) { for (const key of [ 'label', 'html', 'descriptionHTML' ]) { - if (setting[key]) setting[key] = await this.pluginService.translateBy(npmName, setting[key]) + if (setting[key]) setting[key] = await this.pluginService.translateBy(this.npmName, setting[key]) } if (Array.isArray(setting.options)) { @@ -123,7 +127,7 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit for (const o of setting.options) { newOptions.push({ value: o.value, - label: await this.pluginService.translateBy(npmName, o.label) + label: await this.pluginService.translateBy(this.npmName, o.label) }) } diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index c2dcf9fef..1243bac67 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -19,6 +19,7 @@ import { PluginTranslation, PluginType, PublicServerSetting, + RegisterClientSettingsScript, ServerConfigPlugin } from '@shared/models' import { environment } from '../../../environments/environment' @@ -58,6 +59,7 @@ export class PluginService implements ClientHook { private formFields: FormFields = { video: [] } + private settingsScripts: { [ npmName: string ]: RegisterClientSettingsScript } = {} constructor ( private authService: AuthService, @@ -200,6 +202,10 @@ export class PluginService implements ClientHook { return this.formFields.video.filter(f => f.videoFormOptions.type === type) } + getRegisteredSettingsScript (npmName: string) { + return this.settingsScripts[npmName] + } + translateBy (npmName: string, toTranslate: string) { const helpers = this.helpers[npmName] if (!helpers) { @@ -220,6 +226,7 @@ export class PluginService implements ClientHook { return loadPlugin({ hooks: this.hooks, formFields: this.formFields, + onSettingsScripts: options => this.settingsScripts[npmName] = options, pluginInfo, peertubeHelpersFactory: () => helpers }) -- cgit v1.2.3