Commit 27f49a1f authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

autoloaded table on scroll added

parent 65d79ff9
......@@ -36,6 +36,12 @@
<div id="curve_chart_{{ k }}"></div>
<table class="table" id="table_{{ k }}">
<thead>
<th> Time </th>
<th> {{ k }} </th>
</thead>
<tbody id="table_{{ k }}_body">
</tbody>
</table>
</div>
{% endfor %}
......@@ -92,6 +98,16 @@
{% if data %}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
function init_scroll() {
var ts = {
{% for k in data[0][2] %}
{{ k }} : 1,
{% endfor %}
};
return ts;
}
var tscroll = init_scroll();
google.charts.load('current', {'packages':['corechart']});
function drawChart(dname, ddata) {
......@@ -140,8 +156,17 @@
document.getElementById(dname).style.display = "block";
evt.currentTarget.className += " active";
fetch(window.origin+'/dev-data/'+dname+'/graph/1').then(res => res.text()).then(data => drawChart(dname, eval(data)));
fetch(window.origin+'/dev-data/'+dname+'/table/1').then(res => res.text()).then(data => $('#table_'+dname).html(data));
fetch(window.origin+'/dev-data/'+dname+'/graph/'+tscroll[dname]).then(res => res.text()).then(data => drawChart(dname, eval(data)));
fetch(window.origin+'/dev-data/'+dname+'/table/'+tscroll[dname]).then(res => res.text()).then(data => $('#table_'+dname+'_body').html(data));
window.onscroll = function (ev) {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
tscroll[dname] += 1;
fetch(window.origin+'/dev-data/'+dname+'/table/'+tscroll[dname]).then(res => res.text()).then(data => $('#table_'+dname+'_body').append(data));
console.log(tscroll[dname]);
}
};
}
document.getElementById("tab_{{ data[0][2] | first }}").click();
......
{% extends 'layout.html' %}
{% block title %} Home {% endblock %}
{% block title %} HPC&amp;A IoT Server {% endblock %}
{% block content %}
......
......@@ -484,16 +484,17 @@ def dev_data(var, dest, page):
elif dest == 'table':
# for table <cnt> is in items
last = data.get_last_range(session['appkey'], session['devid'], [MAX_PG_ENTRIES_DATA, (int(page)-1)*MAX_PG_ENTRIES_DATA])
t = """ <thead>
<th>Time</th>
<th>{}</th>
</thead>
<tbody>
""".format(var)
#t = """ <thead>
# <th>Time</th>
# <th>{}</th>
# </thead>
# <tbody>
#""".format(var)
t = ''
if last[0]:
for d in last[1]:
t += '<tr><th>'+d[1]+'</th><th>'+str(d[2][var])+'</th></tr>'
t += '</tbody>'
#t += '</tbody>'
return t
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment