import { Component, OnInit, Input, Output, EventEmitter, ElementRef, ViewChild, HostBinding } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { IconModel } from '../../models/icon/icon.model'; import { MenuItemModel } from '../../models/menu/menu-item.model'; import { MenuItemStylingModel } from '../../models/menu/menu-item-styling.model'; import { MenuModel } from '../../models/menu/menu.model'; import { MenuStylingModel } from '../../models/menu/menu-styling.model'; import { MdMenuTrigger } from '@angular/material'; import { MenuTemplates } from '../../templates/menu.template'; /** *

Menu is creating using MenuItemModel Class/Component and Icon Class/Component.

*

Example of using Menu:

*
 * <cf-menu [menu]="menu" [show]="true"></cf-menu>
 * 
*/ @Component({ selector: 'cf-menu', template: "
", styles: [":host { display: block; position: relative; z-index: 0; } :host.cf-menu-is-disabled:before { content: ''; position: absolute; z-index: 1; display: block; width: 100%; height: 100%; } :host.notification-clickable cf-notification:hover { cursor: pointer; } "] }) export class CfMenuComponent extends CfCoreComponent implements OnInit { @HostBinding('class') notifacationClickable = ''; /** * It is an array with menu items generated by MenuItemModel Class and used in Menu component template to render list of menu items. */ cfMenu: MenuModel; /** * It is an attribute [settings] of directive cf-menu which take array with menu items. *

Example of menu item json object:

*
{
	 *	label: 'My menu item label',
	 *	type: 'standard',
	 *	icon: Icon,
	 *	notification: '5',
	 *	display: true,
	 *	disable: false,
	 *	onClick: this.myFunction
	 * }
*

label: string

* It is label of menu item. Default is Menu item label. *

type: string

* It is menu item type. Types are: standard and divider. Default is standard. *

icon: Object

* It is menu item icon generated by Icon Class (look to Icon API Referance). *

notification: string

* It is menu item notification. Can mean number of notifications. *

display: Boolean

* It is menu item visibility. Default is true. *

disable: Boolean

* It is menu item disable status. Default is false. *

onClick: any

* It is menu item click event. */ @Input() public properties: MenuModel; @Input() public styling: MenuStylingModel; @Input() public show: boolean = true; @Input() public disabled: boolean = false; @Output() cfItemAction: EventEmitter = new EventEmitter(); itemClicked(i:number, it:Object) { this.cfItemAction.emit({ cfIndex: i, cfItem: it }); } /** * It is Menu trigger element (icon) in the DOM which give access to open menu programmatically from other GCs Components (like GC Button) by calling function openMenu(). */ @ViewChild(MdMenuTrigger) trigger: MdMenuTrigger; /** * It is function which is called after click on Menu icon (trigger) from other GCs Components (like GC Button) to open list with menu items. */ openMenu() { this.trigger.openMenu(); } /** * 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); } constructor(public elementRef: ElementRef) { super(elementRef); } /** *

On Menu component initialization next things are heppening:

* * */ ngOnInit(): void { if(this.notificationAction.observers.length > 0) this.notifacationClickable = 'notification-clickable'; this.activeTemplate = MenuTemplates["defaultTemplate"]; if(this.properties==null) this.properties = this.properties = new MenuModel(this.activeTemplate["property"]); if(this.styling==null) this.styling = new MenuStylingModel(this.activeTemplate["style"]); this.cfMenu = this.properties; } }