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

gateways view added

parent 5558b6df
from app.helpers.misc import with_psql
from psycopg2 import Binary
@with_psql
def create(cur, name, gwid, desc, secure_key, telemetry_send_freq):
cur.execute(
'INSERT INTO gateways VALUES (%s, %s, %s, %s, %s)',
(name, gwid, desc, Binary(secure_key), telemetry_send_freq)
)
return (True,)
@with_psql
def get(cur, gwid):
cur.execute('SELECT row_to_json(r) FROM (SELECT * FROM gateways WHERE id = %s) r', gwid)
return (True, cur.fetchone()[0][0])
@with_psql
def get_all(cur):
cur.execute('SELECT row_to_json(r) FROM (SELECT * FROM gateways) r')
gws = cur.fetchall()
return (True, [gw[0] for gw in gws])
@with_psql
def delete(cur, gwid):
cur.execute('DELETE FROM gateways WHERE id = %s', gwid)
return (True,)
@with_psql
def update(cur, name, gwid, desc, telemetry_send_freq):
cur.execute(
"""
UPDATE
gateways
SET
name = %s,
desc = %s,
telemetry_send_freq = %s
WHERE
id = %s
""",
(name, desc, telemetry_send_freq, gwid)
)
return (True,)
{% extends 'logged_layout.html' %}
{% block title %} Administration - Gateways - HPC&A IoT {% endblock %}
{% block header %}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
{% endblock %}
{% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration">Administration</a>
<p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/gateways">Gateways</a>
{% endblock %}
{% block stats %}
<!-- Header -->
<div class="row">
<div class="col-xl-4 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Gateways</h5>
<span class="h2 font-weight-bold mb-0">{{ gws|length }}</span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-yellow text-white rounded-circle shadow">
<i class="fas fa-users"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Applications</h5>
<span class="h2 font-weight-bold mb-0">{{ info[1] }}</span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-success text-white rounded-circle shadow">
<i class="fas fa-cubes"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Devices</h5>
<span class="h2 font-weight-bold mb-0">{{ info[2] }}</span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-info text-white rounded-circle shadow">
<i class="fas fa-microchip"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block body %}
<!-- Page content -->
<div class="container-fluid mt--7">
<!-- Table -->
<div class="row">
<div class="col">
<div class="card shadow">
<div class="card-header bg-transparent">
<h3 class="mb-0">Gateways</h3>
</div>
<div class="card-body">
{% if gws %}
<div class="table-responsive">
<table class="table align-items-center table-flush table-hover">
<thead>
<th scope="col"> Name </th>
<th scope="col"> Protocol </th>
<th scope="col"> Status </th>
</thead>
<tbody>
{% for gw in gws %}
<tr onclick="window.location='/administration/gateway/{{ gw["id"] }}';">
<th> {{ gw['name'] }} </th>
<th> {{ gw['protocol'] }} </th>
<th> <span class="badge badge-dot">
{% if (utcnow - gw['last_keep_alive']) > gw['telemetry_send_freq'] %}
<i class="bg-danger"></i> connection-lost
{% else %}
<i class="bg-success"></i> online
{% endif %}
</span> </th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</div>
<div class="card-body">
<div class="col-lg-4">
<a href="/administration/new-gateway"><button class="btn btn-primary" type="submit">New Gateway</button></a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -5,6 +5,7 @@ from flask import render_template, request, redirect, url_for, session, flash, a
import app.dao.user.user as ud
import app.dao.application.application as ad
import app.dao.device.device as dd
import app.dao.gateway.gateway as gd
import app.dao.pend.pend as pend
import app.dao.data.data as data
import app.dao.notification.notification as nfs
......@@ -646,3 +647,30 @@ def administration_user_delete_account(name):
app.logger.critical('Administrator %s with role attempted to delete user %s with role %s', session['name'], session['role'], name, user[1][2])
flash('Warning: the user is admin or does not exist.' ,'danger')
return redirect(url_for('administration_user_settings', name=name))
@app.route('/administration/gateways')
@restricted('admin')
def administration_gateways():
user_cnt = ud.get_count()[1][0]
apps_cnt = ad.get_count()[1][0]
devs_cnt = dd.get_count_all()[1][0]
info = [user_cnt, apps_cnt, devs_cnt]
gws = gd.get_all()[1]
return render_template('views/admin/gateways.html', utcnow=misc.get_utc(), info=info, gws=gws)
@app.route('/administration/gateway/<gwid>')
@restricted('admin')
def administration_gateway(gwid):
user_cnt = ud.get_count()[1][0]
apps_cnt = ad.get_count()[1][0]
devs_cnt = dd.get_count_all()[1][0]
info = [user_cnt, apps_cnt, devs_cnt]
gws = gd.get(gwid)[1]
return render_template('views/admin/gateway.html', utcnow=misc.get_utc(), info=info, gw=gw)
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