Commit d91e17e2 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

definite change to dev-data paged

parent 046f3ba4
{% extends 'layout.html' %}
{% block title %} Device Data: {% endblock %}
{% block content %}
<div class="row">
<div class="col-md-3">
<div class="clickback">
<span class="glyphicon glyphicon-arrow-left"></span>
<p><a class="backlink" onclick="history.back(-1)"></a></p>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-success">
<div class="panel-heading">
<h2><center> {{ devname }} data </center></h2>
</div>
<div class="panel-body">
{% if data %}
<table class="table">
<thead>
<th>Time</th>
<th>Content</th>
</thead>
<tbody>
{% for d in data %}
<tr>
<th> {{ d[1] }} </th>
<th>
{% for k in d[2] %}
{{ k }} : {{ d[2][k] }} <br>
{% endfor %}
</th>
</tr>
{% endfor %}
</tbody>
</table>
<p>Total: <strong>{{ total }}</strong> messages.</p>
<center>
<nav aria-label="Page navigation">
<ul class="pagination">
{% if pp %}
<li>
{% else %}
<li class="disabled">
{% endif %}
<a href="/dev-data-pg?p={{ pp }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% for i in range(pr[0],pr[1]) %}
{% if i == cp %}
<li class="active">
<a href="/dev-data-pg?p={{ i }}">
{{ i }}
<span class="sr-only">(current)</span>
</a>
</li>
{% else %}
<li>
<a href="/dev-data-pg?p={{ i }}"> {{ i }} </a>
</li>
{% endif %}
{% endfor %}
{% if np %}
<li>
{% else %}
<li class="disabled">
{% endif %}
<a href="/dev-data-pg?p={{ np }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
</center>
<br>
<center>
<a href="/data-csv"><button type="submit" class="btn btn-primary">Download CSV</button></a>
</center>
{% else %}
<h3><center>Device have not sent any data yet.</center></h3>
{% endif %}
</div>
</div>
<script type="text/javascrypt">
function conf() {
return confirm("Are you sure? It will remove all device data.")
}
</script>
{% endblock %}
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% if data %} {% if data %}
<p>Last {{ lastctr }} messages:</p>
<table class="table"> <table class="table">
<thead> <thead>
...@@ -40,7 +39,46 @@ ...@@ -40,7 +39,46 @@
</table> </table>
<p>Total: <strong>{{ total }}</strong> messages.</p> <p>Total: <strong>{{ total }}</strong> messages.</p>
<center>
<nav aria-label="Page navigation">
<ul class="pagination">
{% if pp %}
<li>
{% else %}
<li class="disabled">
{% endif %}
<a href="/dev-data-pg?p={{ pp }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% for i in range(pr[0],pr[1]) %}
{% if i == cp %}
<li class="active">
<a href="/dev-data-pg?p={{ i }}">
{{ i }}
<span class="sr-only">(current)</span>
</a>
</li>
{% else %}
<li>
<a href="/dev-data-pg?p={{ i }}"> {{ i }} </a>
</li>
{% endif %}
{% endfor %}
{% if np %}
<li>
{% else %}
<li class="disabled">
{% endif %}
<a href="/dev-data-pg?p={{ np }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
</center>
<br>
<center> <center>
<a href="/data-csv"><button type="submit" class="btn btn-primary">Download CSV</button></a> <a href="/data-csv"><button type="submit" class="btn btn-primary">Download CSV</button></a>
</center> </center>
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<br><br> <br><br>
<center> <center>
<a href="/dev-data-pg"><button type="submit" class="btn btn-primary">Data</button></a> <a href="/dev-data"><button type="submit" class="btn btn-primary">Data</button></a>
<a href="/dev-conf"><button type="submit" class="btn btn-primary">Configure</button></a> <a href="/dev-conf"><button type="submit" class="btn btn-primary">Configure</button></a>
<a href="/delete-dev"><button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure? It will remove all device data.');">Delete Device</button></a> <a href="/delete-dev"><button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure? It will remove all device data.');">Delete Device</button></a>
</center> </center>
......
...@@ -188,27 +188,23 @@ def new_dev(): ...@@ -188,27 +188,23 @@ def new_dev():
def dev(): def dev():
if 'name' in session: if 'name' in session:
if request.method == 'GET': if request.method == 'GET':
ap = ad.get(session['appkey'])
# possible security improvement if session['role'] == 'admin' or session['name'] == ap[1][2]:
#ap = ad.get(session['appkey']) dev = dd.get(session['appkey'], request.args.get('id'))
#if session['role'] == 'admin' or session['name'] == ap[1][2]:
# return render_template(...) session['devid'] = int(dev[1][1])
#else: session['devname'] = dev[1][0]
# return redirect(url_for('index'))
dev = dd.get(session['appkey'], request.args.get('id'))
session['devid'] = int(dev[1][1])
session['devname'] = dev[1][0]
last = data.get_last_n(session['appkey'], session['devid'], 1) last = data.get_last_n(session['appkey'], session['devid'], 1)
ltup = 'Device have not sent data yet' ltup = 'Device have not sent data yet'
if last[0]: if last[0]:
ltup = last[1][0][1] ltup = last[1][0][1]
return render_template('public/dev.html', dev=dev[1], appkey=session['appkey'], ltup=ltup) return render_template('public/dev.html', dev=dev[1], appkey=session['appkey'], ltup=ltup)
else:
return redirect(url_for('index'))
else: else:
res = dd.create(request.form['devname'], request.form['devid'], session['appkey'], request.form['devdesc']) res = dd.create(request.form['devname'], request.form['devid'], session['appkey'], request.form['devdesc'])
...@@ -291,23 +287,6 @@ def delete_dev(): ...@@ -291,23 +287,6 @@ def delete_dev():
@app.route('/dev-data') @app.route('/dev-data')
def dev_data():
if 'name' in session and 'devid' in session:
last = data.get_last_n(session['appkey'], session['devid'], 10)
count = data.get_count(session['appkey'], session['devid'])
last_ctr = 10
if count[1][0] < 10:
last_ctr = count[1][0]
if count[1][0] > 0:
return render_template('public/dev-data.html', data=last[1], total=count[1][0], lastctr=last_ctr, devname=session['devname'])
else:
return render_template('public/dev-data.html', devname=session['devname'])
else:
return redirect(utl_for('index'))
@app.route('/dev-data-pg')
def dev_data_pg(): def dev_data_pg():
if 'name' in session and 'devid' in session: if 'name' in session and 'devid' in session:
cur_pg = 1 cur_pg = 1
...@@ -324,12 +303,12 @@ def dev_data_pg(): ...@@ -324,12 +303,12 @@ def dev_data_pg():
rd = misc.paging(cur_pg, ent_cnt[1][0], MAX_PG_ENTRIES_DATA, MAX_PG) rd = misc.paging(cur_pg, ent_cnt[1][0], MAX_PG_ENTRIES_DATA, MAX_PG)
if ent_cnt[1][0] > 0: if ent_cnt[1][0] > 0:
return render_template('public/dev-data-pg.html', data=last[1], total=ent_cnt[1][0], cp=cur_pg, np=rd[2], pp=rd[0], pr=rd[1], devname=session['devname']) return render_template('public/dev-data.html', data=last[1], total=ent_cnt[1][0], cp=cur_pg, np=rd[2], pp=rd[0], pr=rd[1], devname=session['devname'])
else: else:
return render_template('public/dev-data-pg.html', devname=session['devname']) return render_template('public/dev-data.html', devname=session['devname'])
else: else:
flash('Error: {}'.format(ent_cnt[1]), 'danger') flash('Error: {}'.format(ent_cnt[1]), 'danger')
return render_template('public/dev-data-pg.html', devname=session['devname']) return render_template('public/dev-data.html', devname=session['devname'])
else: else:
return redirect(utl_for('index')) return redirect(utl_for('index'))
...@@ -418,8 +397,7 @@ def user(): ...@@ -418,8 +397,7 @@ def user():
@app.route('/user-delete') @app.route('/user-delete')
def user_delete(): def user_delete():
user = ud.get(request.args.get('name')) user = ud.get(request.args.get('name'))
if user[2] != 'admin' and session['role'] and session['role'] == 'admin': if user[1][2] != 'admin' and session['role'] and session['role'] == 'admin':
pass
def pend_delete_all_ack(): def pend_delete_all_ack():
......
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