From 90999b55aefbd41a55364292ba5d3cf90206284c Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Wed, 16 May 2018 14:34:34 +0200 Subject: [PATCH] mgr/dashboard: Handle errors during deletion - 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 (cherry picked from commit b2fa819fdfee93e6951666198720bce44c37b95d) --- .../rgw-bucket-list.component.ts | 40 +++++++++++++------ .../rgw-user-list/rgw-user-list.component.ts | 39 ++++++++++++------ 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.ts index 1042a1a336ff3..749460968e6f9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.ts @@ -20,16 +20,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 +46,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 +68,30 @@ export class RgwBucketListComponent { metaType: this.selection.hasSingleSelection ? 'bucket' : 'buckets', deletionObserver: (): Observable => { return new Observable((observer: Subscriber) => { + // 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 }); } - } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts index 3304841d7adf3..0e6b129f32323 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts @@ -21,16 +21,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 +63,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 +85,27 @@ export class RgwUserListComponent { metaType: this.selection.hasSingleSelection ? 'user' : 'users', deletionObserver: (): Observable => { return new Observable((observer: Subscriber) => { + // 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 -- 2.39.5