aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts')
-rw-r--r--client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts46
1 files changed, 38 insertions, 8 deletions
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 4e60ca290..2c5dbea95 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
@@ -2,7 +2,7 @@ import { Subscription } from 'rxjs'
2import { map, switchMap } from 'rxjs/operators' 2import { map, switchMap } from 'rxjs/operators'
3import { Component, OnDestroy, OnInit } from '@angular/core' 3import { Component, OnDestroy, OnInit } from '@angular/core'
4import { ActivatedRoute } from '@angular/router' 4import { ActivatedRoute } from '@angular/router'
5import { Notifier } from '@app/core' 5import { Notifier, PluginService } from '@app/core'
6import { BuildFormArgument } from '@app/shared/form-validators' 6import { BuildFormArgument } from '@app/shared/form-validators'
7import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' 7import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
8import { PeerTubePlugin, RegisterServerSettingOptions } from '@shared/models' 8import { PeerTubePlugin, RegisterServerSettingOptions } from '@shared/models'
@@ -22,7 +22,8 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
22 22
23 constructor ( 23 constructor (
24 protected formValidatorService: FormValidatorService, 24 protected formValidatorService: FormValidatorService,
25 private pluginService: PluginApiService, 25 private pluginService: PluginService,
26 private pluginAPIService: PluginApiService,
26 private notifier: Notifier, 27 private notifier: Notifier,
27 private route: ActivatedRoute 28 private route: ActivatedRoute
28 ) { 29 ) {
@@ -46,7 +47,7 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
46 formValidated () { 47 formValidated () {
47 const settings = this.form.value 48 const settings = this.form.value
48 49
49 this.pluginService.updatePluginSettings(this.plugin.name, this.plugin.type, settings) 50 this.pluginAPIService.updatePluginSettings(this.plugin.name, this.plugin.type, settings)
50 .subscribe( 51 .subscribe(
51 () => { 52 () => {
52 this.notifier.success($localize`Settings updated.`) 53 this.notifier.success($localize`Settings updated.`)
@@ -60,18 +61,22 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
60 return Array.isArray(this.registeredSettings) && this.registeredSettings.length !== 0 61 return Array.isArray(this.registeredSettings) && this.registeredSettings.length !== 0
61 } 62 }
62 63
64 isSettingHidden (setting: RegisterServerSettingOptions) {
65 return false
66 }
67
63 private loadPlugin (npmName: string) { 68 private loadPlugin (npmName: string) {
64 this.pluginService.getPlugin(npmName) 69 this.pluginAPIService.getPlugin(npmName)
65 .pipe(switchMap(plugin => { 70 .pipe(switchMap(plugin => {
66 return this.pluginService.getPluginRegisteredSettings(plugin.name, plugin.type) 71 return this.pluginAPIService.getPluginRegisteredSettings(plugin.name, plugin.type)
67 .pipe(map(data => ({ plugin, registeredSettings: data.registeredSettings }))) 72 .pipe(map(data => ({ plugin, registeredSettings: data.registeredSettings })))
68 })) 73 }))
69 .subscribe( 74 .subscribe(
70 ({ plugin, registeredSettings }) => { 75 async ({ plugin, registeredSettings }) => {
71 this.plugin = plugin 76 this.plugin = plugin
72 this.registeredSettings = registeredSettings 77 this.registeredSettings = await this.translateSettings(registeredSettings)
73 78
74 this.pluginTypeLabel = this.pluginService.getPluginTypeLabel(this.plugin.type) 79 this.pluginTypeLabel = this.pluginAPIService.getPluginTypeLabel(this.plugin.type)
75 80
76 this.buildSettingsForm() 81 this.buildSettingsForm()
77 }, 82 },
@@ -104,4 +109,29 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
104 return registered.default 109 return registered.default
105 } 110 }
106 111
112 private async translateSettings (settings: RegisterServerSettingOptions[]) {
113 const npmName = this.pluginService.nameToNpmName(this.plugin.name, this.plugin.type)
114
115 for (const setting of settings) {
116 for (const key of [ 'label', 'html', 'descriptionHTML' ]) {
117 if (setting[key]) setting[key] = await this.pluginService.translateBy(npmName, setting[key])
118 }
119
120 if (Array.isArray(setting.options)) {
121 const newOptions = []
122
123 for (const o of setting.options) {
124 newOptions.push({
125 value: o.value,
126 label: await this.pluginService.translateBy(npmName, o.label)
127 })
128 }
129
130 setting.options = newOptions
131 }
132 }
133
134 return settings
135 }
136
107} 137}