From e1eada8bae03d06dcd9549c06c67392a55a0fc96 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Sep 2022 10:02:46 +0200 Subject: Disable uninstall button on plugin uninstallation --- .../plugin-list-installed.component.html | 9 ++++-- .../plugin-list-installed.component.ts | 34 +++++++++++++++++----- .../plugin-search/plugin-search.component.html | 2 +- .../shared-main/buttons/delete-button.component.ts | 7 ++++- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.html b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.html index c5d440c8c..374c4d96d 100644 --- a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.html +++ b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.html @@ -15,10 +15,15 @@ - + 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 960e711b4..2fdc14d85 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 @@ -24,6 +24,7 @@ export class PluginListInstalledComponent implements OnInit { plugins: PeerTubePlugin[] = [] updating: { [name: string]: boolean } = {} + uninstalling: { [name: string]: boolean } = {} onDataSubject = new Subject() @@ -99,7 +100,11 @@ export class PluginListInstalledComponent implements OnInit { } isUpdating (plugin: PeerTubePlugin) { - return !!this.updating[this.getUpdatingKey(plugin)] + return !!this.updating[this.getPluginKey(plugin)] + } + + isUninstalling (plugin: PeerTubePlugin) { + return !!this.uninstall[this.getPluginKey(plugin)] } isTheme (plugin: PeerTubePlugin) { @@ -107,12 +112,17 @@ export class PluginListInstalledComponent implements OnInit { } async uninstall (plugin: PeerTubePlugin) { + const pluginKey = this.getPluginKey(plugin) + if (this.uninstalling[pluginKey]) return + const res = await this.confirmService.confirm( $localize`Do you really want to uninstall ${plugin.name}?`, $localize`Uninstall` ) if (res === false) return + this.uninstalling[pluginKey] = true + this.pluginApiService.uninstall(plugin.name, plugin.type) .subscribe({ next: () => { @@ -120,15 +130,20 @@ export class PluginListInstalledComponent implements OnInit { this.plugins = this.plugins.filter(p => p.name !== plugin.name) this.pagination.totalItems-- + + this.uninstalling[pluginKey] = false }, - error: err => this.notifier.error(err.message) + error: err => { + this.notifier.error(err.message) + this.uninstalling[pluginKey] = false + } }) } async update (plugin: PeerTubePlugin) { - const updatingKey = this.getUpdatingKey(plugin) - if (this.updating[updatingKey]) return + const pluginKey = this.getPluginKey(plugin) + if (this.updating[pluginKey]) return if (this.isMajorUpgrade(plugin)) { const res = await this.confirmService.confirm( @@ -140,20 +155,23 @@ export class PluginListInstalledComponent implements OnInit { if (res === false) return } - this.updating[updatingKey] = true + this.updating[pluginKey] = true this.pluginApiService.update(plugin.name, plugin.type) .pipe() .subscribe({ next: res => { - this.updating[updatingKey] = false + this.updating[pluginKey] = false this.notifier.success($localize`${plugin.name} updated.`) Object.assign(plugin, res) }, - error: err => this.notifier.error(err.message) + error: err => { + this.notifier.error(err.message) + this.updating[pluginKey] = false + } }) } @@ -165,7 +183,7 @@ export class PluginListInstalledComponent implements OnInit { return this.pluginApiService.getPluginOrThemeHref(this.pluginType, name) } - private getUpdatingKey (plugin: PeerTubePlugin) { + private getPluginKey (plugin: PeerTubePlugin) { return plugin.name + plugin.type } diff --git a/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html b/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html index c989d2e38..08430913a 100644 --- a/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html +++ b/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html @@ -46,7 +46,7 @@ > diff --git a/client/src/app/shared/shared-main/buttons/delete-button.component.ts b/client/src/app/shared/shared-main/buttons/delete-button.component.ts index 1cab10803..0ee7d3757 100644 --- a/client/src/app/shared/shared-main/buttons/delete-button.component.ts +++ b/client/src/app/shared/shared-main/buttons/delete-button.component.ts @@ -3,13 +3,18 @@ import { Component, Input, OnInit } from '@angular/core' @Component({ selector: 'my-delete-button', template: ` - + ` }) export class DeleteButtonComponent implements OnInit { @Input() label: string @Input() title: string @Input() responsiveLabel = false + @Input() disabled: boolean ngOnInit () { if (this.label === undefined && !this.title) { -- cgit v1.2.3