Skip to content

Commit d48e727

Browse files
author
Emmanuel
committed
add checkConfigurationPropertyValue/resetConfigurationPropertyValues
1 parent 5752129 commit d48e727

3 files changed

Lines changed: 89 additions & 34 deletions

File tree

jamrules.js

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
*
99
* -----------------------------------------------------------------------------------------
1010
* Modifications :
11+
* - 20210507 - E.Podvin - V2.4.0
12+
* - !!selectConfigurationPropertyValue is renamed checkConfigurationPropertyValue !!
13+
* - selectConfigurationPropertyValue: select a value as a radio would do (unselecting other values)
14+
* - checkConfigurationPropertyValue: set a value as a checkbox would do
15+
* - resetConfigurationPropertyValues: reset all values of a property
1116
* - 20210504 - E.Podvin - V2.3.0 -
1217
* - add MatchPropertySearch test with wildcard
1318
* - add resetConfigurationProperty
@@ -1371,17 +1376,18 @@ var jamrules = (function() {
13711376
}
13721377

13731378
/**
1374-
* @function selectConfigurationPropertyValue
1379+
* @function checkConfigurationPropertyValue
13751380
* @access public
13761381
* @abstract set a property/property value status in the rules configurator
1382+
* designed for checkboxes/multiple select
13771383
* @param aPropertyName: name of the property that has changed
13781384
* @param aProperyValue: value of the property
13791385
* @param aStatus: [boolean] status of the property for this property value set or not
13801386
* @param doTest: [boolean] [default:true] if false, configure the configurator but does not run the rules engine test
13811387
* @return void
13821388
*/
1383-
var selectConfigurationPropertyValue = function(aPropertyName, aPropertyValue, aStatus, doTest) {
1384-
this.log("selectConfigurationPropertyValue(aPropertyName,aPropertyValue,aStatus):" + aPropertyName + ',' + aPropertyValue + ',' + aStatus);
1389+
var checkConfigurationPropertyValue = function(aPropertyName, aPropertyValue, aStatus, doTest) {
1390+
this.log("checkConfigurationPropertyValue(aPropertyName,aPropertyValue,aStatus):" + aPropertyName + ',' + aPropertyValue + ',' + aStatus);
13851391
if (aStatus == undefined) aStatus = false;
13861392
if (doTest == undefined) doTest = true;
13871393

@@ -1409,10 +1415,57 @@ var jamrules = (function() {
14091415

14101416
}
14111417

1418+
/**
1419+
* @function selectConfigurationPropertyValue
1420+
* @access public
1421+
* @abstract set a property/property value status in the rules configurator
1422+
* designed for radio/exclusive select
1423+
* @param aPropertyName: name of the property that has changed
1424+
* @param aProperyValue: value of the property
1425+
* @param doTest: [boolean] [default:true] if false, configure the configurator but does not run the rules engine test
1426+
* @return void
1427+
*/
1428+
var selectConfigurationPropertyValue = function(aPropertyName, aPropertyValue, doTest) {
1429+
this.log("selectConfigurationPropertyValue(aPropertyName,aPropertyValue):" + aPropertyName + ',' + aPropertyValue );
1430+
if (doTest == undefined) doTest = true;
1431+
1432+
if (!propertiesConfiguration[aPropertyName]) propertiesConfiguration[aPropertyName] = {};
1433+
1434+
this.resetConfigurationPropertyValues(aPropertyName);
1435+
1436+
// set the one...
1437+
propertiesConfiguration[aPropertyName][aPropertyValue] = true;
1438+
1439+
if (this.myRulesEngine && doTest) this.myRulesEngine.trigger('propertyChange', {
1440+
propertyName: aPropertyName,
1441+
propertyValue: aPropertyValue,
1442+
status: true
1443+
});
1444+
else if (!this.myRulesEngine) {
1445+
if (this.options.debug) alert("Rules engine is not started. Call first compile rules (cf compileRules())");
1446+
return;
1447+
}
1448+
}
1449+
/**
1450+
* @function resetConfigurationPropertyValues
1451+
* @access public
1452+
* @abstract reset a property by setting all its property values to a false status in the rules configurator
1453+
* @param aPropertyName: name of the property that has changed
1454+
* @return void
1455+
*/
1456+
var resetConfigurationPropertyValues = function(aPropertyName) {
1457+
this.log("resetConfigurationPropertyValues(aPropertyName):" + aPropertyName);
1458+
//unset all property's values
1459+
for (propertyValue in propertiesConfiguration[aPropertyName]) {
1460+
propertiesConfiguration[aPropertyName][propertyValue]=false;
1461+
}
1462+
1463+
}
1464+
14121465
/**
14131466
* @function resetConfigurationProperty
14141467
* @access public
1415-
* @abstract reset a property completly
1468+
* @abstract reset a property completely
14161469
* @param aPropertyName: name of the property to reset
14171470
* @return void
14181471
*/
@@ -1543,6 +1596,8 @@ var jamrules = (function() {
15431596
,
15441597
runRulesEngine: runRulesEngine,
15451598
selectConfigurationPropertyValue: selectConfigurationPropertyValue,
1599+
checkConfigurationPropertyValue: checkConfigurationPropertyValue,
1600+
resetConfigurationPropertyValues: resetConfigurationPropertyValues,
15461601
resetConfigurationProperty: resetConfigurationProperty,
15471602
createRulesSet: createRulesSet,
15481603
addRule: addRule,

tests/filterDocsExclusive.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ <h3>{%title%}</h3>
196196
select: function(e) {
197197
e.preventDefault();
198198
$(e.currentTarget).parent().find("a.btn").each(function(){
199-
$(this).removeClass('active');
200-
let cat = $(this).attr('data-cat');
201-
let tag = $(this).attr('data-tag');
202-
let year = $(this).attr('data-year');
203-
// reset the configurator values
204-
if (cat) rulesEngine.selectConfigurationPropertyValue("category",(cat=='all')?'*':cat,0,false);
205-
if (tag) rulesEngine.selectConfigurationPropertyValue("tags",(tag=='all')?'*':tag,0,false);
206-
if (year) rulesEngine.selectConfigurationPropertyValue("year",(year=='all')?'*':year,0,false);
199+
$(this).removeClass('active');
200+
// let cat = $(this).attr('data-cat');
201+
// let tag = $(this).attr('data-tag');
202+
// let year = $(this).attr('data-year');
203+
// // reset the configurator values
204+
// if (cat) rulesEngine.checkConfigurationPropertyValue("category",(cat=='all')?'*':cat,0,false);
205+
// if (tag) rulesEngine.checkConfigurationPropertyValue("tags",(tag=='all')?'*':tag,0,false);
206+
// if (year) rulesEngine.checkConfigurationPropertyValue("year",(year=='all')?'*':year,0,false);
207207
});
208208
$(e.currentTarget).addClass("active");
209209
let cat = $(this).attr('data-cat');
@@ -226,7 +226,7 @@ <h3>{%title%}</h3>
226226
rulesEngine.resetConfigurationProperty("title");
227227
searchStrings.map(searchString => {
228228
//create as many keywords to be searched in the configuration of title
229-
rulesEngine.selectConfigurationPropertyValue("title",'*'+searchString+'*',1,false);// we don't process
229+
rulesEngine.checkConfigurationPropertyValue("title",'*'+searchString+'*',1,false);// we don't process
230230
});
231231
rulesEngine.runRulesEngine();// do now the search
232232
},

tests/filterDocsInclusive.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,18 @@ <h3>{%title%}</h3>
225225
$(".filters a.btn").on('click', docFilter.select);
226226
$(".filters a.toggle").on("click", docFilter.toggleTags);
227227

228-
rulesEngine.selectConfigurationPropertyValue("category","minute",0,false);
229-
rulesEngine.selectConfigurationPropertyValue("category","dossier",0,false);
230-
rulesEngine.selectConfigurationPropertyValue("category","annex",0,false);
231-
rulesEngine.selectConfigurationPropertyValue("category","action plan",0,false);
232-
rulesEngine.selectConfigurationPropertyValue("category","press release",0,false);
233-
rulesEngine.selectConfigurationPropertyValue("category","misc",0,false);
234-
rulesEngine.selectConfigurationPropertyValue("tags","anticipation",0,false);
235-
rulesEngine.selectConfigurationPropertyValue("tags","influence",0,false);
236-
rulesEngine.selectConfigurationPropertyValue("tags","club",0,false);
237-
rulesEngine.selectConfigurationPropertyValue("tags","ag",0,false);
238-
rulesEngine.selectConfigurationPropertyValue("tags","ca",0,false);
239-
rulesEngine.selectConfigurationPropertyValue("tags","comittee",0,false);
228+
rulesEngine.checkConfigurationPropertyValue("category","minute",0,false);
229+
rulesEngine.checkConfigurationPropertyValue("category","dossier",0,false);
230+
rulesEngine.checkConfigurationPropertyValue("category","annex",0,false);
231+
rulesEngine.checkConfigurationPropertyValue("category","action plan",0,false);
232+
rulesEngine.checkConfigurationPropertyValue("category","press release",0,false);
233+
rulesEngine.checkConfigurationPropertyValue("category","misc",0,false);
234+
rulesEngine.checkConfigurationPropertyValue("tags","anticipation",0,false);
235+
rulesEngine.checkConfigurationPropertyValue("tags","influence",0,false);
236+
rulesEngine.checkConfigurationPropertyValue("tags","club",0,false);
237+
rulesEngine.checkConfigurationPropertyValue("tags","ag",0,false);
238+
rulesEngine.checkConfigurationPropertyValue("tags","ca",0,false);
239+
rulesEngine.checkConfigurationPropertyValue("tags","comittee",0,false);
240240

241241
rulesEngine.runRulesEngine();
242242

@@ -248,9 +248,9 @@ <h3>{%title%}</h3>
248248
// let cat = $(this).attr('data-cat');
249249
// let tag = $(this).attr('data-tag');
250250
// let year = $(this).attr('data-year');
251-
// if (cat) rulesEngine.selectConfigurationPropertyValue("category",cat,0,false);
252-
// if (tag) rulesEngine.selectConfigurationPropertyValue("tags",tag,0,false);
253-
// if (year) rulesEngine.selectConfigurationPropertyValue("year",year,0,false);
251+
// if (cat) rulesEngine.checkConfigurationPropertyValue("category",cat,0,false);
252+
// if (tag) rulesEngine.checkConfigurationPropertyValue("tags",tag,0,false);
253+
// if (year) rulesEngine.checkConfigurationPropertyValue("year",year,0,false);
254254
// });
255255
let currentTarget = $(e.currentTarget);
256256
let cat = currentTarget.attr('data-cat');
@@ -259,15 +259,15 @@ <h3>{%title%}</h3>
259259
if (currentTarget.hasClass("active"))
260260
{
261261
currentTarget.removeClass("active");
262-
if (cat) rulesEngine.selectConfigurationPropertyValue("category",cat,0,false);
263-
if (tag) rulesEngine.selectConfigurationPropertyValue("tags",tag,0,false);
264-
if (year) rulesEngine.selectConfigurationPropertyValue("year",year,0,false);
262+
if (cat) rulesEngine.checkConfigurationPropertyValue("category",cat,0,false);
263+
if (tag) rulesEngine.checkConfigurationPropertyValue("tags",tag,0,false);
264+
if (year) rulesEngine.checkConfigurationPropertyValue("year",year,0,false);
265265
}
266266
else {
267267
currentTarget.addClass("active");
268-
if (cat) rulesEngine.selectConfigurationPropertyValue("category",cat,1,false);
269-
if (tag) rulesEngine.selectConfigurationPropertyValue("tags",tag,1,false);
270-
if (year) rulesEngine.selectConfigurationPropertyValue("year",year,1,false);
268+
if (cat) rulesEngine.checkConfigurationPropertyValue("category",cat,1,false);
269+
if (tag) rulesEngine.checkConfigurationPropertyValue("tags",tag,1,false);
270+
if (year) rulesEngine.checkConfigurationPropertyValue("year",year,1,false);
271271
}
272272
rulesEngine.runRulesEngine();
273273
},

0 commit comments

Comments
 (0)