]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
b45ef7bf8fe3dcf5ec98d087c7631d4bdc3bd492
[ceph-ci.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 { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
11
12 @Component({
13   selector: 'cd-rbd-trash-restore-modal',
14   templateUrl: './rbd-trash-restore-modal.component.html',
15   styleUrls: ['./rbd-trash-restore-modal.component.scss']
16 })
17 export class RbdTrashRestoreModalComponent implements OnInit {
18   metaType: string;
19   poolName: string;
20   namespace: string;
21   imageName: string;
22   imageSpec: string;
23   imageId: string;
24   executingTasks: ExecutingTask[];
25
26   restoreForm: CdFormGroup;
27
28   constructor(
29     private rbdService: RbdService,
30     public modalRef: BsModalRef,
31     private fb: CdFormBuilder,
32     private taskWrapper: TaskWrapperService
33   ) {}
34
35   ngOnInit() {
36     this.imageSpec = this.rbdService.getImageSpec(this.poolName, this.namespace, this.imageName);
37     this.restoreForm = this.fb.group({
38       name: this.imageName
39     });
40   }
41
42   restore() {
43     const name = this.restoreForm.getValue('name');
44
45     this.taskWrapper
46       .wrapTaskAroundCall({
47         task: new FinishedTask('rbd/trash/restore', {
48           image_id_spec: this.rbdService.getImageSpec(this.poolName, this.namespace, this.imageId),
49           new_image_name: name
50         }),
51         call: this.rbdService.restoreTrash(this.poolName, this.namespace, this.imageId, name)
52       })
53       .subscribe(
54         undefined,
55         () => {
56           this.restoreForm.setErrors({ cdSubmitButton: true });
57         },
58         () => {
59           this.modalRef.hide();
60         }
61       );
62   }
63 }