Commit 45a15aab authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

admin:add-device & device-settings with ddm added and tested

parent 3ad0d9a4
...@@ -38,6 +38,8 @@ function add_variable_name(id, type, name) { ...@@ -38,6 +38,8 @@ function add_variable_name(id, type, name) {
input.setAttribute("class", "form-control"); input.setAttribute("class", "form-control");
input.setAttribute("id", "varname_"+id); input.setAttribute("id", "varname_"+id);
input.setAttribute("name", "varname_"+id); input.setAttribute("name", "varname_"+id);
input.setAttribute("required", "true");
if (typeof name !== "undefined") { if (typeof name !== "undefined") {
input.setAttribute("value", name); input.setAttribute("value", name);
} }
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
{% block title %} Administration - {{ user }} - Add Device - HPC&A IoT {% endblock %} {% block title %} Administration - {{ user }} - Add Device - HPC&A IoT {% endblock %}
{% block header %}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
{% endblock %}
{% block location %} {% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration">Administration</a> <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> <p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
...@@ -39,8 +43,18 @@ ...@@ -39,8 +43,18 @@
<label>dev_id: {{ free_ids }}</label><br> <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> <input type="number" size="3" min="1" max="255" class="form-control" id="devid" name="devid" required><br>
</div> </div>
<br> <br>
<div class="form-group">
<label for="ddm"> Data Model: </label>
<select class="form-control" id="ddm" name="ddm" onchange="return onddm();">
{% for k,v in models.items() %}
<option value="{{ k }}"> {{ v }} </option>
{% endfor %}
</select>
</div>
<div id="ddm_div">
</div>
<br><br>
<div class="form-group"> <div class="form-group">
<button type="submit" class="btn btn-primary">Add Device</button> <button type="submit" class="btn btn-primary">Add Device</button>
</div> </div>
...@@ -51,3 +65,7 @@ ...@@ -51,3 +65,7 @@
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% block script %}
<script type="text/javascript" src="{{ url_for('static', filename='js/application-add-device.js') }}"></script>
{% endblock %}
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
{% block title %} Administration - {{ user }} - {{ app[0] }} - {{ dev[0] }} - Settings - HPC&amp;A IoT {% endblock %} {% block title %} Administration - {{ user }} - {{ app[0] }} - {{ dev[0] }} - Settings - HPC&amp;A IoT {% endblock %}
{% block header %}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
{% endblock %}
{% block location %} {% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration">Administration</a> <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> <p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
...@@ -36,6 +40,17 @@ ...@@ -36,6 +40,17 @@
<label>Description:</label><br> <label>Description:</label><br>
<textarea id="devdesc" maxlength="200" class="form-control" name="devdesc" rows="5"></textarea> <textarea id="devdesc" maxlength="200" class="form-control" name="devdesc" rows="5"></textarea>
</div> </div>
<br>
<div class="form-group">
<label for="ddm"> Data Model: </label>
<select class="form-control" id="ddm" name="ddm" onchange="return onddm();">
{% for k,v in models.items() %}
<option value="{{ k }}"> {{ v }} </option>
{% endfor %}
</select>
</div>
<div id="ddm_div">
</div>
</form> </form>
<br> <br>
<div class="row" style="margin-top: 30px;"> <div class="row" style="margin-top: 30px;">
...@@ -79,5 +94,7 @@ ...@@ -79,5 +94,7 @@
{% block script %} {% block script %}
<script type="text/javascript"> <script type="text/javascript">
document.getElementById("devdesc").value = "{{ dev[2] }}"; document.getElementById("devdesc").value = "{{ dev[2] }}";
var device_data_model = {{ dev[3]|safe }};
</script> </script>
<script type="text/javascript" src="{{ url_for('static', filename='js/application-add-device.js') }}"></script>
{% endblock %} {% endblock %}
{% extends 'logged_layout.html' %} {% extends 'logged_layout.html' %}
{% block title %} HPC&amp;A IoT - Add Device {% endblock %} {% block title %} Add device - HPC&amp;A IoT {% endblock %}
{% block header %} {% block header %}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
......
...@@ -42,44 +42,8 @@ ...@@ -42,44 +42,8 @@
<option value="{{ k }}"> {{ v }} </option> <option value="{{ k }}"> {{ v }} </option>
{% endfor %} {% endfor %}
</select> </select>
<!--
<select class="form-control" id="ddm" name="ddm" onclick="return onddm();">
<option value="{{ dev[3]['model'] }}" default> {{ models[dev[3]['model']] }} </option>
{% for k,v in models.items() %}
{% if k != dev[3]['model'] %}
<option value="{{ k }}"> {{ v }} </option>
{% endif %}
{% endfor %}
</select>
-->
</div> </div>
<div id="ddm_div"> <div id="ddm_div">
<!--
{% if dev[3]['format'] != {} %}
<div id="ddm_ext">
{% if dev[3]['model'] == 'json' or dev[3]['model'] == 'mpack' %}
{% for name, type in dev[3]['format'].items() %}
<div class="row" id="variable_{{ loop.index }}">
<div class="col-lg-6">
<div class="form-group">
<label for="varname_{{ loop.index }}"> Variable name: </label>
<input type="text" maxlength="30" class="form-control" id="varname_{{ loop.index }}" name="varname_{{ loop.index }}" value="{{ name }}">
</div>
</div>
<div class="col-lg-5">
<div class="form-group">
<label for="vartype_{{ loop.index }}"> Type: </label>
<select id="vartype_{{ loop.index }}" name="vartype_{{ loop.index }}" class="form-control" onchange="onvartype('{{ loop.index }}')">
<option value="{{ type }}"> {{ type }} </option>
</select>
</div>
</div>
</div>
{% endfor %}
{% endif %}
</div>
{% endif %}
-->
</div> </div>
</form> </form>
<br> <br>
......
...@@ -190,8 +190,6 @@ def application_device(appkey, devid): ...@@ -190,8 +190,6 @@ def application_device(appkey, devid):
ap = ad.get(appkey) ap = ad.get(appkey)
if session['name'] == ap[1][2]: if session['name'] == ap[1][2]:
dev = dd.get(appkey, devid) dev = dd.get(appkey, devid)
print(dev);
ld = data.get_last_range(appkey, devid, [MAX_PG_ENTRIES_DATA, 0]) ld = data.get_last_range(appkey, devid, [MAX_PG_ENTRIES_DATA, 0])
cnt = data.get_count(appkey, devid) cnt = data.get_count(appkey, devid)
...@@ -521,7 +519,6 @@ def application_new_alert(appkey): ...@@ -521,7 +519,6 @@ def application_new_alert(appkey):
if res[0]: if res[0]:
# create new function and trigger # create new function and trigger
t = tr.create_function_rt(appkey, request.form['devid'], nid, [request.form['varname'],request.form['operation'],request.form['avalue']],'alert',request.form['alertemail']) t = tr.create_function_rt(appkey, request.form['devid'], nid, [request.form['varname'],request.form['operation'],request.form['avalue']],'alert',request.form['alertemail'])
print(t)
tr.create(appkey, request.form['devid'], nid) tr.create(appkey, request.form['devid'], nid)
flash('Alert created', 'success') flash('Alert created', 'success')
return redirect(url_for('application_alerts', appkey=appkey)) return redirect(url_for('application_alerts', appkey=appkey))
...@@ -633,7 +630,6 @@ def application_device_settings(appkey, devid): ...@@ -633,7 +630,6 @@ def application_device_settings(appkey, devid):
return render_template('new/public/device-settings.html', app=ap[1], dev=dev[1], models=ddm.MODELS) return render_template('new/public/device-settings.html', app=ap[1], dev=dev[1], models=ddm.MODELS)
elif request.method == 'POST': elif request.method == 'POST':
ddmin = misc.extract_ddm(request) ddmin = misc.extract_ddm(request)
print(ddmin)
#res = dd.update(appkey, devid, request.form['devname'], request.form['devdesc']) #res = dd.update(appkey, devid, request.form['devname'], request.form['devdesc'])
res = dd.update_ddm(appkey, devid, request.form['devname'], request.form['devdesc'], ddmin) res = dd.update_ddm(appkey, devid, request.form['devname'], request.form['devdesc'], ddmin)
......
...@@ -14,6 +14,7 @@ import app.dao.misc.misc as md ...@@ -14,6 +14,7 @@ import app.dao.misc.misc as md
#import app.helpers.misc as misc #import app.helpers.misc as misc
from app.helpers.misc import restricted from app.helpers.misc import restricted
import app.helpers.device_data_model as ddm
import app.helpers.misc as misc import app.helpers.misc as misc
import binascii import binascii
...@@ -126,20 +127,21 @@ def administration_users_user_application_add_device(name, appkey): ...@@ -126,20 +127,21 @@ def administration_users_user_application_add_device(name, appkey):
if request.method == 'GET': if request.method == 'GET':
ap = ad.get(appkey) ap = ad.get(appkey)
dev_list = dd.get_list(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) return render_template('new/admin/user-add-device.html', app=ap[1], free_ids=misc.prep_id_range(dev_list[1]), models=ddm.MODELS, user=name)
elif request.method == 'POST': elif request.method == 'POST':
res = dd.create(request.form['devname'], request.form['devid'], appkey, request.form['devdesc']) ddmin = misc.extract_ddm(request)
res = dd.create_ddm(request.form['devname'], request.form['devid'], appkey, request.form['devdesc'], ddmin)
if not res[0]: if not res[0]:
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return render_template(request.url) return redirect(request.url)
else: else:
res = data.create_table(appkey, request.form['devid']) res = data.create_table(appkey, request.form['devid'])
if not res[0]: if not res[0]:
dd.delete(appkey, request.form['devid']) dd.delete(appkey, request.form['devid'])
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return render_template(request.url) return rendirect(request.url)
else: else:
return redirect(url_for('administration_users_user_application', name=name, appkey=appkey)) return redirect(url_for('administration_users_user_application', name=name, appkey=appkey))
...@@ -170,15 +172,15 @@ def administration_users_user_application_device_settings(name, appkey, devid): ...@@ -170,15 +172,15 @@ def administration_users_user_application_device_settings(name, appkey, devid):
if request.method == 'GET': if request.method == 'GET':
ap = ad.get(appkey) ap = ad.get(appkey)
dev = dd.get(appkey, devid) dev = dd.get(appkey, devid)
dev_list = dd.get_list(appkey)
return render_template('new/admin/user-application-device-settings.html', app=ap[1], dev=dev[1], free_ids=misc.prep_id_range(dev_list[1]), user=name) return render_template('new/admin/user-application-device-settings.html', app=ap[1], dev=dev[1], models=ddm.MODELS, user=name)
elif request.method == 'POST': elif request.method == 'POST':
res = dd.update(appkey, devid, request.form['devname'], request.form['devdesc']) ddmin = misc.extract_ddm(request)
res = dd.update_ddm(appkey, devid, request.form['devname'], request.form['devdesc'], ddmin)
if not res[0]: if not res[0]:
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return render_template(request.url) return redirect(request.url)
return redirect(request.url) return redirect(request.url)
......
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