]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Handle errors during deletion
authorVolker Theile <vtheile@suse.com>
Tue, 15 May 2018 12:25:30 +0000 (14:25 +0200)
committerVolker Theile <vtheile@suse.com>
Tue, 15 May 2018 12:25:30 +0000 (14:25 +0200)
- Take care that the deletion dialog gets notified about errors to stop the progress spinner and enable the delete button again.
- Prettify JS code.

Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts

index 1042a1a336ff3796594651def9fdae3f23f3c6b4..82e32c050fb27768d5d3d2c92866d14f269ba543 100644 (file)
@@ -7,9 +7,7 @@ import { Observable } from 'rxjs/Observable';
 import { Subscriber } from 'rxjs/Subscriber';
 
 import { RgwBucketService } from '../../../shared/api/rgw-bucket.service';
-import {
-  DeletionModalComponent
-} from '../../../shared/components/deletion-modal/deletion-modal.component';
+import { DeletionModalComponent } from '../../../shared/components/deletion-modal/deletion-modal.component';
 import { TableComponent } from '../../../shared/datatable/table/table.component';
 import { CdTableColumn } from '../../../shared/models/cd-table-column';
 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
@@ -20,16 +18,17 @@ import { CdTableSelection } from '../../../shared/models/cd-table-selection';
   styleUrls: ['./rgw-bucket-list.component.scss']
 })
 export class RgwBucketListComponent {
-
   @ViewChild(TableComponent) table: TableComponent;
 
   columns: CdTableColumn[] = [];
   buckets: object[] = [];
   selection: CdTableSelection = new CdTableSelection();
 
-  constructor(private router: Router,
-              private rgwBucketService: RgwBucketService,
-              private bsModalService: BsModalService) {
+  constructor(
+    private router: Router,
+    private rgwBucketService: RgwBucketService,
+    private bsModalService: BsModalService
+  ) {
     this.columns = [
       {
         name: 'Name',
@@ -45,14 +44,16 @@ export class RgwBucketListComponent {
   }
 
   getBucketList() {
-    this.rgwBucketService.list()
-      .subscribe((resp: object[]) => {
+    this.rgwBucketService.list().subscribe(
+      (resp: object[]) => {
         this.buckets = resp;
-      }, () => {
+      },
+      () => {
         // Force datatable to hide the loading indicator in
         // case of an error.
         this.buckets = [];
-      });
+      }
+    );
   }
 
   updateSelection(selection: CdTableSelection) {
@@ -65,19 +66,30 @@ export class RgwBucketListComponent {
       metaType: this.selection.hasSingleSelection ? 'bucket' : 'buckets',
       deletionObserver: (): Observable<any> => {
         return new Observable((observer: Subscriber<any>) => {
+          // Delete all selected data table rows.
           Observable.forkJoin(
             this.selection.selected.map((bucket: any) => {
               return this.rgwBucketService.delete(bucket.bucket);
-            }))
-            .subscribe(null, null, () => {
+            })
+          ).subscribe(
+            null,
+            (error) => {
+              // Forward the error to the observer.
+              observer.error(error);
+              // Reload the data table content because some deletions might
+              // have been executed successfully in the meanwhile.
+              this.table.refreshBtn();
+            },
+            () => {
+              // Notify the observer that we are done.
               observer.complete();
-              // Finally reload the data table content.
+              // Reload the data table content.
               this.table.refreshBtn();
-            });
+            }
+          );
         });
       },
       modalRef: modalRef
     });
   }
-
 }
index 3304841d7adf3a559b84f9a6e167c108a0155d38..70c4d9142b25e0e3e6bb2290e65b297d367f1b3d 100644 (file)
@@ -7,9 +7,7 @@ import { Observable } from 'rxjs/Observable';
 import { Subscriber } from 'rxjs/Subscriber';
 
 import { RgwUserService } from '../../../shared/api/rgw-user.service';
-import {
-  DeletionModalComponent
-} from '../../../shared/components/deletion-modal/deletion-modal.component';
+import { DeletionModalComponent } from '../../../shared/components/deletion-modal/deletion-modal.component';
 import { TableComponent } from '../../../shared/datatable/table/table.component';
 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
 import { CdTableColumn } from '../../../shared/models/cd-table-column';
@@ -21,16 +19,17 @@ import { CdTableSelection } from '../../../shared/models/cd-table-selection';
   styleUrls: ['./rgw-user-list.component.scss']
 })
 export class RgwUserListComponent {
-
   @ViewChild(TableComponent) table: TableComponent;
 
   columns: CdTableColumn[] = [];
   users: object[] = [];
   selection: CdTableSelection = new CdTableSelection();
 
-  constructor(private router: Router,
-              private rgwUserService: RgwUserService,
-              private bsModalService: BsModalService) {
+  constructor(
+    private router: Router,
+    private rgwUserService: RgwUserService,
+    private bsModalService: BsModalService
+  ) {
     this.columns = [
       {
         name: 'Username',
@@ -62,14 +61,16 @@ export class RgwUserListComponent {
   }
 
   getUserList() {
-    this.rgwUserService.list()
-      .subscribe((resp: object[]) => {
+    this.rgwUserService.list().subscribe(
+      (resp: object[]) => {
         this.users = resp;
-      }, () => {
+      },
+      () => {
         // Force datatable to hide the loading indicator in
         // case of an error.
         this.users = [];
-      });
+      }
+    );
   }
 
   updateSelection(selection: CdTableSelection) {
@@ -82,15 +83,27 @@ export class RgwUserListComponent {
       metaType: this.selection.hasSingleSelection ? 'user' : 'users',
       deletionObserver: (): Observable<any> => {
         return new Observable((observer: Subscriber<any>) => {
+          // Delete all selected data table rows.
           Observable.forkJoin(
             this.selection.selected.map((user: any) => {
               return this.rgwUserService.delete(user.user_id);
-            }))
-            .subscribe(null, null, () => {
+            })
+          ).subscribe(
+            null,
+            (error) => {
+              // Forward the error to the observer.
+              observer.error(error);
+              // Reload the data table content because some deletions might
+              // have been executed successfully in the meanwhile.
+              this.table.refreshBtn();
+            },
+            () => {
+              // Notify the observer that we are done.
               observer.complete();
-              // Finally reload the data table content.
+              // Reload the data table content.
               this.table.refreshBtn();
-            });
+            }
+          );
         });
       },
       modalRef: modalRef