All files / src/app/shared/components/critical-confirmation-modal critical-confirmation-modal.component.ts

95.83% Statements 23/24
85.71% Branches 12/14
83.33% Functions 5/6
95.45% Lines 21/22

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 5998x 98x   98x     98x 98x             98x   98x               18x   18x   98x 15x       15x 1x       98x 5x 4x           1x       98x 5x     98x     98x  
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
 
import { BsModalRef } from 'ngx-bootstrap/modal';
import { Observable } from 'rxjs';
 
import { CdFormGroup } from '../../forms/cd-form-group';
import { SubmitButtonComponent } from '../submit-button/submit-button.component';
 
@Component({
  selector: 'cd-deletion-modal',
  template: require('./critical-confirmation-modal.component.html'),
  styles: []
})
export class CriticalConfirmationModalComponent implements OnInit {
  @ViewChild(SubmitButtonComponent)
  submitButton: SubmitButtonComponent;
  bodyTemplate: TemplateRef<any>;
  bodyContext: object;
  submitActionObservable: () => Observable<any>;
  submitAction: Function;
  deletionForm: CdFormGroup;
  itemDescription: 'entry';
  itemNames: string[];
  actionDescription = 'delete';
 
  constructor(public modalRef: BsModalRef) {}
 
  ngOnInit() {
    this.deletionForm = new CdFormGroup({
      confirmation: new FormControl(false, [Validators.requiredTrue])
    });
 
    if (!(this.submitAction || this.submitActionObservable)) {
      throw new Error('No submit action defined');
    }
  }
 
  callSubmitAction() {
    if (this.submitActionObservable) {
      this.submitActionObservable().subscribe(
        null,
        this.stopLoadingSpinner.bind(this),
        this.hideModal.bind(this)
      );
    } else {
      this.submitAction();
    }
  }
 
  hideModal() {
    this.modalRef.hide();
  }
 
  stopLoadingSpinner() {
    this.deletionForm.setErrors({ cdSubmitButton: true });
  }
}