new battery levels

begin of adminpannel and names editor
This commit is contained in:
BlubbFish 2019-04-07 23:07:29 +02:00
parent 925e30e086
commit e41e6ddabc
6 changed files with 119 additions and 8 deletions

View File

@ -75,6 +75,9 @@
</None>
</ItemGroup>
<ItemGroup>
<Content Include="resources\admin\css\global.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="resources\admin\index.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -187,6 +190,10 @@
<Name>Utils</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="resources\admin\js\menu.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
@ -14,9 +16,26 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model.Admin {
if(!this.CheckAuth(cont)) {
return false;
}
if(cont.Request.Url.PathAndQuery.StartsWith("/admin/get_json_")) {
return this.SendJson(cont);
}
return Webserver.SendFileResponse(cont);
}
private Boolean SendJson(HttpListenerContext cont) {
if(cont.Request.Url.PathAndQuery == "/admin/get_json_names") {
String file = File.ReadAllText("names.json");
Byte[] buf = Encoding.UTF8.GetBytes(file);
cont.Response.ContentLength64 = buf.Length;
cont.Response.OutputStream.Write(buf, 0, buf.Length);
Console.WriteLine("200 - Send names.json " + cont.Request.Url.PathAndQuery);
return true;
}
Helper.WriteError("404 - Section in get_json not found " + cont.Request.Url.PathAndQuery + "!");
cont.Response.StatusCode = 404;
return false;
}
private Boolean Login(HttpListenerContext cont) {
Dictionary<String, String> POST = Webserver.GetPostParams(cont.Request);
if(POST.ContainsKey("user") && POST["user"] == "admin" &&
@ -56,6 +75,9 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model.Admin {
}
private Boolean CheckAuth(HttpListenerContext cont) {
#if DEBUG
return true;
#endif
if(cont.Request.Url.PathAndQuery.StartsWith("/admin/login.html")) {
return true;
} else {

View File

@ -65,13 +65,13 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
}
this.Recievedtime = DateTime.UtcNow;
this.Battery = Math.Round((Double)json["BatteryLevel"], 2);
if(this.Battery < 3.59) {
if(this.Battery < 3.44) {
this.Batterysimple = 0;
} else if(this.Battery < 3.69) {
} else if(this.Battery < 3.53) {
this.Batterysimple = 1;
} else if(this.Battery < 3.77) {
} else if(this.Battery < 3.6525) {
this.Batterysimple = 2;
} else if(this.Battery < 3.97) {
} else if(this.Battery < 3.8825) {
this.Batterysimple = 3;
} else {
this.Batterysimple = 4;

View File

@ -0,0 +1,31 @@
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: Verdana;
}
#header {
font-size: 20px;
font-weight: bold;
padding: 5px;
}
#menu {
width: 200px;
font-size: 12px;
float: left;
}
#menu ul {
padding-left: 20px;
}
#menu ul li a {
color: black;
}
#menu ul li a:hover {
text-decoration: none;
}
#content {
margin-left: 210px;
}

View File

@ -3,9 +3,20 @@
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<title>Adminpannel Lora-Map</title>
<link rel="stylesheet" type="text/css" href="css/global.css" />
<script type="text/javascript" src="js/menu.js"></script>
</head>
<body>
ADMIN
<div id="header">Adminpannel Lora-Map</div>
<div id="menu">
<ul>
<li><a onclick="menu_names(); return false;" href="#">Namen und Icons</a></li>
<li><a onclick="menu_overlay(); return false;" href="#">Karteneditor</a></li>
<li><a onclick="menu_export(); return false;" href="#">Einstellungen Exportieren</a></li>
<li><a onclick="menu_import(); return false;" href="#">Einstellungen Importieren</a></li>
</ul>
</div>
<div id="content">Wilkommen im Adminbereich</div>
</body>
</html>

View File

@ -0,0 +1,40 @@
function menu_names() {
var parsenames = new XMLHttpRequest();
parsenames.onreadystatechange = function() {
if(parsenames.readyState === 4 && parsenames.status === 200) {
NamesEditor.parseJson(parsenames.responseText);
}
};
parsenames.open("GET", "http://{%REQUEST_URL_HOST%}:8080/admin/get_json_names", true);
parsenames.send();
}
function menu_overlay() {
}
function menu_export() {
}
function menu_import() {
}
var NamesEditor = {
parseJson: function (jsontext) {
document.getElementById("content").innerHTML = "";
var namesconfig = JSON.parse(jsontext);
var html = "<div>Einträge</div>";
for (var id in namesconfig) {
if (namesconfig.hasOwnProperty(id)) {
var nameentry = namesconfig[id];
html += "<div>" +
"<span>" + id + "</span>" +
"<span>"+nameentry["name"]+"</span>"+
"</div>";
}
}
document.getElementById("content").innerHTML = html;
}
};