From ba3afd129dfbcc3db757905ab8998d10f77cc587 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 25 Aug 2022 15:37:54 +0200 Subject: [PATCH] implemented autorefresh --- SystemSettings.py | 3 +- Webserver/Templates/dashboard/dashboard.html | 82 +++++++++++++++++ Webserver/Templates/dashboard/pipeline.html | 21 +++++ Webserver/Templates/dashboard/zone.html | 92 ++++++++++++++++++++ Webserver/Templates/header.html | 46 ++++++++++ Webserver/Templates/{ => zones}/zone.html | 0 Webserver/Templates/{ => zones}/zones.html | 0 Webserver/__init__.py | 6 +- Webserver/static/js/action.js | 7 -- main.py | 4 +- 10 files changed, 249 insertions(+), 12 deletions(-) create mode 100644 Webserver/Templates/dashboard/dashboard.html create mode 100644 Webserver/Templates/dashboard/pipeline.html create mode 100644 Webserver/Templates/dashboard/zone.html rename Webserver/Templates/{ => zones}/zone.html (100%) rename Webserver/Templates/{ => zones}/zones.html (100%) diff --git a/SystemSettings.py b/SystemSettings.py index 1891b36..211f132 100644 --- a/SystemSettings.py +++ b/SystemSettings.py @@ -1,7 +1,8 @@ class SystemSettings: - def __init__(self, dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[5, 10, 15, 20, 25, 30, 45, 60]): + def __init__(self, cronJobFrequency=2, dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[5, 10, 15, 20, 25, 30, 45, 60]): + self.cronJobFrequency = cronJobFrequency self.dataDir = dataDir self.multiZoneIrrigation = multiZoneIrrigation self.defaultAutoIrrigationDuration = defaultAutoIrrigationDuration diff --git a/Webserver/Templates/dashboard/dashboard.html b/Webserver/Templates/dashboard/dashboard.html new file mode 100644 index 0000000..18c83ec --- /dev/null +++ b/Webserver/Templates/dashboard/dashboard.html @@ -0,0 +1,82 @@ + + + + + + {{ translater.getTranslation("Irrigation") }}{{ translater.getTranslation("system") }} + + + + + + + + {% include "header.html" %} + + +
+ +

{{ translater.getTranslation("Dashboard") }}

+ + +

{{ translater.getTranslation("planed irrigationjobs") }}

+

+ +

+
+ {% include "dashboard/pipeline.html" %} +
+ + +

{{ translater.getTranslation("irrigation zones") }}

+
+ {% for zone in zoneManager.zones %} +
+ {% include "dashboard/zone.html" %} +
+ + {% endfor %} + + + +
+ +
+



+ + + \ No newline at end of file diff --git a/Webserver/Templates/dashboard/pipeline.html b/Webserver/Templates/dashboard/pipeline.html new file mode 100644 index 0000000..8d852c4 --- /dev/null +++ b/Webserver/Templates/dashboard/pipeline.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + {% for job in zoneManager.pipeLine %} + + + + + + + {% endfor %} + +
ID{{ translater.getTranslation("Zone") }}{{ translater.getTranslation("planed duration") }}
{{ job.id }}{{ job.zone.number|string + ": " + job.zone.name }}{{ ((job.duration/60)|int)|string + " " + translater.getTranslation("minutes")}}
\ No newline at end of file diff --git a/Webserver/Templates/dashboard/zone.html b/Webserver/Templates/dashboard/zone.html new file mode 100644 index 0000000..14f40cb --- /dev/null +++ b/Webserver/Templates/dashboard/zone.html @@ -0,0 +1,92 @@ + +

{{ zone.name }}

+
+ + + + + + + + + + + {% if (zone.setState == 1 or zone.setState == 2) %} + + + + + + + {% endif %} + {% if zone.planedDuration > 0 %} + + + + + + + {% endif %} + + + + + + + + + + + + + + + + + + +
+ + + + {{ translater.getTranslation("state") }}: + {{ translater.getTranslation("switched on") if zone.state else translater.getTranslation("switched off") }} + + + + + +
+ {{translater.getTranslation("until") + zone.endTimeSetState|string}} + + +
+ {{translater.getTranslation("irragation is planed for") + " " + ((zone.planedDuration/60)|int)|string + " " + translater.getTranslation("minutes") + "." }} + + +
+ +

{{'A' if zone.autoMode else 'M'}}

+
+
+ + {{ translater.getTranslation("operating mode") }}:{{translater.getTranslation("automatic mode") if zone.autoMode else translater.getTranslation("manual mode")}} + +
+ + + + {{ translater.getTranslation("actual humidity") }}:{{ zone.actualHumidity}}
+ + {{ translater.getTranslation("desired humidity") }}:{{ zone.desiredHumidity }}
+

{{ zone.number }}

\ No newline at end of file diff --git a/Webserver/Templates/header.html b/Webserver/Templates/header.html index 9751ae0..ecb074d 100644 --- a/Webserver/Templates/header.html +++ b/Webserver/Templates/header.html @@ -14,6 +14,52 @@ var varString = 'command=' + command + '&index=' + index + '&value=' + value; send_web_request(url, messageString, varString, elementId); } + function executeActionByValueID(command, index, valueID, valueFactor){ + var value = document.getElementById(valueID).value * valueFactor; + executeAction(command, index, value); + } + + + + function switchZoneMode(autoMode, zone) { + executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual')); + sleep(1000).then(() => { + refreshZone(zone); + refreshPipeline(); + }); + + } + function switchZoneState(command, zone, value) { + executeAction(command, zone, value); + sleep(1000).then(() => { + refreshZone(zone); + refreshPipeline(); + }); + } + function switchZoneStateByValueID(command, zone, valueID, valueFactor) { + executeActionByValueID(command, zone, valueID, valueFactor); + sleep(1000).then(() => { + refreshZone(zone); + refreshPipeline(); + }); + } + function deleteJobsForZone(command, zone) { + executeAction(command, zone); + sleep(1000).then(() => { + refreshZone(zone); + refreshPipeline(); + }); + } + function deleteJobById(command, jobId, zone) { + executeAction(command, jobId); + sleep(1000).then(() => { + refreshZone(zone); + refreshPipeline(); + }); + } + + +setInterval(refreshContent, {{ (zoneManager.systemSettings.cronJobFrequency + 1) * 1000 }}) diff --git a/Webserver/Templates/zone.html b/Webserver/Templates/zones/zone.html similarity index 100% rename from Webserver/Templates/zone.html rename to Webserver/Templates/zones/zone.html diff --git a/Webserver/Templates/zones.html b/Webserver/Templates/zones/zones.html similarity index 100% rename from Webserver/Templates/zones.html rename to Webserver/Templates/zones/zones.html diff --git a/Webserver/__init__.py b/Webserver/__init__.py index 92e15c9..c638980 100644 --- a/Webserver/__init__.py +++ b/Webserver/__init__.py @@ -91,6 +91,8 @@ class Webserver: if (index): zone = self.zoneManager.getZone(index) return render_template('dashboard/zone.html', translater=self.translater, zoneManager=self.zoneManager, zone=zone) + case "get_dashboard_pipeline_html": + return render_template("dashboard/pipeline.html", translater=self.translater, zoneManager=self.zoneManager) case "get_zone_list": return self.zoneManager.zonesToJSON() case "get_zone_info": @@ -111,9 +113,9 @@ class Webserver: @app.route('/zones/') def showZones(zoneNumber=False): if (zoneNumber): - return render_template('zone.html', translater=self.translater, zone=self.zoneManager.getZone(zoneNumber)) + return render_template('zones/zone.html', translater=self.translater, zone=self.zoneManager.getZone(zoneNumber)) else: - return render_template('zones.html', translater=self.translater, zones=self.zoneManager.zones) + return render_template('zones/zones.html', translater=self.translater, zones=self.zoneManager.zones) @app.route('/times') def showTimes(): diff --git a/Webserver/static/js/action.js b/Webserver/static/js/action.js index 5ce0379..8b13789 100644 --- a/Webserver/static/js/action.js +++ b/Webserver/static/js/action.js @@ -1,8 +1 @@ -function executeActionByValueID(command, index, valueID, valueFactor){ - var value = document.getElementById(valueID).value * valueFactor; - executeAction(command, index, value); -} -function switchZoneMode(autoMode, zone) { - executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual')) -} diff --git a/main.py b/main.py index 8645ade..fce8609 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ from ZoneManager import ZoneManager from SystemSettings import SystemSettings from FileIO import FileIO -systemSettings = SystemSettings(dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[1, 5, 10, 15, 20, 25, 30, 45, 60]) +systemSettings = SystemSettings(cronJobFrequency=2, dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[1, 5, 10, 15, 20, 25, 30, 45, 60]) fileIO = FileIO(systemSettings) zoneManager = ZoneManager(systemSettings=systemSettings, fileIO=fileIO) webserver = Webserver(zoneManager=zoneManager, port=80) @@ -15,7 +15,7 @@ def cronJobs(): while True: zoneManager.cronJobs() print("Cronjobs done\nactual Time: " + str(time.time())) - time.sleep(0.5) + time.sleep(systemSettings.cronJobFrequency) if __name__ == "__main__": cronjob_Thread = threading.Thread(target=cronJobs)