1 import { Component, OnInit } from '@angular/core';
3 import * as moment from 'moment';
4 import { BsModalRef } from 'ngx-bootstrap/modal';
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;
34 dateInputFormat: 'YYYY-MM-DD HH:mm:ss',
35 containerClass: 'theme-default'
40 private rbdService: RbdService,
41 public modalRef: BsModalRef,
42 private fb: CdFormBuilder,
43 private taskWrapper: TaskWrapperService
49 this.moveForm = this.fb.group({
53 CdValidators.custom('format', (expiresAt: string) => {
54 const result = expiresAt === '' || moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').isValid();
57 CdValidators.custom('expired', (expiresAt: string) => {
58 const result = moment().isAfter(expiresAt);
67 this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageName);
68 this.imageSpecStr = this.imageSpec.toString();
69 this.pattern = `${this.poolName}/${this.imageName}`;
74 const expiresAt = this.moveForm.getValue('expiresAt');
77 delay = moment(expiresAt).diff(moment(), 'seconds', true);
86 task: new FinishedTask('rbd/trash/move', {
87 image_spec: this.imageSpecStr
89 call: this.rbdService.moveTrash(this.imageSpec, delay)
91 .subscribe(undefined, undefined, () => {