]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-move-modal/rbd-trash-move-modal.component.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-trash-move-modal / rbd-trash-move-modal.component.ts
1 import { Component, OnInit } from '@angular/core';
2
3 import * as moment from 'moment';
4 import { BsModalRef } from 'ngx-bootstrap/modal';
5
6 import { RbdService } from '../../../shared/api/rbd.service';
7 import { CdFormBuilder } from '../../../shared/forms/cd-form-builder';
8 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
9 import { CdValidators } from '../../../shared/forms/cd-validators';
10 import { ExecutingTask } from '../../../shared/models/executing-task';
11 import { FinishedTask } from '../../../shared/models/finished-task';
12 import { ImageSpec } from '../../../shared/models/image-spec';
13 import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
14
15 @Component({
16 selector: 'cd-rbd-trash-move-modal',
17 templateUrl: './rbd-trash-move-modal.component.html',
18 styleUrls: ['./rbd-trash-move-modal.component.scss']
19 })
20 export class RbdTrashMoveModalComponent implements OnInit {
21 // initial state
22 poolName: string;
23 namespace: string;
24 imageName: string;
25 hasSnapshots: boolean;
26
27 imageSpec: ImageSpec;
28 imageSpecStr: string;
29 executingTasks: ExecutingTask[];
30
31 moveForm: CdFormGroup;
32 minDate = new Date();
33 bsConfig = {
34 dateInputFormat: 'YYYY-MM-DD HH:mm:ss',
35 containerClass: 'theme-default'
36 };
37 pattern: string;
38
39 constructor(
40 private rbdService: RbdService,
41 public modalRef: BsModalRef,
42 private fb: CdFormBuilder,
43 private taskWrapper: TaskWrapperService
44 ) {
45 this.createForm();
46 }
47
48 createForm() {
49 this.moveForm = this.fb.group({
50 expiresAt: [
51 '',
52 [
53 CdValidators.custom('format', (expiresAt: string) => {
54 const result = expiresAt === '' || moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').isValid();
55 return !result;
56 }),
57 CdValidators.custom('expired', (expiresAt: string) => {
58 const result = moment().isAfter(expiresAt);
59 return result;
60 })
61 ]
62 ]
63 });
64 }
65
66 ngOnInit() {
67 this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageName);
68 this.imageSpecStr = this.imageSpec.toString();
69 this.pattern = `${this.poolName}/${this.imageName}`;
70 }
71
72 moveImage() {
73 let delay = 0;
74 const expiresAt = this.moveForm.getValue('expiresAt');
75
76 if (expiresAt) {
77 delay = moment(expiresAt).diff(moment(), 'seconds', true);
78 }
79
80 if (delay < 0) {
81 delay = 0;
82 }
83
84 this.taskWrapper
85 .wrapTaskAroundCall({
86 task: new FinishedTask('rbd/trash/move', {
87 image_spec: this.imageSpecStr
88 }),
89 call: this.rbdService.moveTrash(this.imageSpec, delay)
90 })
91 .subscribe(undefined, undefined, () => {
92 this.modalRef.hide();
93 });
94 }
95 }