X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fapp%2Fcore%2Fplugins%2Fplugin.service.ts;h=c6efcac6d3db146f3c4602b871396a4e57da019f;hb=f375bb3db401e42b4317545a7e40dcfda692604d;hp=3af36765af795ed8de83fbac93b4ccd25add3242;hpb=5c5e587307a27e173333789b5b5167d35f468b01;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index 3af36765a..c6efcac6d 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -12,13 +12,17 @@ import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plu import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' import { HttpClient } from '@angular/common/http' +import { AuthService } from '@app/core/auth' +import { Notifier } from '@app/core/notification' import { RestExtractor } from '@app/shared/rest' +import { MarkdownService } from '@app/shared/renderer' import { PluginType } from '@shared/models/plugins/plugin.type' import { PublicServerSetting } from '@shared/models/plugins/public-server.setting' import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' import { RegisterClientHelpers } from '../../../types/register-client-option.model' import { PluginTranslation } from '@shared/models/plugins/plugin-translation.model' import { importModule } from '@app/shared/misc/utils' +import { CustomModalComponent } from '@app/modal/custom-modal.component' interface HookStructValue extends RegisterClientHookOptions { plugin: ServerConfigPlugin @@ -42,11 +46,15 @@ export class PluginService implements ClientHook { pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject } = { common: new ReplaySubject(1), search: new ReplaySubject(1), - 'video-watch': new ReplaySubject(1) + 'video-watch': new ReplaySubject(1), + signup: new ReplaySubject(1), + login: new ReplaySubject(1) } translationsObservable: Observable + customModal: CustomModalComponent + private plugins: ServerConfigPlugin[] = [] private scopes: { [ scopeName: string ]: PluginInfo[] } = {} private loadedScripts: { [ script: string ]: boolean } = {} @@ -57,6 +65,9 @@ export class PluginService implements ClientHook { constructor ( private router: Router, + private authService: AuthService, + private notifier: Notifier, + private markdownRenderer: MarkdownService, private server: ServerService, private zone: NgZone, private authHttp: HttpClient, @@ -67,9 +78,9 @@ export class PluginService implements ClientHook { } initializePlugins () { - this.server.configLoaded - .subscribe(() => { - this.plugins = this.server.getConfig().plugin.registered + this.server.getConfig() + .subscribe(config => { + this.plugins = config.plugin.registered this.buildScopeStruct() @@ -77,6 +88,10 @@ export class PluginService implements ClientHook { }) } + initializeCustomModal (customModal: CustomModalComponent) { + this.customModal = customModal + } + ensurePluginsAreBuilt () { return this.pluginsBuilt.asObservable() .pipe(first(), shareReplay()) @@ -265,6 +280,36 @@ export class PluginService implements ClientHook { .toPromise() }, + isLoggedIn: () => { + return this.authService.isLoggedIn() + }, + + notifier: { + info: (text: string, title?: string, timeout?: number) => this.notifier.info(text, title, timeout), + error: (text: string, title?: string, timeout?: number) => this.notifier.error(text, title, timeout), + success: (text: string, title?: string, timeout?: number) => this.notifier.success(text, title, timeout) + }, + + showModal: (input: { + title: string, + content: string, + close?: boolean, + cancel?: { value: string, action?: () => void }, + confirm?: { value: string, action?: () => void } + }) => { + this.customModal.show(input) + }, + + markdownRenderer: { + textMarkdownToHTML: (textMarkdown: string) => { + return this.markdownRenderer.textMarkdownToHTML(textMarkdown) + }, + + enhancedMarkdownToHTML: (enhancedMarkdown: string) => { + return this.markdownRenderer.enhancedMarkdownToHTML(enhancedMarkdown) + } + }, + translate: (value: string) => { return this.translationsObservable .pipe(map(allTranslations => allTranslations[npmName]))