Removed unused parts from backend code, moved formatting to frontend, added date column, switched to modification date (might be more interesting in case of the log files)
This commit is contained in:
parent
197d46b511
commit
4a6a458cdd
5 changed files with 51 additions and 27 deletions
|
|
@ -3,31 +3,22 @@ __author__ = "Marc Hannappel Salandora"
|
|||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
|
||||
import os
|
||||
import datetime
|
||||
|
||||
from flask import request, jsonify, make_response, url_for
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
import octoprint.util as util
|
||||
from octoprint.settings import settings, valid_boolean_trues
|
||||
from octoprint.settings import settings
|
||||
|
||||
from octoprint.server import restricted_access, admin_permission
|
||||
from octoprint.server import restricted_access
|
||||
from octoprint.server.util import redirectToTornado
|
||||
from octoprint.server.api import api
|
||||
|
||||
|
||||
@api.route("/logs", methods=["GET"])
|
||||
def getLogData():
|
||||
files = _getLogFiles()
|
||||
return jsonify(files=files)
|
||||
|
||||
@api.route("/logs/online/<filename>", methods=["GET"])
|
||||
def onlineLog(filename):
|
||||
secure = os.path.join(settings().getBaseFolder("logs"), secure_filename(filename))
|
||||
if not os.path.exists(secure):
|
||||
return make_response("Unknown filename: %s" % filename, 404)
|
||||
|
||||
file = open(secure, 'r')
|
||||
return jsonify(data=file.read())
|
||||
|
||||
@api.route("/logs/<filename>", methods=["GET"])
|
||||
def downloadLog(filename):
|
||||
|
|
@ -39,10 +30,11 @@ def downloadLog(filename):
|
|||
def deleteLog(filename):
|
||||
secure = os.path.join(settings().getBaseFolder("logs"), secure_filename(filename))
|
||||
if os.path.exists(secure):
|
||||
os.remove(secure)
|
||||
os.remove(secure)
|
||||
|
||||
return getLogData()
|
||||
|
||||
|
||||
def _getLogFiles():
|
||||
files = []
|
||||
basedir = settings().getBaseFolder("logs")
|
||||
|
|
@ -50,13 +42,11 @@ def _getLogFiles():
|
|||
statResult = os.stat(os.path.join(basedir, osFile))
|
||||
files.append({
|
||||
"name": osFile,
|
||||
"size": util.getFormattedSize(statResult.st_size),
|
||||
"size": statResult.st_size,
|
||||
"bytes": statResult.st_size,
|
||||
"date": util.getFormattedDateTime(datetime.datetime.fromtimestamp(statResult.st_ctime))
|
||||
"date": int(statResult.st_mtime),
|
||||
"url": url_for("index") + "downloads/logs/" + osFile
|
||||
})
|
||||
|
||||
for file in files:
|
||||
file["url"] = url_for("index") + "downloads/logs/" + file["name"]
|
||||
|
||||
return files
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -13,7 +13,7 @@ function LogViewModel(loginStateViewModel) {
|
|||
if (a["name"].toLocaleLowerCase() > b["name"].toLocaleLowerCase()) return 1;
|
||||
return 0;
|
||||
},
|
||||
"creation": function(a, b) {
|
||||
"modification": function(a, b) {
|
||||
// sorts descending
|
||||
if (a["date"] > b["date"]) return -1;
|
||||
if (a["date"] < b["date"]) return 1;
|
||||
|
|
|
|||
|
|
@ -279,6 +279,38 @@ table {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log files
|
||||
&.settings_logs_name {
|
||||
text-overflow: ellipsis;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
&.settings_logs_size {
|
||||
text-align: right;
|
||||
width: 70px;
|
||||
}
|
||||
|
||||
&.settings_logs_date {
|
||||
text-align: left;
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
&.settings_logs_action {
|
||||
text-align: center;
|
||||
width: 70px;
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
|
||||
&.disabled {
|
||||
color: #ccc;
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -542,22 +542,24 @@
|
|||
|
||||
<div class="pull-right">
|
||||
<small>
|
||||
Sort by: <a href="#" data-bind="click: function() { listHelper.changeSorting('name'); }">Name (ascending)</a> | <a href="#" data-bind="click: function() { listHelper.changeSorting('creation'); }">Creation date (descending)</a> | <a href="#" data-bind="click: function() { listHelper.changeSorting('size'); }">Size (descending)</a>
|
||||
Sort by: <a href="#" data-bind="click: function() { listHelper.changeSorting('name'); }">Name (ascending)</a> | <a href="#" data-bind="click: function() { listHelper.changeSorting('modification'); }">Modification date (descending)</a> | <a href="#" data-bind="click: function() { listHelper.changeSorting('size'); }">Size (descending)</a>
|
||||
</small>
|
||||
</div>
|
||||
<table class="table table-striped table-hover table-condensed table-hover" id="log_files">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="log_files_name">Name</th>
|
||||
<th class="log_files_size">Size</th>
|
||||
<th class="log_files_action">Action</th>
|
||||
<th class="settings_logs_name">Name</th>
|
||||
<th class="settings_logs_size">Size</th>
|
||||
<th class="settings_logs_date">Date</th>
|
||||
<th class="settings_logs_action">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody data-bind="foreach: listHelper.paginatedItems">
|
||||
<tr data-bind="attr: {title: name}">
|
||||
<td class="log_files_name" data-bind="text: name"></td>
|
||||
<td class="log_files_size" data-bind="text: size"></td>
|
||||
<td class="log_files_action">
|
||||
<td class="settings_logs_name" data-bind="text: name"></td>
|
||||
<td class="settings_logs_size" data-bind="text: formatSize(size)"></td>
|
||||
<td class="settings_logs_date" data-bind="text: formatDate(date)"></td>
|
||||
<td class="settings_logs_action">
|
||||
<a href="#" class="icon-trash" data-bind="click: function() { if ($root.loginState.isUser()) { $parent.removeFile($data.name); } else { return; } }, css: {disabled: !$root.loginState.isUser()}"></a> | <a href="#" class="icon-download" data-bind="attr: {href: url}"></a>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
Loading…
Reference in a new issue