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

alerts front end finished

parent 2372612c
...@@ -63,7 +63,7 @@ def create_function(cur, appkey, devid, nfid, expr): ...@@ -63,7 +63,7 @@ def create_function(cur, appkey, devid, nfid, expr):
VALUES VALUES
({},{},{}); ({},{},{});
END IF; END IF;
""".format( expr[0], get_type(expr[2]), expr[1], expr[2] """.format( expr[0], get_type(expr[2]), expr[1], expr[2],
ndif, appkey, devid) ndif, appkey, devid)
query += """ query += """
......
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% block title %} Application Alarms: {% endblock %} {% block title %} Application Alerts: {% endblock %}
{% block content %} {% block content %}
...@@ -21,16 +21,16 @@ ...@@ -21,16 +21,16 @@
<th> </th> <th> </th>
</thead> </thead>
<tbody> <tbody>
{% for a in alarm_list %} {% for a in alert_list %}
<tr> <tr>
<th> {{ a[3] }} </th> <th> {{ a[3] }} </th>
<th> {{ a[4] }} </th> <th> {{ a[4] }} </th>
<th> <a href="/alarm-rm?id={{ c[0] }}"> <span class="glyphicon glyphicon-remove"</span> </a> </th> <th> <a href="/alert-rm?id={{ a[0] }}"> <span class="glyphicon glyphicon-remove"</span> </a> </th>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<a href="/new-alarm"><button class="btn btn-primary" type="submit">Create New Alarm</button></a> <center><a href="/new-alert"><button class="btn btn-primary" type="submit">Create New Alert</button></a></center>
</div> </div>
{% else %} {% else %}
<center> There are no alarms for given application. </center> <center> There are no alarms for given application. </center>
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +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="/alerts"><button type="submit" class="btn btn-primary">Alerts</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>
......
{% extends 'layout.html' %}
{% block title %} New Alert {% 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">
<h2> Create New Alert </h2>
<br><br>
<form id="alertform" action="alert" method="post">
<div class="form-group">
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="alertname" name="alertname" required><br>
</div>
<div class="form-group">
<label>Description:</label><br>
<textarea id="alertdesc" maxlength="300" class="form-control" name="alertdesc" rows="5"></textarea>
</div>
<h3> Condition: </h3>
<h4> IF </h4>
<select class="form-control" id="devid" name="devid" onchange="ondev()" required>
<option default value="-">Select Device</option>
{% for d in devs %}
<option value="{{ d[1] }}">{{ d[0] }}</option>
{% endfor %}
</select>
<br>
{% if feedback %}
<p class="text-danger float-right">{{ feedback }}</p>
{% endif %}
</form>
<br>
<h4> THEN </h4>
<h5> Send email to </h5>
<input form="alertform" class="form-control" type="email" id="email" name="email" placeholder="Type email...">
<br>
<div class="form-group">
<button form="alertform" type="submit" class="btn btn-primary">Create Alert</button>
</div>
</div>
</div>
<script type="text/javascript">
function ondev() {
var dev_sel = document.getElementById("devid");
var sel_op = dev_sel.options[dev_sel.selectedIndex].value;
if (!document.getElementById("varname")) {
if (sel_op != "-") {
fetch(window.origin+'/dev-vars?id='+sel_op).then(res => res.text()).then(data => $("#alertform").append(data));
}
} else {
if (sel_op == "-") {
$("#varname").remove();
}
}
}
function onvar() {
if (!document.getElementById("operation")) {
$("#alertform").append("<br><select class='form-control' name='operaton' id='operation' onchange='onop()' required><option default>CHANGES</option><option>></option><option>>=</option><option><</option><option><=</option><option>==</option></select>");
} else {
var var_sel = document.getElementById("varname");
var sel_var = var_sel.options[var_sel.selectedIndex].value;
if (sel_var == "-") {
$("#operation").remove();
}
}
}
function onop() {
if (!document.getElementById("value")) {
var op_sel = document.getElementById("operation");
var sel_op = op_sel.options[op_sel.selectedIndex].text;
if (sel_op != "CHANGES" && !document.getElementById("avalue")) {
$("#alertform").append("<br><input type='numeric' class='form-control' name='avalue' id='avalue' placeholder='Value' required>");
} else {
if (document.getElementById("avalue")) {
$("#avalue").remove();
}
}
}
}
</script>
{% endblock %}
...@@ -8,6 +8,8 @@ import app.dao.application.application as ad ...@@ -8,6 +8,8 @@ import app.dao.application.application as ad
import app.dao.device.device as dd import app.dao.device.device as dd
import app.dao.pend.pend as pend import app.dao.pend.pend as pend
import app.dao.data.data as data import app.dao.data.data as data
import app.dao.notification.notification as nfs
import app.dao.trigger.trigger as tr
import app.helpers.misc as misc import app.helpers.misc as misc
...@@ -281,6 +283,7 @@ def dev_conf_rm(): ...@@ -281,6 +283,7 @@ def dev_conf_rm():
else: else:
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route('/delete-dev') @app.route('/delete-dev')
def delete_dev(): def delete_dev():
if 'name' in session and 'devid' in session: if 'name' in session and 'devid' in session:
...@@ -319,6 +322,20 @@ def dev_data_pg(): ...@@ -319,6 +322,20 @@ def dev_data_pg():
return redirect(utl_for('index')) return redirect(utl_for('index'))
@app.route('/dev-vars')
def dev_vars():
if 'name' in session:
last = data.get_last_n(session['appkey'], request.args.get('id'), 1)
if last[0]:
select = '<select class="form-control" id="varname" name="varname" onchange="onvar(event)" required>'
select += '<option value="-">Select Variable</option>'
for k in last[1][0][2]:
select += '<option>'+k+'</option>'
select += '</select>'
return select
else:
return redirect(url_for('index'))
@app.route('/data-csv') @app.route('/data-csv')
def data_csv(): def data_csv():
...@@ -441,6 +458,7 @@ def user_delete(): ...@@ -441,6 +458,7 @@ def user_delete():
flash('Warning: the user is admin or does not exist.' ,'warning') flash('Warning: the user is admin or does not exist.' ,'warning')
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route('/settings', methods=['GET', 'POST']) @app.route('/settings', methods=['GET', 'POST'])
def settings(): def settings():
if request.method == 'GET': if request.method == 'GET':
...@@ -498,11 +516,38 @@ def dev_data(var, dest, page): ...@@ -498,11 +516,38 @@ def dev_data(var, dest, page):
return t return t
@app.route('/alarms') @app.route('/alerts')
def alarms(): def alerts():
if name in session: if 'name' in session:
alerts = nfs.get_list(session['appkey'])
return render_template('public/alarms.html') return render_template('public/alerts.html', alert_list=alerts[1])
else:
return redirect(url_for('index'))
@app.route('/new-alert')
def new_alert():
if 'name' in session:
devs = dd.get_list(session['appkey'])
return render_template('public/new-alert.html', devs=devs[1])
else:
return redirect(url_for('index'))
@app.route('/alert', methods=['POST'])
def alert():
pass
@app.route('/alert-rm')
def alarm_rm():
if 'name' in session:
res = nfs.delete(session['appkey'], request.args.get('id'))
if res[0]:
flash('Alarm removed', 'success')
return redirect(url_for('alerts'))
else:
flash('Alarm cannot be removed : {}'.format(res[1]), 'danger')
return redirect(url_for('alerts'))
else: else:
return redirect(url_for('index')) return redirect(url_for('index'))
......
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