Skip to content

Commit

Permalink
Merge pull request #262 from emoncms/master
Browse files Browse the repository at this point in the history
Merge master to stable
  • Loading branch information
TrystanLea authored Jul 30, 2020
2 parents 3b92632 + 7c73b21 commit 3fe0d89
Show file tree
Hide file tree
Showing 24 changed files with 250 additions and 335 deletions.
19 changes: 16 additions & 3 deletions Views/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
// Global page vars definition

// Array for all feed details by feed id
var associd = [];
var assocfeed = [];
var associd = {};
var assocfeed = {};
// Array for smooth change values - creation of smooth dial widget
var assoc_curve = [];
var assoc_curve = {};
// Stores timeout state of widgets used for updating a widget on a timeout event
var last_errorCode = {};

var widgetcanvas = {};

Expand Down Expand Up @@ -133,6 +135,7 @@ function curve_value(feed,rate){
if (associd[feed] !== undefined) assoc_curve[feed] = assoc_curve[feed] + ((parseFloat(associd[feed]['value']) - assoc_curve[feed]) * rate);
val = assoc_curve[feed] * 1;
}
if (isNaN(val)) val = 0;
return val;
}

Expand Down Expand Up @@ -163,3 +166,13 @@ function setup_widget_canvas(elementclass){
widgetcanvas[canvasid] = canvas.getContext("2d");
});
}

// Convenience function for shoving things into the widget object
// I'm not sure about calling optionKey "optionKey", but I don't want to just use "options" (because that's what this whole function returns), and it's confusing enough as it is.
function addOption(widget, optionKey, optionType, optionName, optionHint, optionData){
widget["options" ].push(optionKey);
widget["optionstype"].push(optionType);
widget["optionsname"].push(optionName);
widget["optionshint"].push(optionHint);
widget["optionsdata"].push(optionData);
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"forum": "https://community.openenergymonitor.org/"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "1.0.0"
"php-parallel-lint/php-parallel-lint": "^1.2.0"
},
"scripts": {
"test": [
Expand Down
2 changes: 1 addition & 1 deletion dashboard_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function dashboard_controller()
$dashboard = new Dashboard($mysqli);
// id, userid, content, height, name, alias, description, main, public, published, showdescription, fullscreen

$js_css_version = 5;
$js_css_version = 6;

$result = false; $submenu = '';

Expand Down
10 changes: 0 additions & 10 deletions widget/bar/bar_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@

// Convenience function for shoving things into the widget object
// I'm not sure about calling optionKey "optionKey", but I don't want to just use "options" (because that's what this whole function returns), and it's confusing enough as it is.
function addOption(widget, optionKey, optionType, optionName, optionHint, optionData)
{

widget["options" ].push(optionKey);
widget["optionstype"].push(optionType);
widget["optionsname"].push(optionName);
widget["optionshint"].push(optionHint);
widget["optionsdata"].push(optionData);


}
function bar_widgetlist()
{
var widgets =
Expand Down
13 changes: 2 additions & 11 deletions widget/battery/battery_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
http://openenergymonitor.org/emon/forum
*/

// Convenience function for shoving things into the widget object
// I'm not sure about calling optionKey "optionKey", but I don't want to just use "options" (because that's what this whole function returns), and it's confusing enough as it is.
function addOption(widget, optionKey, optionType, optionName, optionHint, optionData){
widget["options" ].push(optionKey);
widget["optionstype"].push(optionType);
widget["optionsname"].push(optionName);
widget["optionshint"].push(optionHint);
widget["optionsdata"].push(optionData);
}

function battery_widgetlist(){
var widgets =
{
Expand Down Expand Up @@ -86,6 +76,7 @@ function battery_widgetlist(){
addOption(widgets["battery"], "scale", "value", _Tr("Scale"), _Tr("Value is multiplied by scale before display"), []);
addOption(widgets["battery"], "units", "dropbox_other", _Tr("Units"), _Tr("Units to show"), _SI);
addOption(widgets["battery"], "unitend", "dropbox", _Tr("Unit position"), _Tr("Where should the unit be shown"), unitEndOptions);
addOption(widgets["battery"], "number_of_blocks", "value", _Tr("Number of blocks"),_Tr("Number of blocks to display"), []);
addOption(widgets["battery"], "decimals", "dropbox", _Tr("Decimals"), _Tr("Decimals to show"), decimalsDropBoxOptions);
addOption(widgets["battery"], "offset", "value", _Tr("Offset"), _Tr("Static offset. Subtracted from value before computing"), []);
addOption(widgets["battery"], "colour", "colour_picker", _Tr("Colour label"), _Tr("Color of the label"), []);
Expand Down Expand Up @@ -153,7 +144,7 @@ function battery_draw(){
var cap_width = battery_width/3;
var line_width = 2;
var margin = 1;
var number_of_blocks = 5;
var number_of_blocks = Math.round(1*$(this).attr("number_of_blocks")) || 5;

var fontname;
if (font === "0"){fontname = "Impact";}
Expand Down
9 changes: 5 additions & 4 deletions widget/button/button_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function button_events()
function button_init()
{
setup_widget_canvas('button');
button_draw();
}

function button_draw()
Expand All @@ -69,8 +68,10 @@ function button_draw()
{
var feedid = $(this).attr("feedid");
if (assocfeed[feedid]!=undefined) feedid = assocfeed[feedid]; // convert tag:name to feedid
if (associd[feedid] === undefined) { console.log("Review config for feed id of " + $(this).attr("class")); return; }
var val = associd[feedid]['value']*1;

var val = 0;
if (associd[feedid] != undefined) val = associd[feedid]['value']*1;

var id = "can-"+$(this).attr("id");
draw_button(widgetcanvas[id], val);
});
Expand All @@ -83,7 +84,7 @@ function button_slowupdate()

function button_fastupdate()
{

if (redraw) button_draw();
}


Expand Down
20 changes: 8 additions & 12 deletions widget/cylinder/cylinder_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
If you have any questions please get in touch, try the forums here:
http://openenergymonitor.org/emon/forum
*/
function addOption(widget, optionKey, optionType, optionName, optionHint, optionData){
widget["options" ].push(optionKey);
widget["optionstype"].push(optionType);
widget["optionsname"].push(optionName);
widget["optionshint"].push(optionHint);
widget["optionsdata"].push(optionData);
}

function cylinder_widgetlist()
{
Expand Down Expand Up @@ -70,7 +63,6 @@ function cylinder_widgetlist()

function drawCylinder(ctx,cylBot,cylTop,width,height,temptype,unitend,decimals)
{

// console.log("Draw cylinder");
if (!ctx) console.log("No CTX");
if (!ctx) return;
Expand Down Expand Up @@ -180,14 +172,18 @@ function cylinder_draw()
var feedid2 = $(this).attr("botfeedid");
if (assocfeed[feedid2]!=undefined) feedid2 = assocfeed[feedid2]; // convert tag:name to feedid

if ((associd[feedid1] === undefined) || (associd[feedid2] === undefined)) { console.log("Review config for feed id of " + $(this).attr("class")); return; }
var cylTop = associd[feedid1]["value"]*1;
var cylBot = associd[feedid2]["value"]*1;
var cylTop = 60;
var cylBot = 20;

if (associd[feedid1] != undefined) cylTop = associd[feedid1]["value"]*1;
if (associd[feedid2] != undefined) cylBot = associd[feedid2]["value"]*1;

var unitend = $(this).attr("unitend") || "0";
var temptype= $(this).attr("temptype") || "0";
var decimals = $(this).attr("decimals") || "-1";

var id = "can-"+$(this).attr("id");

drawCylinder(widgetcanvas[id],cylBot,cylTop,$(this).width(),$(this).height(),temptype,unitend,decimals);
});
}
Expand All @@ -204,5 +200,5 @@ function cylinder_slowupdate()

function cylinder_fastupdate()
{
cylinder_draw();
if (redraw) cylinder_draw();
}
9 changes: 0 additions & 9 deletions widget/dewpoint/dewpoint_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ function dewPoint(RH,T) {
return dp;
}

function addOption(widget, optionKey, optionType, optionName, optionHint, optionData)
{
widget["options" ].push(optionKey);
widget["optionstype"].push(optionType);
widget["optionsname"].push(optionName);
widget["optionshint"].push(optionHint);
widget["optionsdata"].push(optionData);
}

function dewpoint_widgetlist()
{
var widgets =
Expand Down
98 changes: 49 additions & 49 deletions widget/dial/dial_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
http://openenergymonitor.org/emon/forum
*/

// Convenience function for shoving things into the widget object
// I'm not sure about calling optionKey "optionKey", but I don't want to just use "options" (because that's what this whole function returns), and it's confusing enough as it is.
function addOption(widget, optionKey, optionType, optionName, optionHint, optionData){
widget["options" ].push(optionKey);
widget["optionstype"].push(optionType);
widget["optionsname"].push(optionName);
widget["optionshint"].push(optionHint);
widget["optionsdata"].push(optionData);
}

function dial_widgetlist(){
var widgets =
{
Expand Down Expand Up @@ -528,51 +518,56 @@ function dial_define_tooltips(){
var id2 = "can-"+$(this).attr("id");
var canvas2 = document.getElementById(id2);
var parent = canvas2.parentNode; // parent node for canvas
if(document.getElementById(id2 + "-tooltip-1")){}
else{
var div1 = document.createElement("div"); // the tool-tip div 1
div1.id = id2 + "-tooltip-1";
parent.appendChild(div1);}
if(document.getElementById(id2 + "-tooltip-2")){}
else{
var div2 = document.createElement("div"); // the tool-tip div 2
div2.id = id2 + "-tooltip-2";
parent.appendChild(div2);}

if(document.getElementById(id2 + "-tooltip-1")){
} else {
var div1 = document.createElement("div"); // the tool-tip div 1
div1.id = id2 + "-tooltip-1";
parent.appendChild(div1);
}

if (document.getElementById(id2 + "-tooltip-2")){
} else {
var div2 = document.createElement("div"); // the tool-tip div 2
div2.id = id2 + "-tooltip-2";
parent.appendChild(div2);
}
});
}

function dial_draw(){
$(".dial").each(function(index) {
var errorMessage = $(this).attr("errormessagedisplayed");
if (errorMessage === "" || errorMessage === undefined){ //Error Message parameter is empty
errorMessage = "TO Error";
}
var errorTimeout = $(this).attr("timeout");
if (errorTimeout === "" || errorTimeout === undefined){ //Timeout parameter is empty
errorTimeout = 0;
}

var errorCode = "0";
var now = (new Date()).getTime()*0.001;

$(".dial").each(function(index) {

var feedid = $(this).attr("feedid");
if (assocfeed[feedid]!=undefined) feedid = assocfeed[feedid]; // convert tag:name to feedid
var minvaluefeed = $(this).attr("minvaluefeed")||"0";
if (assocfeed[minvaluefeed]!=undefined) minvaluefeed = assocfeed[minvaluefeed];
var maxvaluefeed = $(this).attr("maxvaluefeed")||"0";
if (assocfeed[maxvaluefeed]!=undefined) maxvaluefeed = assocfeed[maxvaluefeed];

if (associd[feedid] === undefined) { console.log("Review config for feed id of " + $(this).attr("class")); return; }

var val = (associd[feedid]["value"] * 1).toFixed(3);
var val_curve = curve_value(feedid,dialrate).toFixed(3);
var val = 0;
var val_curve = 0;
var feed_update_time = now;

if (associd[feedid] != undefined) {
val = (associd[feedid]["value"] * 1).toFixed(3);
val_curve = curve_value(feedid,dialrate).toFixed(3);
feed_update_time = 1*associd[feedid]["time"];
}

// Timeout error
var errorTimeout = $(this).attr("timeout");
if (errorTimeout === "" || errorTimeout === undefined) errorTimeout = 0;

if (errorTimeout !== 0)
{
if (((new Date()).getTime() / 1000 - offsetofTime - (associd[feedid]["time"] * 1)) > errorTimeout)
{
errorCode = "1";
}
}
var errorCode = "0";
if (errorTimeout !== 0) {
if ((now-offsetofTime-feed_update_time) > errorTimeout) errorCode = "1";
}

var id = "can-"+$(this).attr("id");
if (last_errorCode[id]==undefined) last_errorCode[id] = errorCode;

// The minval and maxval feed settings default to the first feed in the feedlist
// which may not be public for use in public dashboards, which will then result in
Expand All @@ -591,16 +586,20 @@ function dial_draw(){
maxval = (associd[maxvaluefeed]["value"] * 1).toFixed(3);
maxval_curve = curve_value(maxvaluefeed,dialrate).toFixed(3);
}
// Here we disable the min/max values feature when one of the feed settings is not valid
var displayminmax = $(this).attr("displayminmax")||"0";
if (associd[minvaluefeed] == undefined || associd[maxvaluefeed] == undefined) {
displayminmax = "0";
}

// ONLY UPDATE ON CHANGE
if (val_curve!=val || minval_curve!=minval || maxval_curve!=maxval ||redraw == 1 || errorTimeout != 0)
if (val_curve!=val || minval_curve!=minval || maxval_curve!=maxval || redraw == 1 || errorCode != last_errorCode[id])
{
var id = "can-"+$(this).attr("id");
// console.log("update dial");
var errorMessage = $(this).attr("errormessagedisplayed");
if (errorMessage === "" || errorMessage === undefined) errorMessage = "TO Error";

// Here we disable the min/max values feature when one of the feed settings is not valid
var displayminmax = $(this).attr("displayminmax")||"0";
if (associd[minvaluefeed] == undefined || associd[maxvaluefeed] == undefined) {
displayminmax = "0";
}

var scale = 1*$(this).attr("scale") || 1;
var unitend = $(this).attr("unitend") || "0";
draw_gauge(widgetcanvas[id],
Expand All @@ -624,6 +623,7 @@ function dial_draw(){
errorMessage
);
}
last_errorCode[id] = errorCode;
});
}

Expand Down
9 changes: 0 additions & 9 deletions widget/feedtime/feedtime_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
http://openenergymonitor.org/emon/forum
*/

function addOption(widget, optionKey, optionType, optionName, optionHint, optionData)
{
widget["options" ].push(optionKey);
widget["optionstype"].push(optionType);
widget["optionsname"].push(optionName);
widget["optionshint"].push(optionHint);
widget["optionsdata"].push(optionData);
}

function feedtime_widgetlist()
{
var widgets =
Expand Down
Loading

0 comments on commit 3fe0d89

Please sign in to comment.