import { VisibilityRuleSource } from './VisibilityRuleSource'; import { VisibilityRule } from './VisibilityRule'; import { Rule } from '../../../models/Rule'; export class VisibilityRulesContext { public rules: Array = new Array(); public getRulesFromKey(id: string): VisibilityRule { for (let i = 0; i < this.rules.length; i++) { if (id == this.rules[i].targetControlId) return this.rules[i] } return null; } public buildVisibilityRuleContext(items: Array) { items.forEach(item => { this.addToVisibilityRulesContext(item) }); } private addToVisibilityRulesContext(item: Rule): void { for (let i = 0; i < this.rules.length; i++) { if (this.rules[i].targetControlId == item.targetField) { this.rules[i].sourceVisibilityRules.push({ sourceControlId: item.sourceField, sourceControlValue: item.requiredValue }); return; } } let newVisibilityRuleArray = [({ sourceControlId: item.sourceField, sourceControlValue: item.requiredValue })]; this.rules.push({ targetControlId: item.targetField, sourceVisibilityRules: newVisibilityRuleArray }) return; } }