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 {
27 executingTasks: ExecutingTask[];
29 moveForm: CdFormGroup;
32 dateInputFormat: 'YYYY-MM-DD HH:mm:ss',
33 containerClass: 'theme-default'
38 private rbdService: RbdService,
39 public modalRef: BsModalRef,
40 private fb: CdFormBuilder,
41 private taskWrapper: TaskWrapperService
47 this.moveForm = this.fb.group({
51 CdValidators.custom('format', (expiresAt) => {
52 const result = expiresAt === '' || moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').isValid();
55 CdValidators.custom('expired', (expiresAt) => {
56 const result = moment().isAfter(expiresAt);
65 this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.imageName);
66 this.imageSpecStr = this.imageSpec.toString();
67 this.pattern = `${this.poolName}/${this.imageName}`;
72 const expiresAt = this.moveForm.getValue('expiresAt');
75 delay = moment(expiresAt).diff(moment(), 'seconds', true);
84 task: new FinishedTask('rbd/trash/move', {
85 image_spec: this.imageSpecStr
87 call: this.rbdService.moveTrash(this.imageSpec, delay)
89 .subscribe(undefined, undefined, () => {