Manual sort of mash steps. Removed some debug logging. Better add mashsteps, set temperature 2 degrees above the previous step.

Sat, 23 May 2020 12:03:33 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 23 May 2020 12:03:33 +0200
changeset 688
0ce464e42d8b
parent 687
93ea9572c780
child 689
499c4921a90f

Manual sort of mash steps. Removed some debug logging. Better add mashsteps, set temperature 2 degrees above the previous step.

www/js/profile_mash.js file | annotate | diff | comparison | revisions
--- 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 <mbroek at mbse dot eu>
  *
- * 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 '<div style="margin: 4px;">' + MashStepTypeData[value].nl + '</div>';
+       return '<span style="margin: 4px; margin-top: 6px; float: left;">' + MashStepTypeData[value].nl + '</span>';
       }
     },
-    { text: 'Begin &deg;C', datafield: 'step_temp', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
-    { text: 'Eind &deg;C', datafield: 'end_temp', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
+    { text: 'Start &deg;C', datafield: 'step_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
+    { text: 'Eind &deg;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 = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
-   addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
+   var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
+   var addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
      'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Add</span></div>');
-   expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
+   var expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
      'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Export</span></div>');
    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();
 });
 

mercurial