88 *
99 * -----------------------------------------------------------------------------------------
1010 * Modifications :
11+ * - 20210418 - E.Podvin - V2.2.0 - add addPropertyObjects
1112 * - 20170402 - E.Podvin - V2.1.0 - adding new objects simplified + possibility to call matching rule functions
1213 * - 20170331 - E.Podvin - V2.0.0 - Refactoring
1314 * - 20170227 - E.Podvin - V1.0.0 - Creation
@@ -36,6 +37,7 @@ var jamrules = (function() {
3637 * @param ObjectProfiles
3738 * @access private
3839 * @abstract list of possible profiles available to all rules
40+ * used as optimization to process filtering on object profiles rather than on each objects...
3941 * a profile is defined by a list of entries [objectKey]:{propertiesSet:<apropertiesSet>,objectsList:[]}
4042 * {
4143 * <objectKey1>:{
@@ -790,8 +792,8 @@ var jamrules = (function() {
790792 for ( aPropertyValue in propertiesObjectProfile [ aPropertyName ] ) {
791793 if (
792794 ( propertiesConfiguration [ aPropertyName ] [ aPropertyValue ] ) &&
793- ( propertiesObjectProfile [ aPropertyName ] [ aPropertyValue ] )
794- // && (propertiesObjectProfile[aPropertyName][aPropertyValue] == propertiesConfiguration[aPropertyName][aPropertyValue])
795+ ( propertiesObjectProfile [ aPropertyName ] [ aPropertyValue ] ) &&
796+ ( propertiesObjectProfile [ aPropertyName ] [ aPropertyValue ] == propertiesConfiguration [ aPropertyName ] [ aPropertyValue ] )
795797 )
796798 return true ;
797799 }
@@ -818,9 +820,11 @@ var jamrules = (function() {
818820 var MatchPropertyValue = function ( aPropertyName , aPropertyValue ) {
819821 var propertiesObjectProfile = this . myRulesEngine . opts . objectProfile . propertiesSet ;
820822 if (
821- ( propertiesConfiguration [ aPropertyName ] && propertiesObjectProfile [ aPropertyName ] ) &&
822- ( propertiesConfiguration [ aPropertyName ] [ aPropertyValue ] && propertiesObjectProfile [ aPropertyName ] [ aPropertyValue ] )
823- // && (propertiesConfiguration[aPropertyName][aPropertyValue] == propertiesObjectProfile[aPropertyName][aPropertyValue])
823+ ( propertiesConfiguration [ aPropertyName ]
824+ && propertiesObjectProfile [ aPropertyName ] )
825+ && ( propertiesConfiguration [ aPropertyName ] [ aPropertyValue ]
826+ && propertiesObjectProfile [ aPropertyName ] [ aPropertyValue ] )
827+ && ( propertiesConfiguration [ aPropertyName ] [ aPropertyValue ] == propertiesObjectProfile [ aPropertyName ] [ aPropertyValue ] )
824828 )
825829 return true ;
826830 else return false ;
@@ -988,7 +992,7 @@ var jamrules = (function() {
988992 /**
989993 * @function ObjectPropertySet
990994 * @access public
991- * @abstract matching rule function, tests if the property in theObjectPropertySett has its value set
995+ * @abstract matching rule function, tests if the property in theObjectPropertySet has its value set
992996 * @param aPropertyName: an element property name
993997 * @param aPropertyValue: a value of aPropertyName
994998 * @param valueSet: [0|1(default)]
@@ -1021,7 +1025,7 @@ var jamrules = (function() {
10211025 var ObjectPropertiesSameValue = function ( aPropertyName1 , aPropertyName2 , aPropertyValue ) {
10221026 propertiesObjectProfile = this . myRulesEngine . opts . objectProfile . propertiesSet ;
10231027
1024- //if undefined, means that we want that one value of the property 1 and property 2 of object are set
1028+ //if undefined, means that we want that one value of the property 1 and property 2 of object are set
10251029 if ( aPropertyValue == undefined ) {
10261030 if ( propertiesObjectProfile [ aPropertyName1 ] !== undefined )
10271031 for ( aPropertyValue in propertiesObjectProfile [ aPropertyName1 ] ) {
@@ -1308,7 +1312,7 @@ var jamrules = (function() {
13081312 * @example
13091313 */
13101314 var addPropertyObject = function ( anObject , aMatchingFunction , aNotMatchingFunction ) {
1311- this . log ( "addObject " ) ;
1315+ this . log ( "addPropertyObject " ) ;
13121316 if ( ! aMatchingFunction && anObject . matched )
13131317 aMatchingFunction = anObject . matched ;
13141318
@@ -1321,6 +1325,35 @@ var jamrules = (function() {
13211325 notmatched : aNotMatchingFunction
13221326 } , this . getObjectProfiles ( ) ) ;
13231327 } ;
1328+ /**
1329+ * @function public addPropertyObjects
1330+ * @abstract add objects to the list of objects to test against rules
1331+ * @param objects: array of property objects. Each object may have these properties set:
1332+ * matched (otion):<function name to call when a rule will match for the object>
1333+ * notmatched (option):<function name to call when there is a change but object does not match any rules>
1334+ * @param aMatchingFunction (option): the matching function, same as to define the "matched" property in the object
1335+ * @param aNotMatchingFunction (option): the matching function, same as to define the "notmatched" property in the object
1336+ * @example
1337+ */
1338+ var addPropertyObjects = function ( objects , aMatchingFunction , aNotMatchingFunction ) {
1339+ this . log ( "addPropertyObjects" ) ;
1340+ let that = this ;
1341+ objects . forEach ( function ( anObject ) {
1342+ if ( ! aMatchingFunction && anObject . matched )
1343+ aMatchingFunction = anObject . matched ;
1344+
1345+ if ( ! aNotMatchingFunction && anObject . notmatched )
1346+ aNotMatchingFunction = anObject . notmatched ;
1347+
1348+ let theObject = anObject ;
1349+ _addObject ( {
1350+ propertiesSet : jamrules . _translateToJamrulesProperties ( anObject ) ,
1351+ matched : aMatchingFunction ,
1352+ notmatched : aNotMatchingFunction ,
1353+ object :theObject
1354+ } , that . getObjectProfiles ( ) ) ;
1355+ } ) ;
1356+ } ;
13241357 /**
13251358 * @access public
13261359 * @abstract log a message on the console for debug
@@ -1342,6 +1375,7 @@ var jamrules = (function() {
13421375 compileRules : compileRules ,
13431376 addObject : addObject ,
13441377 addPropertyObject : addPropertyObject ,
1378+ addPropertyObjects : addPropertyObjects ,
13451379 log : log
13461380 /** Public variables **/
13471381 ,
0 commit comments