Completed framework inline fermentables editor

Thu, 20 Sep 2018 16:19:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 20 Sep 2018 16:19:09 +0200
changeset 57
bb9a06aa9acd
parent 56
d4f4762e59b3
child 58
83ccc36df675

Completed framework inline fermentables editor

www/getfermentablesources.php file | annotate | diff | comparison | revisions
www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/includes/db_recipes.php file | annotate | diff | comparison | revisions
www/js/recipes.js file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/getfermentablesources.php	Thu Sep 20 16:19:09 2018 +0200
@@ -0,0 +1,33 @@
+<?php
+require_once('config.php');
+
+$query = "SELECT * FROM inventory_fermentables ORDER BY name";
+$connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
+if (! $connect) {
+	echo "[]";
+	return;
+}
+$result = mysqli_query($connect, $query);
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+	$fermentables[] = array(
+		'record' => $row['record'],
+		'name' => $row['name'],
+		'type' => $row['type'],
+		'yield' => $row['yield'],
+		'color' => $row['color'],
+		'add_after_boil' => $row['add_after_boil'],
+		'origin' => $row['origin'],
+		'supplier' => $row['supplier'],
+		'coarse_fine_diff' => $row['coarse_fine_diff'],
+		'moisture' => $row['moisture'],
+		'diastatic_power' => $row['diastatic_power'],
+		'protein' => $row['protein'],
+		'max_in_batch' => $row['max_in_batch'],
+		'recommend_mash' => $row['recommend_mash'],
+		'graintype' => $row['graintype'],
+		'di_ph' => $row['di_ph'],
+		'inventory' => $row['inventory'],
+		'cost' => $row['cost']
+	);
+}
+echo json_encode($fermentables);
--- a/www/import/from_brouwhulp.php	Tue Sep 18 23:16:14 2018 +0200
+++ b/www/import/from_brouwhulp.php	Thu Sep 20 16:19:09 2018 +0200
@@ -569,6 +569,7 @@
 					$fermentables .= ',"f_dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN);
 				}
 				($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"f_adjust_to_total_100":true' : $fermentables .= ',"f_adjust_to_total_100":false';
+				$fermentables .= ',"f_percentage":' . floatval($fermentable->PERCENTAGE);
 				if ($fermentable->DI_pH) {
 					$fermentables .= ',"f_di_ph":' . floatval($fermentable->DI_pH);
 				}
--- a/www/includes/db_recipes.php	Tue Sep 18 23:16:14 2018 +0200
+++ b/www/includes/db_recipes.php	Thu Sep 20 16:19:09 2018 +0200
@@ -14,6 +14,7 @@
 
 $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
 $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
+$disallowed = array('visibleindex','uniqueid','boundindex','uid');
 
 // get data and store in a json array
 $query = "SELECT * FROM recipes ORDER BY st_guide,st_letter,st_name,name";
@@ -58,8 +59,23 @@
 
 	syslog(LOG_NOTICE, $sql);	// Log upto this part.
 
-	 syslog(LOG_NOTICE, "json_waters: " . json_encode($_GET['waters']));
-	$sql .= "', json_waters='" . json_encode($_GET['waters']);
+	$array = $_GET['fermentables'];
+	foreach($array as $key => $item){
+		foreach ($disallowed as $disallowed_key) {
+			unset($array[$key]["$disallowed_key"]);
+		}
+	}
+	syslog(LOG_NOTICE, "json_fermentables: " . json_encode($array));
+	$sql .= "', json_fermentables='" . json_encode($array);
+
+	$array = $_GET['waters'];
+	foreach($array as $key => $item){
+		foreach ($disallowed as $disallowed_key) {
+			unset($array[$key]["$disallowed_key"]);
+		}
+	}
+	syslog(LOG_NOTICE, "json_waters: " . json_encode($array));
+	$sql .= "', json_waters='" . json_encode($array);
 
 	if (isset($_GET['insert'])) {
 		$sql .= "';";
--- a/www/js/recipes.js	Tue Sep 18 23:16:14 2018 +0200
+++ b/www/js/recipes.js	Thu Sep 20 16:19:09 2018 +0200
@@ -170,6 +170,7 @@
 				{ name: 'f_recommend_mash', type: 'bool' },
 				{ name: 'f_add_after_boil', type: 'bool' },
 				{ name: 'f_adjust_to_total_100', type: 'bool' },
+				{ name: 'f_percentage', type: 'float' },
 				{ name: 'f_di_ph', type: 'float' }
 			],
 			addrow: function (rowid, rowdata, position, commit) {
@@ -187,20 +188,22 @@
 			datafields: [
 				{ name: 'record', type: 'number' },
 				{ name: 'name', type: 'string' },
-				{ name: 'cost', type: 'float' },
 				{ name: 'type', type: 'string' },
 				{ name: 'yield', type: 'float' },
 				{ name: 'color', type: 'float' },
+				{ name: 'add_after_boil', type: 'bool' },
+				{ name: 'origin', type: 'string' },
+				{ name: 'supplier', type: 'string' },
 				{ name: 'coarse_fine_diff', type: 'float' },
 				{ name: 'moisture', type: 'float' },
 				{ name: 'diastatic_power', type: 'float' },
 				{ name: 'protein', type: 'float' },
 				{ name: 'max_in_batch', type: 'float' },
+				{ name: 'recommend_mash', type: 'bool' },
 				{ name: 'graintype', type: 'string' },
-				{ name: 'added', type: 'string' },
-				{ name: 'dissolved_protein', type: 'float' },
-				{ name: 'adjust_to_total_100', type: 'bool' },
-				{ name: 'di_ph', type: 'float' }
+				{ name: 'di_ph', type: 'float' },
+				{ name: 'inventory', type: 'float' },
+				{ name: 'cost', type: 'float' }
 			],
 			url: fermentableUrl,
 			async: true
@@ -221,10 +224,10 @@
 				var me = this;
 				var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
 				toolbar.append(container);
-				container.append('<div style="float: left; margin-left: 165px;" id="addrowbutton"></div>');
-				container.append('<input style="float: left; margin-left: 230px;" id="deleterowbutton" type="button" value="Verwijder mout" />');
+				container.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');
+				container.append('<input style="float: left; margin-left: 230px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');
 				// add fermentable from dropdownlist.
-				$("#addrowbutton").jqxDropDownList({
+				$("#faddrowbutton").jqxDropDownList({
 					placeHolder: "Kies mout:",
 					theme: theme,
 					source: fermentablelist,
@@ -233,22 +236,44 @@
 					height: 27,
 					dropDownWidth: 300
 				});
-				$("#addrowbutton").on('select', function (event) {
+				$("#faddrowbutton").on('select', function (event) {
 					if (event.args) {
 						var index = event.args.index;
 						var datarecord = fermentablelist.records[index];
 						var row = {};
 						row["f_name"] = datarecord.name;
+						row["f_origin"] = datarecord.origin;
+						row["f_supplier"] = datarecord.supplier;
 						row["f_amount"] = 0;
 						row["f_cost"] = datarecord.cost;
+						row["f_type"] = datarecord.type;
+						row["f_yield"] = datarecord.yield;
+						row["f_color"] = datarecord.color;
+						row["f_coarse_fine_diff"] = datarecord.coarse_fine_diff;
+						row["f_moisture"] = datarecord.moisture;
+						row["f_diastatic_power"] = datarecord.diastatic_power;
+						row["f_protein"] = datarecord.protein;
+						row["f_max_in_batch"] = datarecord.max_in_batch;
+						row["f_graintype"] = datarecord.graintype;
+						if (datarecord.type == "Sugar") {
+							row["f_added"] = "Boil";
+						} else {
+							row["f_added"] = "Mash";
+						}
+						row["f_dissolved_protein"] = 0;
+						row["f_recommend_mash"] = datarecord.recommend_mash;
+						row["f_add_after_boil"] = datarecord.add_after_boil;
+						row["f_adjust_to_total_100"] = 0;
+						row["f_percentage"] = 0;
+						row["f_di_ph"] = datarecord.di_ph;
 						var commit = $("#fermentableGrid").jqxGrid('addrow', null, row);
 					}
 				});
 
 				// delete selected fermentable.
 				// Precentage aanpassen basis mout.
-				$("#deleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
-				$("#deleterowbutton").on('click', function () {
+				$("#fdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
+				$("#fdeleterowbutton").on('click', function () {
 					var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex');
 					var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
 					if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
@@ -260,6 +285,7 @@
 			columns: [
 				{ text: 'Mout/suiker', editable: false, datafield: 'f_name' },
 				{ text: 'Type', editable: false, width: 100, datafield: 'f_type' },
+				{ text: 'Opbrengst', datafield: 'f_yield', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
 				{ text: 'Gewicht', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
 				  columntype: 'numberinput',
 				  validation: function (cell, value) {
@@ -268,7 +294,17 @@
 				  	}
 				  	return true;
 				  }
-				}
+				},
+				{ text: 'Procent', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p3',
+				  columntype: 'numberinput',
+				  validation: function (cell, value) {
+					if (value < 0 || value > 100) {
+						return { result: false, message: "Percentage moet 0-100 zijn" };
+					}
+					return true;
+				  }
+				},
+				{ text: '100%', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 80 }
 			]
 		})
 	};
@@ -342,10 +378,10 @@
 				var me = this;
 				var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
 				toolbar.append(container);
-				container.append('<div style="float: left; margin-left: 165px;" id="addrowbutton"></div>');
-				container.append('<input style="float: left; margin-left: 230px;" id="deleterowbutton" type="button" value="Verwijder water" />');
+				container.append('<div style="float: left; margin-left: 165px;" id="waddrowbutton"></div>');
+				container.append('<input style="float: left; margin-left: 230px;" id="wdeleterowbutton" type="button" value="Verwijder water" />');
 				// add water from dropdownlist.
-				$("#addrowbutton").jqxDropDownList({
+				$("#waddrowbutton").jqxDropDownList({
 					placeHolder: "Kies water:",
 					theme: theme,
 					source: waterlist,
@@ -354,7 +390,7 @@
 					height: 27,
 					dropDownWidth: 300
 				});
-				$("#addrowbutton").on('select', function (event) {
+				$("#waddrowbutton").on('select', function (event) {
 					if (event.args) {
 						var index = event.args.index;
 						var datarecord = waterlist.records[index];
@@ -376,8 +412,8 @@
 
 				// delete selected water.
 				// Overgebleven waters in volume verhogen met het verwijderde water.
-				$("#deleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
-				$("#deleterowbutton").on('click', function () {
+				$("#wdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
+				$("#wdeleterowbutton").on('click', function () {
 					var selectedrowindex = $("#waterGrid").jqxGrid('getselectedrowindex');
 					var rowscount = $("#waterGrid").jqxGrid('getdatainformation').rowscount;
 					if (selectedrowindex >= 0 && selectedrowindex < rowscount) {

mercurial