1 import { Component, OnInit } from '@angular/core';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import * as moment from 'moment';
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';
16 selector: 'cd-rbd-trash-move-modal',
17 templateUrl: './rbd-trash-move-modal.component.html',
18 styleUrls: ['./rbd-trash-move-modal.component.scss']
20 export class RbdTrashMoveModalComponent implements OnInit {
25 hasSnapshots: boolean;
29 executingTasks: ExecutingTask[];
31 moveForm: CdFormGroup;
35 private rbdService: RbdService,
36 public activeModal: NgbActiveModal,
37 private fb: CdFormBuilder,
38 private taskWrapper: TaskWrapperService
44 this.moveForm = this.fb.group({
48 CdValidators.custom('format', (expiresAt: string) => {
49 const result = expiresAt === '' || moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').isValid();
52 CdValidators.custom('expired', (expiresAt: string) => {
53 const result = moment().isAfter(expiresAt);
62 this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageName);
63 this.imageSpecStr = this.imageSpec.toString();
64 this.pattern = `${this.poolName}/${this.imageName}`;
69 const expiresAt = this.moveForm.getValue('expiresAt');
72 delay = moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').diff(moment(), 'seconds', true);
81 task: new FinishedTask('rbd/trash/move', {
82 image_spec: this.imageSpecStr
84 call: this.rbdService.moveTrash(this.imageSpec, delay)
88 this.activeModal.close();