import { Type } from '@angular/core'; import { AbstractControl, FormControl, FormGroup } from '@angular/forms'; import { Observable } from 'rxjs'; import { MtnaWfApiService } from '../../../core/services/index'; import { ConditionChange, Form, Form as WebForm, FormItem, FormItemImpl, MtnaWfFormItemChange, MtnaWfFormItemChangeAction, Section, ValueItem } from '../../../models/index'; import { MtnaWfNgFormService } from './ng-form.service'; import { MtnaWfUIService } from './ui.service'; /** * Allows a caller to (de)serializae an MtnaForm. It contains the determining logic for returning specific form controls * and deserializing new MtnaForms from the reactive values, as well as registering custom Form Items & functions. * * @export */ export declare class MtnaWfManagerService { private apiService; private ngFormManager; private uiService; protected components: Map>; private formChange$; /** ConditionChanges on 'add' must wait until the form rerenders to toggle items */ private itemToggleQue; private _mtnaForm; /** * Observable stream of MtnaForm changes. Used to inform a subscriber that an MtnaForm has been changed. * * @returns Observable to which a caller can subscribe */ readonly formChanges: Observable; constructor(apiService: MtnaWfApiService, ngFormManager: MtnaWfNgFormService, uiService: MtnaWfUIService); /** * Destroys all cached values of the NgFormService & UiService. * This method should be called when complete disposal of a form is desired. * @note Values are cached so they may be recalled even when a `` is destroyed, because they may be useful * when reinitializing that form, such as the case of tab navigation within a larger page */ disposeForm(): void; /** * Adds or removes a FormItem from the form & modifies other affected FormItems * @param change MtnaWfFormItemChange */ changeMtnaFormItem(change: MtnaWfFormItemChange): void; /** * Returns a ConditionChange array for items existing in the which enable/disable FormItems outside the 's scope. * @param item FormItem that effects the condition of other FormItems * @param action Whether this item was added (ADD), or removed (REMOVE) * @returns Array */ generateConditionChangeArray(item: FormItem, action?: MtnaWfFormItemChangeAction): Array; /** * Returns a new MtnaForm using the previous MtnaForm & reactive form values. * * @param mtnaForm MtnaForm requiring value insertion * @param ngFormValues JSON object of ngForm values * @returns new MtnaForm */ insertNewValues(mtnaForm: WebForm, ngFormValues: any): WebForm; /** * Serializes a Form | FormItem into FormControl(s) * * @param item Form | FormItem requiring serialization * @returns FormGroup | FormControl */ serializeMtnaFormItem(item: WebForm | FormItemImpl): AbstractControl; getDynamicComponent(id: string): Type; /** * Registers a map of components to be dynamically rendered inside an MtnaForm. * * @param components the map of components that a ValueItem will use for rendering * @prop string - the type(itemId suffix) of component, used for retrieval * @prop Type - the component to be rendered, an extension of BaseFormItem */ registerDynamicComponents(components: Map>): void; /** * Sets an MtnaForm on the service * @param form MtnaForm to be used for internal modification */ setMtnaForm(form: WebForm): void; /** * Any FormService extension class should override this method in order to call the * dynamicWebFormItemBuilder/dynamicReactiveFormControlBuilder methods. During web form generation, this method is checked & * the current FormItem is passed in, which can be used by the overriding method. * * @example dynamicFormConditional = (item: FormItem) => item.itemId.includes({some itemId}) * */ protected dynamicFormConditional: (item: FormItem) => boolean; /** * Function to be overridden by extended service in order to handle form generation for any application-specific dynamic form components. * Should return a new ValueItem. * Step 3 * * @example dynamicWebFormItemBuilder(section: Section | Form, item: FormItem, ngFormValue: any): ValueItem { * const newValue = this.generateNewValue(item, rfValue, section); * return { ...item, ...newValue } * } * @param section the current FormSection * @param item the current FormItem * @param ngFormValue the ngForm JSON value * @returns a new ValueItem */ protected dynamicWebFormItemBuilder(section: Section | WebForm, item: FormItem, ngFormValue: any, disabledState?: { [instanceId: string]: boolean; }): ValueItem; /** * Function to be overridden by extended service in order to handle reactive form generation * for any application-specific dynamic form components. * Should return FormControl | FormGroup. * * @example dynamicReactiveFormControlBuilder(item: FormItem) { * return this.buildFormControlForDynamicComponent(item: FormItem); * } * @param item FormItem used to generate form controls * @returns FormControl | FormGroup */ protected dynamicReactiveFormControlBuilder(item: FormItem): FormControl | FormGroup; /** * Recursively traverses a Form to insert or remove a designated FormItem. * @param item MtnaForm to search through * @param change: MtnaWfFormItemChange for adding or removing a FormItem * @param newItem FormItem to add to its parent */ protected _modifyFormItem(item: any, change: MtnaWfFormItemChange, newItem?: FormItem): Form | FormItem; /** * Traverses an OptionItemMap of a FormItem to insert or remove a designated FormItem * @param optionItem FormItem with an optionItemMap, e.g. OptionItemImpl | OptionGroupItemImpl * @param change MtnaWfFormItemChange for adding or removing a FormItem * @param newItem FormItem to be added to its parent * @returns FormItem with an optionItemMap containing FormItems */ private _modifyOptionItem; /** * Traverses table rows to insert or remove a FormItem * @param tableItem TableItem to traverse * @param change MtnaWfFormItemChange for adding or removing a FormItem * @param newItem FormItem to be added to its parent * @returns TableItem with a FormItem added or removed */ private _modifyTableItem; /** * Adds or removes instanceIds from the 'itemIds' in a FormItem's condition * @param form MtnaForm to search through & replace formitems with the new condition * @param change The change that recently occurred in the mtnaForm */ private _modifyFormItemConditions; /** * Builds a map of all instanceIds inside an item. Checks 'items' & 'optionItemMap' * @param item Item to recurse * @param idMap map of the item's internal instanceIds */ private _buildInternalIdsMap; /** * Builds an array of ConditionChanges to be implemented in an MtnaForm. * @param item FormItem that was added/removed, which affects conditions of other FormItems * @param changes Array to build up * @param internalIdMap Map of all instanceIds located in the item; in order to exclude them from the condition changes * @param action Whether the item was added or removed */ private _buildConditionChangeArray; /** * Builds an array of ConditionChanges from an item's optionItemMap * @param item FormItem with an optionItemMap * @param conditions Array of ConditionChanges to push on new changes * @param itemMap map of instanceIds exisiting in an item; in order to exclude them from the changes * @param action Whether an item was added or removed */ private _buildArrayFromOptionItemMap; /** * Pushes a new ConditionChange onto the conditions array. If a ConditionChange with matching id exists, * it merges the new values into it * @param enablerId instanceId of the item that enables other FormItems * @param enabled the item's 'enabledItems' array * @param disabled the item's 'disabledItems' array * @param conditions Array of ConditionChanges to build up * @param itemMap map of instanceIds inside an item; to ensure no internal ids are included in a change * @param enable Whether the 'enabledItems' should toggled enabled */ private _pushConditionToArray; }