aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/plugins/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-11 14:40:19 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commitdba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (patch)
tree7695023d90b78f972abafc718346c50264587ff5 /client/src/app/+admin/plugins/shared
parentd00dc28dd73ad9dd419d5a5ac6ac747cefbc6e8b (diff)
downloadPeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.gz
PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.zst
PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.zip
WIP plugins: add plugin settings/uninstall in client
Diffstat (limited to 'client/src/app/+admin/plugins/shared')
-rw-r--r--client/src/app/+admin/plugins/shared/plugin-api.service.ts68
-rw-r--r--client/src/app/+admin/plugins/shared/toggle-plugin-type.scss21
2 files changed, 87 insertions, 2 deletions
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 bfc2b918f..1d33cd179 100644
--- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts
+++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts
@@ -8,6 +8,9 @@ import { PluginType } from '@shared/models/plugins/plugin.type'
8import { ComponentPagination } from '@app/shared/rest/component-pagination.model' 8import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
9import { ResultList } from '@shared/models' 9import { ResultList } from '@shared/models'
10import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' 10import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
11import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model'
12import { InstallPlugin } from '@shared/models/plugins/install-plugin.model'
13import { RegisterSettingOptions } from '@shared/models/plugins/register-setting.model'
11 14
12@Injectable() 15@Injectable()
13export class PluginApiService { 16export class PluginApiService {
@@ -23,16 +26,24 @@ export class PluginApiService {
23 getPluginTypeOptions () { 26 getPluginTypeOptions () {
24 return [ 27 return [
25 { 28 {
26 label: this.i18n('Plugin'), 29 label: this.i18n('Plugins'),
27 value: PluginType.PLUGIN 30 value: PluginType.PLUGIN
28 }, 31 },
29 { 32 {
30 label: this.i18n('Theme'), 33 label: this.i18n('Themes'),
31 value: PluginType.THEME 34 value: PluginType.THEME
32 } 35 }
33 ] 36 ]
34 } 37 }
35 38
39 getPluginTypeLabel (type: PluginType) {
40 if (type === PluginType.PLUGIN) {
41 return this.i18n('plugin')
42 }
43
44 return this.i18n('theme')
45 }
46
36 getPlugins ( 47 getPlugins (
37 type: PluginType, 48 type: PluginType,
38 componentPagination: ComponentPagination, 49 componentPagination: ComponentPagination,
@@ -47,4 +58,57 @@ export class PluginApiService {
47 return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params }) 58 return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params })
48 .pipe(catchError(res => this.restExtractor.handleError(res))) 59 .pipe(catchError(res => this.restExtractor.handleError(res)))
49 } 60 }
61
62 getPlugin (npmName: string) {
63 const path = PluginApiService.BASE_APPLICATION_URL + '/' + npmName
64
65 return this.authHttp.get<PeerTubePlugin>(path)
66 .pipe(catchError(res => this.restExtractor.handleError(res)))
67 }
68
69 getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) {
70 const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings'
71
72 return this.authHttp.get<{ settings: RegisterSettingOptions[] }>(path)
73 .pipe(catchError(res => this.restExtractor.handleError(res)))
74 }
75
76 updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) {
77 const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/settings'
78
79 return this.authHttp.put(path, { settings })
80 .pipe(catchError(res => this.restExtractor.handleError(res)))
81 }
82
83 uninstall (pluginName: string, pluginType: PluginType) {
84 const body: ManagePlugin = {
85 npmName: this.nameToNpmName(pluginName, pluginType)
86 }
87
88 return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/uninstall', body)
89 .pipe(catchError(res => this.restExtractor.handleError(res)))
90 }
91
92 install (npmName: string) {
93 const body: InstallPlugin = {
94 npmName
95 }
96
97 return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/install', body)
98 .pipe(catchError(res => this.restExtractor.handleError(res)))
99 }
100
101 nameToNpmName (name: string, type: PluginType) {
102 const prefix = type === PluginType.PLUGIN
103 ? 'peertube-plugin-'
104 : 'peertube-theme-'
105
106 return prefix + name
107 }
108
109 pluginTypeFromNpmName (npmName: string) {
110 return npmName.startsWith('peertube-plugin-')
111 ? PluginType.PLUGIN
112 : PluginType.THEME
113 }
50} 114}
diff --git a/client/src/app/+admin/plugins/shared/toggle-plugin-type.scss b/client/src/app/+admin/plugins/shared/toggle-plugin-type.scss
new file mode 100644
index 000000000..ea2eda28c
--- /dev/null
+++ b/client/src/app/+admin/plugins/shared/toggle-plugin-type.scss
@@ -0,0 +1,21 @@
1@import '_variables';
2@import '_mixins';
3
4.toggle-plugin-type {
5 display: flex;
6 justify-content: center;
7 margin-bottom: 30px;
8
9 p-selectButton {
10 /deep/ {
11 .ui-button-text {
12 font-size: 15px;
13 }
14
15 .ui-button.ui-state-active {
16 background-color: var(--mainColor);
17 border-color: var(--mainColor);
18 }
19 }
20 }
21}