Skip to content
Snippets Groups Projects
Commit ba05052d authored by jkerdreu's avatar jkerdreu
Browse files

Added edit_metadata, filter and sort in devices list

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@2024 b32b6428-25c9-4566-ad07-03861ab6144f
parent ca6f519c
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ def setup():
engine.add_device(dev)
db_server = None
if 'db_server' in cfg['config'].keys():
if 'db_server' in cfg['config']:
db_server = cfg['config']['db_server']
else:
logger.info('You can set "db_server" in the config file')
......@@ -74,3 +74,12 @@ def get_uptime():
def get_device(addr):
return monitor.devices.get_with_addr(addr)
def update_kv(addr,kv):
dev = get_device(addr)
db_server = monitor.db_server
if dev:
body = {'device':dev.address,'map':kv}
print(body)
send_request(db_server,'updateKeysValues',body)
dev.update_cache_db(kv)
\ No newline at end of file
from .default import view,route,xaal_core
from bottle import request,redirect
from bottle import request,redirect,get,post
import copy
......@@ -52,6 +52,40 @@ def get_device(addr):
r.update({"dev" : dev})
return r
@get('/edit_metadata/<addr>')
@view('edit_metadata.mako')
def edit_metadata(addr):
r = {"title" : "device %s" % addr}
dev = xaal_core.get_device(addr)
if dev:
r.update({"dev" : dev})
return r
@post('/edit_metadata/<addr>')
@view('edit_metadata.mako')
def save_metadata(addr):
form = dict(request.forms.decode()) # just to shut up lint
kv = {}
for k in form:
key = str(k)
if form[k]=='': continue
if key.startswith('key_'):
id_ = key.split('key_')[-1]
v_key = 'value_'+id_
if v_key in form:
if form[v_key] =='':
value = None
else:
value = form[v_key]
kv.update({form[k]:value})
xaal_core.update_kv(addr,kv)
return edit_metadata(addr)
@route('/grid')
@view('grid.mako')
......
<%inherit file="base.mako"/>
<script src="/static/js/sorttable.js"></script>
<h2>Information</h2>
<!-- https://www.w3schools.com/howto/howto_js_filter_table.asp -->
<script>
function filterFunc(input_id,col) {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById(input_id);
filter = input.value.toUpperCase();
table = document.getElementById("devices");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[col];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<h2>Devices</h2>
<p>You can filter devices below. You can sort them too.</p>
<table width=100%>
<tr><th>Addr</th><th>devtype</th><th>Info</th><th>Attributes</th></tr>
<tr>
<td width=20%><input type="text" id="address" onkeyup="filterFunc('address',0)" placeholder="Filter address"></td>
<td width=15%><input type="text" id="devtype" onkeyup="filterFunc('devtype',1)" placeholder="Filter devtypes"></td>
<td width=15%><input type="text" id="name" onkeyup="filterFunc('name',2)" placeholder="Filter name"></td>
<td width=15%><input type="text" id="info" onkeyup="filterFunc('info',3)" placeholder="Filter info"></td>
<td width=35%><input type="text" id="attributes" onkeyup="filterFunc('attributes',4)" placeholder="Filter attribute"></td>
</tr>
</table>
</table>
<table width=100% class="sortable" id="devices">
<tr><th width=20%>Address</th><th width=15%>devtype</th><th width=15%>Name</th><th width=15%>Info</th><th width=35%>Attributes</th></tr>
% for dev in devs:
<tr>
<td><a href="/generic/${dev.address}">${dev.address}</a></td>
<td>${dev.devtype}</td>
<td>${dev.display_name}</td>
%if 'info' in dev.description.keys():
<td>${dev.description['info']}</td>
%else:
......
<%inherit file="base.mako"/>
<h2>Meta Data</h2>
<form method=post>
<table width=100%>
<tr><th>key</th><th>value</th></tr>
% for k in dev.db:
<tr><td><input name="key_${loop.index}" value="${k}"></td><td><input name="value_${loop.index}" value="${dev.db[k]}"</td></tr>
% endfor
<tr><td><input name="key_add1"></td><td><input name="value_add1"></td></tr>
<!--<tr><td><input name="key_add2"></td><td><input name="value_add2"></td></tr>-->
</table>
<input type="submit" value="Save">
</form>
\ No newline at end of file
<%inherit file="base.mako"/>
<table width=100%>
<tr valign=top><td>
<h2>Information</h2>
<table width=100%>
<tr><th>Name</th><th>value</th></tr>
<tr><td>address</td><td>${dev.address}</td></tr>
<tr><td>devtype</td><td>${dev.devtype}</td></tr>
</table>
</td>
<td>
<h2>Description</h2>
<table width=100%>
<tr><th>Name</th><th>value</th></tr>
......@@ -21,6 +23,8 @@
<tr><td>${k}</td><td>${value}</td></tr>
% endfor
</table>
</td></tr>
</table>
<h2>Attributes</h2>
<div data-is="generic-attrs" xaal_addr="${dev.address}"></div>
......@@ -33,3 +37,4 @@
<tr><td>${k}</td><td>${dev.db[k]}</td></tr>
% endfor
</table>
<a href="/edit_metadata/${dev.address}">Edit meta-data</a>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment