aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html2
-rw-r--r--client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts46
-rw-r--r--client/src/app/+admin/plugins/shared/plugin-api.service.ts16
-rw-r--r--client/src/app/core/plugins/plugin.service.ts20
4 files changed, 58 insertions, 26 deletions
diff --git a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html
index cb2894568..ad65293d4 100644
--- a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html
+++ b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html
@@ -7,7 +7,7 @@
7 7
8 <form *ngIf="hasRegisteredSettings()" role="form" (ngSubmit)="formValidated()" [formGroup]="form"> 8 <form *ngIf="hasRegisteredSettings()" role="form" (ngSubmit)="formValidated()" [formGroup]="form">
9 <div class="form-group" *ngFor="let setting of registeredSettings"> 9 <div class="form-group" *ngFor="let setting of registeredSettings">
10 <my-dynamic-form-field [form]="form" [setting]="setting" [formErrors]="formErrors"></my-dynamic-form-field> 10 <my-dynamic-form-field [hidden]="isSettingHidden(setting)" [form]="form" [setting]="setting" [formErrors]="formErrors"></my-dynamic-form-field>
11 </div> 11 </div>
12 12
13 <input type="submit" i18n value="Update plugin settings" [disabled]="!form.valid"> 13 <input type="submit" i18n value="Update plugin settings" [disabled]="!form.valid">
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}
diff --git a/client/src/app/+admin/plugins/shared/plugin-api.service.ts b/client/src/app/+admin/plugins/shared/plugin-api.service.ts
index fad30576b..d91fccc09 100644
--- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts
+++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts
@@ -94,7 +94,6 @@ export class PluginApiService {
94 94
95 return this.authHttp.get<RegisteredServerSettings>(path) 95 return this.authHttp.get<RegisteredServerSettings>(path)
96 .pipe( 96 .pipe(
97 switchMap(res => this.translateSettingsLabel(npmName, res)),
98 catchError(res => this.restExtractor.handleError(res)) 97 catchError(res => this.restExtractor.handleError(res))
99 ) 98 )
100 } 99 }
@@ -141,19 +140,4 @@ export class PluginApiService {
141 140
142 return `https://www.npmjs.com/package/peertube-${typeString}-${name}` 141 return `https://www.npmjs.com/package/peertube-${typeString}-${name}`
143 } 142 }
144
145 private translateSettingsLabel (npmName: string, res: RegisteredServerSettings): Observable<RegisteredServerSettings> {
146 return this.pluginService.translationsObservable
147 .pipe(
148 map(allTranslations => allTranslations[npmName]),
149 map(translations => {
150 const registeredSettings = res.registeredSettings
151 .map(r => {
152 return Object.assign({}, r, { label: peertubeTranslate(r.label, translations) })
153 })
154
155 return { registeredSettings }
156 })
157 )
158 }
159} 143}
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts
index 54dba5e17..c2dcf9fef 100644
--- a/client/src/app/core/plugins/plugin.service.ts
+++ b/client/src/app/core/plugins/plugin.service.ts
@@ -46,7 +46,10 @@ export class PluginService implements ClientHook {
46 customModal: CustomModalComponent 46 customModal: CustomModalComponent
47 47
48 private plugins: ServerConfigPlugin[] = [] 48 private plugins: ServerConfigPlugin[] = []
49 private helpers: { [ npmName: string ]: RegisterClientHelpers } = {}
50
49 private scopes: { [ scopeName: string ]: PluginInfo[] } = {} 51 private scopes: { [ scopeName: string ]: PluginInfo[] } = {}
52
50 private loadedScripts: { [ script: string ]: boolean } = {} 53 private loadedScripts: { [ script: string ]: boolean } = {}
51 private loadedScopes: PluginClientScope[] = [] 54 private loadedScopes: PluginClientScope[] = []
52 private loadingScopes: { [id in PluginClientScope]?: boolean } = {} 55 private loadingScopes: { [id in PluginClientScope]?: boolean } = {}
@@ -197,13 +200,28 @@ export class PluginService implements ClientHook {
197 return this.formFields.video.filter(f => f.videoFormOptions.type === type) 200 return this.formFields.video.filter(f => f.videoFormOptions.type === type)
198 } 201 }
199 202
203 translateBy (npmName: string, toTranslate: string) {
204 const helpers = this.helpers[npmName]
205 if (!helpers) {
206 console.error('Unknown helpers to translate %s from %s.', toTranslate, npmName)
207 return toTranslate
208 }
209
210 return helpers.translate(toTranslate)
211 }
212
200 private loadPlugin (pluginInfo: PluginInfo) { 213 private loadPlugin (pluginInfo: PluginInfo) {
201 return this.zone.runOutsideAngular(() => { 214 return this.zone.runOutsideAngular(() => {
215 const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType)
216
217 const helpers = this.buildPeerTubeHelpers(pluginInfo)
218 this.helpers[npmName] = helpers
219
202 return loadPlugin({ 220 return loadPlugin({
203 hooks: this.hooks, 221 hooks: this.hooks,
204 formFields: this.formFields, 222 formFields: this.formFields,
205 pluginInfo, 223 pluginInfo,
206 peertubeHelpersFactory: pluginInfo => this.buildPeerTubeHelpers(pluginInfo) 224 peertubeHelpersFactory: () => helpers
207 }) 225 })
208 }) 226 })
209 } 227 }