Skip to content

Commit 59cdbfa

Browse files
committed
add MatchPropertySearch+resetConfigurationProperty+demos
1 parent 411dd88 commit 59cdbfa

5 files changed

Lines changed: 300 additions & 77 deletions

File tree

README.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For example, connected to a dialog box of criteria managed with checkboxes, JamR
1919

2020
As an object filter library, Jamrules is your best friend! Ideal for product configurators, objects selection on criteria, ...
2121

22-
[See JamRules in action](https://demo.intersel.fr/jamrules/tests/filterDocs.html) (source code in test/filterDocs.html)
22+
[See JamRules in action](https://demo.intersel.fr/jamrules/tests/filterDocsExclusive.html) (source code in test/filterDocsExclusive.html)
2323

2424
# How it works...
2525
To run jamrules, you will have to:
@@ -140,9 +140,11 @@ Any object that matches the rules will have their "Matched" function called. Any
140140

141141
//initialisation of jamrules and its configurator
142142
var rulesEngine = jamrules.build({
143-
"debug": "<boolean>",
144-
"matched": "<a function to call when the rule find a match>",
145-
"notmatched": "<a function to call when the rule did not find a match>"
143+
"debug": "<boolean>", //default: false
144+
"matched": "<a function to call when the rule find a match>", // default: null
145+
"notmatched": "<a function to call when the rule did not find a match>",// default: null
146+
"matchedFunctionName": "<property name for the 'matched' function in objects>",// default: matched
147+
"matchedFunctionName": "<property name for the 'notmatched' function in objects>"// default: notmatched
146148
});
147149
```
148150

@@ -151,7 +153,7 @@ var rulesEngine = jamrules.build({
151153
if true, the rule engine will send debug message on the console
152154

153155

154-
### the Matched and NotMatched functions
156+
### the "Matched" and "NotMatched" functions
155157

156158
The "matched" and "notmatched" functions are called whenever the rule engine matches an object profile.
157159

@@ -160,6 +162,12 @@ Functions have the following parameters:
160162

161163
**Remarks**: These functions are not to be confused with the ones defined on the object level...
162164

165+
### "matchedFunctionName" and "notmatchedFunctionName" options
166+
167+
These options allows to change the default property names of the object that define the 'matched' and 'notmatched' functions of it.
168+
May be used if by any chance, these property names are used for other things...
169+
170+
163171
# The JamRules Objects
164172
In order to test objects with jamrules, you have to give it objects to test against the rules defined in the rule engine.
165173

@@ -253,6 +261,7 @@ There are several filtering functions that may help to test a configuration in t
253261
* MatchProperties
254262
* MatchPropertiesSameValue
255263
* MatchPropertiesSameValues
264+
* MatchObjectSearch
256265
* ConfigurationPropertySet
257266
* ConfigurationPropertiesSameValue
258267
* ConfigurationPropertiesSameValues
@@ -266,8 +275,8 @@ rulesEngine.createRulesSet("SameTrousers");
266275
rulesEngine.addRule("SameTrousers","O1Trouser",'ObjectPropertySet("object1","trouser")');
267276
rulesEngine.addRule("SameTrousers","O2Trouser",'ObjectPropertiesSameValue("object1","object2")');
268277
rulesEngine.createRulesSet("SameShirts",["object1","object2"]);
269-
rulesEngine.addRule("SameColorTrousersPack","O1Shirt",'ObjectPropertySet("object1","shirt")');
270-
rulesEngine.addRule("SameColorTrousersPack","O2Shirt",'ObjectPropertiesSameValue("object1","object2")');
278+
rulesEngine.addRule("SameShirts","O1Shirt",'ObjectPropertySet("object1","shirt")');
279+
rulesEngine.addRule("SameShirts","O2Shirt",'ObjectPropertiesSameValue("object1","object2")');
271280
```
272281

273282
# Adding Objects to test by JamRules
@@ -422,7 +431,9 @@ Set a property/property value status in the filtering configurator
422431
* **doTest**: <boolean> <default:true> (option) if false, configure the configurator but does not run the rules engine test
423432

424433
### Remarks
425-
If "doTest" is set, the rules engine will **run** and process -only- the rules sets that have configured the "aPropertyName" in the "ruleEvents" parameter of createRulesSet function.
434+
If "doTest" is set, the rules engine will **run** and process -only- the rules sets that have configured the "aPropertyName" in the "ruleEvents" parameter in createRulesSet function.
435+
436+
aPropertyValue may be set to "*" to match any value of aPropertyName.
426437

427438
### Example
428439
```javascript
@@ -524,7 +535,7 @@ Returns true if all properties values of aConfigurationPropertyName and of anObj
524535
* configuration.activity.priority1=1
525536
* configuration.strawberry.priority2=1
526537
* MatchPropertiesSameValues('activity','priority') -> match
527-
* MatchPropertiesSameValues('strawberry','priority','priority1') -> no match
538+
* MatchPropertiesSameValues('strawberry','priority') -> no match
528539

529540
## MatchProperties(aConfigurationPropertyName,anObjectPropertyName)
530541
Tests if at least a property value exists and is set between the configurator property and the object property
@@ -544,6 +555,28 @@ returns true if it exists a value of aConfigurationPropertyName that is the same
544555
* MatchProperties('activity','priority') -> match
545556
* MatchProperties('strawberry','priority') -> no match
546557

558+
## MatchObjectSearch(aConfigurationPropertyName,anObjectPropertyName)
559+
Tests if the value of a configuration property string is found in the values of object's properties
560+
561+
### parameters
562+
* aPropertyValueWithWildcard: a string to search in the property values of objects.
563+
wildcards are possible: '*' (0 or more char), '?' (0 or 1 char)
564+
eg: 'my*propert?' will match 'myproperty','mygivenpropert','myREDproperts'
565+
won't match 'property', 'myREDproperties'
566+
567+
### returns
568+
returns true if aPropertyValueWithWildcard is found as a property value of the object
569+
570+
### Example
571+
* object.priority.priority1=1
572+
* object.technician.technician1=1
573+
* configuration.technician.technician2=1
574+
* MatchObjectSearch('priority1') -> match
575+
* MatchObjectSearch('prior*') -> match
576+
* MatchObjectSearch('tec?ician') -> no match
577+
* MatchObjectSearch('tec*ician2') -> no match
578+
579+
547580
## ObjectPropertySet(aPropertyName,aPropertyValue,valueSet)
548581
tests if the property in theObjectPropertySett has its value set
549582

0 commit comments

Comments
 (0)