www/js/mon_co2meter.js

changeset 506
8ab0e87d579e
parent 505
c09b67fd8323
child 507
17f244137a9b
--- a/www/js/mon_co2meter.js	Fri Oct 11 13:38:31 2019 +0200
+++ b/www/js/mon_co2meter.js	Fri Oct 11 21:04:48 2019 +0200
@@ -25,8 +25,7 @@
 
 	var record = {},
 	blank = {},
-//	newBase = false,
-//	newProduct = false,
+	newProduct = false,
 	schedule = 0,
 
 	productSource = {
@@ -43,7 +42,7 @@
 	productlist = new $.jqx.dataAdapter(productSource, {
 		beforeLoadComplete: function (records) {
 			var row, i, data = new Array();
-			// Create a dummy beer on top to store in idle fermenters.
+			// Create a dummy beer on top to store in idle meters.
 			blank['code'] = "Free";	 // Will override this later.
 			blank['name'] = 'Dummy';
 			blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5';
@@ -59,10 +58,10 @@
 		},
 	}),
         gaugeoptionst = {
-                min: 0, max: 40, width: 375, height: 375,
-                ranges: [{ startValue:  0, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
-                         { startValue: 20, endValue: 26, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
-                         { startValue: 26, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
+                min: 10, max: 40, width: 375, height: 375,
+                ranges: [{ startValue: 10, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
+                         { startValue: 20, endValue: 28, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
+                         { startValue: 28, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
                 ticksMinor: { interval: 1, size: '5%' },
                 ticksMajor: { interval: 5, size: '9%' },
                 labels: { interval: 5 },
@@ -110,15 +109,22 @@
                         $("#info_uuid").html(record.uuid);
                         $("#info_system").html(record.node +  "/" + record.alias);
                         $("#info_online").html(oline);
-                        $("#info_mode").jqxDropDownList('selectItem', record.mode);
+			$("#info_beer").html(record.beercode + " - " + record.beername);
+                        $("#info_mode").html(record.mode);
                         blank['name'] = record.alias;
                         blank['code'] = record.alias.toUpperCase();
                         blank['uuid'] = record.uuid;
 
                         if (record.online && (record.mode != "OFF")) {
                                 $("#co2meter_powerled").html('<div class="LEDblue_on"></div>Power');
+                                $("#select_beer").jqxDropDownList({ disabled: true });
+                                $("#select_beer").jqxDropDownList('clearSelection');
+                                $("#select_beer").hide();
                         } else {
                                 $("#co2meter_powerled").html('<div class="LEDblue_off"></div>Power');
+                                $("#select_beer").show();
+                                $("#select_beer").jqxDropDownList({ disabled: false });
+
                         }
 			if (record.online && (record.alarm != "0")) {
                                 $("#co2meter_alarmled").html('<div class="LEDred_on"></div>Alarm');
@@ -163,32 +169,28 @@
 	$("#gaugeContainer_pressure").jqxGauge( gaugeoptionsp );
 	$("#gaugeContainer_pressure").jqxGauge( { caption: { value: 'Bar: 00.000' }} );
 
-	srcMode = [ "OFF", "ON" ];
-	$("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 62 });
-
-//	function sendProduct(code, name, uuid, yeast_lo, yeast_hi) {
+	function sendProduct(code, name, uuid) {
 
-//		console.log("sendProduct("+code+", "+name+", "+uuid+", "+yeast_lo+", "+yeast_hi+")");
-//		var data  = 'node='+record.node+'&alias='+record.alias+'&payload=';
-//		    data += '{"product":{"code":"'+code+'","name":"'+name+'","uuid":"'+uuid+'","yeast_lo":'+yeast_lo+',"yeast_hi":'+yeast_hi+'}}';
-//		$.ajax({
-//			url: "cmd_fermenter.php",
-//			data: data,
-//			type: "POST",
-//			success: function(data) {},
-//			error: function(jqXHR, textStatus, errorThrown) { console.log("sendProduct() error"); }
-//		});
-//	}
+		console.log("sendProduct("+code+", "+name+", "+uuid+")");
+		var data  = 'uuid='+record.uuid+'&beeruuid='+uuid+'&beercode='+code+'&beername='+name;
+		$.ajax({
+			url: "cmd_co2meter.php",
+			data: data,
+			type: "POST",
+			success: function(data) {},
+			error: function(jqXHR, textStatus, errorThrown) { console.log("sendProduct() error"); }
+		});
+	}
 
 	// Get the data immediatly and then at regular intervals to refresh.
 	dataAdapter.dataBind();
 	setInterval(function() {
 		var skip = false;
-//		if (newProduct) {
-//			sendProduct(record.beercode, record.beername, record.beeruuid, record.yeast_lo, record.yeast_hi);
-//			newProduct = false;
-//			skip = true;
-//		}
+		if (newProduct) {
+			sendProduct(record.beercode, record.beername, record.beeruuid);
+			newProduct = false;
+			skip = true;
+		}
 		if (skip) {
 			schedule = 4;	// 2 seconds wait to get the results
 		} else {
@@ -202,29 +204,20 @@
 		}
 	}, 500);
 
-	$('#info_mode').on('change', function (event) {
-		var args = event.args;
-		if (args) {
-			record.mode = args.item.value;
+	$("#select_beer").on('select', function (event) {
+		if (event.args) {
+			var index = event.args.index,
+			datarecord = productlist.records[index];
+			record.beercode = datarecord.code;
+			record.beername = datarecord.name;
+			record.beeruuid = datarecord.uuid;
+			newProduct = true;
 		}
-//		newBase = true;
 	});
-//	$("#select_beer").on('select', function (event) {
-//		if (event.args) {
-//			var index = event.args.index,
-//			datarecord = productlist.records[index];
-//			record.beercode = datarecord.code;
-//			record.beername = datarecord.name;
-//			record.beeruuid = datarecord.uuid;
-//			record.yeast_lo = datarecord.yeast_lo;
-//			record.yeast_hi = datarecord.yeast_hi;
-//			newProduct = true;
-//		}
-//	});
 
 	// The chart button.
    	$("#FLog").jqxButton({ template: "primary", width: '150px', theme: theme });
 	$("#FLog").click(function () {
-		window.open('log_fermentation.php?code=' + record.beercode + '&name=' + record.beername);
+		window.open('log_co2meter.php?code=' + record.beercode + '&name=' + record.beername);
 	});
 });

mercurial