mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-20 16:03:59 +01:00
Changed Logs page to use ajax for retrieving log messages as needed instead of getting all at the start and freezing the browser
This commit is contained in:
@@ -16,21 +16,6 @@ lossless<%inherit file="base.html"/>
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
%for line in lineList:
|
|
||||||
<%
|
|
||||||
timestamp, message, level, threadname = line
|
|
||||||
|
|
||||||
if level == 'WARNING' or level == 'ERROR':
|
|
||||||
grade = 'X'
|
|
||||||
else:
|
|
||||||
grade = 'Z'
|
|
||||||
%>
|
|
||||||
<tr class="grade${grade}">
|
|
||||||
<td id="timestamp">${timestamp}</td>
|
|
||||||
<td id="level">${level}</td>
|
|
||||||
<td id="message">${message}</td>
|
|
||||||
</tr>
|
|
||||||
%endfor
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</%def>
|
</%def>
|
||||||
@@ -42,22 +27,39 @@ lossless<%inherit file="base.html"/>
|
|||||||
<%def name="javascriptIncludes()">
|
<%def name="javascriptIncludes()">
|
||||||
<script src="js/libs/jquery.dataTables.min.js"></script>
|
<script src="js/libs/jquery.dataTables.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function()
|
$(document).ready(function() {
|
||||||
{
|
$('#log_table').dataTable( {
|
||||||
$('#log_table').dataTable(
|
"bProcessing": true,
|
||||||
{
|
"bServerSide": true,
|
||||||
"oLanguage": {
|
"sAjaxSource": 'getLog',
|
||||||
|
"sPaginationType": "full_numbers",
|
||||||
|
"bStateSave": true,
|
||||||
|
"oLanguage": {
|
||||||
"sLengthMenu":"Show _MENU_ lines per page",
|
"sLengthMenu":"Show _MENU_ lines per page",
|
||||||
"sEmptyTable": "No log information available",
|
"sEmptyTable": "No log information available",
|
||||||
"sInfo":"Showing _START_ to _END_ of _TOTAL_ lines",
|
"sInfo":"Showing _START_ to _END_ of _TOTAL_ lines",
|
||||||
"sInfoEmpty":"Showing 0 to 0 of 0 lines",
|
"sInfoEmpty":"Showing 0 to 0 of 0 lines",
|
||||||
"sInfoFiltered":"(filtered from _MAX_ total lines)"},
|
"sInfoFiltered":"(filtered from _MAX_ total lines)"},
|
||||||
"bStateSave": true,
|
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
|
||||||
"iDisplayLength": 100,
|
if (aData[1] === "WARNING" || aData[1] === "ERROR")
|
||||||
"sPaginationType": "full_numbers",
|
{
|
||||||
"aaSorting": []
|
$('td', nRow).closest('tr').addClass("gradeX");
|
||||||
|
}
|
||||||
});
|
else
|
||||||
});
|
{
|
||||||
|
$('td', nRow).closest('tr').addClass("gradeZ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return nRow;
|
||||||
|
},
|
||||||
|
"fnServerData": function ( sSource, aoData, fnCallback ) {
|
||||||
|
/* Add some extra data to the sender */
|
||||||
|
$.getJSON( sSource, aoData, function (json) {
|
||||||
|
fnCallback(json)
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
} );
|
||||||
</script>
|
</script>
|
||||||
</%def>
|
</%def>
|
||||||
@@ -394,6 +394,38 @@ class WebInterface(object):
|
|||||||
return serve_template(templatename="logs.html", title="Log", lineList=headphones.LOG_LIST)
|
return serve_template(templatename="logs.html", title="Log", lineList=headphones.LOG_LIST)
|
||||||
logs.exposed = True
|
logs.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
def getLog(self,iDisplayStart=0,iDisplayLength=100,iSortCol_0=0,iSortCol_1=0,iSortCol_2=0,
|
||||||
|
sSortDir_0="desc",sSortDir_1="desc",sSortDir_2="desc",
|
||||||
|
sSearch="",**kwargs):
|
||||||
|
|
||||||
|
iDisplayStart = int(iDisplayStart)
|
||||||
|
iDisplayLength = int(iDisplayLength)
|
||||||
|
|
||||||
|
filtered = []
|
||||||
|
if sSearch == "":
|
||||||
|
filtered = headphones.LOG_LIST[::]
|
||||||
|
else:
|
||||||
|
filtered = [row for row in headphones.LOG_LIST for column in row if sSearch in column]
|
||||||
|
|
||||||
|
sortcolumn = 0
|
||||||
|
if iSortCol_0 == '1':
|
||||||
|
sortcolumn = 2
|
||||||
|
elif iSortCol_0 == '2':
|
||||||
|
sortcolumn = 1
|
||||||
|
filtered.sort(key=lambda x:x[sortcolumn],reverse=sSortDir_0 == "desc")
|
||||||
|
|
||||||
|
rows = filtered[iDisplayStart:(iDisplayStart+iDisplayLength)]
|
||||||
|
rows = [[row[0],row[2],row[1]] for row in rows]
|
||||||
|
|
||||||
|
dict = {'iTotalDisplayRecords':len(filtered),
|
||||||
|
'iTotalRecords':len(headphones.LOG_LIST),
|
||||||
|
'aaData':rows,
|
||||||
|
}
|
||||||
|
s = simplejson.dumps(dict)
|
||||||
|
return s
|
||||||
|
getLog.exposed = True
|
||||||
|
|
||||||
def clearhistory(self, type=None):
|
def clearhistory(self, type=None):
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
if type == 'all':
|
if type == 'all':
|
||||||
|
|||||||
Reference in New Issue
Block a user