From e90bd678c11386597be8845aba83ce4e4a26228e Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 13 Apr 2021 21:11:35 +0200 Subject: [PATCH] add settings for History --- Lora-Map/Model/Settings.cs | 27 ++++++++++ Lora-Map/resources/admin/js/settings.js | 69 ++++++++++++++++++++----- 2 files changed, 82 insertions(+), 14 deletions(-) diff --git a/Lora-Map/Model/Settings.cs b/Lora-Map/Model/Settings.cs index bf4d88d..b1130c6 100644 --- a/Lora-Map/Model/Settings.cs +++ b/Lora-Map/Model/Settings.cs @@ -124,6 +124,18 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { } this.External.Sensors = sensors; } + if(json.ContainsKey("History") && json["History"].IsObject) { + if(json["History"].ContainsKey("enabled") && json["History"]["enabled"].IsBoolean) { + this.External.History.Enabled = (Boolean)json["History"]["enabled"]; + } + if(this.External.History.Enabled) { + this.External.History.Time = json["History"].ContainsKey("time") && json["History"]["time"].IsInt ? (Int32)json["History"]["time"] : 0; + this.External.History.Time = json["History"].ContainsKey("amount") && json["History"]["amount"].IsInt ? (Int32)json["History"]["amount"] : 0; + } else { + this.External.History.Amount = 0; + this.External.History.Time = 0; + } + } this.gridradius = json.ContainsKey("GridRadius") && json["GridRadius"].IsInt && this.External.Startloclat != 0 && this.External.Startloclon != 0 ? (Int32)json["GridRadius"] : 0; this.GenerateGrid(); this.FindMapLayer(); @@ -294,6 +306,18 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { } } + public class History { + public Boolean Enabled { + get; set; + } = false; + public Int32 Time { + get; set; + } = 0; + public Int32 Amount { + get; set; + } = 0; + } + public class PublicSettings { public Double Startloclat { get; set; @@ -319,6 +343,9 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { public JsonData GeoLayer { get; set; } + public History History { + get; set; + } = new History(); } public class PrivateSettings { diff --git a/Lora-Map/resources/admin/js/settings.js b/Lora-Map/resources/admin/js/settings.js index def9417..2519a52 100644 --- a/Lora-Map/resources/admin/js/settings.js +++ b/Lora-Map/resources/admin/js/settings.js @@ -58,34 +58,38 @@ " "; }, ParseJson: function (jsonsettings) { - if (typeof jsonsettings.StartPos === "undefined") { + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "StartPos")) { jsonsettings.StartPos = { lat: 0, lon: 0 }; } - if (typeof jsonsettings.CellIds === "undefined") { + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "CellIds")) { jsonsettings.CellIds = []; } - if (typeof jsonsettings.GridRadius === "undefined") { + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "GridRadius")) { jsonsettings.GridRadius = 1000; } - if (typeof jsonsettings.FightDedection === "undefined") { + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "FightDedection")) { jsonsettings.FightDedection = []; } - if (typeof jsonsettings.CrwodDensity === "undefined") { + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "CrwodDensity")) { jsonsettings.CrwodDensity = []; } - if (typeof jsonsettings.Counting === "undefined") { + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "Counting")) { jsonsettings.Counting = []; } - if (typeof jsonsettings.Sensors === "undefined") { + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "Sensors")) { jsonsettings.Sensors = []; } + if (!Object.prototype.hasOwnProperty.call(jsonsettings, "History")) { + jsonsettings.History = []; + } var html = "
Einstellungen
"; - html += "
Startpunkt: Lat, Lon
"; - html += "
CellId's für DWD-Wetterwarnungen: (Trennen durch \";\", cap_warncellids_csv)
"; - html += "
Radius für das Grid um den Startpunkt: m
"; - html += "
Fight Dedection Kameras:
" + this._renderFightDedection(jsonsettings.FightDedection) + "
"; - html += "
Crowd Density Kameras:
" + this._renderCrowdDensity(jsonsettings.CrwodDensity) + "
"; - html += "
Sensors:
" + this._renderSensorSettings(jsonsettings.Sensors) + "
"; + html += "
Startpunkt: Lat, Lon

"; + html += "
CellId's für DWD-Wetterwarnungen: (Trennen durch \";\", cap_warncellids_csv)

"; + html += "
Radius für das Grid um den Startpunkt: m

"; + html += "
Fight Dedection Kameras:
" + this._renderFightDedection(jsonsettings.FightDedection) + "

"; + html += "
Crowd Density Kameras:
" + this._renderCrowdDensity(jsonsettings.CrwodDensity) + "

"; + html += "
Sensors:
" + this._renderSensorSettings(jsonsettings.Sensors) + "

"; + html += "
History: "+this._renderHistorySettings(jsonsettings.History)+"

"; html += "
"; document.getElementById("content").innerHTML = html + "
"; }, @@ -159,6 +163,29 @@ } ret.Sensors = sensorjson; + ret.History = {}; + if (document.getElementById("hist_yes").checked && !document.getElementById("hist_no").checked) { + ret.History.enabled = true; + var time = parseInt(document.getElementById("history_time").value); + if (isNaN(time)) { + time = 0; + } + var amount = parseInt(document.getElementById("history_amount").value); + if (isNaN(amount)) { + amount = 0; + } + if (time !== 0 && amount !== 0) { + alert("History: Entweder Zeit oder Menge muss 0 sein."); + return; + } + ret.History.time = time; + ret.History.amount = amount; + } else { + ret.History.enabled = false; + ret.History.time = 0; + ret.History.amount = 0; + } + var savesettings = new XMLHttpRequest(); savesettings.onreadystatechange = function () { if (savesettings.readyState === 4) { @@ -306,6 +333,20 @@ ret += ""; return ret; }, + _renderHistorySettings: function (json) { + if (!Object.prototype.hasOwnProperty.call(json, "enabled")) { + json.enabled = false; + } + if (!Object.prototype.hasOwnProperty.call(json, "time")) { + json.time = 0; + } + if (!Object.prototype.hasOwnProperty.call(json, "amount")) { + json.amount = 0; + } + var html = "Aktiv:
"; + html += "Zeit: s, Menge: " + return html; + }, _renderSensorSettings: function (json) { var ret = ""; ret += ""; @@ -326,5 +367,5 @@ ret += ""; ret += "
"; return ret; - }, + } }; \ No newline at end of file