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

application settings integrated & tested

parent ac18fafa
{% extends 'logged_layout.html' %}
{% block title %} HPC&A IoT - Application Settings {% endblock %}
{% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/applications">Applications</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="/application/{{ app[1] }}">{{ app[0] }}</a>
{% 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">Application Settings</h3>
</div>
<div class="card-body">
<form action="/application/{{ app[1] }}/settings" method="post" id="appsettings">
<div class="form-group">
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="appname" name="appname" value="{{ app[0] }}" required><br>
</div>
<div class="form-group">
<label>Description:</label><br>
<textarea id="appdesc" maxlength="200" class="form-control" name="appdesc" rows="5"></textarea>
</div>
<br>
<div class="custom-control custom-control-alternative custom-checkbox">
<input class="custom-control-input" id="secure" type="checkbox" name="secure" {% if app[4] %} checked {% endif %}>
<label class="custom-control-label" for="secure">
<span class="text-muted">Secure</span>
</label>
</div>
<br>
<p> Note, if you use secure option, make sure your device uses aes128 ctr with the corresponding key.</p>
<br>
</form>
<div class="row" style="margin-top: 30px;">
<div class="col-lg-3">
<button type="submit" form="appsettings" class="btn btn-primary btn-block">Save</button>
</div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
<button type="button" class="btn btn-danger btn-block" data-toggle="modal" data-target="#exampleModal">Delete</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
This action will remove permanently the application and all its devices with their corresponding data.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<a href="/application/{{ app[1] }}/delete"><button type="button" class="btn btn-danger">Delete Application</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
document.getElementById("appdesc").value = "{{ app[3] }}";
</script>
{% endblock %}
......@@ -12,7 +12,7 @@
<div class="col">
<div class="card shadow">
<div class="card-header bg-transparent">
<h3 class="mb-0">Applications</h3>
<h3 class="mb-0">New Application</h3>
</div>
<div class="card-body">
<form action="new-application" method="post">
......
......@@ -137,7 +137,7 @@ def application(appkey):
@app.route('/new-application', methods=['GET', 'POST'])
def new_application():
def application_create():
if 'name' in session:
if request.method == 'GET':
return render_template('new/public/new-application.html')
......@@ -145,7 +145,7 @@ def new_application():
if request.form['appname'] == '':
flash('Application name cannot be empty.', 'danger')
return render_template(request.url)
else:
elif request.method == 'POST':
appkey = misc.rand_str(app.config['APPKEY_LENGTH']).decode('utf-8')
secure_key = misc.gen_skey_b64(16)
secure = False
......@@ -171,6 +171,28 @@ def new_application():
return redirect(url_for('login', users_signup=app.config['USERS_SIGNUP']))
@app.route('/application/<appkey>/delete')
def application_delete(appkey):
if 'name' in session:
devs = dd.get_list(appkey)
for dev in devs[1]:
data.delete_table(appkey, dev[1])
dd.delete_table(appkey)
res = ad.delete(appkey)
if not res[0]:
flash('Error deleting application: {}'.format(res[1]), 'danger')
return redirect(url_for('application', appkey=appkey))
else:
flash('Application deleted.', 'success')
return redirect(url_for('applications'))
else:
return redirect(url_for('login'))
@app.route('/application/<appkey>/device/<devid>')
def application_device(appkey, devid):
if 'name' in session:
......@@ -842,6 +864,30 @@ def application_new_automation(appkey):
return redirect(url_for('login'))
@app.route('/application/<appkey>/settings', methods=['GET', 'POST'])
def application_settings(appkey):
if 'name' in session:
if request.method == 'GET':
ap = ad.get(appkey)
return render_template('new/public/application-settings.html', app=ap[1])
elif request.method == 'POST':
if request.form.getlist('secure') and request.form.getlist('secure')[0] == 'on':
secure = True
else:
secure = False
res = ad.update(appkey, request.form['appname'], request.form['appdesc'], secure)
if not res[0]:
flash('Error: {}'.format(res[1]), 'danger')
return render_template(request.url)
return redirect(request.url)
else:
return redirect(url_for('login'))
@app.route('/alerts')
def alerts():
if 'name' in session:
......@@ -850,6 +896,7 @@ def alerts():
else:
return redirect(url_for('index'))
@app.route('/new-alert')
def new_alert():
if 'name' in session:
......
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