Added multiple fields in dataTable row

pull/18/head
Sami Mokaddem 2017-10-24 15:17:52 +02:00
parent d7a60139f7
commit 99542c5316
5 changed files with 25 additions and 13 deletions

View File

@ -10,7 +10,8 @@ size_openStreet_pannel_perc = 55
size_world_pannel_perc = 35
[Log]
fieldname_order=["id", "category", "type", "value"]
fieldname_order=["id", "category", "type", ["value", "comment"]]
char_separator=||
[RedisLog]
host=localhost

View File

@ -32,8 +32,14 @@ eventNumber = 0
class LogItem():
FIELDNAME_ORDER = []
FIELDNAME_ORDER_HEADER = []
FIELDNAME_ORDER.append("time")
FIELDNAME_ORDER_HEADER.append("time")
for item in json.loads(cfg.get('Log', 'fieldname_order')):
if type(item) is list:
FIELDNAME_ORDER_HEADER.append(" | ".join(item))
else:
FIELDNAME_ORDER_HEADER.append(item)
FIELDNAME_ORDER.append(item)
def __init__(self, feed):
@ -46,18 +52,18 @@ class LogItem():
def get_head_row(self):
to_ret = []
for fn in LogItem.FIELDNAME_ORDER:
for fn in LogItem.FIELDNAME_ORDER_HEADER:
to_ret.append(fn[0].upper()+fn[1:])
return to_ret
def get_row(self):
to_ret = {}
#Number to keep them sorted (jsonify sort keys)
for i in range(len(LogItem.FIELDNAME_ORDER)):
for item in range(len(LogItem.FIELDNAME_ORDER)):
try:
to_ret[i] = self.fields[i]
to_ret[item] = self.fields[item]
except IndexError: # not enough field in rcv item
to_ret[i] = ''
to_ret[item] = ''
return to_ret
@ -91,6 +97,7 @@ def index():
return render_template('index.html',
pannelSize=pannelSize,
graph_log_refresh_rate=cfg.getint('Dashboard' ,'graph_log_refresh_rate'),
char_separator=cfg.get('Log', 'char_separator'),
rotation_wait_time=cfg.getint('Dashboard' ,'rotation_wait_time'),
max_img_rotation=cfg.getint('Dashboard' ,'max_img_rotation'),
hours_spanned=cfg.getint('Dashboard' ,'hours_spanned'),

View File

@ -224,12 +224,16 @@ function slideAndMax(orig, newData) {
function createRow(tableBody, log) {
var tr = document.createElement('TR');
//var action = document.createElement('TD');
for (var key in log) {
if (log.hasOwnProperty(key)) {
var td = document.createElement('TD');
td.appendChild(document.createTextNode(log[key]));
var textToAddArray = log[key].split(char_separator);
for(var i in textToAddArray){
if (i > 0)
td.appendChild(document.createElement("br"));
td.appendChild(document.createTextNode(textToAddArray[i]));
}
tr.appendChild(td);
}
}
@ -245,10 +249,6 @@ function createRow(tableBody, log) {
tr.className = "danger"
}
// action
//action.appendChild(document.createTextNode("ACTION"));
//tr.appendChild(action);
tableBody.appendChild(tr);
}

View File

@ -234,6 +234,7 @@ small {
/* DATA FROM CONF */
var graph_log_refresh_rate = {{ graph_log_refresh_rate }};
var char_separator = "{{ char_separator }}";
var rotation_wait_time = {{ rotation_wait_time }};
var max_img_rotation = {{ max_img_rotation }};
var hours_spanned = {{ hours_spanned }};

View File

@ -104,8 +104,11 @@ def handler_attribute(jsonattr):
jsonattr = jsonattr['Attribute']
to_push = []
for field in json.loads(cfg.get('Log', 'fieldname_order')):
to_push.append(jsonattr[field])
to_push.append("blabla")
if type(field) is list:
to_add = cfg.get('Log', 'char_separator').join([ jsonattr[subField] for subField in field ])
else:
to_add = jsonattr[field]
to_push.append(to_add)
#try to get coord
if jsonattr['category'] == "Network activity":