diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-12 11:39:58 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | b5f919ac8eb2a1c20e26582fdfd377d687710d8f (patch) | |
tree | 5ec28be6f750f54bba560803ddba681103c2d82e /client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts | |
parent | 8d2be0ed7bb87283a1ec98609df6b82d83db706a (diff) | |
download | PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.gz PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.zst PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.zip |
WIP plugins: update plugin
Diffstat (limited to 'client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts')
-rw-r--r-- | client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts index 26a9a616e..67a11c3a8 100644 --- a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts | |||
@@ -6,6 +6,7 @@ import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pa | |||
6 | import { ConfirmService, Notifier } from '@app/core' | 6 | import { ConfirmService, Notifier } from '@app/core' |
7 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' | 7 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' |
8 | import { ActivatedRoute, Router } from '@angular/router' | 8 | import { ActivatedRoute, Router } from '@angular/router' |
9 | import { compareSemVer } from '@app/shared/misc/utils' | ||
9 | 10 | ||
10 | @Component({ | 11 | @Component({ |
11 | selector: 'my-plugin-list-installed', | 12 | selector: 'my-plugin-list-installed', |
@@ -26,6 +27,9 @@ export class PluginListInstalledComponent implements OnInit { | |||
26 | sort = 'name' | 27 | sort = 'name' |
27 | 28 | ||
28 | plugins: PeerTubePlugin[] = [] | 29 | plugins: PeerTubePlugin[] = [] |
30 | updating: { [name: string]: boolean } = {} | ||
31 | |||
32 | PluginType = PluginType | ||
29 | 33 | ||
30 | constructor ( | 34 | constructor ( |
31 | private i18n: I18n, | 35 | private i18n: I18n, |
@@ -49,7 +53,7 @@ export class PluginListInstalledComponent implements OnInit { | |||
49 | this.pagination.currentPage = 1 | 53 | this.pagination.currentPage = 1 |
50 | this.plugins = [] | 54 | this.plugins = [] |
51 | 55 | ||
52 | this.router.navigate([], { queryParams: { pluginType: this.pluginType }}) | 56 | this.router.navigate([], { queryParams: { pluginType: this.pluginType } }) |
53 | 57 | ||
54 | this.loadMorePlugins() | 58 | this.loadMorePlugins() |
55 | } | 59 | } |
@@ -82,6 +86,18 @@ export class PluginListInstalledComponent implements OnInit { | |||
82 | return this.i18n('You don\'t have themes installed yet.') | 86 | return this.i18n('You don\'t have themes installed yet.') |
83 | } | 87 | } |
84 | 88 | ||
89 | isUpdateAvailable (plugin: PeerTubePlugin) { | ||
90 | return plugin.latestVersion && compareSemVer(plugin.latestVersion, plugin.version) > 0 | ||
91 | } | ||
92 | |||
93 | getUpdateLabel (plugin: PeerTubePlugin) { | ||
94 | return this.i18n('Update to {{version}}', { version: plugin.latestVersion }) | ||
95 | } | ||
96 | |||
97 | isUpdating (plugin: PeerTubePlugin) { | ||
98 | return !!this.updating[this.getUpdatingKey(plugin)] | ||
99 | } | ||
100 | |||
85 | async uninstall (plugin: PeerTubePlugin) { | 101 | async uninstall (plugin: PeerTubePlugin) { |
86 | const res = await this.confirmService.confirm( | 102 | const res = await this.confirmService.confirm( |
87 | this.i18n('Do you really want to uninstall {{pluginName}}?', { pluginName: plugin.name }), | 103 | this.i18n('Do you really want to uninstall {{pluginName}}?', { pluginName: plugin.name }), |
@@ -102,7 +118,32 @@ export class PluginListInstalledComponent implements OnInit { | |||
102 | ) | 118 | ) |
103 | } | 119 | } |
104 | 120 | ||
121 | async update (plugin: PeerTubePlugin) { | ||
122 | const updatingKey = this.getUpdatingKey(plugin) | ||
123 | if (this.updating[updatingKey]) return | ||
124 | |||
125 | this.updating[updatingKey] = true | ||
126 | |||
127 | this.pluginService.update(plugin.name, plugin.type) | ||
128 | .pipe() | ||
129 | .subscribe( | ||
130 | res => { | ||
131 | this.updating[updatingKey] = false | ||
132 | |||
133 | this.notifier.success(this.i18n('{{pluginName}} updated.', { pluginName: plugin.name })) | ||
134 | |||
135 | Object.assign(plugin, res) | ||
136 | }, | ||
137 | |||
138 | err => this.notifier.error(err.message) | ||
139 | ) | ||
140 | } | ||
141 | |||
105 | getShowRouterLink (plugin: PeerTubePlugin) { | 142 | getShowRouterLink (plugin: PeerTubePlugin) { |
106 | return [ '/admin', 'plugins', 'show', this.pluginService.nameToNpmName(plugin.name, plugin.type) ] | 143 | return [ '/admin', 'plugins', 'show', this.pluginService.nameToNpmName(plugin.name, plugin.type) ] |
107 | } | 144 | } |
145 | |||
146 | private getUpdatingKey (plugin: PeerTubePlugin) { | ||
147 | return plugin.name + plugin.type | ||
148 | } | ||
108 | } | 149 | } |