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 { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
15 selector: 'cd-rbd-trash-move-modal',
16 templateUrl: './rbd-trash-move-modal.component.html',
17 styleUrls: ['./rbd-trash-move-modal.component.scss']
19 export class RbdTrashMoveModalComponent implements OnInit {
25 executingTasks: ExecutingTask[];
27 moveForm: CdFormGroup;
30 dateInputFormat: 'YYYY-MM-DD HH:mm:ss',
31 containerClass: 'theme-default'
36 private rbdService: RbdService,
37 public modalRef: BsModalRef,
38 private fb: CdFormBuilder,
39 private taskWrapper: TaskWrapperService
45 this.moveForm = this.fb.group({
49 CdValidators.custom('format', (expiresAt) => {
50 const result = expiresAt === '' || moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').isValid();
53 CdValidators.custom('expired', (expiresAt) => {
54 const result = moment().isAfter(expiresAt);
63 this.imageSpec = this.rbdService.getImageSpec(this.poolName, this.namespace, this.imageName);
64 this.pattern = `${this.poolName}/${this.imageName}`;
69 const expiresAt = this.moveForm.getValue('expiresAt');
72 delay = moment(expiresAt).diff(moment(), 'seconds', true);
81 task: new FinishedTask('rbd/trash/move', {
82 image_spec: this.imageSpec
84 call: this.rbdService.moveTrash(this.poolName, this.namespace, this.imageName, delay)
86 .subscribe(undefined, undefined, () => {