chg: [sever UI v0.2] filter sensors by active connection

pull/8/head
Terrtia 2019-01-29 09:22:21 +01:00
parent 69b9c12054
commit d0a2bee4f2
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
2 changed files with 62 additions and 3 deletions

View File

@ -30,7 +30,8 @@ json_type_description_path = os.path.join(os.environ['D4_HOME'], 'web/static/jso
redis_server_stream = redis.StrictRedis(
host=host_redis_stream,
port=port_redis_stream,
db=0)
db=0,
decode_responses=True)
host_redis_metadata = "localhost"
port_redis_metadata= 6380
@ -113,8 +114,21 @@ def _json_daily_type_stats():
@app.route('/sensors_status')
def sensors_status():
active_connection_filter = request.args.get('active_connection_filter')
if active_connection_filter is None:
active_connection_filter = False
else:
if active_connection_filter=='True':
active_connection_filter = True
else:
active_connection_filter = False
date = datetime.datetime.now().strftime("%Y%m%d")
daily_uuid = redis_server_metadata.zrange('daily_uuid:{}'.format(date), 0, -1)
if not active_connection_filter:
daily_uuid = redis_server_metadata.zrange('daily_uuid:{}'.format(date), 0, -1)
else:
daily_uuid = redis_server_stream.smembers('active_connection')
status_daily_uuid = []
for result in daily_uuid:
@ -138,7 +152,22 @@ def sensors_status():
"active_connection": active_connection,
"first_seen_gmt": first_seen_gmt, "last_seen_gmt": last_seen_gmt, "Error": Error})
return render_template("sensors_status.html", status_daily_uuid=status_daily_uuid)
return render_template("sensors_status.html", status_daily_uuid=status_daily_uuid,
active_connection_filter=active_connection_filter)
@app.route('/show_active_uuid')
def show_active_uuid():
#swap switch value
active_connection_filter = request.args.get('show_active_connection')
if active_connection_filter is None:
active_connection_filter = True
else:
if active_connection_filter=='True':
active_connection_filter = False
else:
active_connection_filter = True
return redirect(url_for('sensors_status', active_connection_filter=active_connection_filter))
@app.route('/server_management')
def server_management():

View File

@ -38,6 +38,31 @@
</ul>
</nav>
<div class="card mt-2 mb-2">
<div class="card-body bg-dark text-white">
<div class="row">
<div class="col-8">
<div class="custom-control custom-switch mt-2">
<input type="checkbox" class="custom-control-input" id="show_active_connection" {%if active_connection_filter%}checked value="True"{%else%}value=""{%endif%} onclick="window.location.href ='{{ url_for('show_active_uuid') }}?&show_active_connection='+$('#show_active_connection').val();">
<label class="custom-control-label" for="show_active_connection">Active Connection</label>
</div>
</div>
<div class="col-4">
<div class="form-row">
<div class="col-10">
<input type="text" class="form-control mt-1" id="search_uuid" placeholder="Search UUID">
</div>
<div class="col-2">
<button type="button" class="btn btn-outline-light" onclick="window.location.href ='{{ url_for('uuid_management') }}?redirect=0&uuid='+$('#search_uuid').val();">
<i class="fa fa-search fa-2x"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% for row_uuid in status_daily_uuid %}
<div class="card text-center mt-3 ml-2 mr-2">
<a href="{{ url_for('uuid_management') }}?uuid={{row_uuid['uuid']}}">
@ -89,4 +114,9 @@
</div>
{% endfor %}
<script>
var res = $('#show_active_connection').val();
console.log(res)
</script>
</body>