]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
c471a0151e8fea19e8c4c54513ea21f80a0d6899
[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 { 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   imageName: string;
21   imageId: string;
22   executingTasks: ExecutingTask[];
23
24   restoreForm: CdFormGroup;
25
26   constructor(
27     private rbdService: RbdService,
28     public modalRef: BsModalRef,
29     private fb: CdFormBuilder,
30     private taskWrapper: TaskWrapperService
31   ) {}
32
33   ngOnInit() {
34     this.restoreForm = this.fb.group({
35       name: this.imageName
36     });
37   }
38
39   restore() {
40     const name = this.restoreForm.getValue('name');
41
42     this.taskWrapper
43       .wrapTaskAroundCall({
44         task: new FinishedTask('rbd/trash/restore', {
45           pool_name: this.poolName,
46           image_id: this.imageId,
47           image_name: this.imageName,
48           new_image_name: name
49         }),
50         call: this.rbdService.restoreTrash(this.poolName, this.imageId, name)
51       })
52       .subscribe(
53         undefined,
54         () => {
55           this.restoreForm.setErrors({ cdSubmitButton: true });
56         },
57         () => {
58           this.modalRef.hide();
59         }
60       );
61   }
62 }