# HG changeset patch # User Michiel Broek # Date 1590228213 -7200 # Node ID 0ce464e42d8bb04b9f258f17b704e7a4eeb49922 # Parent 93ea9572c780ebae6e2f5216f78a8177fa05e60a Manual sort of mash steps. Removed some debug logging. Better add mashsteps, set temperature 2 degrees above the previous step. diff -r 93ea9572c780 -r 0ce464e42d8b www/js/profile_mash.js --- a/www/js/profile_mash.js Thu May 21 17:14:08 2020 +0200 +++ b/www/js/profile_mash.js Sat May 23 12:03:33 2020 +0200 @@ -1,9 +1,9 @@ /***************************************************************************** - * Copyright (C) 2014-2019 + * Copyright (C) 2014-2020 * * Michiel Broek * - * This file is part of BrewCloud + * This file is part of Brewery Management System * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -73,7 +73,6 @@ type: 'POST', success: function(data, status, xhr) { commit(true); - console.log('mash deleterow ' + rowid + ' success'); location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { @@ -92,7 +91,6 @@ type: 'POST', success: function(data, status, xhr) { commit(true); - console.log('mash addrow ' + rowid + ' success'); location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { @@ -111,7 +109,6 @@ type: 'POST', success: function(data, status, xhr) { commit(true); - console.log('mash updaterow ' + rowid + ' success'); location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { @@ -126,16 +123,6 @@ // Inline steps editor editsteps = function(data) { - var generaterow = function() { - var row = {}; - row['step_name'] = 'Stap 1'; - row['step_type'] = 0; - row['step_temp'] = 62.0; - row['step_time'] = 20.0; - row['ramp_time'] = 1.0; - row['end_temp'] = 62.0; - return row; - }; var stepSource = { localdata: data.steps, datatype: 'local', @@ -147,12 +134,8 @@ { name: 'ramp_time', type: 'float' }, { name: 'end_temp', type: 'float' } ], - addrow: function(rowid, rowdata, position, commit) { - commit(true); - }, - deleterow: function(rowid, commit) { - commit(true); - } + addrow: function(rowid, rowdata, position, commit) { commit(true); }, + deleterow: function(rowid, commit) { commit(true); } }, stepAdapter = new $.jqx.dataAdapter(stepSource); @@ -172,8 +155,19 @@ $('#deleterowbutton').jqxButton({ template: 'danger', theme: theme, width: 150 }); // create new row. $('#addrowbutton').on('click', function() { - var datarow = generaterow(); - $('#grid').jqxGrid('addrow', null, datarow); + var row = {}, rowscount = $('#grid').jqxGrid('getdatainformation').rowscount; + var temp = $('#grid').jqxGrid('getcell', rowscount -1, 'step_temp'); + row['step_name'] = 'Stap ' + (rowscount + 1); + if (rowscount > 0) { + row['step_type'] = 1; + row['step_temp'] = row['end_temp'] = temp.value + 2; + } else { + row['step_type'] = 0; + row['step_temp'] = row['end_temp'] = 62.0; + } + row['step_time'] = 20.0; + row['ramp_time'] = 1.0; + $('#grid').jqxGrid('addrow', null, row); }); // delete row. $('#deleterowbutton').on('click', function() { @@ -189,14 +183,38 @@ { text: 'Stap naam', datafield: 'step_name' }, { text: 'Stap type', datafield: 'step_type', width: 150, cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { - return '
' + MashStepTypeData[value].nl + '
'; + return '' + MashStepTypeData[value].nl + ''; } }, - { text: 'Begin °C', datafield: 'step_temp', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, - { text: 'Eind °C', datafield: 'end_temp', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Start °C', datafield: 'step_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Eind °C', datafield: 'end_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, { text: 'Rust min.', datafield: 'step_time', width: 90, align: 'right', cellsalign: 'right' }, { text: 'Stap min.', datafield: 'ramp_time', width: 90, align: 'right', cellsalign: 'right' }, - { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', + { text: '', columntype: 'button', width: 15, align: 'center', + cellsrenderer: function(row) { + if (row < 2) + return ' '; + return '▴'; + }, buttonclick: function(row) { + if (row >= 2) { + swapMash(row, row-1); + } + } + }, + { text: '', columntype: 'button', width: 15, align: 'center', + cellsrenderer: function(row) { + rowscount = $('#grid').jqxGrid('getdatainformation').rowscount; + if (row < 1 || row > (rowscount -2)) + return ' '; + return '▾'; + }, buttonclick: function(row) { + rowscount = $('#grid').jqxGrid('getdatainformation').rowscount; + if (row >= 1 && row <= (rowscount -2)) { + swapMash(row, row+1); + } + } + }, + { text: '', datafield: 'Edit', columntype: 'button', width: 80, align: 'center', cellsrenderer: function() { return 'Wijzig'; }, buttonclick: function(row) { @@ -247,10 +265,10 @@ theme: theme, showstatusbar: true, renderstatusbar: function(statusbar) { - var addButton, container = $('
'); - addButton = $('
'); + var addButton = $('
Add
'); - expButton = $('
Export
'); container.append(addButton); container.append(expButton); @@ -269,8 +287,6 @@ window.open('export_mashs.php'); }); }, - filterable: true, - filtermode: 'excel', columns: [ { text: 'Maish schema', datafield: 'name', width: 250 }, { text: 'Opmerkingen', datafield: 'notes' }, @@ -364,6 +380,20 @@ } $('#popupWindow').jqxWindow('hide'); }); + + function swapMash(r1, r2) { + + console.log('swap mash rows ' + r1 + ' ' + r2); + var row1 = $('#grid').jqxGrid('getrowdata', r1); + var row2 = $('#grid').jqxGrid('getrowdata', r2); + var obj1 = { step_name: row1.step_name, step_type: row1.step_type, step_temp: row1.step_temp, step_time: row1.step_time, + ramp_time: row1.ramp_time, end_temp: row1.end_temp }; + var obj2 = { step_name: row2.step_name, step_type: row2.step_type, step_temp: row2.step_temp, step_time: row2.step_time, + ramp_time: row2.ramp_time, end_temp: row2.end_temp }; + $("#grid").jqxGrid('updaterow', r1, obj2); + $("#grid").jqxGrid('updaterow', r2, obj1); + } + createDelElements(); });