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

notifiaction creation success

parent ad155bf6
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{% if alarm_list %} {% if alert_list %}
<div> <div>
<table class="table"> <table class="table">
<thead> <thead>
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<h4> THEN </h4> <h4> THEN </h4>
<h5> Send email to </h5> <h5> Send email to </h5>
<input form="alertform" class="form-control" type="email" id="email" name="email" placeholder="Type email..."> <input form="alertform" class="form-control" type="email" id="alertemail" name="alertemail" placeholder="Type email...">
<br> <br>
<div class="form-group"> <div class="form-group">
<button form="alertform" type="submit" class="btn btn-primary">Create Alert</button> <button form="alertform" type="submit" class="btn btn-primary">Create Alert</button>
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
} }
function onvar() { function onvar() {
if (!document.getElementById("operation")) { if (!document.getElementById("operation")) {
$("#alertform").append("<select class='form-control notifelem' name='operaton' id='operation' onchange='onop()' required><option default>CHANGES</option><option>></option><option>>=</option><option><</option><option><=</option><option>==</option></select>"); $("#alertform").append("<select class='form-control notifelem' name='operation' id='operation' onchange='onop()' required><option default>CHANGES</option><option>></option><option>>=</option><option><</option><option><=</option><option>==</option></select>");
} else { } else {
var var_sel = document.getElementById("varname"); var var_sel = document.getElementById("varname");
var sel_var = var_sel.options[var_sel.selectedIndex].value; var sel_var = var_sel.options[var_sel.selectedIndex].value;
......
...@@ -131,6 +131,8 @@ def app_(): ...@@ -131,6 +131,8 @@ def app_():
ap = ad.get(session['appkey']) ap = ad.get(session['appkey'])
devs = dd.get_list(ap[1][1]) devs = dd.get_list(ap[1][1])
session['appname'] = ap[1][0]
if session['role'] == 'admin' or session['name'] == ap[1][2]: if session['role'] == 'admin' or session['name'] == ap[1][2]:
return render_template('public/app.html', app=ap[1], devs=devs[1]) return render_template('public/app.html', app=ap[1], devs=devs[1])
else: else:
...@@ -535,7 +537,31 @@ def new_alert(): ...@@ -535,7 +537,31 @@ def new_alert():
@app.route('/alert', methods=['POST']) @app.route('/alert', methods=['POST'])
def alert(): def alert():
pass if 'name' in session:
if request.method == 'POST':
# create new notification
nid = misc.rand_str(app.config['NID_LENGTH']).decode('utf-8')
dev = dd.get(session['appkey'], request.form['devid'])
try:
desc_ext = request.form['alertdesc'] + ' (Application '+session['appname']+' => '+dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']+' '+request.form['avalue']+')'
except:
desc_ext = request.form['alertdesc'] + ' (Application '+session['appname']+' => '+dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']+')'
res = nfs.create(nid, session['appkey'], request.form['devid'], request.form['alertname'], desc_ext, 'alert', request.form['alertemail'])
if res[0]:
print('notification created')
return redirect(url_for('alerts'))
else:
flash('Error creating new notification: {}'.format(res[1]), 'danger')
return redirect(url_for('alerts'))
# create new function and trigger
else:
return redirect(url_for('index'))
else:
return redirect(url_for('index'))
@app.route('/alert-rm') @app.route('/alert-rm')
def alarm_rm(): def alarm_rm():
...@@ -543,10 +569,10 @@ def alarm_rm(): ...@@ -543,10 +569,10 @@ def alarm_rm():
res = nfs.delete(session['appkey'], request.args.get('id')) res = nfs.delete(session['appkey'], request.args.get('id'))
if res[0]: if res[0]:
flash('Alarm removed', 'success') flash('Alert removed', 'success')
return redirect(url_for('alerts')) return redirect(url_for('alerts'))
else: else:
flash('Alarm cannot be removed : {}'.format(res[1]), 'danger') flash('Alert cannot be removed : {}'.format(res[1]), 'danger')
return redirect(url_for('alerts')) return redirect(url_for('alerts'))
else: else:
return redirect(url_for('index')) return redirect(url_for('index'))
......
...@@ -14,6 +14,7 @@ class Config(object): ...@@ -14,6 +14,7 @@ class Config(object):
REMEMBER_COOKIE_SECURE = True REMEMBER_COOKIE_SECURE = True
APPKEY_LENGTH = 8 APPKEY_LENGTH = 8
NID_LENGTH = 5
DATA_DOWNLOAD_DIR = 'data' DATA_DOWNLOAD_DIR = 'data'
DATA_DOWNLOAD_DIR_OS = 'app/data' DATA_DOWNLOAD_DIR_OS = 'app/data'
......
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