Added table to web

This commit is contained in:
Igor Nurullaev
2019-08-27 19:42:34 +03:00
parent 738b7f971f
commit 53ee657620
7 changed files with 72 additions and 10 deletions

7
Server/static/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
html, body, .container {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}

3
Server/static/css/tabulator.min.css vendored Normal file

File diff suppressed because one or more lines are too long

24
Server/static/js/main.js Normal file
View File

@@ -0,0 +1,24 @@
var tabledata = [];
updateData();
function updateData() {
let req = new XMLHttpRequest();
req.open('POST', '/selfcheck/all', false);
req.send();
tabledata = JSON.parse(req.response);
}
var table = new Tabulator("#example-table", {
data: tabledata,
reactiveData: true,
layout: "fitColumns",
columns: [ //Define Table Columns
{title: "Name", field: "name"},
{title: "IP", field: "ip"},
{title: "Animation id", field: "anim_id"},
{title: "Batt voltage", field: "batt_voltage"},
{title: "Cell voltage", field: "cell_voltage"},
{title: "Selfcheck", field: "selfcheck"},
{title: "Time", field: "time"},
]
});

11
Server/static/js/tabulator.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -3,8 +3,18 @@
<head>
<meta charset="UTF-8">
<title>Main</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/tabulator.min.css">
<link rel="stylesheet" href="/static/css/main.css">
<script lang="js" src="/static/js/tabulator.min.js"></script>
</head>
<body>
{{ data }}
<div class="container">
<div class="table-container">
<div id="example-table"></div>
</div>
<div class="command-container"></div>
</div>
<script lang="js" src="/static/js/main.js"></script>
</body>
</html>

View File

@@ -1,9 +1,9 @@
import threading
from web_server_models import WebCopter
from server import *
from flask import Flask, render_template, jsonify, request
from flask import Flask, render_template, jsonify, request, send_from_directory
app = Flask(__name__)
app = Flask(__name__, static_url_path='/static')
copters = []
@@ -55,20 +55,20 @@ def selfcheck_selected():
return jsonify(data)
@app.route('/selfcheck/all')
@app.route('/selfcheck/all', methods=["GET", "POST"])
def selfcheck_all():
data = dict()
ip = request.args.get("ip")
data = []
for copter in copters:
copter.refresh()
data[copter.ip] = {
data.append({
'anim_id': copter.anim_id,
'batt_voltage': copter.batt_voltage,
'cell_voltage': copter.cell_voltage,
'selfcheck': copter.selfcheck,
'ip': copter.ip,
'time': copter.time,
'name': copter.name,
}
})
return jsonify(data)
@@ -80,6 +80,6 @@ class ServerThread(threading.Thread):
pass
server_thread = ServerThread()
server_thread.start()
# server_thread = ServerThread()
# server_thread.start()
app.run(host='0.0.0.0', debug=False)