]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Disable uninstall button on plugin uninstallation
authorChocobozzz <me@florianbigard.com>
Fri, 16 Sep 2022 08:02:46 +0000 (10:02 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 16 Sep 2022 08:02:46 +0000 (10:02 +0200)
client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.html
client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts
client/src/app/+admin/plugins/plugin-search/plugin-search.component.html
client/src/app/shared/shared-main/buttons/delete-button.component.ts

index c5d440c8cee4e068c2a07a3a29f030d83db13f2b..374c4d96dbe409ab0950be487de80ed4533c20ab 100644 (file)
 
         <my-button
           class="update-button" *ngIf="isUpdateAvailable(plugin)" (click)="update(plugin)" [loading]="isUpdating(plugin)"
-          [label]="getUpdateLabel(plugin)" icon="refresh" [attr.disabled]="isUpdating(plugin)" [responsiveLabel]="true"
+          [attr.disabled]="isUpdating(plugin) || isUninstalling(plugin)"
+          [label]="getUpdateLabel(plugin)" icon="refresh" [responsiveLabel]="true"
         ></my-button>
 
-        <my-delete-button (click)="uninstall(plugin)" label="Uninstall" i18n-label [responsiveLabel]="true"></my-delete-button>
+        <my-delete-button
+          (click)="uninstall(plugin)"
+          label="Uninstall" i18n-label [responsiveLabel]="true"
+          [disabled]="isUpdating(plugin) || isUninstalling(plugin)"
+        ></my-delete-button>
       </div>
     </my-plugin-card>
   </ng-container>
index 960e711b4def4324cbe17714a14e41b0ba1b3442..2fdc14d85959fe3376bec223e18c6f05afdabb5e 100644 (file)
@@ -24,6 +24,7 @@ export class PluginListInstalledComponent implements OnInit {
 
   plugins: PeerTubePlugin[] = []
   updating: { [name: string]: boolean } = {}
+  uninstalling: { [name: string]: boolean } = {}
 
   onDataSubject = new Subject<any[]>()
 
@@ -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
   }
 
index c989d2e387058bba4accfa1f5c6f05ec1a6af401..08430913a5d6c92ad107333cc2929df3a05b8773 100644 (file)
@@ -46,7 +46,7 @@
         ></my-edit-button>
 
         <my-button
-          class="update-button" *ngIf="plugin.installed === false" (click)="install(plugin)"
+          *ngIf="plugin.installed === false" (click)="install(plugin)"
           [loading]="isInstalling(plugin)" label="Install" [responsiveLabel]="true"
           icon="cloud-download" [attr.disabled]="isInstalling(plugin)"
         ></my-button>
index 1cab10803437e0ff8a5875520af4218fb546850d..0ee7d3757451fe463849fd1c5518fe000bdbecf0 100644 (file)
@@ -3,13 +3,18 @@ import { Component, Input, OnInit } from '@angular/core'
 @Component({
   selector: 'my-delete-button',
   template: `
-  <my-button icon="delete" className="grey-button" [label]="label" [title]="title" [responsiveLabel]="responsiveLabel"></my-button>
+    <my-button
+      icon="delete" className="grey-button"
+      [disabled]="disabled" [label]="label" [title]="title"
+      [responsiveLabel]="responsiveLabel"
+    ></my-button>
   `
 })
 export class DeleteButtonComponent implements OnInit {
   @Input() label: string
   @Input() title: string
   @Input() responsiveLabel = false
+  @Input() disabled: boolean
 
   ngOnInit () {
     if (this.label === undefined && !this.title) {