# HG changeset patch # User Michiel Broek # Date 1544912531 -3600 # Node ID 122f6471616137658198de4df7d8f8e74d8cf774 # Parent 793af7691a5eb8188e8943aff366f1b0cfbec198 During recipes import of miscs ingredients, convert time in Secondary to days. The hop grid also display the country of origin. Misc ingredients now use a temporary weight table just like the hops. diff -r 793af7691a5e -r 122f64716161 www/import/from_brouwhulp.php --- a/www/import/from_brouwhulp.php Sat Dec 15 21:27:01 2018 +0100 +++ b/www/import/from_brouwhulp.php Sat Dec 15 23:22:11 2018 +0100 @@ -664,9 +664,12 @@ $miscs .= ',"m_type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"'; $miscs .= ',"m_use_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"'; ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":true' : $miscs.= ',"m_amount_is_weight":false'; - if ($misc->TIME) - $miscs .= ',"m_time":' . floatval($misc->TIME); - else + if ($misc->TIME) { + if (mysqli_real_escape_string($db, $misc->USE) == "Secondary") + $miscs .= ',"m_time":' . floatval($misc->TIME) / 1440; + else + $miscs .= ',"m_time":' . floatval($misc->TIME); + } else $miscs .= ',"m_time":0'; $miscs .= "}"; } diff -r 793af7691a5e -r 122f64716161 www/includes/db_recipes.php --- a/www/includes/db_recipes.php Sat Dec 15 21:27:01 2018 +0100 +++ b/www/includes/db_recipes.php Sat Dec 15 23:22:11 2018 +0100 @@ -14,7 +14,7 @@ $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"); $rescapers = array("'"); $rreplacements = array("\\'"); -$disallowed = array('visibleindex','uniqueid','boundindex','uid','h_weight'); +$disallowed = array('visibleindex','uniqueid','boundindex','uid','h_weight','m_weight'); if (isset($_POST['insert']) || isset($_POST['update'])) { if (isset($_POST['insert'])) { diff -r 793af7691a5e -r 122f64716161 www/js/rec_edit.js --- a/www/js/rec_edit.js Sat Dec 15 21:27:01 2018 +0100 +++ b/www/js/rec_edit.js Sat Dec 15 23:22:11 2018 +0100 @@ -877,7 +877,7 @@ var hoplist = new $.jqx.dataAdapter(hopInvSource); $("#hopGrid").jqxGrid({ - width: 1150, + width: 1050, height: 400, source: hopAdapter, theme: theme, @@ -948,7 +948,13 @@ $('#jqxTabs').jqxTabs('next'); }, columns: [ - { text: 'Hop', editable: false, datafield: 'h_name' }, + { text: 'Hop', editable: false, datafield: 'h_name', + cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) { + var rowData = $("#hopGrid").jqxGrid('getrowdata', row); + return "" +rowData.h_origin+" / "+rowData.h_name+""; + }, + }, { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' }, { text: 'Vorm', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_form' }, { text: 'Alpha', editable: false, datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, @@ -1052,7 +1058,8 @@ { name: 'm_type', type: 'string' }, { name: 'm_use_use', type: 'string' }, { name: 'm_time', type: 'float' }, - { name: 'm_amount_is_weight', type: 'bool' } + { name: 'm_amount_is_weight', type: 'bool' }, + { name: 'm_weight', type: 'float' } ], addrow: function (rowid, rowdata, position, commit) { commit(true); @@ -1061,7 +1068,20 @@ commit(true); } }; - var miscAdapter = new $.jqx.dataAdapter(miscSource); + var miscAdapter = new $.jqx.dataAdapter(miscSource, { + beforeLoadComplete: function (records) { + var data = new Array(); + for (var i = 0; i < records.length; i++) { + var row = records[i]; + row.m_weight = row.m_amount * 1000; + data.push(row); + } + return data; + }, + loadError: function(jqXHR, status, error) { + $('#err').text(status + ' ' + error); + }, + }); // dropdownlist datasource from inventory_miscs var miscUrl = "getmiscsources.php"; var miscInvSource = { @@ -1117,6 +1137,7 @@ row["m_type"] = datarecord.type; row["m_use_use"] = datarecord.use_use; row["m_time"] = 0; + row["m_weight"] = 0; row["m_amount_is_weight"] = datarecord.amount_is_weight; var commit = $("#miscGrid").jqxGrid('addrow', null, row); } @@ -1146,12 +1167,11 @@ }, { datafield: 'm_amount_is_weight', hidden: true }, // We need to declare this column { datafield: 'm_amount', hidden: true }, // We need to declare this column - { text: 'Hoeveelheid', datafield: 'grammen', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f2', + { text: 'Hoeveelheid', datafield: 'm_weight', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f2', columntype: 'numberinput', cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { - var gram = rowdata.m_amount * 1000; var vstr = rowdata.m_amount_is_weight ? "gr":"ml"; - return "
"+dataAdapter.formatNumber(gram,"f2")+" "+vstr+"
"; + return "
"+dataAdapter.formatNumber(value,"f2")+" "+vstr+"
"; }, validation: function (cell, value) { var high = parseFloat(dataRecord.boil_size) * 1000; @@ -1161,19 +1181,19 @@ return true; }, initeditor: function (row, cellvalue, editor) { - editor.jqxNumberInput({ inputMode: 'simple', min: 0, decimalDigits: 2, spinButtons: false }); + editor.jqxNumberInput({ + inputMode: 'simple', min: 0, max: parseFloat(dataRecord.boil_size) * 1000, + decimalDigits: 2, spinButtons: false + }); } }, - { datafield: 'm_time' }, - { text: 'Tijd', datafield: 'time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0', + { text: 'Tijd', datafield: 'm_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0', columntype: 'numberinput', cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { if (rowdata.m_use_use == 'Boil') { - var tijd = rowdata.m_time; - return "
"+dataAdapter.formatNumber(tijd, "f0")+" m
"; + return "
"+dataAdapter.formatNumber(value, "f0")+" m
"; } else if (rowdata.m_use_use == 'Secondary') { - var tijd = Math.round(rowdata.m_time / 1440); - return "
"+dataAdapter.formatNumber(tijd, "f0")+" d
"; + return "
"+dataAdapter.formatNumber(value, "f0")+" d
"; } else { var tijd = 0; return "
"; @@ -1184,7 +1204,7 @@ }, cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { var use = $("#miscGrid").jqxGrid('getcellvalue', row, "m_use_use"); - if (use != "Boil") + if ((use != "Boil") && (use != "Secondary")) return oldvalue; }, validation: function (cell, value) { @@ -1200,17 +1220,9 @@ $("#miscGrid").on('cellendedit', function (event) { var args = event.args; console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value); - if (args.datafield == 'grammen') { - $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_amount', parseFloat(args.value / 1000)); - } else if (args.datafield == 'time') { - var use_use = $("#miscGrid").jqxGrid('getcellvalue', args.rowindex, 'm_use_use'); - console.log("use: "+use_use); - if (use_use == 'Secondary') - $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_time', parseFloat(args.value * 1440)); - else - $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_time', parseFloat(args.value)); - } else { - $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value); + $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value); + if (args.datafield == 'm_weight') { + $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_amount', parseFloat(args.value) / 1000); } }); };