import { Component, Input, Output, OnInit, OnDestroy, Renderer2, ChangeDetectorRef, ChangeDetectionStrategy, EventEmitter } from '@angular/core'; import { Subject } from 'rxjs/Subject'; import { Observable } from 'rxjs/Observable'; import { DialogService } from '../../services/dialog/dialog.service'; import { GLOBAL_UI_CONSTANTS } from '../../constants/ui.constants'; import { Alert } from '../../models/alert.interface'; @Component({ selector: 'hdca-dialog', templateUrl: './dialog.component.html', changeDetection: ChangeDetectionStrategy.OnPush }) export class DialogComponent implements OnInit, OnDestroy { @Input() dialogTitle: string; @Input() dialogFooter: any; @Input() dialogOpen: boolean; @Input() dialogId: string; @Input() fullScreen: boolean; @Input() dialogType: string; // Used for displaying icon in the header of the dialog @Input() isIconHeader: boolean; @Input() iconType: string; @Input() padding: string; // Specify whether modal content has padding or not @Input() useButtonContainer: boolean; // Specifies whether or not to wrap the buttons in a container // Handle vertical centering @Input() centerVertically: boolean; // Handle whether or not to include modal content @Input() omitContent: boolean; @Input() index?: number; @Input() alerts: Array = []; // Outputs @Output() onClose: EventEmitter = new EventEmitter(); @Output() clearAlertEvent = new EventEmitter(); // Determine whether or not to display the header // Displaying header depends on whether or not full bleed (to top edge) is needed, currently only for Brightcove video showHeader: boolean; isStatic: boolean; private afterOpenSubject = new Subject(); private afterCloseSubject = new Subject(); afterOpen$: Observable = this.afterOpenSubject.asObservable(); afterClose$: Observable = this.afterCloseSubject.asObservable(); // Get SVG path for close buttons GLOBAL_ICONS_SVG_PATH = GLOBAL_UI_CONSTANTS.GLOBAL_ICONS_SVG_PATH; constructor(private dialogService: DialogService, private renderer: Renderer2, private ref: ChangeDetectorRef) { } ngOnInit() { this.initData(); } private initData() { this.dialogTitle = this.dialogTitle ? this.dialogTitle : ''; this.dialogOpen = this.dialogOpen ? this.dialogOpen : false; this.dialogService.add(this); // Set the boolean flag that determines whether or not the header is shown this.showHeader = this.dialogType === 'brightcove' ? false : true; } open(data?: any) { this.dialogOpen = true; if (typeof document !== 'undefined') { this.renderer.addClass(document.body, 'hdca-body--has-open-modal'); } if (data) { this.afterOpenSubject.next(data); this.isStatic = data.static; } this.ref.markForCheck(); } close(data?: any) { this.onClose.emit(); if (data) { this.afterCloseSubject.next(data); } if (typeof document !== 'undefined') { this.renderer.removeClass(document.body, 'hdca-body--has-open-modal'); } this.dialogOpen = false; if (!this.ref['destroyed']) { this.ref.detectChanges(); } } clearAlert(id) { this.clearAlertEvent.emit(id); } ngOnDestroy() { this.dialogService.remove(this); } }