Skip to content

Commit 09cde35

Browse files
author
Emmanuel
committed
add startProcessing and stopProcessing
1 parent 3b5a5e2 commit 09cde35

7 files changed

Lines changed: 79 additions & 47 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ var rulesEngine = jamrules.build({
145145
"notmatched": "<a function to call when the rule did not find a match>",// default: null
146146
"matchedFunctionName": "<property name for the 'matched' function in objects>",// default: matched
147147
"matchedFunctionName": "<property name for the 'notmatched' function in objects>"// default: notmatched
148+
"startProcessing": "<a function to call when rule engine starts to process rules>"// default: null
149+
"stopProcessing": "<a function to call when rule engine finished to process rules>"// default: null
148150
});
149151
```
150152

@@ -564,7 +566,7 @@ Generally used for a text input in the configuration, as search input...
564566
wildcards are possible: '*' (0 or more char), '?' (0 or 1 char)
565567
eg: 'my*propert?' will match 'myproperty','mygivenpropert','myREDproperts'
566568
won't match 'property', 'myREDproperties'
567-
* searchMode:
569+
* searchMode:
568570
- or (default): blank are considered as 'or' operator between keywords to find
569571
- and: blank are considered as 'and' operator with all keywords to be found in any property values
570572

jamrules.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* -----------------------------------------------------------------------------------------
1010
* Modifications :
11+
* - 20210508 - E.Podvin - V2.5.0 - add startProcessing and stopProcessing
1112
* - 20210507 - E.Podvin - V2.4.0
1213
* - !!selectConfigurationPropertyValue is renamed checkConfigurationPropertyValue !!
1314
* - selectConfigurationPropertyValue: select a value as a radio would do (unselecting other values)
@@ -636,7 +637,11 @@ var jamrules = (function() {
636637
this.opts.ObjectProfiles = this.opts.jamrules.getAllObjectProfiles();
637638
this.opts.maxObjectProfiles = Object.keys(this.opts.ObjectProfiles).length;
638639
// start processing rules on the element profiles list
639-
if (this.opts.maxObjectProfiles > 0) this.trigger(this.opts.aPropertyConfiguration.propertyName);
640+
if (this.opts.maxObjectProfiles > 0)
641+
{
642+
this.trigger('startProcessing');
643+
this.trigger(this.opts.aPropertyConfiguration.propertyName);
644+
}
640645
},
641646
},
642647
/*
@@ -653,9 +658,25 @@ var jamrules = (function() {
653658
this.opts.ObjectProfiles = this.opts.jamrules.getAllObjectProfiles();
654659
this.opts.maxObjectProfiles = Object.keys(this.opts.ObjectProfiles).length;
655660
// start processing rules on the element profiles list
656-
if (this.opts.maxObjectProfiles > 0) this.trigger('testRules');
661+
if (this.opts.maxObjectProfiles > 0)
662+
{
663+
this.trigger('startProcessing');
664+
this.trigger('testRules');
665+
}
657666
},
658667
},
668+
startProcessing: {
669+
init_function: function() {
670+
if (this.opts.jamrules.options.startProcessing)
671+
this.opts.jamrules.options.startProcessing(this.jamrules);
672+
}
673+
},
674+
stopProcessing: {
675+
init_function: function() {
676+
if (this.opts.jamrules.options.stopProcessing)
677+
this.opts.jamrules.options.stopProcessing(this.jamrules);
678+
}
679+
},
659680
/*
660681
* internal event - starts the process to test the rules against the current configuration and the different element profiles
661682
* event should send a 'aPropertyConfiguration' data object as:
@@ -675,6 +696,9 @@ var jamrules = (function() {
675696
this.opts.objectProfile = this.opts.ObjectProfiles[Object.keys(this.opts.ObjectProfiles)[this.opts.objectProfileId]];
676697
this.trigger(this.opts.aPropertyConfiguration.propertyName);
677698
}
699+
else{
700+
this.trigger('stopProcessing');
701+
}
678702
},
679703

680704
},

tests/JamRulesExample1.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,16 @@ <h1>Result Matching</h1>
141141
$("#filterbox section").each(function(){
142142
var propertyName = this.id;
143143
$(this).find("input.checkbox").each(function(){
144-
rulesForPriorityLayer.selectConfigurationPropertyValue(propertyName,$(this).val(),$(this).prop('checked'));
144+
rulesForPriorityLayer.checkConfigurationPropertyValue(propertyName,$(this).val(),$(this).prop('checked'));
145145
});
146146
});
147147

148148

149149
// test if object is technician tech1
150150
// test if object is compliant with tech1
151-
/* rulesForPriorityLayer.selectConfigurationPropertyValue("priority","priority1",1);
152-
rulesForPriorityLayer.selectConfigurationPropertyValue("activities","compliant",1);
153-
rulesForPriorityLayer.selectConfigurationPropertyValue("priority","priority1",0);
151+
/* rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",1);
152+
rulesForPriorityLayer.checkConfigurationPropertyValue("activities","compliant",1);
153+
rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",0);
154154
*/
155155
// ---------------------------------
156156
// Test input FSM
@@ -181,7 +181,7 @@ <h1>Result Matching</h1>
181181
{
182182
init_function: function(data,aEvent,dataFromCheckbox){
183183
$("#debug").html("who:"+dataFromCheckbox.who.attr('id')+"<br>propertyName:"+dataFromCheckbox.propertyName+"<br>propertyValue:"+dataFromCheckbox.propertyValue+"<br>status:"+dataFromCheckbox.status);
184-
dataFromCheckbox.ruleEngine.selectConfigurationPropertyValue(dataFromCheckbox.propertyName,dataFromCheckbox.propertyValue,dataFromCheckbox.status);
184+
dataFromCheckbox.ruleEngine.checkConfigurationPropertyValue(dataFromCheckbox.propertyName,dataFromCheckbox.propertyValue,dataFromCheckbox.status);
185185
}
186186
}
187187
}

tests/exampleReadMe.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ <h1>Filter box</h1>
1919
<p>Select some filters to see the selection of some animals</p>
2020
<section id='type' onclick="
2121
let radioVal = $('input[name=type]:checked').val();
22-
rulesEngine.selectConfigurationPropertyValue('type', 'mammal', radioVal=='mammal'?'1':'0');
23-
rulesEngine.selectConfigurationPropertyValue('type', 'other' , radioVal=='other' ?'1':'0');
22+
rulesEngine.checkConfigurationPropertyValue('type', 'mammal', radioVal=='mammal'?'1':'0');
23+
rulesEngine.checkConfigurationPropertyValue('type', 'other' , radioVal=='other' ?'1':'0');
2424
">
2525
<h3>Type</h3>
2626
<label>
@@ -35,26 +35,26 @@ <h3>Type</h3>
3535
</section>
3636
<section id='name'>
3737
<label>
38-
<input id="nameCat" type="checkbox" onclick="rulesEngine.selectConfigurationPropertyValue('name', 'cat' , $(this).is(':checked') ? '1' : '0');">
38+
<input id="nameCat" type="checkbox" onclick="rulesEngine.checkConfigurationPropertyValue('name', 'cat' , $(this).is(':checked') ? '1' : '0');">
3939
Cat
4040
</label>
4141
<label>
42-
<input id="nameDog" type="checkbox" onclick="rulesEngine.selectConfigurationPropertyValue('name', 'dog' , $(this).is(':checked') ? '1' : '0');">
42+
<input id="nameDog" type="checkbox" onclick="rulesEngine.checkConfigurationPropertyValue('name', 'dog' , $(this).is(':checked') ? '1' : '0');">
4343
Dog
4444
</label>
4545

4646
</section>
4747
<section id='color'>
4848
<label>
49-
<input class="checkbox" id="colorBlack" type="checkbox" onclick="rulesEngine.selectConfigurationPropertyValue('color', 'black' , $(this).is(':checked') ? '1' : '0');">
49+
<input class="checkbox" id="colorBlack" type="checkbox" onclick="rulesEngine.checkConfigurationPropertyValue('color', 'black' , $(this).is(':checked') ? '1' : '0');">
5050
Black
5151
</label>
5252
<label>
53-
<input class="checkbox" id="colorWhite" type="checkbox" onclick="rulesEngine.selectConfigurationPropertyValue('color', 'white' , $(this).is(':checked') ? '1' : '0');">
53+
<input class="checkbox" id="colorWhite" type="checkbox" onclick="rulesEngine.checkConfigurationPropertyValue('color', 'white' , $(this).is(':checked') ? '1' : '0');">
5454
White
5555
</label>
5656
<label>
57-
<input class="checkbox" id="colorGrey" type="checkbox" onclick="rulesEngine.selectConfigurationPropertyValue('color', 'grey' , $(this).is(':checked') ? '1' : '0');">
57+
<input class="checkbox" id="colorGrey" type="checkbox" onclick="rulesEngine.checkConfigurationPropertyValue('color', 'grey' , $(this).is(':checked') ? '1' : '0');">
5858
Grey
5959
</label>
6060
</section>

tests/filterDocsExclusive.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
<script>
1818

1919
//create a rule engine
20-
var rulesEngine = jamrules.build({'debug':true,'notmatchedFunctionName':'notselected','matchedFunctionName':'selected'});
20+
var rulesEngine = jamrules.build({
21+
'debug':true,
22+
'notmatchedFunctionName':'notselected',
23+
'matchedFunctionName':'selected',
24+
'startProcessing':function() {console.log('on Commence!');},
25+
'stopProcessing':function() {console.log('on a fini!');}
26+
});
2127

2228
</script>
2329
</head>

tests/mastermind.html

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -237,35 +237,35 @@ <h1>Raw test of jamrules</h1>
237237

238238
//
239239
$("#msg").append("<h2>prepare configuration of Mastermind </h2>");
240-
rulesEngineBlack1.selectConfigurationPropertyValue("dotColor1", "red", 1);
241-
rulesEngineBlack2.selectConfigurationPropertyValue("dotColor2", "blue", 1);
242-
rulesEngineBlack3.selectConfigurationPropertyValue("dotColor3", "red", 1);
243-
rulesEngineBlack4.selectConfigurationPropertyValue("dotColor4", "yellow", 1);
240+
rulesEngineBlack1.checkConfigurationPropertyValue("dotColor1", "red", 1);
241+
rulesEngineBlack2.checkConfigurationPropertyValue("dotColor2", "blue", 1);
242+
rulesEngineBlack3.checkConfigurationPropertyValue("dotColor3", "red", 1);
243+
rulesEngineBlack4.checkConfigurationPropertyValue("dotColor4", "yellow", 1);
244244

245-
rulesEngineWhite1.selectConfigurationPropertyValue("dotColor1", "red", 1, false);
246-
rulesEngineWhite1.selectConfigurationPropertyValue("dotColor2", "blue", 1, false);
247-
rulesEngineWhite1.selectConfigurationPropertyValue("dotColor3", "red", 1, false);
248-
rulesEngineWhite1.selectConfigurationPropertyValue("dotColor4", "yellow", 1);
245+
rulesEngineWhite1.checkConfigurationPropertyValue("dotColor1", "red", 1, false);
246+
rulesEngineWhite1.checkConfigurationPropertyValue("dotColor2", "blue", 1, false);
247+
rulesEngineWhite1.checkConfigurationPropertyValue("dotColor3", "red", 1, false);
248+
rulesEngineWhite1.checkConfigurationPropertyValue("dotColor4", "yellow", 1);
249249

250-
rulesEngineWhite2.selectConfigurationPropertyValue("dotColor1", "red", 1, false);
251-
rulesEngineWhite2.selectConfigurationPropertyValue("dotColor2", "blue", 1, false);
252-
rulesEngineWhite2.selectConfigurationPropertyValue("dotColor3", "red", 1, false);
253-
rulesEngineWhite2.selectConfigurationPropertyValue("dotColor4", "yellow", 1);
250+
rulesEngineWhite2.checkConfigurationPropertyValue("dotColor1", "red", 1, false);
251+
rulesEngineWhite2.checkConfigurationPropertyValue("dotColor2", "blue", 1, false);
252+
rulesEngineWhite2.checkConfigurationPropertyValue("dotColor3", "red", 1, false);
253+
rulesEngineWhite2.checkConfigurationPropertyValue("dotColor4", "yellow", 1);
254254

255-
rulesEngineWhite3.selectConfigurationPropertyValue("dotColor1", "red", 1, false);
256-
rulesEngineWhite3.selectConfigurationPropertyValue("dotColor2", "blue", 1, false);
257-
rulesEngineWhite3.selectConfigurationPropertyValue("dotColor3", "red", 1, false);
258-
rulesEngineWhite3.selectConfigurationPropertyValue("dotColor4", "yellow", 1);
255+
rulesEngineWhite3.checkConfigurationPropertyValue("dotColor1", "red", 1, false);
256+
rulesEngineWhite3.checkConfigurationPropertyValue("dotColor2", "blue", 1, false);
257+
rulesEngineWhite3.checkConfigurationPropertyValue("dotColor3", "red", 1, false);
258+
rulesEngineWhite3.checkConfigurationPropertyValue("dotColor4", "yellow", 1);
259259

260-
rulesEngineWhite4.selectConfigurationPropertyValue("dotColor1", "red", 1, false);
261-
rulesEngineWhite4.selectConfigurationPropertyValue("dotColor2", "blue", 1, false);
262-
rulesEngineWhite4.selectConfigurationPropertyValue("dotColor3", "red", 1, false);
263-
rulesEngineWhite4.selectConfigurationPropertyValue("dotColor4", "yellow", 1);
260+
rulesEngineWhite4.checkConfigurationPropertyValue("dotColor1", "red", 1, false);
261+
rulesEngineWhite4.checkConfigurationPropertyValue("dotColor2", "blue", 1, false);
262+
rulesEngineWhite4.checkConfigurationPropertyValue("dotColor3", "red", 1, false);
263+
rulesEngineWhite4.checkConfigurationPropertyValue("dotColor4", "yellow", 1);
264264

265-
rulesEngineWin.selectConfigurationPropertyValue("dotColor1", "red", 1, false);
266-
rulesEngineWin.selectConfigurationPropertyValue("dotColor2", "blue", 1, false);
267-
rulesEngineWin.selectConfigurationPropertyValue("dotColor3", "red", 1, false);
268-
rulesEngineWin.selectConfigurationPropertyValue("dotColor4", "yellow", 1);
265+
rulesEngineWin.checkConfigurationPropertyValue("dotColor1", "red", 1, false);
266+
rulesEngineWin.checkConfigurationPropertyValue("dotColor2", "blue", 1, false);
267+
rulesEngineWin.checkConfigurationPropertyValue("dotColor3", "red", 1, false);
268+
rulesEngineWin.checkConfigurationPropertyValue("dotColor4", "yellow", 1);
269269

270270
$("#msg").append("<h3>configuration of the configurator:</h3><pre>" + JSON.stringify(rulesEngineWin.propertiesConfiguration) + "</pre>");
271271
</script>

tests/testJamRules.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h1>Raw test of jamrules</h1>
2222
//initialisation of jamrules and its configurator
2323
var rulesForPriorityLayer = jamrules.build({debug:true});
2424
/* initialisation of the configurator if needed*/
25-
rulesForPriorityLayer.selectConfigurationPropertyValue("priority","priority1",1,false);
25+
rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",1,false);
2626

2727
// rules setting
2828
rulesForPriorityLayer.createRulesSet("PriorityMatch1",["activities","priority"]);
@@ -56,27 +56,27 @@ <h1>Raw test of jamrules</h1>
5656

5757
//activate activities to display all in the configurator
5858
var msg = "set activities->all->on"
59-
rulesForPriorityLayer.selectConfigurationPropertyValue("activities","all",1);
59+
rulesForPriorityLayer.checkConfigurationPropertyValue("activities","all",1);
6060
//-> match
6161
// activate priority / priority1
6262
msg = "set priority->priority1->on"
63-
rulesForPriorityLayer.selectConfigurationPropertyValue("priority","priority1",1);
63+
rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",1);
6464
//-> match
6565
// activate technician / technician1
6666
msg = "set technician->technician1->on"
67-
rulesForPriorityLayer.selectConfigurationPropertyValue("technician","technician1",1);
67+
rulesForPriorityLayer.checkConfigurationPropertyValue("technician","technician1",1);
6868
//-> match
6969
// activate display activities compliant
7070
msg = "set activities->compliant->on"
71-
rulesForPriorityLayer.selectConfigurationPropertyValue("activities","compliant",1);
71+
rulesForPriorityLayer.checkConfigurationPropertyValue("activities","compliant",1);
7272
//-> match
7373
//deactivate priority/priority1
7474
msg = "set priority->priority1->off"
75-
rulesForPriorityLayer.selectConfigurationPropertyValue("priority","priority1",0);
75+
rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",0);
7676
//-> not match
7777
// deactivate display activities compliant
7878
msg = "set activities->compliant->off"
79-
rulesForPriorityLayer.selectConfigurationPropertyValue("activities","compliant",0);
79+
rulesForPriorityLayer.checkConfigurationPropertyValue("activities","compliant",0);
8080
//-> match
8181

8282
</script>

0 commit comments

Comments
 (0)