]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
40750922c34e9f2dc862e405bac296ae31f236f3
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2
3 import { BsModalRef } from 'ngx-bootstrap/modal';
4
5 import { RbdService } from '../../../shared/api/rbd.service';
6 import { CdFormBuilder } from '../../../shared/forms/cd-form-builder';
7 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
8 import { ExecutingTask } from '../../../shared/models/executing-task';
9 import { FinishedTask } from '../../../shared/models/finished-task';
10 import { ImageSpec } from '../../../shared/models/image-spec';
11 import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
12
13 @Component({
14   selector: 'cd-rbd-trash-restore-modal',
15   templateUrl: './rbd-trash-restore-modal.component.html',
16   styleUrls: ['./rbd-trash-restore-modal.component.scss']
17 })
18 export class RbdTrashRestoreModalComponent implements OnInit {
19   metaType: string;
20   poolName: string;
21   namespace: string;
22   imageName: string;
23   imageSpec: string;
24   imageId: string;
25   executingTasks: ExecutingTask[];
26
27   restoreForm: CdFormGroup;
28
29   constructor(
30     private rbdService: RbdService,
31     public modalRef: BsModalRef,
32     private fb: CdFormBuilder,
33     private taskWrapper: TaskWrapperService
34   ) {}
35
36   ngOnInit() {
37     this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageName).toString();
38     this.restoreForm = this.fb.group({
39       name: this.imageName
40     });
41   }
42
43   restore() {
44     const name = this.restoreForm.getValue('name');
45     const imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageId);
46
47     this.taskWrapper
48       .wrapTaskAroundCall({
49         task: new FinishedTask('rbd/trash/restore', {
50           image_id_spec: imageSpec.toString(),
51           new_image_name: name
52         }),
53         call: this.rbdService.restoreTrash(imageSpec, name)
54       })
55       .subscribe(
56         undefined,
57         () => {
58           this.restoreForm.setErrors({ cdSubmitButton: true });
59         },
60         () => {
61           this.modalRef.hide();
62         }
63       );
64   }
65 }