|
@@ -250,6 +250,17 @@ angesprochen und sollte aus einer Mehrzahl von Gründen nicht
|
|
|
def __respond_list(self, query):
|
|
|
"""List stored data."""
|
|
|
|
|
|
+ list_header_info = {
|
|
|
+ # Caption => ('field', 'sortkey-or-None'),
|
|
|
+ "ID": ('node_id', 'id'),
|
|
|
+ "Name": ('hostname', 'name'),
|
|
|
+ "Status": ('status', None),
|
|
|
+ "Type": ('type', None),
|
|
|
+ }
|
|
|
+ list_headers = ('ID', 'Name', 'Status', 'Type')
|
|
|
+
|
|
|
+ sortkey = query.get('sort')
|
|
|
+
|
|
|
self.__send_headers()
|
|
|
|
|
|
self.wfile.write('<!DOCTYPE html><html>\n')
|
|
@@ -258,18 +269,49 @@ angesprochen und sollte aus einer Mehrzahl von Gründen nicht
|
|
|
self.wfile.write('<H1>BATCAVE - LIST</H1>\n')
|
|
|
|
|
|
self.wfile.write('<table>\n')
|
|
|
- self.wfile.write('<thead><tr><th>ID</th><th>Name</th></tr></thead>\n')
|
|
|
+ self.wfile.write('<thead><tr>')
|
|
|
+ for caption in list_headers:
|
|
|
+ info = list_header_info[caption]
|
|
|
+ th_attrib, th_prefix, th_suffix = '', '', ''
|
|
|
+
|
|
|
+ if info[1] is not None:
|
|
|
+ th_prefix = '<a href=\"/list?sort=' + info[1] + '\">'
|
|
|
+ th_suffix = '</a>'
|
|
|
+ if sortkey == info[1]:
|
|
|
+ th_attrib = ' class="sorted"'
|
|
|
+
|
|
|
+ self.wfile.write(
|
|
|
+ '<th' + th_attrib + '>' +
|
|
|
+ th_prefix + caption + th_suffix +
|
|
|
+ '</th>')
|
|
|
+ self.wfile.write('</tr></thead>\n')
|
|
|
self.wfile.write('<tbody>\n')
|
|
|
|
|
|
- sortkey = query['sort'] if 'sort' in query else None
|
|
|
data = self.server.storage.get_nodes(sortby=sortkey)
|
|
|
+ count_status = {'active': 0}
|
|
|
+ count_type = {'gateway': 0, 'node': 0}
|
|
|
+
|
|
|
for node in data:
|
|
|
- nodeid = node.get('node_id')
|
|
|
- nodename = node.get('hostname', '<?>')
|
|
|
+ nodestatus = self.server.storage.get_nodestatus(node=node)
|
|
|
+ nodetype = node.get('type', 'node')
|
|
|
+
|
|
|
+ count_status[nodestatus] = count_status.get(nodestatus, 0) + 1
|
|
|
+ count_type[nodetype] = count_type.get(nodetype, 0) + 1
|
|
|
+
|
|
|
+ self.wfile.write('<tr>')
|
|
|
+ for caption in list_headers:
|
|
|
+ info = list_header_info[caption]
|
|
|
+ value = node.get(info[0], '<?>')
|
|
|
+ cellcontent = value
|
|
|
+
|
|
|
+ # special cell contents
|
|
|
+ if info[0] == 'node_id':
|
|
|
+ cellcontent = \
|
|
|
+ '<a href="/node/{0}.json">{0}</a>'.format(value)
|
|
|
+ elif info[0] == 'status':
|
|
|
+ cellcontent = nodestatus
|
|
|
|
|
|
- self.wfile.write('<tr>\n')
|
|
|
- self.wfile.write(' <td><a href="/node/{0}.json">{0}</a></td>\n'.format(nodeid))
|
|
|
- self.wfile.write(' <td>{0}</td>\n'.format(nodename))
|
|
|
+ self.wfile.write('<td>' + cellcontent + '</td>')
|
|
|
self.wfile.write('</tr>\n')
|
|
|
|
|
|
self.wfile.write('</tbody>\n')
|