From c0c1ece86c7ee2214131f899730a99acf4bcdcb5 Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Fri, 18 Dec 2015 08:43:19 +0100 Subject: [PATCH 01/11] Added support for messages from the server with ohSnap --- js/main.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/js/main.js b/js/main.js index 0d05c5b..92be56b 100644 --- a/js/main.js +++ b/js/main.js @@ -32,6 +32,30 @@ function showErrorsInNotification(socketResponse){ return false; } +function getMessagesFromServer() +{ + "use strict"; + $.ajax({ + type: "POST", + dataType:"json", + cache: false, + contentType:"application/x-www-form-urlencoded; charset=utf-8", + data: {messageType: "getMessages", message: ""}, + url: 'socketmessage.php', + success: function(controlConstantsJSON){ + jQuery.each(controlConstantsJSON.messages, function(i, val) { + switch (val.messageType) { + case 'error': var m_color = "red"; break; + case 'info': var m_color = "green"; break; + case 'warning': var m_color = "orange"; break; + } + ohSnap(val.message, {color: m_color, duration: 4000}); + console.log(val); + }); + } + }); + window.setTimeout(getMessagesFromServer,20000); +} function receiveControlConstants(){ "use strict"; $.ajax({ @@ -435,5 +459,6 @@ $(document).ready(function(){ receiveControlSettings(); receiveControlVariables(); refreshLcd(); //will call refreshLcd and alternate between the two + getMessagesFromServer(); // get Logs from server }); From fe69611e169c5e13b5a0025c44e1ec473405ef12 Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Fri, 18 Dec 2015 11:15:48 +0100 Subject: [PATCH 02/11] Corrected ohSnap messages were showing on top of each other, instead of being stacked --- css/ohsnap.css | 3 +-- css/style.css | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/css/ohsnap.css b/css/ohsnap.css index 3af2ff3..b00e16f 100644 --- a/css/ohsnap.css +++ b/css/ohsnap.css @@ -3,10 +3,9 @@ .alert { padding: 15px; - margin-bottom: 20px; + margin-bottom: 10px; border: 1px solid #eed3d7; border-radius: 4px; - position: absolute; bottom: 0px; right: 21px; /* Each alert has its own width */ diff --git a/css/style.css b/css/style.css index e1c2c97..f3e6e49 100644 --- a/css/style.css +++ b/css/style.css @@ -13,6 +13,12 @@ body { font-size: 12px; } +#ohsnap +{ + position: absolute; + bottom: 0; + right: 0; +} #top-bar button.script-status{ margin:10px; } From 1e0778703edbbd3ef33072ba0b260c491fba90cc Mon Sep 17 00:00:00 2001 From: Elco Jacobs Date: Mon, 11 Jan 2016 14:04:54 +0100 Subject: [PATCH 03/11] added photon to menu to program from web ui --- maintenance-panel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maintenance-panel.php b/maintenance-panel.php index 907a65b..3a35688 100644 --- a/maintenance-panel.php +++ b/maintenance-panel.php @@ -87,7 +87,8 @@ function echoRotarySelect($optionName){ - + +
From 1455e43e32c1dc5b4a61692cabda33712ae37c39 Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sat, 23 Jan 2016 13:15:06 +0100 Subject: [PATCH 04/11] Added simple page for controlling the valves and setting them to predefined states --- hermstool.php | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 hermstool.php diff --git a/hermstool.php b/hermstool.php new file mode 100644 index 0000000..0ffe7c4 --- /dev/null +++ b/hermstool.php @@ -0,0 +1,246 @@ + + + + + + + BrewPi HERMS tool page + + + + + + + + + + + + +
+
+ + +
+ + + + + From d95d0747b7d6bf7f8e8706e84340b8f86e18ee4e Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sun, 24 Jan 2016 07:49:13 +0100 Subject: [PATCH 05/11] Revert "Added simple page for controlling the valves and setting them to predefined states" This reverts commit 1455e43e32c1dc5b4a61692cabda33712ae37c39. --- hermstool.php | 246 -------------------------------------------------- 1 file changed, 246 deletions(-) delete mode 100644 hermstool.php diff --git a/hermstool.php b/hermstool.php deleted file mode 100644 index 0ffe7c4..0000000 --- a/hermstool.php +++ /dev/null @@ -1,246 +0,0 @@ - - - - - - - BrewPi HERMS tool page - - - - - - - - - - - - -
-
- - -
- - - - - From 8ef6ca55f24ab52f1c5f10a3d0487ce33492d5df Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sun, 24 Jan 2016 09:39:05 +0100 Subject: [PATCH 06/11] Added a wrapped ajax handler to get the messages from the server in one response --- js/main.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/js/main.js b/js/main.js index 92be56b..7e4c813 100644 --- a/js/main.js +++ b/js/main.js @@ -23,6 +23,27 @@ var controlConstants = {}; var controlSettings = {}; var controlVariables = {}; + +function wrapped_ajax(options) { + var success = options.success; + options.success = function(data, textStatus, jqXHR) { + // Strip out the messages here {'response': data, 'messages': getLogMessages()} + jQuery.each(data.messages, function(i, val) { + switch (val.messageType) { + case 'error': var m_color = "red"; break; + case 'info': var m_color = "green"; break; + case 'warning': var m_color = "orange"; break; + } + ohSnap(val.message, {color: m_color, duration: 4000}); + console.log(val); + }); + // Send the 'response' part on to the original handler + if(success) + success(data.response, textStatus, jqXHR); + }; + return $.ajax(options); +} + function showErrorsInNotification(socketResponse){ if(socketResponse.indexOf("ERROR: ") == 0){ var errorMessage = socketResponse.replace("ERROR: ", ""); @@ -54,11 +75,11 @@ function getMessagesFromServer() }); } }); - window.setTimeout(getMessagesFromServer,20000); + //window.setTimeout(getMessagesFromServer,20000); } function receiveControlConstants(){ "use strict"; - $.ajax({ + wrapped_ajax({ type: "POST", dataType:"json", cache: false, @@ -84,7 +105,7 @@ function receiveControlConstants(){ function receiveControlSettings(callback){ "use strict"; - $.ajax({ + wrapped_ajax({ type: "POST", dataType:"json", cache: false, @@ -147,7 +168,7 @@ function syntaxHighlight(json) { function receiveControlVariables(){ "use strict"; - $.ajax({ + wrapped_ajax({ type: "POST", dataType:"text", // do not use json, because it changes the order cache: false, @@ -210,7 +231,7 @@ function startScript(){ function refreshLcd(){ "use strict"; - $.ajax({ + wrapped_ajax({ type: "POST", dataType:"json", cache: false, From a0f58f0b973bf7b414bbc33a8a14883f090741ab Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sun, 24 Jan 2016 10:10:12 +0100 Subject: [PATCH 07/11] no message --- js/main.js | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/js/main.js b/js/main.js index 7e4c813..efe299b 100644 --- a/js/main.js +++ b/js/main.js @@ -24,8 +24,26 @@ var controlSettings = {}; var controlVariables = {}; +function ajaxSuccessHandler(func){ + return function(data) { + jQuery.each(data.messages, function(i, val) { + switch (val.messageType) { + case 'error': var m_color = "red"; break; + case 'info': var m_color = "green"; break; + case 'warning': var m_color = "orange"; break; + } + ohSnap(val.message, {color: m_color, duration: 4000}); + console.log(val); + }); + // Send the 'response' part on to the original handler + func(data.response); + + }; +} + function wrapped_ajax(options) { var success = options.success; + var done = options.done; options.success = function(data, textStatus, jqXHR) { // Strip out the messages here {'response': data, 'messages': getLogMessages()} jQuery.each(data.messages, function(i, val) { @@ -38,6 +56,8 @@ function wrapped_ajax(options) { console.log(val); }); // Send the 'response' part on to the original handler + if(done) + done(data.response, textStatus, jqXHR); if(success) success(data.response, textStatus, jqXHR); }; @@ -63,7 +83,7 @@ function getMessagesFromServer() contentType:"application/x-www-form-urlencoded; charset=utf-8", data: {messageType: "getMessages", message: ""}, url: 'socketmessage.php', - success: function(controlConstantsJSON){ + success: ajaxSuccessHandler( function(controlConstantsJSON){ jQuery.each(controlConstantsJSON.messages, function(i, val) { switch (val.messageType) { case 'error': var m_color = "red"; break; @@ -73,20 +93,20 @@ function getMessagesFromServer() ohSnap(val.message, {color: m_color, duration: 4000}); console.log(val); }); - } + }) }); //window.setTimeout(getMessagesFromServer,20000); } function receiveControlConstants(){ "use strict"; - wrapped_ajax({ + .ajax({ type: "POST", dataType:"json", cache: false, contentType:"application/x-www-form-urlencoded; charset=utf-8", data: {messageType: "getControlConstants", message: ""}, url: 'socketmessage.php', - success: function(controlConstantsJSON){ + success: ajaxSuccessHandler (function(controlConstantsJSON){ window.controlConstants = controlConstantsJSON; for (var i in window.controlConstants){ if(window.controlConstants.hasOwnProperty(i)){ @@ -99,20 +119,20 @@ function receiveControlConstants(){ $('.cc.'+i+' .val').text(window.controlConstants[i]); } } - } + }) }); } function receiveControlSettings(callback){ "use strict"; - wrapped_ajax({ + .ajax({ type: "POST", dataType:"json", cache: false, contentType:"application/x-www-form-urlencoded; charset=utf-8", url: 'socketmessage.php', data: {messageType: "getControlSettings", message: ""}, - success: function(controlSettingsJSON){ + success: ajaxSuccessHandler( function(controlSettingsJSON){ window.controlSettings = controlSettingsJSON; for (var i in controlSettings) { if(controlSettings.hasOwnProperty(i)){ @@ -143,7 +163,7 @@ function receiveControlSettings(callback){ if (callback && typeof(callback) === "function") { callback(); } - } + }) }); } @@ -168,20 +188,20 @@ function syntaxHighlight(json) { function receiveControlVariables(){ "use strict"; - wrapped_ajax({ + .ajax({ type: "POST", dataType:"text", // do not use json, because it changes the order cache: false, contentType:"application/x-www-form-urlencoded; charset=utf-8", url: 'socketmessage.php', data: {messageType: "getControlVariables", message: ""}, - success: function(controlVariablesJSON){ + success: ajaxSuccessHandler( function(controlVariablesJSON){ if(showErrorsInNotification(controlVariablesJSON)){ return; } var jsonPretty = JSON.stringify(JSON.parse(controlVariablesJSON),null,2); $('#algorithm-json').html(syntaxHighlight(jsonPretty)); - } + }) }); } @@ -231,7 +251,7 @@ function startScript(){ function refreshLcd(){ "use strict"; - wrapped_ajax({ + .ajax({ type: "POST", dataType:"json", cache: false, @@ -239,13 +259,13 @@ function refreshLcd(){ url: 'socketmessage.php', data: {messageType: "lcd", message: ""} }) - .done( function(lcdText){ + .done( ajaxSuccessHandler (function(lcdText){ var $lcdText = $('#lcd .lcd-text'); for (var i = lcdText.length - 1; i >= 0; i--) { $lcdText.find('#lcd-line-' + i).html(lcdText[i]); } updateScriptStatus(true); - }) + })) .fail(function() { var $lcdText = $('#lcd .lcd-text'); $lcdText.find('#lcd-line-0').html("Cannot receive"); From 740fe87a70897cc253c05d657d7be7fe41ac67d0 Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sun, 24 Jan 2016 10:11:43 +0100 Subject: [PATCH 08/11] no message --- js/main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/main.js b/js/main.js index efe299b..ef04c70 100644 --- a/js/main.js +++ b/js/main.js @@ -99,7 +99,7 @@ function getMessagesFromServer() } function receiveControlConstants(){ "use strict"; - .ajax({ + $.ajax({ type: "POST", dataType:"json", cache: false, @@ -125,7 +125,7 @@ function receiveControlConstants(){ function receiveControlSettings(callback){ "use strict"; - .ajax({ + $.ajax({ type: "POST", dataType:"json", cache: false, @@ -188,7 +188,7 @@ function syntaxHighlight(json) { function receiveControlVariables(){ "use strict"; - .ajax({ + $.ajax({ type: "POST", dataType:"text", // do not use json, because it changes the order cache: false, @@ -251,7 +251,7 @@ function startScript(){ function refreshLcd(){ "use strict"; - .ajax({ + $.ajax({ type: "POST", dataType:"json", cache: false, From 3fb884df18d22bcb016c204ae5bd7d5992af9cd1 Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sun, 24 Jan 2016 10:17:06 +0100 Subject: [PATCH 09/11] Modified ajax calls to process the log messages coming from the server --- js/control-panel.js | 4 ++-- js/device-config.js | 4 ++-- js/main.js | 50 ++--------------------------------------- js/maintenance-panel.js | 4 ++-- 4 files changed, 8 insertions(+), 54 deletions(-) diff --git a/js/control-panel.js b/js/control-panel.js index cd780e4..820b1c7 100644 --- a/js/control-panel.js +++ b/js/control-panel.js @@ -418,7 +418,7 @@ function showProfileEditDialog(editableName, dialogTitle, isSaveAs) { url: "save_beer_profile.php", dataType: "json", data: { name: profName, profile: profData }, - success: function(response) { + success: ajaxSuccessHandler( function(response) { if ( response.status !== 'error' ) { loadProfile(profName, renderProfile); $('#profileSaveError').hide(); @@ -431,7 +431,7 @@ function showProfileEditDialog(editableName, dialogTitle, isSaveAs) { console.log("profile save error: " + decodeURIComponent(response.message)); $('#profileSaveError').show(); } - }, + }), error: function(xhr, ajaxOptions, thrownError) { console.log("profile save HTTP error - request status: " + xhr.status + " - error: " + thrownError); $('#profileSaveError').show(); diff --git a/js/device-config.js b/js/device-config.js index 6fcbd2c..40c9e5d 100644 --- a/js/device-config.js +++ b/js/device-config.js @@ -19,7 +19,7 @@ function getDeviceList(){ type: 'POST', url: 'socketmessage.php', data: {messageType: "getDeviceList", message: ""}, - success: function(response){ + success: ajaxSuccessHandler( function(response){ if(showErrorsInNotification(response)){ return; } @@ -90,7 +90,7 @@ function getDeviceList(){ // scroll box down var deviceConsole = document.getElementById('device-console'); deviceConsole.scrollTop = deviceConsole.scrollHeight; - }, + }), async:true }); } diff --git a/js/main.js b/js/main.js index ef04c70..4f4a365 100644 --- a/js/main.js +++ b/js/main.js @@ -41,29 +41,6 @@ function ajaxSuccessHandler(func){ }; } -function wrapped_ajax(options) { - var success = options.success; - var done = options.done; - options.success = function(data, textStatus, jqXHR) { - // Strip out the messages here {'response': data, 'messages': getLogMessages()} - jQuery.each(data.messages, function(i, val) { - switch (val.messageType) { - case 'error': var m_color = "red"; break; - case 'info': var m_color = "green"; break; - case 'warning': var m_color = "orange"; break; - } - ohSnap(val.message, {color: m_color, duration: 4000}); - console.log(val); - }); - // Send the 'response' part on to the original handler - if(done) - done(data.response, textStatus, jqXHR); - if(success) - success(data.response, textStatus, jqXHR); - }; - return $.ajax(options); -} - function showErrorsInNotification(socketResponse){ if(socketResponse.indexOf("ERROR: ") == 0){ var errorMessage = socketResponse.replace("ERROR: ", ""); @@ -73,30 +50,7 @@ function showErrorsInNotification(socketResponse){ return false; } -function getMessagesFromServer() -{ - "use strict"; - $.ajax({ - type: "POST", - dataType:"json", - cache: false, - contentType:"application/x-www-form-urlencoded; charset=utf-8", - data: {messageType: "getMessages", message: ""}, - url: 'socketmessage.php', - success: ajaxSuccessHandler( function(controlConstantsJSON){ - jQuery.each(controlConstantsJSON.messages, function(i, val) { - switch (val.messageType) { - case 'error': var m_color = "red"; break; - case 'info': var m_color = "green"; break; - case 'warning': var m_color = "orange"; break; - } - ohSnap(val.message, {color: m_color, duration: 4000}); - console.log(val); - }); - }) - }); - //window.setTimeout(getMessagesFromServer,20000); -} + function receiveControlConstants(){ "use strict"; $.ajax({ @@ -500,6 +454,6 @@ $(document).ready(function(){ receiveControlSettings(); receiveControlVariables(); refreshLcd(); //will call refreshLcd and alternate between the two - getMessagesFromServer(); // get Logs from server + }); diff --git a/js/maintenance-panel.js b/js/maintenance-panel.js index ac8fc1f..8aba776 100644 --- a/js/maintenance-panel.js +++ b/js/maintenance-panel.js @@ -159,9 +159,9 @@ function updateControllerVersion() { contentType:"application/x-www-form-urlencoded; charset=utf-8", url: 'socketmessage.php', data: {messageType: "getVersion", message: ""}, - success: function(controllerVersionJSON){ + success: ajaxSuccessHandler( function(controllerVersionJSON){ setControllerVersion(controllerVersionJSON); - } + }) }); } From d59a4be0b17ba22bb1d55b7eca7e504c815132c0 Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sun, 24 Jan 2016 10:32:13 +0100 Subject: [PATCH 10/11] no message --- js/main.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/main.js b/js/main.js index 4f4a365..a1d16cb 100644 --- a/js/main.js +++ b/js/main.js @@ -26,6 +26,8 @@ var controlVariables = {}; function ajaxSuccessHandler(func){ return function(data) { + if (data !== null && typeof data === 'object') + { jQuery.each(data.messages, function(i, val) { switch (val.messageType) { case 'error': var m_color = "red"; break; @@ -37,6 +39,10 @@ function ajaxSuccessHandler(func){ }); // Send the 'response' part on to the original handler func(data.response); + } else { + // Send the response to the handler + func(data); + } }; } From 902862dc19da861ab876f160b52da95d1386b30b Mon Sep 17 00:00:00 2001 From: Lukas Demetz Date: Sun, 24 Jan 2016 10:41:22 +0100 Subject: [PATCH 11/11] Ok seems to work now --- js/device-config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/device-config.js b/js/device-config.js index 40c9e5d..a071e33 100644 --- a/js/device-config.js +++ b/js/device-config.js @@ -34,6 +34,7 @@ function getDeviceList(){ try { deviceAndPinList = JSON.parse(response); + deviceAndPinList = deviceAndPinList.response; deviceList = deviceAndPinList.deviceList; pinList = deviceAndPinList.pinList; jsonParsed = true;