]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-form/rbd-form.component.ts
import ceph 14.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-form / rbd-form.component.ts
index ba22359761fa6791cb393818cc26f00f8d261a82..6e9bb294ce1d4ee6bc301134f38d8aa572047b9a 100644 (file)
@@ -4,7 +4,8 @@ import { ActivatedRoute, Router } from '@angular/router';
 
 import { I18n } from '@ngx-translate/i18n-polyfill';
 import * as _ from 'lodash';
-import { Observable } from 'rxjs';
+import { AsyncSubject, Observable } from 'rxjs';
+import { switchMap } from 'rxjs/operators';
 
 import { PoolService } from '../../../shared/api/pool.service';
 import { RbdService } from '../../../shared/api/rbd.service';
@@ -82,6 +83,7 @@ export class RbdFormComponent implements OnInit {
   ];
   action: string;
   resource: string;
+  private rbdImage = new AsyncSubject();
 
   constructor(
     private authStorageService: AuthStorageService,
@@ -227,6 +229,7 @@ export class RbdFormComponent implements OnInit {
         }
         this.rbdService.get(poolName, rbdName).subscribe((resp: RbdFormResponseModel) => {
           this.setResponse(resp, this.snapName);
+          this.rbdImage.next(resp);
         });
       });
     } else {
@@ -638,22 +641,28 @@ export class RbdFormComponent implements OnInit {
   }
 
   submit() {
-    let action: Observable<any>;
-
-    if (this.mode === this.rbdFormMode.editing) {
-      action = this.editAction();
-    } else if (this.mode === this.rbdFormMode.cloning) {
-      action = this.cloneAction();
-    } else if (this.mode === this.rbdFormMode.copying) {
-      action = this.copyAction();
-    } else {
-      action = this.createAction();
+    if (!this.mode) {
+      this.rbdImage.next('create');
     }
-
-    action.subscribe(
-      undefined,
-      () => this.rbdForm.setErrors({ cdSubmitButton: true }),
-      () => this.router.navigate(['/block/rbd'])
-    );
+    this.rbdImage.complete();
+    this.rbdImage
+      .pipe(
+        switchMap(() => {
+          if (this.mode === this.rbdFormMode.editing) {
+            return this.editAction();
+          } else if (this.mode === this.rbdFormMode.cloning) {
+            return this.cloneAction();
+          } else if (this.mode === this.rbdFormMode.copying) {
+            return this.copyAction();
+          } else {
+            return this.createAction();
+          }
+        })
+      )
+      .subscribe(
+        () => {},
+        () => this.rbdForm.setErrors({ cdSubmitButton: true }),
+        () => this.router.navigate(['/block/rbd'])
+      );
   }
 }