@ -13,6 +13,7 @@ export class VisibilityRulesService {
private definition : DescriptionTemplateDefinition ;
private rulesBySources : Map < String , RuleWithTarget [ ] > ;
public isVisibleMap : { [ key : string ] : boolean } = null ;
private _isVisibleMap : { [ key : string ] : boolean } = null ;
constructor (
protected formService : FormService
@ -23,7 +24,7 @@ export class VisibilityRulesService {
this . definition = definition ;
this . form = form ;
this . rulesBySources = null ;
this . isVisibleMap = null ;
this . _ isVisibleMap = null ;
this . calculateVisibility ( ) ;
}
@ -52,12 +53,12 @@ export class VisibilityRulesService {
public reloadVisibility() {
this . rulesBySources = null ;
this . isVisibleMap = null ;
this . _ isVisibleMap = null ;
this . calculateVisibility ( ) ;
}
private calculateVisibility ( ) {
if ( this . isVisibleMap != null ) return ;
if ( this . _ isVisibleMap != null ) return ;
if ( this . definition == null || this . form == null ) return ;
this . initRules ( ) ;
@ -66,6 +67,7 @@ export class VisibilityRulesService {
this . setDefaultVisibilityForNotCaclucted ( ) ;
this . hideParentIfAllChildrenAreHidden ( ) ;
this . ensureFieldSetVisibility ( ) ;
this . isVisibleMap = this . _isVisibleMap ;
}
private initRules ( ) {
@ -176,11 +178,11 @@ export class VisibilityRulesService {
}
private buildTargetVisibility ( ) {
this . isVisibleMap = { } ;
this . _isVisibleMap = { } ;
const propertyDefinition : DescriptionPropertyDefinitionPersist = this . formService . getValue ( this . form . getRawValue ( ) ) as DescriptionPropertyDefinitionPersist ;
this . rulesBySources . forEach ( ( ruleForSource : RuleWithTarget [ ] , ruleForSourceKey : string ) = > {
for ( let i = 0 ; i < ruleForSource . length ; i ++ ) {
const rule = ruleForSource [ i ] ;
const propertyDefinition : DescriptionPropertyDefinitionPersist = this . formService . getValue ( this . form . value ) as DescriptionPropertyDefinitionPersist ;
if ( propertyDefinition . fieldSets != null ) {
new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . forEach ( ( propertyDefinitionFieldSet : DescriptionPropertyDefinitionFieldSetPersist , propertyDefinitionFieldSetKey : string ) = > {
if ( propertyDefinitionFieldSet . items != null && propertyDefinitionFieldSet . items . length > 0 ) {
@ -192,21 +194,22 @@ export class VisibilityRulesService {
if ( new Map ( Object . entries ( definitionFieldSetItem . fields ) ) . has ( rule . target ) ) { //Rule applies only for current multiple item
const fieldKey = this . buildVisibilityKey ( rule . target , definitionFieldSetItem . ordinal ) ;
const currentState = this . isVisibleMap [ fieldKey ] ? ? false ;
this . isVisibleMap [ fieldKey ] = currentState || this . ruleIsTrue ( rule , field ) ;
const currentState = this . _isVisibleMap [ fieldKey ] ? ? false ;
this . _isVisibleMap [ fieldKey ] = currentState || this . ruleIsTrue ( rule , field ) ;
//console.log(fieldKey + " " + this._isVisibleMap[fieldKey] + " " + field.textListValue);
} else if ( this . getDescriptionTemplateDefinitionFieldById ( this . definition , rule . target ) . length > 0 || this . getDescriptionTemplateDefinitionFieldSetById ( this . definition , rule . target ) . length > 0 ) { //Rule applies to different fieldset, so we apply for all multiple items
const ordinals : number [ ] = this . getKeyOrdinals ( rule . target , propertyDefinition ) ;
for ( let k = 0 ; k < ordinals . length ; k ++ ) {
const ordinal = ordinals [ j ] ;
const fieldKey = this . buildVisibilityKey ( rule . target , ordinal ) ;
const currentState = this . isVisibleMap[ fieldKey ] ? ? false ;
this . isVisibleMap[ fieldKey ] = currentState || this . ruleIsTrue ( rule , field ) ;
const currentState = this . _ isVisibleMap[ fieldKey ] ? ? false ;
this . _ isVisibleMap[ fieldKey ] = currentState || this . ruleIsTrue ( rule , field ) ;
}
} else {
const fieldKey = this . buildVisibilityKey ( rule . target , null ) ; //Ordinal is null if target not on field
const currentState = this . isVisibleMap[ fieldKey ] ? ? false ;
this . isVisibleMap[ fieldKey ] = currentState || this . ruleIsTrue ( rule , field ) ;
const currentState = this . _ isVisibleMap[ fieldKey ] ? ? false ;
this . _ isVisibleMap[ fieldKey ] = currentState || this . ruleIsTrue ( rule , field ) ;
}
}
} ) ;
@ -276,7 +279,7 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < this . definition ? . pages . length ; i ++ ) {
const pageEntity = this . definition ? . pages [ i ] ;
const fieldKey = this . buildVisibilityKey ( pageEntity . id , null ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
this . expandPageVisibility ( pageEntity , currentValue ) ;
}
}
@ -286,16 +289,16 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < pageEntity . sections . length ; i ++ ) {
const sectionEntity = pageEntity . sections [ i ] ;
const fieldKey = this . buildVisibilityKey ( sectionEntity . id , null ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue != null ) {
if ( parentVisibility != null && ! parentVisibility ) { //Parent is hidden so all childs should be hidden
this . isVisibleMap[ fieldKey ] = false ;
this . _ isVisibleMap[ fieldKey ] = false ;
this . expandSectionVisibility ( sectionEntity , currentValue ) ;
} else {
this . expandSectionVisibility ( sectionEntity , currentValue ) ;
}
} else {
if ( parentVisibility != null ) this . isVisibleMap[ fieldKey ] = parentVisibility ;
if ( parentVisibility != null ) this . _ isVisibleMap[ fieldKey ] = parentVisibility ;
this . expandSectionVisibility ( sectionEntity , parentVisibility ) ;
}
}
@ -305,41 +308,41 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < sectionEntity . sections . length ; i ++ ) {
const subSectionEntity = sectionEntity . sections [ i ] ;
const fieldKey = this . buildVisibilityKey ( subSectionEntity . id , null ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue != null ) {
if ( parentVisibility != null && ! parentVisibility ) { //Parent is hidden so all childs should be hidden
this . isVisibleMap[ fieldKey ] = false ;
this . _ isVisibleMap[ fieldKey ] = false ;
this . expandSectionVisibility ( subSectionEntity , currentValue ) ;
} else {
this . expandSectionVisibility ( subSectionEntity , currentValue ) ;
}
} else {
if ( parentVisibility != null ) this . isVisibleMap[ fieldKey ] = parentVisibility ;
if ( parentVisibility != null ) this . _ isVisibleMap[ fieldKey ] = parentVisibility ;
this . expandSectionVisibility ( subSectionEntity , parentVisibility ) ;
}
}
}
if ( sectionEntity . fieldSets != null ) {
const propertyDefinition = this . formService . getValue ( this . form . getRawValue ( ) ) as DescriptionPropertyDefinitionPersist ;
for ( let i = 0 ; i < sectionEntity . fieldSets . length ; i ++ ) {
const fieldSetEntity = sectionEntity . fieldSets [ i ] ;
const propertyDefinition = this . formService . getValue ( this . form . value ) as DescriptionPropertyDefinitionPersist ;
if ( propertyDefinition . fieldSets != null && new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . has ( fieldSetEntity . id ) ) {
const propertyDefinitionFieldSet = new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . get ( fieldSetEntity . id )
if ( propertyDefinitionFieldSet . items != null && propertyDefinitionFieldSet . items . length > 0 ) {
for ( let j = 0 ; j < propertyDefinitionFieldSet . items . length ; j ++ ) {
const definitionFieldSetItem = propertyDefinitionFieldSet . items [ j ] ;
const fieldKey = this . buildVisibilityKey ( fieldSetEntity . id , definitionFieldSetItem . ordinal ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue != null ) {
if ( parentVisibility != null && ! parentVisibility ) { //Parent is hidden so all childs should be hidden
this . isVisibleMap[ fieldKey ] = false ;
this . _ isVisibleMap[ fieldKey ] = false ;
this . expandFieldSetVisibility ( fieldSetEntity , currentValue , definitionFieldSetItem . ordinal ) ;
} else {
this . expandFieldSetVisibility ( fieldSetEntity , currentValue , definitionFieldSetItem . ordinal ) ;
}
} else {
if ( parentVisibility != null ) this . isVisibleMap[ fieldKey ] = parentVisibility ;
if ( parentVisibility != null ) this . _ isVisibleMap[ fieldKey ] = parentVisibility ;
this . expandFieldSetVisibility ( fieldSetEntity , parentVisibility , definitionFieldSetItem . ordinal ) ;
}
}
@ -354,13 +357,13 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < fieldSetEntity . fields . length ; i ++ ) {
const fieldEntity = fieldSetEntity . fields [ i ] ;
const fieldKey = this . buildVisibilityKey ( fieldEntity . id , ordinal ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue != null ) {
if ( parentVisibility != null && ! parentVisibility ) { //Parent is hidden so all childs should be hidden
this . isVisibleMap[ fieldKey ] = false ;
this . _ isVisibleMap[ fieldKey ] = false ;
}
} else if ( parentVisibility != null ) {
this . isVisibleMap[ fieldKey ] = parentVisibility ;
this . _ isVisibleMap[ fieldKey ] = parentVisibility ;
}
}
}
@ -371,8 +374,8 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < this . definition ? . pages . length ; i ++ ) {
const pageEntity = this . definition ? . pages [ i ] ;
const fieldKey = this . buildVisibilityKey ( pageEntity . id , null ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue == null ) this . isVisibleMap[ fieldKey ] = true ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue == null ) this . _ isVisibleMap[ fieldKey ] = true ;
this . setDefaultPageVisibility ( pageEntity ) ;
}
}
@ -382,9 +385,9 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < pageEntity . sections . length ; i ++ ) {
const sectionEntity = pageEntity . sections [ i ] ;
const fieldKey = this . buildVisibilityKey ( sectionEntity . id , null ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue == null ) {
this . isVisibleMap[ fieldKey ] = true ;
this . _ isVisibleMap[ fieldKey ] = true ;
this . setDefaultSectionVisibility ( sectionEntity ) ;
}
}
@ -395,27 +398,27 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < sectionEntity . sections . length ; i ++ ) {
const subSectionEntity = sectionEntity . sections [ i ] ;
const fieldKey = this . buildVisibilityKey ( subSectionEntity . id , null ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue == null ) {
this . isVisibleMap[ fieldKey ] = true ;
this . _ isVisibleMap[ fieldKey ] = true ;
this . setDefaultSectionVisibility ( subSectionEntity ) ;
}
}
}
if ( sectionEntity . fieldSets != null ) {
const propertyDefinition = this . formService . getValue ( this . form . getRawValue ( ) ) as DescriptionPropertyDefinitionPersist ;
for ( let i = 0 ; i < sectionEntity . fieldSets . length ; i ++ ) {
const fieldSetEntity = sectionEntity . fieldSets [ i ] ;
const propertyDefinition = this . formService . getValue ( this . form . value ) as DescriptionPropertyDefinitionPersist ;
if ( propertyDefinition . fieldSets != null && new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . has ( fieldSetEntity . id ) ) {
const propertyDefinitionFieldSet = new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . get ( fieldSetEntity . id )
if ( propertyDefinitionFieldSet . items != null && propertyDefinitionFieldSet . items . length > 0 ) {
for ( let j = 0 ; j < propertyDefinitionFieldSet . items . length ; j ++ ) {
const definitionFieldSetItem = propertyDefinitionFieldSet . items [ j ] ;
const fieldKey = this . buildVisibilityKey ( fieldSetEntity . id , definitionFieldSetItem . ordinal ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue == null ) {
this . isVisibleMap[ fieldKey ] = true ;
this . _ isVisibleMap[ fieldKey ] = true ;
this . setDefaultFieldSetVisibility ( fieldSetEntity , definitionFieldSetItem . ordinal ) ;
}
}
@ -430,9 +433,9 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < fieldSetEntity . fields . length ; i ++ ) {
const fieldEntity = fieldSetEntity . fields [ i ] ;
const fieldKey = this . buildVisibilityKey ( fieldEntity . id , ordinal ) ;
const currentValue : boolean | null = this . isVisibleMap[ fieldKey ] ? ? null ;
const currentValue : boolean | null = this . _ isVisibleMap[ fieldKey ] ? ? null ;
if ( currentValue == null ) {
this . isVisibleMap[ fieldKey ] = true ;
this . _ isVisibleMap[ fieldKey ] = true ;
}
}
}
@ -445,8 +448,8 @@ export class VisibilityRulesService {
const fieldKey = this . buildVisibilityKey ( pageEntity . id , null ) ;
const isCurrentHidden = this . isHiddenPageVisibilityIfAllChildrenIsHidden ( pageEntity ) ;
if ( isCurrentHidden && ( this . isVisibleMap[ fieldKey ] ? ? true ) ) {
this . isVisibleMap[ fieldKey ] = false ;
if ( isCurrentHidden && ( this . _ isVisibleMap[ fieldKey ] ? ? true ) ) {
this . _ isVisibleMap[ fieldKey ] = false ;
}
}
}
@ -458,8 +461,8 @@ export class VisibilityRulesService {
const sectionEntity = pageEntity . sections [ i ] ;
const fieldKey = this . buildVisibilityKey ( sectionEntity . id , null ) ;
const isCurrentHidden = this . isHiddenSectionIfAllChildrenIsHidden ( sectionEntity ) ;
if ( isCurrentHidden && ( this . isVisibleMap[ fieldKey ] ? ? true ) ) {
this . isVisibleMap[ fieldKey ] = false ;
if ( isCurrentHidden && ( this . _ isVisibleMap[ fieldKey ] ? ? true ) ) {
this . _ isVisibleMap[ fieldKey ] = false ;
}
isHidden = isHidden && isCurrentHidden ;
}
@ -473,16 +476,16 @@ export class VisibilityRulesService {
const subSectionEntity = sectionEntity . sections [ i ] ;
const fieldKey = this . buildVisibilityKey ( subSectionEntity . id , null ) ;
const isCurrentHidden = this . isHiddenSectionIfAllChildrenIsHidden ( subSectionEntity ) ;
if ( isCurrentHidden && ( this . isVisibleMap[ fieldKey ] ? ? true ) ) {
this . isVisibleMap[ fieldKey ] = false ;
if ( isCurrentHidden && ( this . _ isVisibleMap[ fieldKey ] ? ? true ) ) {
this . _ isVisibleMap[ fieldKey ] = false ;
}
isHidden = isHidden && isCurrentHidden ;
}
}
if ( sectionEntity . fieldSets != null ) {
const propertyDefinition = this . formService . getValue ( this . form . getRawValue ( ) ) as DescriptionPropertyDefinitionPersist ;
for ( let i = 0 ; i < sectionEntity . fieldSets . length ; i ++ ) {
const fieldSetEntity = sectionEntity . fieldSets [ i ] ;
const propertyDefinition = this . formService . getValue ( this . form . value ) as DescriptionPropertyDefinitionPersist ;
if ( propertyDefinition . fieldSets != null && new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . has ( fieldSetEntity . id ) ) {
const propertyDefinitionFieldSet = new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . get ( fieldSetEntity . id )
if ( propertyDefinitionFieldSet . items != null && propertyDefinitionFieldSet . items . length > 0 ) {
@ -490,8 +493,8 @@ export class VisibilityRulesService {
const definitionFieldSetItem = propertyDefinitionFieldSet . items [ j ] ;
const fieldKey = this . buildVisibilityKey ( fieldSetEntity . id , definitionFieldSetItem . ordinal ) ;
const isCurrentHidden = this . isHiddenFieldSetIfAllChildrenIsHidden ( fieldSetEntity , definitionFieldSetItem . ordinal ) ;
if ( isCurrentHidden && ( this . isVisibleMap[ fieldKey ] ? ? true ) ) {
this . isVisibleMap[ fieldKey ] = false ;
if ( isCurrentHidden && ( this . _ isVisibleMap[ fieldKey ] ? ? true ) ) {
this . _ isVisibleMap[ fieldKey ] = false ;
}
isHidden = isHidden && isCurrentHidden ;
}
@ -508,7 +511,7 @@ export class VisibilityRulesService {
for ( let i = 0 ; i < fieldSetEntity . fields . length ; i ++ ) {
const fieldEntity = fieldSetEntity . fields [ i ] ;
const fieldKey = this . buildVisibilityKey ( fieldEntity . id , ordinal ) ;
const currentValue : boolean | null = ( this . isVisibleMap[ fieldKey ] ? ? true ) ;
const currentValue : boolean | null = ( this . _ isVisibleMap[ fieldKey ] ? ? true ) ;
isHidden = isHidden && ! currentValue ;
}
return isHidden ;
@ -540,23 +543,23 @@ export class VisibilityRulesService {
}
}
if ( sectionEntity . fieldSets != null ) {
const propertyDefinition = this . formService . getValue ( this . form . getRawValue ( ) ) as DescriptionPropertyDefinitionPersist ;
for ( let i = 0 ; i < sectionEntity . fieldSets . length ; i ++ ) {
const fieldSetEntity = sectionEntity . fieldSets [ i ] ;
let isHidden = true ;
const propertyDefinition = this . formService . getValue ( this . form . value ) as DescriptionPropertyDefinitionPersist ;
if ( propertyDefinition . fieldSets != null && new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . has ( fieldSetEntity . id ) ) {
const propertyDefinitionFieldSet = new Map ( Object . entries ( propertyDefinition . fieldSets ) ) . get ( fieldSetEntity . id )
if ( propertyDefinitionFieldSet . items != null && propertyDefinitionFieldSet . items . length > 0 ) {
for ( let j = 0 ; j < propertyDefinitionFieldSet . items . length ; j ++ ) {
const definitionFieldSetItem = propertyDefinitionFieldSet . items [ j ] ;
const fieldKey = this . buildVisibilityKey ( fieldSetEntity . id , definitionFieldSetItem . ordinal ) ;
const isCurrentHidden = ! this . isVisibleMap[ fieldKey ] ? ? false ;
const isCurrentHidden = ! this . _ isVisibleMap[ fieldKey ] ? ? false ;
isHidden = isHidden && isCurrentHidden ;
}
}
}
const globalFieldSetKey = this . buildVisibilityKey ( fieldSetEntity . id , null ) ;
this . isVisibleMap[ globalFieldSetKey ] = ! isHidden ;
this . _ isVisibleMap[ globalFieldSetKey ] = ! isHidden ;
}
}
}