www/js/mon_ispindel.js

Wed, 06 May 2020 14:14:14 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 May 2020 14:14:14 +0200
changeset 667
1246550451ca
parent 655
f4e00869f39f
child 680
0bb48333d133
permissions
-rw-r--r--

Removed the last compressed css file. Reworked all mash steps, implemented deconction steps. Added calculations for infuse amounts and decoctions amounts. The mash steps are now manually sorted in the editor grids to have full control over the steps order. Display errors in red in the grid. Updated beerxml export, the product checklist and print output of the products and recipes for all these mash steps changes.

/*****************************************************************************
 * Copyright (C) 2019-2020
 *
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of BMS
 *
 * 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
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * Brewery Management System istributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/


$(document).ready(function() {

 var record = {},
 blank = {},
 newProduct = false,
 newMode = false,
 schedule = 0,

 productSource = {
  datatype: 'json',
  cache: false,
  datafields: [
   { name: 'code', type: 'string' },
   { name: 'name', type: 'string' },
   { name: 'uuid', type: 'string' }
  ],
  id: 'code',
  url: 'includes/db_product.php?select=ferment'
 },
 productlist = new $.jqx.dataAdapter(productSource, {
  beforeLoadComplete: function(records) {
   var row, i, data = new Array();
   // Create a dummy beer on top to store in idle meters.
   blank['code'] = 'Free';  // Will override this later.
   blank['name'] = 'Dummy';
   blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5';
   data.push(blank);
   for (i = 0; i < records.length; i++) {
    row = records[i];
    data.push(row);
   }
   return data;
  },
  loadError: function(jqXHR, status, error) {
   $('#err').text(status + ' ' + error);
  },
 }),
 gaugeoptionst = {
  min: 10, max: 40, width: 375, height: 375,
  ranges: [{ startValue: 10, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
           { startValue: 20, endValue: 28, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
           { startValue: 28, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
  ticksMinor: { interval: 1, size: '5%' },
  ticksMajor: { interval: 5, size: '9%' },
  labels: { interval: 5 },
  style: { fill: '#eeeeee', stroke: '#666666' },
  value: 0,
  colorScheme: 'scheme05'
 },
 gaugeoptionsg = {
  orientation: 'vertical',
  labels: { position: 'near', interval: 10 },
  ticksMinor: { size: '5%', interval: 2 },
  ticksMajor: { size: '9%', interval: 10 },
  ticksPosition: 'near',
  min: 0990, max: 1150, width: 120, height: 375,
  value: 1000,
  pointer: { pointerType: 'arrow', size: '15%', visible: true, offset: 0 },
  colorScheme: 'scheme05',
  showRanges: false
 },
 url = 'getispindel.php?uuid="' + my_uuid + '"',
 source = {
  datatype: 'json',
  datafields: [
   { name: 'record', type: 'int' },
   { name: 'uuid', type: 'string' },
   { name: 'alias', type: 'string' },
   { name: 'node', type: 'string' },
   { name: 'online', type: 'int' },
   { name: 'beercode', type: 'string' },
   { name: 'beername', type: 'string' },
   { name: 'beeruuid', type: 'string' },
   { name: 'alarm', type: 'int' },
   { name: 'angle', type: 'float' },
   { name: 'temperature', type: 'float' },
   { name: 'battery', type: 'float' },
   { name: 'gravity', type: 'float' },
   { name: 'up_interval', type: 'int' },
   { name: 'mode', type: 'string' },
   { name: 'og_gravity', type: 'float' }
  ],
  id: 'record',
  url: url
 },
 dataAdapter = new $.jqx.dataAdapter(source, {
  loadComplete: function(records) {
   record = dataAdapter.records[0];
   var oline = (record.online) ? 'On-line' : 'Off-line';
   $('#info_uuid').html(record.uuid);
   $('#info_system').html(record.node + '/' + record.alias);
   $('#info_online').html(oline);
   $('#info_beer').html(record.beercode + ' - ' + record.beername);
   $('#info_mode').jqxDropDownList('selectItem', record.mode);
   blank['name'] = record.alias;
   blank['code'] = record.alias.toUpperCase();
   blank['uuid'] = record.uuid;

   if (record.online && (record.mode != 'OFF')) {
    $('#ispindel_powerled').html('<div class="LEDblue_on"></div>Power');
    $('#select_beer').jqxDropDownList({ disabled: true });
    $('#select_beer').jqxDropDownList('clearSelection');
    $('#select_beer').hide();
   } else {
    $('#ispindel_powerled').html('<div class="LEDblue_off"></div>Power');
    $('#select_beer').show();
    $('#select_beer').jqxDropDownList({ disabled: false });
   }
   if (record.online && (record.alarm != '0')) {
    $('#ispindel_alarmled').html('<div class="LEDred_on"></div>Alarm');
   } else {
    $('#ispindel_alarmled').html('<div class="LEDred_off"></div>Alarm');
   }

   $('#gaugeContainer_temperature').jqxGauge({ caption: { value: record.temperature.toFixed(3) + '°C' }});
   $('#gaugeContainer_temperature').jqxGauge({ value: record.temperature });

   var sg = plato_to_sg(record.gravity);

   $('#info_battery').val(record.battery);
   $('#info_tilt').val(record.angle);
   $('#info_plato').val(record.gravity);
   $('#info_sg').val(sg);

   if (record.og_gravity) {
    var og = plato_to_sg(record.og_gravity);
    var svg = calc_svg(og, sg);

    $('#vg_og1').html(og.toFixed(4));
    $('#vg_og2').html(record.og_gravity.toFixed(1) + '&deg;P');
    $('#vg_sg1').html(sg.toFixed(4));
    $('#vg_sg2').html(record.gravity.toFixed(1) + '&deg;P');
    $('#vg_svg').html(svg.toFixed(1) + '%');
    $('#vg_abv').html(abvol(og, sg).toFixed(2) + '%');
   } else {
    $('#vg_og1').html('');
    $('#vg_og2').html('');
    $('#vg_sg1').html('');
    $('#vg_sg2').html('');
    $('#vg_svg').html('');
    $('#vg_abv').html('');
   }

   var batt = record.battery - 3.064; // 0% voltage.
   if (batt < 0)
    batt = 0;
   batt = Math.round(batt / 1.17875 * 100); // 100% range
   if (batt > 100)
    batt = 100;
   $('#vg_batt').html(batt + '%');


   var gravity = sg * 1000;
   $('#gaugeContainer_gravity').jqxLinearGauge({ value: gravity });
  }
 });

 $('#select_beer').jqxDropDownList({
  placeHolder: 'Kies bier:',
  theme: theme,
  source: productlist,
  displayMember: 'code',
  width: 150,
  height: 24,
  dropDownWidth: 500,
  autoDropDownHeight: true,
  renderer: function(index, label, value) {
   var datarecord = productlist.records[index];
   return datarecord.code + ' - ' + datarecord.name;
  }
 });

 $('#info_battery').jqxNumberInput(Show3dec);
 $('#info_tilt').jqxNumberInput(Show5dec);
 $('#info_plato').jqxNumberInput(Show2dec);
 $('#info_sg').jqxNumberInput(Show4dec);

 $('#gaugeContainer_temperature').jqxGauge(gaugeoptionst);
 $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: 00.000' }});
 $('#gaugeContainer_gravity').jqxLinearGauge(gaugeoptionsg);

 srcMode = ['OFF', 'ON'];
 $('#info_mode').jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 65 });

 function sendProduct(code, name, uuid) {

  console.log('sendProduct(' + code + ', ' + name + ', ' + uuid + ')');
  var data = 'uuid=' + record.uuid + '&beeruuid=' + uuid + '&beercode=' + code + '&beername=' + name;
  $.ajax({
   url: 'cmd_ispindel.php',
   data: data,
   type: 'POST',
   success: function(data) {},
   error: function(jqXHR, textStatus, errorThrown) { console.log('sendProduct() error'); }
  });
 }

 function sendMode(mode) {

  console.log('sendMode(' + mode + ')');
  var data = 'uuid=' + record.uuid + '&mode=' + mode;
  $.ajax({
   url: 'cmd_ispindel.php',
   data: data,
   type: 'POST',
   success: function(data) {},
   error: function(jqXHR, textStatus, errorThrown) { console.log('sendMode() error'); }
  });
 }

 // Get the data immediatly and then at regular intervals to refresh.
 dataAdapter.dataBind();
 setInterval(function() {
  var skip = false;
  if (newMode) {
   sendMode(record.mode);
   newMode = false;
   skip = true;
  }
  if (newProduct) {
   sendProduct(record.beercode, record.beername, record.beeruuid);
   newProduct = false;
   skip = true;
  }
  if (skip) {
   schedule = 4; // 2 seconds wait to get the results
  } else {
   if (schedule > 0)
    schedule--;
  }

  if (schedule <= 0) {
   dataAdapter.dataBind();
   schedule = 20;
  }
 }, 500);

 $('#select_beer').on('select', function(event) {
  if (event.args) {
   var index = event.args.index,
   datarecord = productlist.records[index];
   record.beercode = datarecord.code;
   record.beername = datarecord.name;
   record.beeruuid = datarecord.uuid;
   newProduct = true;
  }
 });
 $('#info_mode').on('select', function(event) {
  if (event.args) {
   record.mode = event.args.item.value;
   newMode = true;
  }
 });

 // The chart button.
 $('#VLog').jqxButton({ template: 'primary', width: '150px', theme: theme });
 $('#VLog').click(function() {
  window.open('log_ispindel.php?code=' + record.beercode + '&name=' + record.beername);
 });
});

mercurial