www/js/log_fermentation.js

Wed, 20 May 2020 21:49:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 20 May 2020 21:49:09 +0200
changeset 684
ccb9f24d0fe9
parent 602
10b61aacb1c1
permissions
-rw-r--r--

Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.

/*****************************************************************************
 * 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 Managment System  is distributed 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() {

 $('#jqxMenu').jqxMenu('destroy');

 $('#jqxLoader').jqxLoader({
  width: 250,
  height: 150,
  isModal: true,
  text: 'Opmaken grafiek ...',
  theme: theme
 });
 $('#jqxLoader').jqxLoader('open');

 function getExportServer() {
  return 'https://www.jqwidgets.com/export_server/export.php';
 }

 var sourceA = {
  datatype: 'json',
  datafields: [
   { name: 'date', type: 'date', format: 'yyyy-MM-dd HH:mm' },
   { name: 'air', type: 'float' },
   { name: 'beer', type: 'float' },
   { name: 'chiller', type: 'float' },
   { name: 'room', type: 'float' },
   { name: 'tlo', type: 'float' },
   { name: 'thi', type: 'float' },
   { name: 'heater', type: 'int' },
   { name: 'cooler', type: 'int' },
   { name: 'event', type: 'string' }
  ],
  url: 'getfermentlog.php?code=' + my_code + '&name=' + my_name
 },
 dataAdapter = new $.jqx.dataAdapter(sourceA, {
  autoBind: true,
  async: false,
  loadComplete: function() {
   $('#jqxLoader').jqxLoader('close');
  },
  loadError: function(jqXHR, status, error) {
  }
 }),
 settings = {
   title: my_code + ' "' + my_name + '"',
   description: '',
   source: dataAdapter,
   xAxis: {
    dataField: 'date',
    type: 'date',
    formatFunction: function(value) {
     return value.getDate() + '-' + (value.getMonth() + 1) + '-' + value.getFullYear();
    },
    toolTipFormatFunction: function(value) {
     var h = value.getHours(), m = value.getMinutes();
     return value.getDate() + '-' + (value.getMonth() + 1) + '-' + value.getFullYear() +
      ' ' + (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m);
    },
    textRotationAngle: 45,
    howGridLines: false,
    rangeSelector: {
    size: 90,
    dataField: 'beer',
    serieType: 'line',
    gridLines: {visible: false},
   }
   },
   colorScheme: 'scheme01',
   seriesGroups: [
    {
    type: 'area',
    valueAxis: {
     minValue: 0,
     maxValue: 100,
     displayValueAxis: false,
     description: 'Verwarm/Koel %'
    },
    series: [
      { dataField: 'cooler', lineWidth: 1, displayText: 'Koel %', opacity: 0.4 },
      { dataField: 'heater', lineWidth: 1, displayText: 'Verwarm %', opacity: 0.3 }
     ]
    },
   {
    type: 'spline',
    valueAxis: {
     minValue: 0,
     description: 'Graden C'
    },
    series: [
     { dataField: 'air', lineWidth: 1, displayText: 'Lucht' },
     { dataField: 'beer', lineWidth: 2, displayText: 'Bier' },
     { dataField: 'tlo', lineWidth: 1, displayText: 'Doel laag', opacity: 0.7 },
     { dataField: 'thi', lineWidth: 1, displayText: 'Doel hoog', opacity: 0.7 },
     { dataField: 'room', lineWidth: 1, displayText: 'Ruimte', opacity: 0.5 },
     { dataField: 'chiller', lineWidth: 1, displayText: 'Koeler', color: '#0000bb' }
    ]
   }
   ]
 };
 $('#fermenter_chart').jqxChart(settings);

 $('#print').click(function() {
  var content = $('#fermenter_chart')[0].outerHTML,
  newWindow = window.open('', '', 'width=865, height=425'),
  document = newWindow.document.open(),
  pageContent =
   '<!DOCTYPE html>' +
   '<html>' +
   '<head>' +
   '<link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />' +
   '<meta charset="utf-8" />' +
   '<title>' + my_code + ' ' + my_name + ' klimaatkast</title>' +
   '</head>' +
   '<body>' + content + '</body></html>';
  document.write(pageContent);
  document.close();
  newWindow.print();
 });
 $('#print').jqxButton({ template: 'primary', width: 125, theme: theme });

 $('#pdfButton').click(function() {
  $('#fermenter_chart').jqxChart('saveAsPDF', 'klimaatkast_' + my_code + '.pdf', getExportServer());
 });
 $('#pdfButton').jqxButton({ template: 'primary', width: 125, theme: theme });

 $('#pngButton').click(function() {
  $('#fermenter_chart').jqxChart('saveAsPNG', 'klimaatkast_' + my_code + '.png', getExportServer());
 });
 $('#pngButton').jqxButton({ template: 'primary', width: 125, theme: theme });

 $('#Close').jqxButton({ template: 'success', width: 125, theme: theme });
 $('#Close').click(function() {
  window.close();
 });
});

mercurial