www/js/mon_co2meter.js

Sun, 23 May 2021 16:41:35 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 23 May 2021 16:41:35 +0200
changeset 752
f68e3bbc1ada
parent 694
a165f6c20a44
permissions
-rw-r--r--

Fermentables, hops, miscs and yeast now have tests against the added moment with the brewing stage. Added to inventory edit rows, delete rows, and pick choices for the moment to add or edit. Some more popups to explain certain blocks.

/*****************************************************************************
 * 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 = {},

 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) { console.log(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'
 },
 gaugeoptionsp = {
  min: 0, max: 6, width: 375, height: 375,
  ranges: [{ startValue: 0, endValue: 3, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
           { startValue: 3, endValue: 6, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
  ticksMinor: { interval: 0.2, size: '5%' },
  ticksMajor: { interval: 1, size: '9%' },
  labels: { interval: 1 },
  style: { fill: '#eeeeee', stroke: '#666666' },
  value: 0,
  colorScheme: 'scheme05'
 },
 url = 'getco2meter.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: 'mode', type: 'string' },
   { name: 'alarm', type: 'int' },
   { name: 'temperature_state', type: 'string' },
   { name: 'temperature_address', type: 'string' },
   { name: 'temperature', type: 'float' },
   { name: 'pressure_state', type: 'string' },
   { name: 'pressure_channel', type: 'int' },
   { name: 'pressure_voltage', type: 'float' },
   { name: 'pressure_zero', type: 'float' },
   { name: 'pressure_bar', type: 'float' }
  ],
  id: 'record',
  url: url
 },
 dataAdapter = new $.jqx.dataAdapter(source, {
  loadComplete: function(records) {
   record = dataAdapter.records[0];
   updateScreen();
   blank['name'] = record.alias;
   blank['code'] = record.alias.toUpperCase();
   blank['uuid'] = record.uuid;
  }
 });

 function updateScreen() {
   $('#info_uuid').html(record.uuid);
   $('#info_system').html(record.node + '/' + record.alias);
   $('#info_beer').html(record.beercode + ' - ' + record.beername);
   $('#info_mode').html(record.mode);

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

  if (record.online) {
   $('#info_online').html('On-line');
   if (record.temperature_state == 'OK') {
    $('#gaugeContainer_temperature').jqxGauge({ disabled: false });
   } else {
    $('#gaugeContainer_temperature').jqxGauge({ disabled: true });
   }
   if (record.pressure_state == 'OK') {
    $('#gaugeContainer_pressure').jqxGauge({ disabled: false });
   } else {
    $('#gaugeContainer_pressure').jqxGauge({ disabled: true });
   }
   $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: ' + record.temperature.toFixed(3) }});
   $('#gaugeContainer_temperature').jqxGauge({ value: record.temperature });
   $('#gaugeContainer_pressure').jqxGauge({ caption: { value: 'Bar: ' + record.pressure_bar.toFixed(2) }});
   $('#gaugeContainer_pressure').jqxGauge({ value: record.pressure_bar });
  } else {
   $('#info_online').html('Off-line');
   $('#gaugeContainer_temperature').jqxGauge({ disabled: true });
   $('#gaugeContainer_pressure').jqxGauge({ disabled: true });
  }
 }

 $('#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;
  }
 });

 $('#gaugeContainer_temperature').jqxGauge(gaugeoptionst);
 $('#gaugeContainer_temperature').jqxGauge({ caption: { value: 'Temp: 00.000' }});
 $('#gaugeContainer_pressure').jqxGauge(gaugeoptionsp);
 $('#gaugeContainer_pressure').jqxGauge({ caption: { value: 'Bar: 00.000' }});

 // Get the data
 dataAdapter.dataBind();

 $('#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;
   console.log('Select beer ' + record.beercode + ', ' + record.beername);
   websocket.send('{"device":"co2meters","node":"' + record.node + '","unit":"' + record.alias +
             '","beeruuid":"' + record.beeruuid + '","beercode":"' + record.beercode + '","beername":"' + record.beername + '"}');
  }
 });

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

 websocket.onmessage = function(evt) {
  var msg = evt.data;
  var obj = JSON.parse(msg);
  if (obj.device == "co2meters" && obj.node == record.node && obj.unit == record.alias) {
   console.log('ws got this device ' + msg);
   record.online = obj.online;
   if (obj.online) {
    record.beeruuid = obj.beeruuid;
    record.beercode = obj.beercode;
    record.beername = obj.beername;
    record.mode = obj.mode;
    record.alarm = obj.alarm;
    record.temperature_state = obj.temperature_state;
    record.temperature_address = obj.temperature_address;
    record.temperature = obj.temperature;
    record.pressure_state = obj.pressure_state;
    record.pressure_channel = obj.pressure_channel;
    record.pressure_voltage = obj.pressure_voltage;
    record.pressure_zero = obj.pressure_zero;
    record.pressure_bar = obj.pressure_bar;
   }
   updateScreen();
  }
 }
});

mercurial