All files / src/app/ceph/block/rbd-trash-restore-modal rbd-trash-restore-modal.component.ts

100% Statements 22/22
75% Branches 12/16
100% Functions 6/6
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 625x   5x   5x 5x     5x 5x             5x                   3x 3x 3x 3x     5x 3x         5x 2x   2x                       1x     1x       5x  
import { Component, OnInit } from '@angular/core';
 
import { BsModalRef } from 'ngx-bootstrap/modal';
 
import { RbdService } from '../../../shared/api/rbd.service';
import { CdFormBuilder } from '../../../shared/forms/cd-form-builder';
import { CdFormGroup } from '../../../shared/forms/cd-form-group';
import { ExecutingTask } from '../../../shared/models/executing-task';
import { FinishedTask } from '../../../shared/models/finished-task';
import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
 
@Component({
  selector: 'cd-rbd-trash-restore-modal',
  template: require('./rbd-trash-restore-modal.component.html'),
  styles: []
})
export class RbdTrashRestoreModalComponent implements OnInit {
  metaType: string;
  poolName: string;
  imageName: string;
  imageId: string;
  executingTasks: ExecutingTask[];
 
  restoreForm: CdFormGroup;
 
  constructor(
    private rbdService: RbdService,
    public modalRef: BsModalRef,
    private fb: CdFormBuilder,
    private taskWrapper: TaskWrapperService
  ) {}
 
  ngOnInit() {
    this.restoreForm = this.fb.group({
      name: this.imageName
    });
  }
 
  restore() {
    const name = this.restoreForm.getValue('name');
 
    this.taskWrapper
      .wrapTaskAroundCall({
        task: new FinishedTask('rbd/trash/restore', {
          pool_name: this.poolName,
          image_id: this.imageId,
          new_image_name: name
        }),
        call: this.rbdService.restoreTrash(this.poolName, this.imageId, name)
      })
      .subscribe(
        undefined,
        () => {
          this.restoreForm.setErrors({ cdSubmitButton: true });
        },
        () => {
          this.modalRef.hide();
        }
      );
  }
}