import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ActionItem } from 'src/app/_services/action-factory.service'; @Component({ selector: 'app-card-actionables', templateUrl: './card-actionables.component.html', styleUrls: ['./card-actionables.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) export class CardActionablesComponent implements OnInit { @Input() iconClass = 'fa-ellipsis-v'; @Input() btnClass = ''; @Input() actions: ActionItem[] = []; @Input() labelBy = 'card'; @Input() disabled: boolean = false; @Output() actionHandler = new EventEmitter>(); adminActions: ActionItem[] = []; nonAdminActions: ActionItem[] = []; constructor(private readonly cdRef: ChangeDetectorRef) { } ngOnInit(): void { this.nonAdminActions = this.actions.filter(item => !item.requiresAdmin); this.adminActions = this.actions.filter(item => item.requiresAdmin); this.cdRef.markForCheck(); } preventClick(event: any) { event.stopPropagation(); event.preventDefault(); } performAction(event: any, action: ActionItem) { this.preventClick(event); if (typeof action.callback === 'function') { this.actionHandler.emit(action); } } }