1 import { Component, OnInit } from '@angular/core';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import moment from 'moment';
6 import { RbdService } from '~/app/shared/api/rbd.service';
7 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
8 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
9 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
10 import { CdValidators } from '~/app/shared/forms/cd-validators';
11 import { ExecutingTask } from '~/app/shared/models/executing-task';
12 import { FinishedTask } from '~/app/shared/models/finished-task';
13 import { ImageSpec } from '~/app/shared/models/image-spec';
14 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
17 selector: 'cd-rbd-trash-move-modal',
18 templateUrl: './rbd-trash-move-modal.component.html',
19 styleUrls: ['./rbd-trash-move-modal.component.scss']
21 export class RbdTrashMoveModalComponent implements OnInit {
26 hasSnapshots: boolean;
30 executingTasks: ExecutingTask[];
32 moveForm: CdFormGroup;
36 private rbdService: RbdService,
37 public activeModal: NgbActiveModal,
38 public actionLabels: ActionLabelsI18n,
39 private fb: CdFormBuilder,
40 private taskWrapper: TaskWrapperService
46 this.moveForm = this.fb.group({
50 CdValidators.custom('format', (expiresAt: string) => {
51 const result = expiresAt === '' || moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').isValid();
54 CdValidators.custom('expired', (expiresAt: string) => {
55 const result = moment().isAfter(expiresAt);
64 this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageName);
65 this.imageSpecStr = this.imageSpec.toString();
66 this.pattern = `${this.poolName}/${this.imageName}`;
71 const expiresAt = this.moveForm.getValue('expiresAt');
74 delay = moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').diff(moment(), 'seconds', true);
83 task: new FinishedTask('rbd/trash/move', {
84 image_spec: this.imageSpecStr
86 call: this.rbdService.moveTrash(this.imageSpec, delay)
90 this.activeModal.close();