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

admin:user application settings+delete

parent 200052e2
{% extends 'logged_layout.html' %}
{% block title %} Administration - {{ user }} - {{ app[0] }} - Settings - HPC&A IoT {% 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>
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/users">Users</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="/administration/users/{{ user }}">{{ user }}</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="/administration/users/{{ user }}/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="/administration/users/{{ user }}/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="/administration/users/{{ user }}/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="/administration/users/{{ user }}/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 %}
...@@ -243,6 +243,55 @@ def administration_users_user_application_new_automation(name, appkey): ...@@ -243,6 +243,55 @@ def administration_users_user_application_new_automation(name, appkey):
return redirect(request.url) return redirect(request.url)
@app.route('/administration/users/<name>/application/<appkey>/delete')
@restricted(access_level='admin')
def administration_users_user_application_delete(name, appkey):
devs = dd.get_list(appkey)
for dev in devs[1]:
data.delete_table(appkey, dev[1])
# delete notifications
nq.delete_per_device(appkey, dev[1])
nfss = nfs.get_per_device(appkey, dev[1])
for nf in nfss[1]:
tr.delete(appkey, dev[1], nf[0])
tr.delete_function(appkey, dev[1], nf[0])
nfs.delete(appkey, dev[1], nf[0])
dd.delete_table(appkey)
res = ad.delete(appkey)
if not res[0]:
flash('Error deleting application: {}'.format(res[1]), 'danger')
return redirect(url_for('administration_users_user_application_settings', name=name, appkey=appkey))
else:
flash('Application deleted.', 'success')
return redirect(url_for('administration_users_user_applications', name=name))
@app.route('/administration/users/<name>/application/<appkey>/settings', methods=['GET', 'POST'])
@restricted(access_level='admin')
def administration_users_user_application_settings(name, appkey):
if request.method == 'GET':
ap = ad.get(appkey)
return render_template('new/admin/user-application-settings.html', app=ap[1], user=name)
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)
@app.route('/administration/users/<name>/application/<appkey>/delete-<ntype>') @app.route('/administration/users/<name>/application/<appkey>/delete-<ntype>')
@restricted(access_level='admin') @restricted(access_level='admin')
def administration_users_user_application_notification_remove(name, appkey, ntype): def administration_users_user_application_notification_remove(name, appkey, ntype):
......
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