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

alarms in progress

parent c6c61238
{% extends 'layout.html' %}
{% block title %} Application Alarms: {% 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">
{% if alarm_list %}
<div>
<table class="table">
<thead>
<th> Name </th>
<th> Description </th>
<th> </th>
</thead>
<tbody>
{% for a in alarm_list %}
<tr>
<th> {{ a[3] }} </th>
<th> {{ a[4] }} </th>
<th> <a href="/alarm-rm?id={{ c[0] }}"> <span class="glyphicon glyphicon-remove"</span> </a> </th>
</tr>
{% endfor %}
</tbody>
</table>
<a href="/new-alarm"><button class="btn btn-primary" type="submit">Create New Alarm</button></a>
</div>
{% else %}
<center> There are no alarms for given application. </center>
{% endif %}
</div>
</div>
{% endblock %}
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
<center> <center>
<a href="/add-dev"><button type="submit" class="btn btn-primary">Add Device</button></a> <a href="/add-dev"><button type="submit" class="btn btn-primary">Add Device</button></a>
<a href="/alarms"><button type="submit" class"btn btn-primary">Alarms</button></a>
<a href="/delete-app"><button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure? It will remove all devices and data.');">Delete Application</button></a> <a href="/delete-app"><button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure? It will remove all devices and data.');">Delete Application</button></a>
</center> </center>
<br> <br>
......
...@@ -498,5 +498,13 @@ def dev_data(var, dest, page): ...@@ -498,5 +498,13 @@ def dev_data(var, dest, page):
return t return t
@app.route('/alarms')
def alarms():
if name in session:
return render_template('public/alarms.html')
else:
return redirect(url_for('index'))
def pend_delete_all_ack(): def pend_delete_all_ack():
pend.delete_all_ack() pend.delete_all_ack()
CREATE TABLE public.notifications (
id VARCHAR(10) UNIQUE NOT NULL,
app_key VARCHAR(30) UNIQUE NOT NULL,
dev_id NUMERIC(3) NOT NULL,
name VARCHAR(50) NOT NULL,
description VARCHAR(300),
action_type VARCHAR(20) NOT NULL,
action VARCHAR (200) NOT NULL
);
CREATE TABLE public.notifications_queue (
nf_id VARCHAR(10) NOT NULL,
app_key VARCHAR(30) NOT NULL,
dev_id NUMERIC(3) NOT NULL
);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_pkey PRIMARY KEY (id, app_key, dev_id);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_pkey PRIMARY KEY (nf_id, app_key, dev_id);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_app_key_fkey FOREIGN KEY (app_key) REFERENCES public.applications(app_key);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_app_key_fkey FOREIGN KEY (app_key) REFERENCES public.notifications(app_key);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_nf_id_fkey FOREIGN KEY (nf_id) REFERENCES public.notifications(id);
CREATE OR REPLACE FUNCTION nf_4e662f03_1_aaaaa()
RETURNS trigger AS
$BODY$
BEGIN
IF (NEW.data->>'temperature')::int > 70 THEN
INSERT INTO notifications_queue VALUES('aaaaa', '4e662f03', 1);
END IF;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
CREATE TRIGGER tr_4e662f03_1_aaaaa
AFTER INSERT
on dev_4e662f03_1
FOR EACH ROW
EXECUTE PROCEDURE nf_4e662f03_1_aaaaa();
...@@ -41,7 +41,7 @@ SET default_with_oids = false; ...@@ -41,7 +41,7 @@ SET default_with_oids = false;
CREATE TABLE public.applications ( CREATE TABLE public.applications (
name character varying(30) NOT NULL, name character varying(30) NOT NULL,
app_key character varying(30) NOT NULL, app_key character varying(30) NOT NULL,
username character varying(30), username character varying(30) NOT NULL,
description character varying(200) description character varying(200)
); );
......
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