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