File: tests/testJamRules.html

Recommend this page to a friend!
  Classes of Emmanuel Podvin  >  Jam Rules  >  tests/testJamRules.html  >  Download  
File: tests/testJamRules.html
Role: Example script
Content type: text/plain
Description: Example
Class: Jam Rules
Match objects against a list of rules
Author: By
Last change: add startProcessing and stopProcessing
add new example filterDocs
Date: 1 month ago
Size: 3,608 bytes
 

Contents

Class file image Download
<html>
	<head>
		<title>testJamRules</title>
	 	<meta charset="utf-8" />
		<script type="text/javascript" src="../extlib/jQuery/jquery-3.2.0.min.js"></script>
		<script type="text/javascript" src="../extlib/iFSM/extlib/jquery.dorequesttimeout.js"></script>
		<script type="text/javascript" src="../extlib/iFSM/extlib/jquery.attrchange.js"></script>
		<script type="text/javascript" src="../extlib/iFSM/iFSM.js"></script>
		<script type="text/javascript" src="../extlib/jQuery-MD5/jquery.md5.js"></script>
		<script type="text/javascript" src="../jamrules.js"></script>
	</head>
	<body>

	<div id="filterbox">
		<h1>Raw test of jamrules</h1>
		<div id="msg"></div>
	</div>
	<script>



	//initialisation of jamrules and its configurator
	var rulesForPriorityLayer = jamrules.build({debug:true});
	/* initialisation of the configurator if needed*/
	rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",1,false);

	// rules setting
	rulesForPriorityLayer.createRulesSet("PriorityMatch1",["activities","priority"]);
	rulesForPriorityLayer.addRule("PriorityMatch1","testPriorityExist",'MatchProperty("priority")');
	rulesForPriorityLayer.addRule("PriorityMatch1","testActivityNotCompliant",'!ConfigurationPropertySet("activities","compliant")');
	rulesForPriorityLayer.addRule("PriorityMatch1","testDisplayAll",'ConfigurationPropertySet("activities","all")');

	rulesForPriorityLayer.createRulesSet("PriorityMatch2",["activities","priority","technician"]);
	rulesForPriorityLayer.addRule("PriorityMatch2","testPriorityExist",'MatchProperty("priority")');
	rulesForPriorityLayer.addRule("PriorityMatch2","technicianCompliant",'MatchProperties("technician","compliantTechnician")');
	rulesForPriorityLayer.addRule("PriorityMatch2","testActivityCompliant",'ConfigurationPropertySet("activities","compliant")');
	rulesForPriorityLayer.addRule("PriorityMatch2","testDisplayAll",'ConfigurationPropertySet("activities","all")');

	// prepare the rule engine
	rulesForPriorityLayer.compileRules();

	//add objects that we want to test if they match the rules
	var el1={propertiesSet:{priority:{priority1:1 },compliantTechnician:{technician1:1}},matched:null,notmatched:null};
	rulesForPriorityLayer.addObject(el1);
	el1.matched=function(){
		msg="el1 matched for "+msg;
		//alert(msg);
		$("#msg").append("<p>"+msg+"</p>");
	};
	el1.notmatched=function(){
		msg="el1 did not matched for "+msg;
		//alert(msg);
		$("#msg").append("<p>"+msg+"</p>");
	};
	$("#msg").append("el1 configuration:"+JSON.stringify(el1));

	//activate activities to display all in the configurator
	var msg = "set activities->all->on"
	rulesForPriorityLayer.checkConfigurationPropertyValue("activities","all",1);
	//-> match
	// activate priority / priority1
	msg = "set priority->priority1->on"
	rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",1);
	//-> match
	// activate technician / technician1
	msg = "set technician->technician1->on"
	rulesForPriorityLayer.checkConfigurationPropertyValue("technician","technician1",1);
	//-> match
	// activate display activities compliant
	msg = "set activities->compliant->on"
	rulesForPriorityLayer.checkConfigurationPropertyValue("activities","compliant",1);
	//-> match
	//deactivate priority/priority1
	msg = "set priority->priority1->off"
	rulesForPriorityLayer.checkConfigurationPropertyValue("priority","priority1",0);
	//-> not match
	// deactivate display activities compliant
	msg = "set activities->compliant->off"
	rulesForPriorityLayer.checkConfigurationPropertyValue("activities","compliant",0);
	//-> match

</script>

	</body>

</html>