diff options
author | Kim <1877318+kimsible@users.noreply.github.com> | 2020-04-15 09:08:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-15 09:08:59 +0200 |
commit | 74c2dece42d387506421623fbfadc83da811ebcd (patch) | |
tree | 4dc2afe77cdcaafd36461351990d6851da9ca071 | |
parent | bb152476c819e4c7487d080433c616f0d523e049 (diff) | |
download | PeerTube-74c2dece42d387506421623fbfadc83da811ebcd.tar.gz PeerTube-74c2dece42d387506421623fbfadc83da811ebcd.tar.zst PeerTube-74c2dece42d387506421623fbfadc83da811ebcd.zip |
Add notifier to plugin helpers (#2627)
* Add notifier to client PeerTubeHelpers plugin
* Add doc for notifier PeerTubeHelpers
* Add getBaseClientScriptsRoute to client PeerTubeHelpers plugin
* Add doc for getBaseClientScriptsRoute PeerTubeHelpers
* Remove unused helper
Co-authored-by: kimsible <kimsible@users.noreply.github.com>
-rw-r--r-- | client/src/app/core/plugins/plugin.service.ts | 5 | ||||
-rw-r--r-- | client/src/types/register-client-option.model.ts | 3 | ||||
-rw-r--r-- | support/doc/plugins/guide.md | 12 |
3 files changed, 18 insertions, 2 deletions
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index da5114048..b9d55a7e4 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts | |||
@@ -12,7 +12,7 @@ import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plu | |||
12 | import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' | 12 | import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' |
13 | import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' | 13 | import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' |
14 | import { HttpClient } from '@angular/common/http' | 14 | import { HttpClient } from '@angular/common/http' |
15 | import { AuthService } from '@app/core/auth' | 15 | import { AuthService, Notifier } from '@app/core' |
16 | import { RestExtractor } from '@app/shared/rest' | 16 | import { RestExtractor } from '@app/shared/rest' |
17 | import { PluginType } from '@shared/models/plugins/plugin.type' | 17 | import { PluginType } from '@shared/models/plugins/plugin.type' |
18 | import { PublicServerSetting } from '@shared/models/plugins/public-server.setting' | 18 | import { PublicServerSetting } from '@shared/models/plugins/public-server.setting' |
@@ -60,6 +60,7 @@ export class PluginService implements ClientHook { | |||
60 | constructor ( | 60 | constructor ( |
61 | private router: Router, | 61 | private router: Router, |
62 | private authService: AuthService, | 62 | private authService: AuthService, |
63 | private notifier: Notifier, | ||
63 | private server: ServerService, | 64 | private server: ServerService, |
64 | private zone: NgZone, | 65 | private zone: NgZone, |
65 | private authHttp: HttpClient, | 66 | private authHttp: HttpClient, |
@@ -272,6 +273,8 @@ export class PluginService implements ClientHook { | |||
272 | return this.authService.isLoggedIn() | 273 | return this.authService.isLoggedIn() |
273 | }, | 274 | }, |
274 | 275 | ||
276 | notifier: this.notifier, | ||
277 | |||
275 | translate: (value: string) => { | 278 | translate: (value: string) => { |
276 | return this.translationsObservable | 279 | return this.translationsObservable |
277 | .pipe(map(allTranslations => allTranslations[npmName])) | 280 | .pipe(map(allTranslations => allTranslations[npmName])) |
diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts index 638b08653..1faf13c42 100644 --- a/client/src/types/register-client-option.model.ts +++ b/client/src/types/register-client-option.model.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' | 1 | import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' |
2 | import { Notifier } from '@app/core' | ||
2 | 3 | ||
3 | export type RegisterClientOptions = { | 4 | export type RegisterClientOptions = { |
4 | registerHook: (options: RegisterClientHookOptions) => void | 5 | registerHook: (options: RegisterClientHookOptions) => void |
@@ -13,5 +14,7 @@ export type RegisterClientHelpers = { | |||
13 | 14 | ||
14 | getSettings: () => Promise<{ [ name: string ]: string }> | 15 | getSettings: () => Promise<{ [ name: string ]: string }> |
15 | 16 | ||
17 | notifier: Notifier | ||
18 | |||
16 | translate: (toTranslate: string) => Promise<string> | 19 | translate: (toTranslate: string) => Promise<string> |
17 | } | 20 | } |
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index bdc9d2ad8..5251ce48a 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md | |||
@@ -197,7 +197,7 @@ The `ping` route can be accessed using: | |||
197 | 197 | ||
198 | ### Client helpers (themes & plugins) | 198 | ### Client helpers (themes & plugins) |
199 | 199 | ||
200 | ### Plugin static route | 200 | #### Plugin static route |
201 | 201 | ||
202 | To get your plugin static route: | 202 | To get your plugin static route: |
203 | 203 | ||
@@ -206,6 +206,16 @@ const baseStaticUrl = peertubeHelpers.getBaseStaticRoute() | |||
206 | const imageUrl = baseStaticUrl + '/images/chocobo.png' | 206 | const imageUrl = baseStaticUrl + '/images/chocobo.png' |
207 | ``` | 207 | ``` |
208 | 208 | ||
209 | #### Notifier | ||
210 | |||
211 | To notify the user with the PeerTube ToastModule: | ||
212 | |||
213 | ```js | ||
214 | const { notifier } = peertubeHelpers | ||
215 | notifier.success('Success message content.') | ||
216 | notifier.error('Error message content.') | ||
217 | ``` | ||
218 | |||
209 | #### Translate | 219 | #### Translate |
210 | 220 | ||
211 | You can translate some strings of your plugin (PeerTube will use your `translations` object of your `package.json` file): | 221 | You can translate some strings of your plugin (PeerTube will use your `translations` object of your `package.json` file): |