1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
3 import { logger } from '@root-helpers/logger'
6 selector: 'my-custom-modal',
7 templateUrl: './custom-modal.component.html',
8 styleUrls: [ './custom-modal.component.scss' ]
10 export class CustomModalComponent {
11 @ViewChild('modal', { static: true }) modal: ElementRef
13 @Input() title: string
14 @Input() content: string
15 @Input() close?: boolean
16 @Input() cancel?: { value: string, action?: () => void }
17 @Input() confirm?: { value: string, action?: () => void }
19 private modalRef: NgbModalRef
22 private modalService: NgbModal
29 cancel?: { value: string, action?: () => void }
30 confirm?: { value: string, action?: () => void }
32 if (this.modalRef instanceof NgbModalRef && this.modalService.hasOpenModals()) {
33 logger.error('Cannot open another custom modal, one is already opened.')
37 const { title, content, close, cancel, confirm } = input
40 this.content = content
43 this.confirm = confirm
45 this.modalRef = this.modalService.open(this.modal, {
56 if (typeof this.cancel.action === 'function') {
71 if (typeof this.confirm.action === 'function') {
79 return typeof this.cancel !== 'undefined'
83 return typeof this.confirm !== 'undefined'