Added hops inline editor framework

Thu, 20 Sep 2018 17:50:30 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 20 Sep 2018 17:50:30 +0200
changeset 58
83ccc36df675
parent 57
bb9a06aa9acd
child 59
ad28e09e3abd

Added hops inline editor framework

www/gethopsources.php file | annotate | diff | comparison | revisions
www/import/from_brouwhulp.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/gethopsources.php	Thu Sep 20 17:50:30 2018 +0200
@@ -0,0 +1,31 @@
+<?php
+require_once('config.php');
+
+$query = "SELECT * FROM inventory_hops 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)) {
+	$hops[] = array(
+		'record' => $row['record'],
+		'name' => $row['name'],
+		'alpha' => $row['alpha'],
+		'beta' => $row['beta'],
+		'humulene' => $row['humulene'],
+		'caryophyllene' => $row['caryophyllene'],
+		'cohumulone' => $row['cohumulone'],
+		'myrcene' => $row['myrcene'],
+		'hsi' => $row['hsi'],
+		'total_oil' => $row['total_oil'],
+		'useat' => $row['useat'],
+		'type' => $row['type'],
+		'form' => $row['form'],
+		'origin' => $row['origin'],
+		'inventory' => $row['inventory'],
+		'cost' => $row['cost']
+	);
+}
+echo json_encode($hops);
--- a/www/import/from_brouwhulp.php	Thu Sep 20 16:19:09 2018 +0200
+++ b/www/import/from_brouwhulp.php	Thu Sep 20 17:50:30 2018 +0200
@@ -598,7 +598,7 @@
 				$hops .= ',"h_cost":' . floatval($hop->COST);
 				$hops .= ',"h_type":"' . mysqli_real_escape_string($db, $hop->TYPE) . '"';
 				$hops .= ',"h_form":"' . mysqli_real_escape_string($db, $hop->FORM) . '"';
-				$hops .= ',"h_use":"' . mysqli_real_escape_string($db, $hop->USE) . '"';
+				$hops .= ',"h_useat":"' . mysqli_real_escape_string($db, $hop->USE) . '"';
 				if ($hop->TIME)
 					$hops .= ',"h_time":' . floatval($hop->TIME);
 				$hops .= ',"h_alpha":' . floatval($hop->ALPHA);
--- a/www/js/recipes.js	Thu Sep 20 16:19:09 2018 +0200
+++ b/www/js/recipes.js	Thu Sep 20 17:50:30 2018 +0200
@@ -310,6 +310,151 @@
 	};
 
 	// Inline hops editor
+        var editHop = function (data) {
+                var hopSource = {
+                        localdata: data.hops,
+                        datatype: "local",
+                        datafields: [
+                                { name: 'h_name', type: 'string' },
+                                { name: 'h_origin', type: 'string' },
+                                { name: 'h_amount', type: 'float' },
+                                { name: 'h_cost', type: 'float' },
+				{ name: 'h_type', type: 'string' },
+				{ name: 'h_form', type: 'string' },
+				{ name: 'h_useat', type: 'string' },
+                                { name: 'h_time', type: 'float' },
+				{ name: 'h_alpha', type: 'float' },
+				{ name: 'h_beta', type: 'float' },
+				{ name: 'h_hsi', type: 'float' },
+				{ name: 'h_humulene', type: 'float' },
+				{ name: 'h_carophyllene', type: 'float' },
+				{ name: 'h_cohumulone', type: 'float' },
+				{ name: 'h_myrcene', type: 'float' },
+				{ name: 'h_total_oil', type: 'float' }
+                        ],
+                        addrow: function (rowid, rowdata, position, commit) {
+                                commit(true);
+                        },
+                        deleterow: function (rowid, commit) {
+                                commit(true);
+                        }
+                };
+                var hopAdapter = new $.jqx.dataAdapter(hopSource);
+                // dropdownlist datasource from inventory_hops
+                var hopUrl = "gethopsources.php";
+                var hopInvSource = {
+                        datatype: "json",
+                        datafields: [
+                                { name: 'record', type: 'number' },
+                                { name: 'name', type: 'string' },
+				{ name: 'origin', type: 'string' },
+                                { name: 'type', type: 'string' },
+                                { name: 'alpha', type: 'float' },
+                                { name: 'beta', type: 'float' },
+				{ name: 'humulene', type: 'float' },
+				{ name: 'caryophyllene', type: 'float' },
+				{ name: 'cohumulone', type: 'float' },
+				{ name: 'myrcene', type: 'float' },
+				{ name: 'hsi', type: 'float' },
+                                { name: 'useat', type: 'string' },
+				{ name: 'form', type: 'string' },
+				{ name: 'total_oil', type: 'float' },
+				{ name: 'cost', type: 'float' }
+                        ],
+                        url: hopUrl,
+                        async: true
+                };
+                var hoplist = new $.jqx.dataAdapter(hopInvSource);
+
+                $("#hopGrid").jqxGrid({
+                        width: 960,
+                        height: 400,
+                        source: hopAdapter,
+                        theme: theme,
+                        selectionmode: 'singlerow',
+                        editmode: 'selectedrow',
+                        editable: true,
+                        localization: getLocalization(),
+                        showtoolbar: true,
+                        rendertoolbar: function (toolbar) {
+                                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="haddrowbutton"></div>');
+                                container.append('<input style="float: left; margin-left: 230px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');
+                                // add hop from dropdownlist.
+                                $("#haddrowbutton").jqxDropDownList({
+                                        placeHolder: "Kies hop:",
+                                        theme: theme,
+                                        source: hoplist,
+                                        displayMember: "name",
+                                        width: 150,
+                                        height: 27,
+                                        dropDownWidth: 300
+                                });
+                                $("#haddrowbutton").on('select', function (event) {
+                                        if (event.args) {
+                                                var index = event.args.index;
+                                                var datarecord = hoplist.records[index];
+                                                var row = {};
+                                                row["h_name"] = datarecord.name;
+                                                row["h_origin"] = datarecord.origin;
+                                                row["h_amount"] = 0;
+                                                row["h_cost"] = datarecord.cost;
+                                                row["h_type"] = datarecord.type;
+						row["h_form"] = datarecord.form;
+						row["h_useat"] = datarecord.useat;
+						row["h_time"] = 0;
+						row["h_alpha"] = datarecord.alpha;
+						row["h_beta"] = datarecord.beta;
+						row["h_hsi"] = datarecord.hsi;
+						row["h_humulene"] = datarecord.humulene;
+						row["h_carophyllene"] = datarecord.carophyllene;
+						row["h_cohumulone"] = datarecord.cohumulone;
+						row["h_myrcene"] = datarecord.myrcene;
+						row["h_total_oil"] = datarecord.total_oil;
+                                                var commit = $("#hopGrid").jqxGrid('addrow', null, row);
+                                        }
+                                });
+
+                                // delete selected hop.
+                                $("#hdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
+                                $("#hdeleterowbutton").on('click', function () {
+                                        var selectedrowindex = $("#hopGrid").jqxGrid('getselectedrowindex');
+                                        var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount;
+                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+                                                var id = $("#hopGrid").jqxGrid('getrowid', selectedrowindex);
+                                                var commit = $("#hopGrid").jqxGrid('deleterow', id);
+                                        }
+                                });
+                        },
+                        columns: [
+                                { text: 'Hop', editable: false, datafield: 'h_name' },
+                                { text: 'Type', editable: false, width: 100, datafield: 'h_type' },
+                                { text: 'Alpha', datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
+				{ text: 'Beta', datafield: 'h_beta', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
+                                { text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
+                                  columntype: 'numberinput',
+                                  validation: function (cell, value) {
+                                        if (value < 0 || value > 100000000000 ) {
+                                                return { result: false, message: "Volume moet  0-~ zijn" };
+                                        }
+                                        return true;
+                                  }
+                                },
+				{ text: 'Tijd', datafield: 'h_time', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f0',
+				  columntype: 'numberinput',
+				  validation: function (cell, value) {
+				  	if (value < 0 || value > 100000000000 ) {
+						return { result: false, message: "De tijd moet  0-~ zijn" };
+					}
+					return true;
+				  }
+				}
+                        ]
+                })
+        };
+
 
 	// Inline miscs editor
 
@@ -510,6 +655,7 @@
 				$("#mash_ph").val(5.4);
 				$("#mash_name").val('');
 				editFermentable('');
+				editHop('');
 				editWater('');
 				$("#popupWindow").jqxWindow('open');
 			});
@@ -553,6 +699,7 @@
 					$("#mash_ph").val(dataRecord.mash_ph);
 					$("#mash_sparge_temp").val(dataRecord.mash_sparge_temp);
 					editFermentable(dataRecord);
+					editHop(dataRecord);
 					editWater(dataRecord);
 					// show the popup window.
 					$("#popupWindow").jqxWindow('open');
@@ -603,6 +750,7 @@
 	// update the edited row when the user clicks the 'Save' button.
 	$("#Save").click(function () {
 		var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
+		var hoprow = $('#hopGrid').jqxGrid('getrows');
 		var waterrow = $('#waterGrid').jqxGrid('getrows');
 		if (editrow >= 0) {
 			var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
@@ -640,6 +788,7 @@
 				mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
 				mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
 				fermentables: fermentablerow,
+				hops: hopwor,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('updaterow', rowID, row);
@@ -679,6 +828,7 @@
 				mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
 				mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
 				fermentables: fermentablerow,
+				hops: hoprow,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('addrow', null, newrow);

mercurial