import { Component, OnInit } from '@angular/core'; import { NbWindowRef, NbIconLibraries } from '@nebular/theme'; import { ActionOptions } from '../../../model/componets'; import { ComponentsService } from '../../../services/components.service'; interface CustomContext { data: ActionOptions; formType: 'update' | 'add'; } @Component({ selector: 'ngx-action-form', templateUrl: './action-form.component.html', styleUrls: ['./action-form.component.scss'], }) export class ActionFormComponent implements OnInit { source: ActionOptions; public get actionType(): string { return this.source.actionType; } public set actionType(value: string) { if (this.source) { this.source.actionType = value; this.initActionConfig(); } } actionList: any[]; actionConfig: any[]; formType: string; constructor( public windowRef: NbWindowRef, private componentsService: ComponentsService, iconsLibrary: NbIconLibraries, ) {} ngOnInit() { const context = this.windowRef.config.context as CustomContext; this.source = context.data; this.formType = context.formType; this.initActionConfig(); } initActionConfig() { this.componentsService.getActionConfig().then(({ actionConfig, actionList }) => { this.actionConfig = [...actionConfig]; this.actionList = [...actionList]; }); } submit() { this.close(); } close() { this.windowRef.close(); } cancel() { if (this.formType === 'add') { this.deleteAction(); } this.close(); } deleteAction() { this.componentsService.deleteCurrentAction(); } setObjectParam(obj: any, index: string) { const ev = window.event || arguments[0]; const value = ev.target.value; obj[index] = value; } appendChildTo(objectParam: any) { objectParam.push('Please change contents'); } }