|
1 /***************************************************************************** |
|
2 * Copyright (C) 2019 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of BMS |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * Brewery Management System istributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 |
|
24 $(document).ready(function () { |
|
25 |
|
26 var record = {}, |
|
27 blank = {}, |
|
28 // newBase = false, |
|
29 // newProduct = false, |
|
30 schedule = 0, |
|
31 |
|
32 productSource = { |
|
33 datatype: "json", |
|
34 cache: false, |
|
35 datafields: [ |
|
36 { name: 'code', type: 'string' }, |
|
37 { name: 'name', type: 'string' }, |
|
38 { name: 'uuid', type: 'string' } |
|
39 ], |
|
40 id: 'code', |
|
41 url: "includes/db_product.php?select=ferment" |
|
42 }, |
|
43 productlist = new $.jqx.dataAdapter(productSource, { |
|
44 beforeLoadComplete: function (records) { |
|
45 var row, i, data = new Array(); |
|
46 // Create a dummy beer on top to store in idle fermenters. |
|
47 blank['code'] = "Free"; // Will override this later. |
|
48 blank['name'] = 'Dummy'; |
|
49 blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5'; |
|
50 data.push(blank); |
|
51 for (i = 0; i < records.length; i++) { |
|
52 row = records[i]; |
|
53 data.push(row); |
|
54 } |
|
55 return data; |
|
56 }, |
|
57 loadError: function(jqXHR, status, error) { |
|
58 $('#err').text(status + ' ' + error); |
|
59 }, |
|
60 }), |
|
61 gaugeoptionst = { |
|
62 min: 0, max: 40, width: 375, height: 375, |
|
63 ranges: [{ startValue: 0, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
|
64 { startValue: 20, endValue: 26, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
|
65 { startValue: 26, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], |
|
66 ticksMinor: { interval: 1, size: '5%' }, |
|
67 ticksMajor: { interval: 5, size: '9%' }, |
|
68 labels: { interval: 5 }, |
|
69 style: { fill: '#eeeeee', stroke: '#666666' }, |
|
70 value: 0, |
|
71 colorScheme: 'scheme05' |
|
72 }, |
|
73 gaugeoptionsp = { |
|
74 min: 0, max: 6, width: 375, height: 375, |
|
75 ranges: [{ startValue: 0, endValue: 3, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
|
76 { startValue: 3, endValue: 6, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], |
|
77 ticksMinor: { interval: 0.2, size: '5%' }, |
|
78 ticksMajor: { interval: 1, size: '9%' }, |
|
79 labels: { interval: 1 }, |
|
80 style: { fill: '#eeeeee', stroke: '#666666' }, |
|
81 value: 0, |
|
82 colorScheme: 'scheme05' |
|
83 }, |
|
84 url = "getco2meter.php?uuid='" + my_uuid + "'", |
|
85 source = { |
|
86 datatype: "json", |
|
87 datafields: [ |
|
88 { name: 'record', type: 'int' }, |
|
89 { name: 'uuid', type: 'string' }, |
|
90 { name: 'alias', type: 'string' }, |
|
91 { name: 'node', type: 'string' }, |
|
92 { name: 'online', type: 'int' }, |
|
93 { name: 'beercode', type: 'string' }, |
|
94 { name: 'beername', type: 'string' }, |
|
95 { name: 'beeruuid', type: 'string' }, |
|
96 { name: 'mode', type: 'string' }, |
|
97 { name: 'temperature_state', type: 'string' }, |
|
98 { name: 'temperature', type: 'float' }, |
|
99 { name: 'pressure_state', type: 'string' }, |
|
100 { name: 'pressure_bar', type: 'float' } |
|
101 ], |
|
102 id: 'record', |
|
103 url: url |
|
104 }, |
|
105 dataAdapter = new $.jqx.dataAdapter(source, { |
|
106 loadComplete: function (records) { |
|
107 record = dataAdapter.records[0]; |
|
108 var oline = (record.online) ? "On-line" : "Off-line"; |
|
109 $("#info_uuid").html(record.uuid); |
|
110 $("#info_system").html(record.node + "/" + record.alias); |
|
111 $("#info_online").html(oline); |
|
112 $("#info_mode").jqxDropDownList('selectItem', record.mode); |
|
113 blank['name'] = record.alias; |
|
114 blank['code'] = record.alias.toUpperCase(); |
|
115 blank['uuid'] = record.uuid; |
|
116 |
|
117 if (record.online && (record.mode != "OFF")) { |
|
118 $("#co2meter_powerled").html('<div class="LEDblue_on"></div>Power'); |
|
119 } else { |
|
120 $("#co2meter_powerled").html('<div class="LEDblue_off"></div>Power'); |
|
121 } |
|
122 |
|
123 $("#gaugeContainer_temperature").jqxGauge({ caption: { value: 'Temp: '+record.temperature.toFixed(3) }}); |
|
124 $('#gaugeContainer_temperature').jqxGauge({ value: record.temperature }); |
|
125 if (record.temperature_state == "OK") { |
|
126 $("#gaugeContainer_temperature").jqxGauge({ disabled: false }); |
|
127 } else { |
|
128 $("#gaugeContainer_temperature").jqxGauge({ disabled: true }); |
|
129 } |
|
130 $("#gaugeContainer_pressure").jqxGauge({ caption: { value: 'Bar: '+record.pressure_bar.toFixed(2) }}); |
|
131 $('#gaugeContainer_pressure').jqxGauge({ value: record.pressure_bar }); |
|
132 if (record.pressure_state == "OK") { |
|
133 $("#gaugeContainer_pressure").jqxGauge({ disabled: false }); |
|
134 } else { |
|
135 $("#gaugeContainer_pressure").jqxGauge({ disabled: true }); |
|
136 } |
|
137 } |
|
138 }); |
|
139 |
|
140 $("#select_beer").jqxDropDownList({ |
|
141 placeHolder: "Kies bier:", |
|
142 theme: theme, |
|
143 source: productlist, |
|
144 displayMember: "code", |
|
145 width: 150, |
|
146 height: 24, |
|
147 dropDownWidth: 500, |
|
148 autoDropDownHeight: true, |
|
149 renderer: function (index, label, value) { |
|
150 var datarecord = productlist.records[index]; |
|
151 return datarecord.code + " - " + datarecord.name; |
|
152 } |
|
153 }); |
|
154 |
|
155 $("#gaugeContainer_temperature").jqxGauge( gaugeoptionst ); |
|
156 $("#gaugeContainer_temperature").jqxGauge( { caption: { value: 'Temp: 00.000' }} ); |
|
157 $("#gaugeContainer_pressure").jqxGauge( gaugeoptionsp ); |
|
158 $("#gaugeContainer_pressure").jqxGauge( { caption: { value: 'Bar: 00.000' }} ); |
|
159 |
|
160 srcMode = [ "OFF", "ON" ]; |
|
161 $("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 62 }); |
|
162 |
|
163 // function sendProduct(code, name, uuid, yeast_lo, yeast_hi) { |
|
164 |
|
165 // console.log("sendProduct("+code+", "+name+", "+uuid+", "+yeast_lo+", "+yeast_hi+")"); |
|
166 // var data = 'node='+record.node+'&alias='+record.alias+'&payload='; |
|
167 // data += '{"product":{"code":"'+code+'","name":"'+name+'","uuid":"'+uuid+'","yeast_lo":'+yeast_lo+',"yeast_hi":'+yeast_hi+'}}'; |
|
168 // $.ajax({ |
|
169 // url: "cmd_fermenter.php", |
|
170 // data: data, |
|
171 // type: "POST", |
|
172 // success: function(data) {}, |
|
173 // error: function(jqXHR, textStatus, errorThrown) { console.log("sendProduct() error"); } |
|
174 // }); |
|
175 // } |
|
176 |
|
177 // Get the data immediatly and then at regular intervals to refresh. |
|
178 dataAdapter.dataBind(); |
|
179 setInterval(function() { |
|
180 var skip = false; |
|
181 // if (newProduct) { |
|
182 // sendProduct(record.beercode, record.beername, record.beeruuid, record.yeast_lo, record.yeast_hi); |
|
183 // newProduct = false; |
|
184 // skip = true; |
|
185 // } |
|
186 if (skip) { |
|
187 schedule = 4; // 2 seconds wait to get the results |
|
188 } else { |
|
189 if (schedule > 0) |
|
190 schedule--; |
|
191 } |
|
192 |
|
193 if (schedule <= 0) { |
|
194 dataAdapter.dataBind(); |
|
195 schedule = 20; |
|
196 } |
|
197 }, 500); |
|
198 |
|
199 $('#info_mode').on('change', function (event) { |
|
200 var args = event.args; |
|
201 if (args) { |
|
202 record.mode = args.item.value; |
|
203 } |
|
204 // newBase = true; |
|
205 }); |
|
206 // $("#select_beer").on('select', function (event) { |
|
207 // if (event.args) { |
|
208 // var index = event.args.index, |
|
209 // datarecord = productlist.records[index]; |
|
210 // record.beercode = datarecord.code; |
|
211 // record.beername = datarecord.name; |
|
212 // record.beeruuid = datarecord.uuid; |
|
213 // record.yeast_lo = datarecord.yeast_lo; |
|
214 // record.yeast_hi = datarecord.yeast_hi; |
|
215 // newProduct = true; |
|
216 // } |
|
217 // }); |
|
218 |
|
219 // The chart button. |
|
220 $("#FLog").jqxButton({ template: "primary", width: '150px', theme: theme }); |
|
221 $("#FLog").click(function () { |
|
222 window.open('log_fermentation.php?code=' + record.beercode + '&name=' + record.beername); |
|
223 }); |
|
224 }); |