1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
4 import { BsModalRef } from 'ngx-bootstrap/modal';
5 import { Subject } from 'rxjs';
7 import { RbdService } from '../../../shared/api/rbd.service';
8 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
9 import { FinishedTask } from '../../../shared/models/finished-task';
10 import { NotificationService } from '../../../shared/services/notification.service';
11 import { TaskManagerService } from '../../../shared/services/task-manager.service';
14 selector: 'cd-rbd-snapshot-form',
15 templateUrl: './rbd-snapshot-form.component.html',
16 styleUrls: ['./rbd-snapshot-form.component.scss']
18 export class RbdSnapshotFormComponent implements OnInit {
23 snapshotForm: CdFormGroup;
27 public onSubmit: Subject<string>;
30 public modalRef: BsModalRef,
31 private rbdService: RbdService,
32 private taskManagerService: TaskManagerService,
33 private notificationService: NotificationService
39 this.snapshotForm = new CdFormGroup({
40 snapshotName: new FormControl('', {
41 validators: [Validators.required]
47 this.onSubmit = new Subject();
50 setSnapName(snapName) {
51 this.snapName = snapName;
52 this.snapshotForm.get('snapshotName').setValue(snapName);
56 * Set the 'editing' flag. If set to TRUE, the modal dialog is in
57 * 'Edit' mode, otherwise in 'Create' mode.
58 * @param {boolean} editing
60 setEditing(editing: boolean = true) {
61 this.editing = editing;
65 const snapshotName = this.snapshotForm.getValue('snapshotName');
66 const finishedTask = new FinishedTask();
67 finishedTask.name = 'rbd/snap/edit';
68 finishedTask.metadata = {
69 pool_name: this.poolName,
70 image_name: this.imageName,
71 snapshot_name: snapshotName
74 .renameSnapshot(this.poolName, this.imageName, this.snapName, snapshotName)
77 this.taskManagerService.subscribe(
79 finishedTask.metadata,
80 (asyncFinishedTask: FinishedTask) => {
81 this.notificationService.notifyTask(asyncFinishedTask);
85 this.onSubmit.next(this.snapName);
88 this.snapshotForm.setErrors({ cdSubmitButton: true });
93 const snapshotName = this.snapshotForm.getValue('snapshotName');
94 const finishedTask = new FinishedTask();
95 finishedTask.name = 'rbd/snap/create';
96 finishedTask.metadata = {
97 pool_name: this.poolName,
98 image_name: this.imageName,
99 snapshot_name: snapshotName
102 .createSnapshot(this.poolName, this.imageName, snapshotName)
105 this.taskManagerService.subscribe(
107 finishedTask.metadata,
108 (asyncFinishedTask: FinishedTask) => {
109 this.notificationService.notifyTask(asyncFinishedTask);
112 this.modalRef.hide();
113 this.onSubmit.next(snapshotName);
116 this.snapshotForm.setErrors({ cdSubmitButton: true });