Add action:admin-plugin-settings.init client hook

pull/4012/head
Chocobozzz 2021-04-22 11:18:13 +02:00
parent 302eba0d89
commit 0ea9f463a9
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 25 additions and 3 deletions

View File

@ -6,7 +6,7 @@
</h2>
<form *ngIf="hasRegisteredSettings()" role="form" (ngSubmit)="formValidated()" [formGroup]="form">
<div class="form-group" *ngFor="let setting of registeredSettings">
<div class="form-group" *ngFor="let setting of registeredSettings" [id]="getWrapperId(setting)">
<my-dynamic-form-field [hidden]="isSettingHidden(setting)" [form]="form" [setting]="setting" [formErrors]="formErrors"></my-dynamic-form-field>
</div>

View 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()
@ -70,6 +71,12 @@ 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 => {
@ -103,6 +110,8 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit
this.buildForm(buildOptions)
this.form.patchValue(settingsValues)
setTimeout(() => this.hooks.runAction('action:admin-plugin-settings.init', 'admin-plugin', { npmName: this.npmName }))
}
private getSetting (name: string) {

View File

@ -34,6 +34,7 @@ export class PluginService implements ClientHook {
pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = {
common: new ReplaySubject<boolean>(1),
'admin-plugin': new ReplaySubject<boolean>(1),
search: new ReplaySubject<boolean>(1),
'video-watch': new ReplaySubject<boolean>(1),
signup: new ReplaySubject<boolean>(1),

View File

@ -85,6 +85,10 @@ export const clientActionHookObject = {
// Fired when the registration page is being initialized
'action:signup.register.init': true,
// PeerTube >= 3.2
// Fired when the admin plugin settings page is being initialized
'action:admin-plugin-settings.init': true,
// Fired when the video upload page is being initalized
'action:video-upload.init': true,
// Fired when the video import by URL page is being initalized

View File

@ -1 +1,9 @@
export type PluginClientScope = 'common' | 'video-watch' | 'search' | 'signup' | 'login' | 'embed' | 'video-edit'
export type PluginClientScope =
'common' |
'video-watch' |
'search' |
'signup' |
'login' |
'embed' |
'video-edit' |
'admin-plugin'