From fd162ff98af13bdf33be1f952f6bef1ba990306b Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Wed, 25 Oct 2023 22:35:07 +1100 Subject: [PATCH] =?UTF-8?q?Notification=20Report=20page=20rewrite=20v0.1?= =?UTF-8?q?=F0=9F=93=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/css/pialert.css | 18 ++- front/js/pialert_common.js | 26 +++ front/php/server/util.php | 10 +- front/php/templates/language/en_us.json | 6 +- front/plugins/_publisher_apprise/config.json | 9 +- front/plugins/_publisher_email/config.json | 11 +- front/plugins/_publisher_ntfy/config.json | 9 +- .../plugins/_publisher_pushsafer/config.json | 9 +- front/plugins/_publisher_webhook/config.json | 9 +- front/pluginsCore.php | 8 + front/report.php | 151 ++++++++++++++++-- front/settings.php | 62 ++----- pialert/plugin.py | 32 ---- 13 files changed, 245 insertions(+), 115 deletions(-) diff --git a/front/css/pialert.css b/front/css/pialert.css index e15c470a..2d62d69f 100755 --- a/front/css/pialert.css +++ b/front/css/pialert.css @@ -585,8 +585,24 @@ height: 50px; .infobox_label { font-size: 16px !important; } +/* --------------------------------------------------------- */ +/* report */ +/* --------------------------------------------------------- */ -/*settings*/ +#notificationData textarea{ + width: 100%; +} + +#notificationData pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; } +.string { color: green; } +.number { color: darkorange; } +.boolean { color: blue; } +.null { color: magenta; } +.key { color: red; } + +/* --------------------------------------------------------- */ +/* settings */ +/* --------------------------------------------------------- */ @media (max-width: 767px) { /* hide on mobile */ diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 9a904ec3..4645a3d6 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -304,6 +304,32 @@ function showMessage (textMessage="") { } +// ----------------------------------------------------------------------------- +// String utilities +// ----------------------------------------------------------------------------- +function jsonSyntaxHighlight(json) { + if (typeof json != 'string') { + json = JSON.stringify(json, undefined, 2); + } + json = json.replace(/&/g, '&').replace(//g, '>'); + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { + var cls = 'number'; + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'key'; + } else { + cls = 'string'; + } + } else if (/true|false/.test(match)) { + cls = 'boolean'; + } else if (/null/.test(match)) { + cls = 'null'; + } + return '' + match + ''; + }); +} + + // ----------------------------------------------------------------------------- // General utilities // ----------------------------------------------------------------------------- diff --git a/front/php/server/util.php b/front/php/server/util.php index cbe9a986..5f7d567a 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -20,21 +20,21 @@ if(array_key_exists('function', $_REQUEST) != FALSE) { $FUNCTION = $_REQUEST['function']; } +if(array_key_exists('settings', $_REQUEST) != FALSE) +{ + $SETTINGS = $_REQUEST['settings']; +} // call functions based on requested params switch ($FUNCTION) { case 'savesettings': + saveSettings(); break; case 'cleanLog': - if(array_key_exists('settings', $_REQUEST) != FALSE) - { - $SETTINGS = $_REQUEST['settings']; - } - cleanLog($SETTINGS); break; diff --git a/front/php/templates/language/en_us.json b/front/php/templates/language/en_us.json index e37ab71d..6d4e7736 100755 --- a/front/php/templates/language/en_us.json +++ b/front/php/templates/language/en_us.json @@ -452,7 +452,7 @@ "run_event_tooltip" : "Enable the setting and save your changes at first before you run it.", "run_event_icon" : "fa-play", "general_event_title" : "Executing an ad-hoc event", - "general_event_description" : " The event you nove triggered might take a while until background processes finish. The execution ended once you see finished below. Check the error log if you didn not get the expected result.

Status: ", + "general_event_description" : " The event you nove triggered might take a while until background processes finish. The execution ended once the below execution queue empties (Check the error log if you envounter issues).

Execution queue:", "Plugins_Unprocessed_Events" : "Unprocessed Events", "Plugins_Objects" : "Plugin Objects", "Plugins_DeleteAll" : "Delete all (filters are ignored)", @@ -602,7 +602,9 @@ "Systeminfo_System_System": "System:", "Systeminfo_System_Uname": "Uname:", "Systeminfo_System_Uptime": "Uptime:", - "Systeminfo_USB_Devices" : "USB Devices", + "Systeminfo_USB_Devices" : "USB Devices", + "report_select_format": "Select Format:", + "report_time": "Notification time:", "Donations_Title" : "Donations", "Donations_Text" : "Hey πŸ‘‹!
Thanks for clicking on this menu item πŸ˜…

I'm trying to collect some donations to make you better software. Also, it would help me not to get burned out. Me burning out might mean end of support for this app. Any small (recurring or not) sponsorship makes me want ot put more effort into this app. I don't want to lock features (new plugins) behind paywalls πŸ”.
Currently, I'm waking up 2h before work so I contribute to the app a bit. If I had some recurring income I could shorten my workweek and in the remaining time fully focus on PiAlert. You'd get more functionality, a more polished app and less bugs.

Thanks for reading - I'm super grateful for any support β€πŸ™

TL;DR: By supporting me you get:


πŸ“§Email me to jokob@duck.com if you want to get in touch or if I should add other sponsorship platforms.
", "Donations_Platforms" : "Sponsor platforms", diff --git a/front/plugins/_publisher_apprise/config.json b/front/plugins/_publisher_apprise/config.json index d4eb57c3..315eb944 100755 --- a/front/plugins/_publisher_apprise/config.json +++ b/front/plugins/_publisher_apprise/config.json @@ -127,9 +127,14 @@ "column": "Watched_Value1", "css_classes": "col-sm-2", "show": true, - "type": "label", + "type": "eval", "default_value":"", - "options": [], + "options": [ + { + "type": "eval", + "param": "`${value}`" + } + ], "localized": ["name"], "name":[{ "language_code": "en_us", diff --git a/front/plugins/_publisher_email/config.json b/front/plugins/_publisher_email/config.json index 3f51249a..a7bdb40f 100755 --- a/front/plugins/_publisher_email/config.json +++ b/front/plugins/_publisher_email/config.json @@ -156,9 +156,14 @@ "column": "Watched_Value1", "css_classes": "col-sm-2", "show": true, - "type": "label", - "default_value": "", - "options": [], + "type": "eval", + "default_value":"", + "options": [ + { + "type": "eval", + "param": "`${value}`" + } + ], "localized": [ "name" ], diff --git a/front/plugins/_publisher_ntfy/config.json b/front/plugins/_publisher_ntfy/config.json index dd3ffed1..a22f909d 100755 --- a/front/plugins/_publisher_ntfy/config.json +++ b/front/plugins/_publisher_ntfy/config.json @@ -94,9 +94,14 @@ "column": "Watched_Value1", "css_classes": "col-sm-3", "show": true, - "type": "label", + "type": "eval", "default_value":"", - "options": [], + "options": [ + { + "type": "eval", + "param": "`${value}`" + } + ], "localized": ["name"], "name":[{ "language_code": "en_us", diff --git a/front/plugins/_publisher_pushsafer/config.json b/front/plugins/_publisher_pushsafer/config.json index fb4d67c9..ebfbf61e 100755 --- a/front/plugins/_publisher_pushsafer/config.json +++ b/front/plugins/_publisher_pushsafer/config.json @@ -94,9 +94,14 @@ "column": "Watched_Value1", "css_classes": "col-sm-3", "show": true, - "type": "label", + "type": "eval", "default_value":"", - "options": [], + "options": [ + { + "type": "eval", + "param": "`${value}`" + } + ], "localized": ["name"], "name":[{ "language_code": "en_us", diff --git a/front/plugins/_publisher_webhook/config.json b/front/plugins/_publisher_webhook/config.json index bb0db76a..a1e36beb 100755 --- a/front/plugins/_publisher_webhook/config.json +++ b/front/plugins/_publisher_webhook/config.json @@ -94,9 +94,14 @@ "column": "Watched_Value1", "css_classes": "col-sm-3", "show": true, - "type": "label", + "type": "eval", "default_value":"", - "options": [], + "options": [ + { + "type": "eval", + "param": "`${value}`" + } + ], "localized": ["name"], "name":[{ "language_code": "en_us", diff --git a/front/pluginsCore.php b/front/pluginsCore.php index e0d6fdb6..ee5c3293 100755 --- a/front/pluginsCore.php +++ b/front/pluginsCore.php @@ -169,6 +169,14 @@ function processColumnValue(dbColumnDef, value, index, type) { } } break; + case 'eval': + + for (const option of dbColumnDef.options) { + if (option.type === type) { + value = eval(value); + } + } + break; default: value = value + `
` ; diff --git a/front/report.php b/front/report.php index 499af5ce..09f84e2c 100755 --- a/front/report.php +++ b/front/report.php @@ -30,20 +30,145 @@
-Error"; - echo lang('REPORT_ERROR'); -} -?> +
+ +
+ +
+
- -
+ +
+ + +
+ + +
+ + Timestamp +
+ + +
+ +
+ + + + + + fetchArray (SQLITE3_ASSOC)) { modalEventStatusId = 'modal-message-front-event' - function handleEvent (element){ - - // value has to be in format event|param. e.g. run|ARPSCAN - value = $(element).attr('data-myevent') + '|'+ $(element).attr('data-myparam-plugin') - - setParameter ('Front_Event', value) - - // show message - showModalOk("", " "); - - // Periodically update state of the requested action - getParam(modalEventStatusId,"Front_Event", true, updateModalState) - - updateModalState() - } - - - // function updateModalState(){ - - // setTimeout(function(){ - // displayedEvent = $('#'+modalEventStatusId).html() - - // // loop until finished - // if(displayedEvent.indexOf('finished') == -1) // if the message is different from finished, check again in 2s - // { - - // getParam(modalEventStatusId,"Front_Event", true) - - // updateModalState() - - // } - // }, 2000); - // } - - // -------------------------------------------------------- // Calls a backend function to add a front-end event (specified by the attributes 'data-myevent' and 'data-myparam-plugin' on the passed element) to an execution queue function addToExecutionQueue(element) @@ -882,34 +847,34 @@ function addToExecutionQueue(element) // value has to be in format event|param. e.g. run|ARPSCAN action = `${getGuid()}|${$(element).attr('data-myevent')}|${$(element).attr('data-myparam-plugin')}` - // addToExecutionQueue(action) - $.ajax({ method: "POST", url: "php/server/util.php", data: { function: "addToExecutionQueue", action: action }, success: function(data, textStatus) { - showModalOk ('Result', data ); + // showModalOk ('Result', data ); + + // show message + showModalOk(getString("general_event_title"), `${getString("general_event_description")}

`); + + updateModalState() } }) } -// TODO +// -------------------------------------------------------- +// Updating the execution queue in in modal pop-up function updateModalState() { setTimeout(function() { // Fetch the content from the log file using an AJAX request $.ajax({ - url: '~/log/execution_queue.log', + url: '/log/execution_queue.log', type: 'GET', success: function(data) { // Update the content of the HTML element (e.g., a div with id 'logContent') - $('#logContent').html(data); + $('#'+modalEventStatusId).html(data); - // Check if the displayed content contains 'finished' - if (data.indexOf('finished') === -1) { - // If not finished, continue to update - updateModalState(); - } + updateModalState(); }, error: function() { // Handle error, such as the file not being found @@ -919,11 +884,6 @@ function updateModalState() { }, 2000); } -// Call the function to start the periodic updates -updateModalState(); - - - // ----------------------------------------------------------------------------- // handling events on the backend initiated by the front end END diff --git a/pialert/plugin.py b/pialert/plugin.py index d81c4861..b939f177 100755 --- a/pialert/plugin.py +++ b/pialert/plugin.py @@ -727,38 +727,6 @@ class plugin_object_class: #=============================================================================== # Handling of user initialized front-end events #=============================================================================== - -#------------------------------------------------------------------------------- -# def check_and_run_user_event(db, pluginsState): - -# sql = db.sql # TO-DO -# sql.execute(""" select * from Parameters where par_ID = "Front_Event" """) -# rows = sql.fetchall() - -# event, param = ['',''] -# if len(rows) > 0 and rows[0]['par_Value'] != 'finished': -# keyValue = rows[0]['par_Value'].split('|') - -# if len(keyValue) == 2: -# event = keyValue[0] -# param = keyValue[1] -# else: -# return pluginsState - -# if event == 'test': -# pluginsState = handle_test(param, db, pluginsState) -# if event == 'run': -# pluginsState = handle_run(param, db, pluginsState) - -# # clear event execution flag -# sql.execute ("UPDATE Parameters SET par_Value='finished' WHERE par_ID='Front_Event'") - -# # commit to DB -# db.commitDB() - -# return pluginsState - - def check_and_run_user_event(db, pluginsState): # Check if the log file exists logFile = os.path.join(logPath, "execution_queue.log")