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

gateway front-end management fully added & tested

parent 70503a0f
from app.helpers.misc import with_psql
from psycopg2 import Binary
@with_psql
def create(cur, name, gwid, protocol, desc, secure_key, telemetry_send_freq):
......@@ -29,7 +28,7 @@ def get_all(cur):
@with_psql
def delete(cur, gwid):
cur.execute('DELETE FROM gateways WHERE id = %s', gwid)
cur.execute('DELETE FROM gateways WHERE id = %s', (gwid,))
return (True,)
......
......@@ -2,6 +2,10 @@
{% block title %} Administration - Gateway - {{ gw['id'] }} - Settings - 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>
......@@ -73,7 +77,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<a href="/administration/gateway/{{ gw['id'] }}/delete"><button type="button" class="btn btn-danger">Delete Gateway</button></a>
<button type="button" onclick="gateway_delete({{ gw['id'] }})" class="btn btn-danger">Delete Gateway</button>
</div>
</div>
</div>
......@@ -90,5 +94,16 @@
{% block script %}
<script type="text/javascript">
document.getElementById("gwdesc").value = "{{ gw['description'] }}";
function gateway_delete(gwid) {
$.ajax({
url:"/administration/gateway/"+gwid+"/delete",
type:"DELETE",
success: function() {
console.log("success");
window.location.href = "/administration/gateways";
}
});
}
</script>
{% endblock %}
......@@ -650,7 +650,7 @@ def administration_user_delete_account(name):
return redirect(url_for('administration_user_settings', name=name))
@app.route('/administration/gateways')
@app.route('/administration/gateways', methods=["GET", "DELETE"])
@restricted('admin')
def administration_gateways():
user_cnt = ud.get_count()[1][0]
......@@ -663,7 +663,7 @@ def administration_gateways():
return render_template('views/admin/gateways.html', utcnow=misc.get_utc(), info=info, gws=gws)
@app.route('/administration/gateway/<gwid>')
@app.route('/administration/gateway/<gwid>', methods=["GET", "POST", "DELETE"])
@restricted('admin')
def administration_gateway(gwid):
user_cnt = ud.get_count()[1][0]
......@@ -710,3 +710,14 @@ def administration_gateway_settings(gwid):
return redirect(request.url)
return redirect(url_for('administration_gateway', gwid=gwid))
@app.route('/administration/gateway/<gwid>/delete', methods=["DELETE"])
@restricted('admin')
def administration_gateway_delete(gwid):
res = gd.delete(gwid)
if res[0]:
flash("Gateway '{}' deleted.".format(gwid), 'success')
return redirect(url_for('administration_gateways'))
else:
flash('Error: {}'.format(res[1]), 'danger')
return redirect(url_for('administration_gateway', gwid=gwid))
......@@ -95,16 +95,15 @@ CREATE TABLE public.notifications (
action character varying (200) NOT NULL
);
-- ALTER TABLE public.notifications_queue OWNER TO pi;
--
-- Name: users; Type: TABLE; Schema: public; Owner: pi
--
CREATE TABLE public.notifications_queue (
nf_id character varying(10) NOT NULL,
app_key character varying(30) NOT NULL,
dev_id numeric(3) NOT NULL,
fired_on timestamp(6) NOT NULL DEFAULT now()
CREATE TABLE public.gateways (
name character varying(30) NOT NULL,
id character varying(20) NOT NULL,
protocol character varying(30) NOT NULL,
description character varying(300),
telemetry_send_freq numeric NOT NULL,
last_keep_alive numeric DEFAULT 0,
num_errors numeric DEFAULT 0,
last_report character varying(1000)
);
......@@ -155,6 +154,12 @@ ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_app_key_fkey FOREIGN KEY (app_key) REFERENCES public.applications(app_key);
--
-- Name: gateways gateways_id_pkey; Type: CONSTRAINT; Schema: public; Owner: pi
--
ALTER TABLE ONLY public.gateways
ADD CONSTRAINT gateways_id_pkey PRIMARY KEY (id);
--
-- Name: notifications notifications_queue_pkey; Type: CONSTRAINT; Schema: public; Owner: pi
--
ALTER TABLE ONLY public.notifications_queue
......
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