]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
860d66cc0173b885cccf49506d7dd050766a6c43
[ceph-ci.git] /
1 import { Component, OnInit } from '@angular/core';
2
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4
5 import { RbdService } from '~/app/shared/api/rbd.service';
6 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
7 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
8 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
9 import { ExecutingTask } from '~/app/shared/models/executing-task';
10 import { FinishedTask } from '~/app/shared/models/finished-task';
11 import { ImageSpec } from '~/app/shared/models/image-spec';
12 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
13
14 @Component({
15   selector: 'cd-rbd-trash-restore-modal',
16   templateUrl: './rbd-trash-restore-modal.component.html',
17   styleUrls: ['./rbd-trash-restore-modal.component.scss']
18 })
19 export class RbdTrashRestoreModalComponent implements OnInit {
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 activeModal: NgbActiveModal,
32     public actionLabels: ActionLabelsI18n,
33     private fb: CdFormBuilder,
34     private taskWrapper: TaskWrapperService
35   ) {}
36
37   ngOnInit() {
38     this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageName).toString();
39     this.restoreForm = this.fb.group({
40       name: this.imageName
41     });
42   }
43
44   restore() {
45     const name = this.restoreForm.getValue('name');
46     const imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageId);
47
48     this.taskWrapper
49       .wrapTaskAroundCall({
50         task: new FinishedTask('rbd/trash/restore', {
51           image_id_spec: imageSpec.toString(),
52           new_image_name: name
53         }),
54         call: this.rbdService.restoreTrash(imageSpec, name)
55       })
56       .subscribe({
57         error: () => {
58           this.restoreForm.setErrors({ cdSubmitButton: true });
59         },
60         complete: () => {
61           this.activeModal.close();
62         }
63       });
64   }
65 }