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';
];
action: string;
resource: string;
+ private rbdImage = new AsyncSubject();
constructor(
private authStorageService: AuthStorageService,
}
this.rbdService.get(poolName, rbdName).subscribe((resp: RbdFormResponseModel) => {
this.setResponse(resp, this.snapName);
+ this.rbdImage.next(resp);
});
});
} else {
}
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'])
+ );
}
}