import { Component, OnInit, Input, ElementRef, HostBinding } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { ImageModel } from '../../models/image/image.model'; import { ImageStylingModel } from '../../models/image/image-styling.model'; import { ImageTemplates } from '../../templates/image.template'; @Component({ selector: 'cf-image', template: "
The object bound to the tempalte.
*/ cfImage: ImageModel; /** *
The properties object of the image.
*/ @Input() properties: ImageModel; /** * It is function for creating Notification click events by using Core Component notificationAction event emmiter. * @param notification it is json notification object */ cfNotificationAction(notification) { this.notificationAction.emit(notification); } /** *
The styling object of the image.
*/ @Input() styling: ImageStylingModel; /** *
Display or hide the image
*/ @Input() display: boolean; /** *The label of the image.
*/ @Input() label: string; /** *The label position of the image.
*/ @Input() labelPosition: string; /** *The url of the iamge.
*/ @Input() url: string; constructor(public elementRef: ElementRef) { super(elementRef); } /** *Initialize the proerties and styling object with the appropriate values.
*/ ngOnInit(): void { if(this.notificationAction.observers.length > 0) this.notifacationClickable = 'notification-clickable'; this.activeTemplate = ImageTemplates["defaultTemplate"]; if(this.compTemplate!=null && this.compTemplate!="") { if(ImageTemplates[this.compTemplate]!=null) { this.activeTemplate = ImageTemplates[this.compTemplate]; } else this.activeTemplate = this.compTemplate; } if(this.properties==null) { this.properties = new ImageModel(this.activeTemplate["property"]); } else { var mainKeys = Object.keys(this.activeTemplate["property"]); for(let key of mainKeys) { if(this.properties[key]==null) this.properties[key]=this.activeTemplate["property"][key]; } } if(this.styling==null) this.styling = new ImageStylingModel (this.activeTemplate["style"]); if(this.display!=null) this.properties.display = this.display; if(this.label!=null) this.properties.label = this.label; if(this.labelPosition!=null) this.properties.labelPosition = this.labelPosition; if(this.url!=null) this.properties.url = this.url; this.cfImage = this.properties; } /** *Update the properties object with hte changes on the inputs to keep the image dynamic.
* @param changes */ ngOnChanges(changes: any){ if(changes.display!=null) this.properties.display = changes.display.currentValue; if(changes.label!=null) this.properties.label = changes.label.currentValue; if(changes.labelPosition!=null) this.properties.labelPosition = changes.labelPosition.currentValue; if(changes.url!=null) this.properties.url = changes.url.currentValue; } }