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>
pull/2654/head
Kim 2020-04-15 09:08:59 +02:00 committed by GitHub
parent bb152476c8
commit 74c2dece42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -12,7 +12,7 @@ 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 { AuthService, Notifier } from '@app/core'
import { RestExtractor } from '@app/shared/rest'
import { PluginType } from '@shared/models/plugins/plugin.type'
import { PublicServerSetting } from '@shared/models/plugins/public-server.setting'
@ -60,6 +60,7 @@ export class PluginService implements ClientHook {
constructor (
private router: Router,
private authService: AuthService,
private notifier: Notifier,
private server: ServerService,
private zone: NgZone,
private authHttp: HttpClient,
@ -272,6 +273,8 @@ export class PluginService implements ClientHook {
return this.authService.isLoggedIn()
},
notifier: this.notifier,
translate: (value: string) => {
return this.translationsObservable
.pipe(map(allTranslations => allTranslations[npmName]))

View File

@ -1,4 +1,5 @@
import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
import { Notifier } from '@app/core'
export type RegisterClientOptions = {
registerHook: (options: RegisterClientHookOptions) => void
@ -13,5 +14,7 @@ export type RegisterClientHelpers = {
getSettings: () => Promise<{ [ name: string ]: string }>
notifier: Notifier
translate: (toTranslate: string) => Promise<string>
}

View File

@ -197,7 +197,7 @@ The `ping` route can be accessed using:
### Client helpers (themes & plugins)
### Plugin static route
#### Plugin static route
To get your plugin static route:
@ -206,6 +206,16 @@ const baseStaticUrl = peertubeHelpers.getBaseStaticRoute()
const imageUrl = baseStaticUrl + '/images/chocobo.png'
```
#### Notifier
To notify the user with the PeerTube ToastModule:
```js
const { notifier } = peertubeHelpers
notifier.success('Success message content.')
notifier.error('Error message content.')
```
#### Translate
You can translate some strings of your plugin (PeerTube will use your `translations` object of your `package.json` file):