Skip to content

Commit 5d037e4

Browse files
committed
yep v2
1 parent efd2cef commit 5d037e4

5 files changed

Lines changed: 68 additions & 64 deletions

File tree

jamrules.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* -----------------------------------------------------------------------------------------
1010
* Modifications :
11+
* - 20170331 - E.Podvin - V2.0.0 - Creation
1112
* - 20170227 - E.Podvin - V1.0.0 - Creation
1213
*
1314
* -----------------------------------------------------------------------------------------
@@ -16,7 +17,7 @@
1617
* @fileoverview :
1718
* @see {@link https://github.com/intersel/jamrules}
1819
* @author : Emmanuel Podvin - emmanuel.podvin@intersel.fr
19-
* @version : 1.0.0
20+
* @version : 2.0.0
2021
* -----------------------------------------------------------------------------------------
2122
*/
2223

@@ -28,7 +29,37 @@
2829
*/
2930

3031
var jamrules = (function(){
32+
3133

34+
/**
35+
* @param ObjectProfiles
36+
* @access private
37+
* @abstract list of possible profiles available to all rules
38+
* a profile is defined by a list of entries [objectKey]:{propertiesSet:<apropertiesSet>,objectsList:[]}
39+
* {
40+
* <objectKey1>:{
41+
* propertiesSet:
42+
* {
43+
* <propertyName1>:{
44+
* type:<discreteValuesList>,
45+
* <propertyValue1>:1|0,
46+
* <propertyValue2>:1|0,
47+
* ...
48+
* },
49+
* ... same as propertiesConfiguration definition
50+
* <propertyName1>.<propertyValue1>:1|0,
51+
* <propertyName2>.<propertyValue2>:1|0
52+
* ....
53+
* ],
54+
* elementList:[ //element objects that share the same properties set
55+
* ]
56+
* },
57+
* <objectKey2>:{
58+
* ....
59+
* }
60+
*/
61+
var ObjectProfiles = {};
62+
3263

3364
var jamrulesClass = function(aJqueryObj,options) {
3465

@@ -67,35 +98,6 @@ var jamrules = (function(){
6798
*/
6899
var propertiesConfiguration = {};
69100

70-
/**
71-
* @param ObjectProfiles
72-
* @access private
73-
* @abstract list of possible profiles available to all rules
74-
* a profile is defined by a list of entries [objectKey]:{propertiesSet:<apropertiesSet>,objectsList:[]}
75-
* {
76-
* <objectKey1>:{
77-
* propertiesSet:
78-
* {
79-
* <propertyName1>:{
80-
* type:<discreteValuesList>,
81-
* <propertyValue1>:1|0,
82-
* <propertyValue2>:1|0,
83-
* ...
84-
* },
85-
* ... same as propertiesConfiguration definition
86-
* <propertyName1>.<propertyValue1>:1|0,
87-
* <propertyName2>.<propertyValue2>:1|0
88-
* ....
89-
* ],
90-
* elementList:[ //element objects that share the same properties set
91-
* ]
92-
* },
93-
* <objectKey2>:{
94-
* ....
95-
* }
96-
*/
97-
var ObjectProfiles = {};
98-
99101
/**
100102
* @param matchRuleTemplate
101103
* @abstract template to create new rule in the state definition of the rules engine
@@ -681,7 +683,7 @@ var jamrules = (function(){
681683
*
682684
*/
683685
this.getAllObjectProfiles = function(){
684-
return $.extend( ObjectProfiles, this.getObjectProfiles() );
686+
return $.extend( {}, ObjectProfiles, this.getObjectProfiles() );
685687
}
686688
};
687689

tests/JamRulesExample1.html

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,31 @@ <h1>Filter box</h1>
4949
<h1>Elément 1</h1>
5050
<section id='priority' class="property">
5151
<label>
52-
<input class="checkbox" id="el1-priority-un" type="checkbox" value="priority1" checked>
52+
<input class="checkbox" id="el1-priority-un" type="checkbox" value="priority1" checked disabled>
5353
Priority 1
5454
</label>
5555
<label>
56-
<input class="checkbox" id="el1-priority-deux" type="checkbox" value="priority2">
56+
<input class="checkbox" id="el1-priority-deux" type="checkbox" value="priority2" disabled>
5757
Priority 2
5858
</label>
5959
</section>
6060
<section id='technician' class='property'>
6161
<label>
62-
<input class="checkbox" id="el1-technician1" type="checkbox" value="technician1" checked>
62+
<input class="checkbox" id="el1-technician1" type="checkbox" value="technician1" checked disabled>
6363
Technician 1
6464
</label>
6565
<label>
66-
<input class="checkbox" id="el1-technician2" type="checkbox" value="technician2">
66+
<input class="checkbox" id="el1-technician2" type="checkbox" value="technician2" disabled>
6767
Technician 2
6868
</label>
6969
</section>
7070
<section id='compliantTechnician' class='property'>
7171
<label>
72-
<input class="checkbox" id="el1-technician1-compliant" type="checkbox" value="technician1" checked>
72+
<input class="checkbox" id="el1-technician1-compliant" type="checkbox" value="technician1" checked disabled>
7373
Technician 1 Compliant
7474
</label>
7575
<label>
76-
<input class="checkbox" id="el1-technician2-compliant" type="checkbox" value="technician2">
76+
<input class="checkbox" id="el1-technician2-compliant" type="checkbox" value="technician2" disabled>
7777
Technician 2 Compliant
7878
</label>
7979
</section>
@@ -84,10 +84,11 @@ <h1>Result Matching</h1>
8484
<input class="checkbox" id="el1-match" type="checkbox" disabled>
8585
object 1 match?
8686
</label>
87-
<label>
87+
<!-- <label>
8888
<input class="checkbox" id="el2-match" type="checkbox" disabled>
8989
object 2 match?
9090
</label>
91+
-->
9192
<div id="debug">
9293
</div>
9394
</section>
@@ -114,18 +115,8 @@ <h1>Result Matching</h1>
114115
// ---------------------------------
115116

116117
//initialisation of jamrules and its configurator
117-
var rulesForPriorityLayer = new jamrules($('#filterbox'),{debug:true});
118+
var rulesForPriorityLayer = jamrules.build($('#filterbox'),{debug:true});
118119

119-
/* initialisation if needed*/
120-
// checked the input in the above html (#filterbox section) you'd like to have set in the configurator
121-
// section id is a property name and input value is the value of the property and 'checked' the status
122-
$("#filterbox section").each(function(){
123-
var propertyName = this.id;
124-
$(this).find("input.checkbox").each(function(){
125-
rulesForPriorityLayer.selectConfigurationPropertyValue(propertyName,$(this).val(),$(this).prop('checked'));
126-
});
127-
});
128-
129120
// rules setting
130121
rulesForPriorityLayer.createRulesSet("PriorityMatch1",["activities","priority"]);
131122
rulesForPriorityLayer.addRule("PriorityMatch1","testPriorityExist",'MatchProperty("priority")');
@@ -143,6 +134,17 @@ <h1>Result Matching</h1>
143134

144135
//add objects that we want to test if they match the rules
145136
rulesForPriorityLayer.addObject(el1);
137+
138+
/* initialisation if needed*/
139+
// checked the input in the above html (#filterbox section) you'd like to have set in the configurator
140+
// section id is a property name and input value is the value of the property and 'checked' the status
141+
$("#filterbox section").each(function(){
142+
var propertyName = this.id;
143+
$(this).find("input.checkbox").each(function(){
144+
rulesForPriorityLayer.selectConfigurationPropertyValue(propertyName,$(this).val(),$(this).prop('checked'));
145+
});
146+
});
147+
146148

147149
// test if object is technician tech1
148150
// test if object is compliant with tech1

tests/JamRulesPackExemple2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h1>Raw test of jamrules</h1>
2020

2121

2222
//initialisation of jamrules and its configurator
23-
var rulesEngine = new jamrules($('#filterbox'),{debug:true});
23+
var rulesEngine = jamrules.build($('#filterbox'),{debug:true});
2424

2525
// rules setting
2626

tests/mastermind.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ <h1>Raw test of jamrules</h1>
2020

2121

2222
//initialisation of jamrules and its configurator
23-
var rulesEngineBlack1 = new jamrules($('#filterbox'),{debug:true,LogLevel:3,name:"rulesEngineBlack1"});
24-
var rulesEngineBlack2 = new jamrules($('#filterbox'),{name:"rulesEngineBlack2"});
25-
var rulesEngineBlack3 = new jamrules($('#filterbox'),{name:"rulesEngineBlack3"});
26-
var rulesEngineBlack4 = new jamrules($('#filterbox'),{name:"rulesEngineBlack4"});
27-
var rulesEngineWhite1 = new jamrules($('#filterbox'),{name:"rulesEngineWhite1"});
28-
var rulesEngineWhite2 = new jamrules($('#filterbox'),{name:"rulesEngineWhite2"});
29-
var rulesEngineWhite3 = new jamrules($('#filterbox'),{name:"rulesEngineWhite3"});
30-
var rulesEngineWhite4 = new jamrules($('#filterbox'),{name:"rulesEngineWhite4"});
31-
var rulesEngineWin = new jamrules($('#filterbox'),{debug:false,LogLevel:3,name:"rulesEngineWin"});
23+
var rulesEngineBlack1 = jamrules.build($('#filterbox'),{debug:true,LogLevel:3,name:"rulesEngineBlack1"});
24+
var rulesEngineBlack2 = jamrules.build($('#filterbox'),{name:"rulesEngineBlack2"});
25+
var rulesEngineBlack3 = jamrules.build($('#filterbox'),{name:"rulesEngineBlack3"});
26+
var rulesEngineBlack4 = jamrules.build($('#filterbox'),{name:"rulesEngineBlack4"});
27+
var rulesEngineWhite1 = jamrules.build($('#filterbox'),{name:"rulesEngineWhite1"});
28+
var rulesEngineWhite2 = jamrules.build($('#filterbox'),{name:"rulesEngineWhite2"});
29+
var rulesEngineWhite3 = jamrules.build($('#filterbox'),{name:"rulesEngineWhite3"});
30+
var rulesEngineWhite4 = jamrules.build($('#filterbox'),{name:"rulesEngineWhite4"});
31+
var rulesEngineWin = jamrules.build($('#filterbox'),{debug:false,LogLevel:3,name:"rulesEngineWin"});
3232

3333
var nbFoundDotColor=0;
3434

@@ -111,7 +111,7 @@ <h1>Raw test of jamrules</h1>
111111
case 'rulesEngineWhite4':
112112
this.nbWhiteDotFound++;
113113
$("#msg").append("<p>matched</p>");
114-
$.each(aEngineRule.ruleEngine.opts.reason,function(index,value) {
114+
$.each(aEngineRule.myRulesEngine.opts.reason,function(index,value) {
115115
if (value.indexOf("DefaultState")==-1)
116116
$("#msg").append("Match reason: State "+index+" --> "+value);
117117
});
@@ -122,7 +122,7 @@ <h1>Raw test of jamrules</h1>
122122
case 'rulesEngineBlack4':
123123
this.nbBlackDotFound++;
124124
$("#msg").append("<p>matched</p>");
125-
$.each(aEngineRule.ruleEngine.opts.reason,function(index,value) {
125+
$.each(aEngineRule.myRulesEngine.opts.reason,function(index,value) {
126126
if (value.indexOf("DefaultState")==-1)
127127
$("#msg").append("Match reason: State "+index+" --> "+value);
128128
});
@@ -141,7 +141,7 @@ <h1>Raw test of jamrules</h1>
141141
break;
142142
default:
143143
$("#msg").append("<p>not matched</p>");
144-
$.each(aEngineRule.ruleEngine.opts.reason,function(index,value) {
144+
$.each(aEngineRule.myRulesEngine.opts.reason,function(index,value) {
145145
if (value.indexOf("DefaultState")==-1)
146146
$("#msg").append("Don't Match reason: State "+index+" --> "+value);
147147
});

tests/testJamRules.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ <h1>Raw test of jamrules</h1>
2020

2121

2222
//initialisation of jamrules and its configurator
23-
var rulesForPriorityLayer = new jamrules($('#filterbox'),{debug:true});
23+
var rulesForPriorityLayer = jamrules.build($('#filterbox'),{debug:true});
2424
/* initialisation of the configurator if needed*/
25-
rulesForPriorityLayer.selectConfigurationPropertyValue("priority","priority1",1);
25+
rulesForPriorityLayer.selectConfigurationPropertyValue("priority","priority1",1,false);
2626

2727
// rules setting
2828
rulesForPriorityLayer.createRulesSet("PriorityMatch1",["activities","priority"]);

0 commit comments

Comments
 (0)