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

admin: user application add device view added

parent d4b024ed
{% extends 'logged_layout.html' %}
{% block title %} Administration - {{ user }} - Add Device - 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">Add Device</h3>
</div>
<div class="card-body">
<form action="/administration/users/{{ user }}/application/{{ app[1] }}/add-device" method="post">
<div class="form-group">
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="devname" name="devname" required><br>
</div>
<div class="form-group">
<label>Description:</label><br>
<textarea id="devdesc" maxlength="200" class="form-control" name="devdesc" rows="5"></textarea>
</div>
<br>
<div class="form-group">
<label>dev_id: {{ free_ids }}</label><br>
<input type="number" size="3" min="1" max="255" class="form-control" id="devid" name="devid" required><br>
</div>
<br>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add Device</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -435,7 +435,7 @@ def dev():
last = data.get_last_n(session['appkey'], session['devid'], 1)
ltup = 'Device have not sent data yet'
ltup = 'Device has not sent data yet'
if last[0]:
ltup = last[1][0][1]
......
......@@ -77,6 +77,7 @@ def administration_users_user_applications(name):
@app.route('/administration/users/<name>/new-application', methods=['GET', 'POST'])
@restricted(access_level='admin')
def administration_users_user_application_create(name):
if request.method == 'GET':
return render_template('new/admin/user-new-application.html', user=name)
......@@ -118,6 +119,30 @@ def administration_users_user_application(name, appkey):
return render_template('new/admin/user-application.html', app=ap, devs=devs, user=name)
@app.route('/administration/users/<name>/application/<appkey>/add-device', methods=['GET', 'POST'])
@restricted(access_level='admin')
def administration_users_user_application_add_device(name, appkey):
if request.method == 'GET':
ap = ad.get(appkey)
dev_list = dd.get_list(appkey)
return render_template('new/admin/user-add-device.html', app=ap[1], free_ids=misc.prep_id_range(dev_list[1]), user=name)
elif request.method == 'POST':
res = dd.create(request.form['devname'], request.form['devid'], appkey, request.form['devdesc'])
if not res[0]:
flash('Error: {}'.format(res[1]), 'danger')
return render_template(request.url)
else:
res = data.create_table(appkey, request.form['devid'])
if not res[0]:
dd.delete(appkey, request.form['devid'])
flash('Error: {}'.format(res[1]), 'danger')
return render_template(request.url)
else:
return redirect(url_for('administration_users_user_application', name=name, appkey=appkey))
@app.route('/administration/users/<name>/application/<appkey>/device/<devid>')
@restricted(access_level='admin')
def administration_users_user_application_device(name, appkey, devid):
......@@ -127,7 +152,7 @@ def administration_users_user_application_device(name, appkey, devid):
ld = data.get_last_range(appkey, devid, [MAX_PG_ENTRIES_DATA, 0])
cnt = data.get_count(appkey, devid)
ltup = 'Device have not any sent data yet'
ltup = 'Device has not any sent data yet'
if ld[0] and ld[1][0] != []:
ltup = ld[1][0][1]
......
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