fixed sort order to work with datatables sorting
This commit is contained in:
7
job.py
7
job.py
@@ -139,14 +139,17 @@ def joblog(id):
|
||||
else:
|
||||
refresh=True
|
||||
log_cnt = db.session.execute( f"select count(id) from joblog where job_id = {id}" ).first()[0]
|
||||
newest_logs = Joblog.query.filter(Joblog.job_id==id).order_by(Joblog.log_date.desc() ).limit(NEWEST_LOG_LIMIT).all()
|
||||
newest_logs = Joblog.query.filter(Joblog.job_id==id).order_by(Joblog.log_date.desc()).limit(NEWEST_LOG_LIMIT).all()
|
||||
oldest_logs = Joblog.query.filter(Joblog.job_id==id).order_by(Joblog.log_date).limit(OLDEST_LOG_LIMIT).all()
|
||||
logs=sorted( set( newest_logs + oldest_logs ), key=lambda el: el.log_date, reverse=True)
|
||||
logs=sorted( set( oldest_logs + newest_logs ), key=lambda el: el.log_date )
|
||||
if log_cnt > (NEWEST_LOG_LIMIT+OLDEST_LOG_LIMIT):
|
||||
display_more=True
|
||||
else:
|
||||
display_more=False
|
||||
order="desc"
|
||||
print( f"order={order}" )
|
||||
for l in logs:
|
||||
print( f"log={l.log_date}" )
|
||||
|
||||
if joblog.pa_job_state == "Completed":
|
||||
duration=(joblog.last_update-joblog.start_time)
|
||||
|
||||
4
main.py
4
main.py
@@ -10,7 +10,7 @@ import os
|
||||
import re
|
||||
import socket
|
||||
from status import st, Status
|
||||
from shared import CreateSelect, CreateFoldersSelect, LocationIcon, DB_URL, PROD_HOST, NEWEST_LOG_LIMIT
|
||||
from shared import CreateSelect, CreateFoldersSelect, LocationIcon, DB_URL, PROD_HOST, OLDEST_LOG_LIMIT
|
||||
|
||||
# for ldap auth
|
||||
from flask_ldap3_login import LDAP3LoginManager
|
||||
@@ -72,7 +72,7 @@ app.jinja_env.globals['ClearJM_Message'] = ClearJM_Message
|
||||
app.jinja_env.globals['CreateSelect'] = CreateSelect
|
||||
app.jinja_env.globals['CreateFoldersSelect'] = CreateFoldersSelect
|
||||
app.jinja_env.globals['LocationIcon'] = LocationIcon
|
||||
app.jinja_env.globals['NEWEST_LOG_LIMIT'] = NEWEST_LOG_LIMIT
|
||||
app.jinja_env.globals['OLDEST_LOG_LIMIT'] = OLDEST_LOG_LIMIT
|
||||
app.jinja_env.globals['current_user'] = current_user
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<link rel="stylesheet" href="{{ url_for( 'internal', filename='upstream/DataTables-1.11.3/css/jquery.dataTables.min.css' ) }}">
|
||||
<script src="{{url_for( 'internal', filename='upstream/DataTables-1.11.3/js/jquery.dataTables.min.js' )}}"></script>
|
||||
<style>
|
||||
table.dataTable tbody td {
|
||||
padding: 4px 4px;
|
||||
border-bottom-width: 0px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="container-fluid">
|
||||
<h3>Show Job Details</h3>
|
||||
<dl class="row">
|
||||
@@ -48,16 +57,16 @@
|
||||
{% endif %}
|
||||
</dl>
|
||||
|
||||
{{order}}
|
||||
|
||||
<table id="jobort_tbl" class="table table-striped table-sm sm-txt" data-toolbar="#toolbar" data-search="true">
|
||||
<thead><tr class="table-primary"><th>When
|
||||
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#sort-num-{{order}}"/></svg>
|
||||
</th><th>Details</th></tr></thead>
|
||||
<table id="joblog_tbl" class="table table-striped table-sm sm-txt" data-toolbar="#toolbar" data-search="true">
|
||||
<thead><tr class="table-info"><th>#</th><th>When</th><th>Details</th></tr></thead>
|
||||
<tbody>
|
||||
{% for log in logs %}
|
||||
<tr><td>{{log.log_date|vicdate}}</td><td>{{log.log|safe}}</td></tr>
|
||||
{% if display_more and loop.index == NEWEST_LOG_LIMIT %}
|
||||
<tr><td>{{loop.index}}</td><td>{{log.log_date|vicdate}}</td><td>{{log.log|safe}}</td></tr>
|
||||
{% if display_more and loop.index == OLDEST_LOG_LIMIT %}
|
||||
<tr>
|
||||
<td>{{loop.index}}.1</td>
|
||||
<td class="align-middle">Remaining logs hidden</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-outline-info my-0 py-1 sm-txt" onClick="document.body.innerHTML+='<form id=_fm method=POST action={{url_for('joblog', id=job.id)}}></form>';document.getElementById('_fm').submit();">Show all logs</button>
|
||||
@@ -71,8 +80,23 @@
|
||||
{% endblock main_content %}
|
||||
{% block script_content %}
|
||||
<script>
|
||||
{% if refresh and job.pa_job_state != "Completed" %}
|
||||
setTimeout(function(){ window.location.reload(1); }, 3000 )
|
||||
{% endif %}
|
||||
$(document).ready(function() {
|
||||
$('#joblog_tbl').DataTable(
|
||||
{
|
||||
'paging': false, 'info': false,
|
||||
'order': [[1, "{{order}}"]],
|
||||
'columnDefs': [
|
||||
{ 'orderData':[0], 'targets': [1] },
|
||||
{
|
||||
'targets': [0],
|
||||
'visible': false,
|
||||
'searchable': false
|
||||
},
|
||||
]
|
||||
} );
|
||||
{% if refresh and job.pa_job_state != "Completed" %}
|
||||
setTimeout(function(){ window.location.reload(1); }, 3000 )
|
||||
{% endif %}
|
||||
} );
|
||||
</script>
|
||||
{% endblock script_content %}
|
||||
|
||||
Reference in New Issue
Block a user