import { Processor } from './Processor'; import { Arithmetic, ConditionRange, DecisionTable, DecisionTable2C, DecisionTree, ExecutionFlow, GroovyScript, MathFormula, NumberRange, ObjectProperties, OptionValue, Pmml, Rule, ScoreCard, SingleRule, Sql, Ternary, WhenThen, } from './processors'; class ProcessorManager { static PROCESSOR_TYPES_PARAMETER: string[] = [ 'OBJECT_PROPERTIES', 'OPTION_VALUE', 'MATH_FORMULA', 'ARITHMETIC', 'TERNARY', 'WHEN_THEN', 'NUMBER_RANGE', 'CONDITION_RANGE', 'SCORE_CARD', 'DECISION_TABLE_2C', 'DECISION_TABLE', 'DECISION_TREE', 'EXECUTION_FLOW', 'PMML', 'GROOVY_SCRIPT', 'SQL', 'RULE', 'SINGLE_RULE', ]; static PROCESSOR_TYPES_INDICATOR = [ 'OBJECT_PROPERTIES', 'MATH_FORMULA', 'ARITHMETIC', 'TERNARY', 'WHEN_THEN', 'NUMBER_RANGE', 'CONDITION_RANGE', 'GROOVY_SCRIPT', 'SQL', ]; targetType: string; processors: any; constructor(targetType: string) { this.targetType = targetType; this.processors = {}; this.processors.ARITHMETIC = new Arithmetic(this.targetType); this.processors.CONDITION_RANGE = new ConditionRange(this.targetType); this.processors.DECISION_TABLE = new DecisionTable(this.targetType); this.processors.DECISION_TABLE_2C = new DecisionTable2C(this.targetType); this.processors.DECISION_TREE = new DecisionTree(this.targetType); this.processors.EXECUTION_FLOW = new ExecutionFlow(this.targetType); this.processors.GROOVY_SCRIPT = new GroovyScript(this.targetType); this.processors.MATH_FORMULA = new MathFormula(this.targetType); this.processors.NUMBER_RANGE = new NumberRange(this.targetType); this.processors.OBJECT_PROPERTIES = new ObjectProperties(this.targetType); this.processors.OPTION_VALUE = new OptionValue(this.targetType); this.processors.PMML = new Pmml(this.targetType); this.processors.RULE = new Rule(this.targetType); this.processors.SCORE_CARD = new ScoreCard(this.targetType); this.processors.SINGLE_RULE = new SingleRule(this.targetType); this.processors.SQL = new Sql(this.targetType); this.processors.TERNARY = new Ternary(this.targetType); this.processors.WHEN_THEN = new WhenThen(this.targetType); } public getToolbarAction(target: any): any { const result: any = []; switch (this.targetType) { case Processor.PARAMETER: ProcessorManager.PROCESSOR_TYPES_PARAMETER.forEach((name) => { result.push(this.processors[name].getToolbarAction(target)); }); break; case Processor.INDICATOR: ProcessorManager.PROCESSOR_TYPES_INDICATOR.forEach((name) => { result.push(this.processors[name].getToolbarAction(target)); }); break; } return result; } public format(value: any, row: any): any { if (this.processors[row.type]) { return this.processors[row.type].format(row); } return value; } public getEditorFields(context?: any): any { const result: any = []; switch (this.targetType) { case Processor.PARAMETER: ProcessorManager.PROCESSOR_TYPES_PARAMETER.forEach((name) => { result.push(...this.processors[name].getEditorFields(context)); }); break; case Processor.INDICATOR: ProcessorManager.PROCESSOR_TYPES_INDICATOR.forEach((name) => { result.push(...this.processors[name].getEditorFields(context)); }); break; } return result; } public getViewerFields(context?: any): any { const result: any = []; switch (this.targetType) { case Processor.PARAMETER: ProcessorManager.PROCESSOR_TYPES_PARAMETER.forEach((name) => { result.push(...this.processors[name].getViewerFields(context)); }); break; case Processor.INDICATOR: ProcessorManager.PROCESSOR_TYPES_INDICATOR.forEach((name) => { result.push(...this.processors[name].getViewerFields(context)); }); break; } return result; } public beforeEditorDataSubmit(args: any): void { if (this.processors[args.data.type]) { this.processors[args.data.type].beforeEditorDataSubmit(args); } } public afterEditorOpen(args: any): void { //const type = args.grid.getEditorForm().getFieldValue('type'); const type = 'OPTION_VALUE'; if (this.processors[type]) { this.processors[type].afterEditorOpen(args); } } } export { ProcessorManager };