From e83a6221522eef91ac5191f243e7bbc1673e4df3 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sun, 23 Jul 2023 09:43:12 +1000 Subject: [PATCH] Flows + settings metadata work --- docker-compose.yml | 8 ++--- front/js/handle_version.js | 11 +++++-- front/settings.php | 14 ++++++-- pialert/flows/unmark_new.json | 61 +++++++++++++++++++++++++++++++++++ pialert/initialise.py | 13 ++++++-- 5 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 pialert/flows/unmark_new.json diff --git a/docker-compose.yml b/docker-compose.yml index 3c3c71b1..cf3a4c5c 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,10 +11,10 @@ services: network_mode: host restart: unless-stopped volumes: - # - ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config - - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config - # - ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db - - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db + - ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config + # - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config + - ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db + # - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db # (optional) useful for debugging if you have issues setting up the container - ${LOGS_LOCATION}:/home/pi/pialert/front/log # --------------------------------------------------------------------------- diff --git a/front/js/handle_version.js b/front/js/handle_version.js index fa9d7194..f8947fc5 100755 --- a/front/js/handle_version.js +++ b/front/js/handle_version.js @@ -35,7 +35,12 @@ function handleVersion(){ function getVersion() { - release_timestamp = getCookie("release_timestamp") + release_timestamp = getCookie("release_timestamp") + + release_timestampNum = Number(release_timestamp) + + // logging + console.log(`Latest release in cookie: ${new Date(release_timestampNum*1000)}`) // no cached value available if(release_timestamp == "") @@ -43,11 +48,13 @@ function handleVersion(){ $.get('https://api.github.com/repos/jokob-sk/Pi.Alert/releases').done(function(response) { // Handle successful response var releases = response; + + console.log(response) if(releases.length > 0) { - release_datetime = releases[0].published_at; + release_datetime = releases[0].published_at; // get latest release release_timestamp = new Date(release_datetime).getTime() / 1000; // cache value diff --git a/front/settings.php b/front/settings.php index f1a89680..72d55c69 100755 --- a/front/settings.php +++ b/front/settings.php @@ -286,7 +286,12 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { // Remove all interfaces button $input = $input.'
'; - } + } + // json + elseif ($set['Type'] == 'json') + { + $input = ''; + } $html = $html.$input; @@ -427,8 +432,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { foreach ($settings as $set) { if(in_array($set['Type'] , $noConversion)) - { - + { echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", "'.$set["Type"].'", $("#'.$set["Code_Name"].'").val() ]);'; } elseif ($set['Type'] == "boolean") @@ -469,6 +473,10 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { "; echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", "'.$set["Type"].'", temps ]);'; } + elseif ($set['Type'] == "json") + { + // todo + } } ?> diff --git a/pialert/flows/unmark_new.json b/pialert/flows/unmark_new.json new file mode 100644 index 00000000..10321cfb --- /dev/null +++ b/pialert/flows/unmark_new.json @@ -0,0 +1,61 @@ +{ + "name":"unmark_new", + "triggers": [ + { + "type": "new", + "object": + { + "type": "db.row", + "target": "Devices" + } + } + ], + "steps": [ + { + "step_type":"wait", + "params": [ + { + "days": 3, + "hours": 0, + "minutes": 0, + "seconds": 0 + } + ] + }, + { + "step_type":"condition", + "params": [ + { + "left": { + "value": "triggers[0].object['dev_NewDevice']", + "use_quotes": true, + "js_template": "'{value}'.toString()" + }, + "operator": { + "value" : "==", + "data_type": "boolean" + }, + "right": { + "value": true, + "use_quotes": false, + "js_template": "'{value}'.toString()" + } + } + ] + }, + { + "step_type":"action", + "params": [ + { + "type": "plugin", + "params": + { + "name": "UNMRK_NEW", + "CMD": "db.row" + } + + } + ] + } + ] +} \ No newline at end of file diff --git a/pialert/initialise.py b/pialert/initialise.py index 9dcef252..9454d2db 100755 --- a/pialert/initialise.py +++ b/pialert/initialise.py @@ -5,6 +5,7 @@ from pytz import timezone from cron_converter import Cron from pathlib import Path import datetime +import json import conf from const import fullConfPath @@ -23,7 +24,7 @@ from plugin import get_plugins_configs, print_plugin_info #------------------------------------------------------------------------------- # Import user values # Check config dictionary -def ccd(key, default, config_dir, name, inputtype, options, group, events=[], desc = "", regex = ""): +def ccd(key, default, config_dir, name, inputtype, options, group, events=[], desc = "", regex = "", setJsonMetadata = {}): result = default # use existing value if already supplied, otherwise default value is used @@ -33,8 +34,16 @@ def ccd(key, default, config_dir, name, inputtype, options, group, events=[], de if inputtype == 'text': result = result.replace('\'', "{s-quote}") + # # store setting metadata as a JSON + # ccd(f'{key}__metadata', set, c_d, "", "json" , "", pref) + # if inputtype == 'json': + # result = json.dumps(result) + conf.mySettingsSQLsafe.append((key, name, desc, inputtype, options, regex, str(result), group, str(events))) + conf.mySettingsSQLsafe.append((f'{key}__metadata', "metadata name", "metadata desc", 'json', "", "", json.dumps(setJsonMetadata), group, "")) + conf.mySettings.append((key, name, desc, inputtype, options, regex, result, group, str(events))) + conf.mySettings.append((f'{key}__metadata', "metadata name", "metadata desc", 'json', "", "", json.dumps(setJsonMetadata), group, "")) return result #------------------------------------------------------------------------------- @@ -199,7 +208,7 @@ def importConfigs (db): # Setting code name / key key = pref + "_" + setFunction - v = ccd(key, set["default_value"], c_d, set["name"][0]["string"], set["type"] , str(set["options"]), pref) + v = ccd(key, set["default_value"], c_d, set["name"][0]["string"], set["type"] , str(set["options"]), pref, set) # Save the user defined value into the object set["value"] = v