No more caching of log files, also better handling of logs on page load

pull/33/merge
Mark McDowall 11 years ago
parent 7d9eaf8cfc
commit ee2973efe7

@ -22,8 +22,8 @@ module.exports = function (grunt) {
'src/UI/JsLibraries/backbone.backgrid.paginator.js' : 'http://raw.github.com/wyuenho/backgrid/master/lib/extensions/paginator/backgrid-paginator.js',
'src/UI/JsLibraries/backbone.backgrid.filter.js' : 'http://raw.github.com/wyuenho/backgrid/master/lib/extensions/filter/backgrid-filter.js',
'src/UI/JsLibraries/backbone.backgrid.selectall.js' : 'http://raw.github.com/wyuenho/backgrid-select-all/master/backgrid-select-all.js',
'src/UI/Content/Backgrid/selectall.css' : 'http://raw.github.com/wyuenho/backgrid-select-all/master/backgrid-select-all.css',
'src/UI/JsLibraries/backbone.backgrid.selectall.js' : 'http://raw.github.com/wyuenho/backgrid-select-all/master/backgrid-select-all.js',
'src/UI/Content/Backgrid/selectall.css' : 'http://raw.github.com/wyuenho/backgrid-select-all/master/backgrid-select-all.css',
'src/UI/JsLibraries/backbone.validation.js' : 'https://raw.github.com/thedersen/backbone.validation/master/dist/backbone-validation.js',

@ -24,6 +24,12 @@ namespace NzbDrone.Api.Frontend
if (context.Request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
if (context.Request.Path.EndsWith("app.js")) return false;
if (context.Request.Path.StartsWith("/log", StringComparison.CurrentCultureIgnoreCase) &&
context.Request.Path.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
if (context.Response != null)
{
if (context.Response.ContentType.Contains("text/html")) return false;

@ -14,7 +14,7 @@ define(
var date = this.model.get(this.column.get('name'));
if (date) {
this.$el.html("<span title='" + Moment(date).format('LLLL') + "' >" + FormatHelpers.dateHelper(date) + "</span");
this.$el.html('<span title="' + Moment(date).format('LLLL') + '" >' + FormatHelpers.dateHelper(date) + '</span>');
}
return this;

@ -102,3 +102,7 @@ td.episode-status-cell, td.quality-cell {
width: 20px;
text-align: center !important;
}
.download-log-cell {
width: 80px;
}

@ -40,7 +40,7 @@ define(
},
_updateExamples: function () {
//TODO: make this use events/listeners
var self = this;
var promise = $.ajax({

@ -4,5 +4,14 @@ define(
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
url: function () {
return '/log/' + this.get('filename');
},
parse: function (contents) {
var response = {};
response.contents = contents;
return response;
}
});
});

@ -0,0 +1,17 @@
'use strict';
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
className: 'download-log-cell',
render: function () {
this.$el.empty();
this.$el.html('<a href="/log/{0}" class="no-router" target="_blank">Download</a>'.format(this.cellValue));
return this;
}
});
});

@ -6,13 +6,25 @@ define(
'backgrid',
'System/Logs/Files/FilenameCell',
'Cells/RelativeDateCell',
'System/Logs/Files/DownloadLogCell',
'System/Logs/Files/LogFileCollection',
'System/Logs/Files/Row',
'System/Logs/Files/ContentsView',
'System/Logs/Files/ContentsModel',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView'
], function (App, Marionette, Backgrid, FilenameCell, RelativeDateCell, LogFileCollection, LogFileRow, ContentsView, ContentsModel, ToolbarLayout, LoadingView) {
], function (App,
Marionette,
Backgrid,
FilenameCell,
RelativeDateCell,
DownloadLogCell,
LogFileCollection,
LogFileRow,
ContentsView,
ContentsModel,
ToolbarLayout,
LoadingView) {
return Marionette.Layout.extend({
template: 'System/Logs/Files/LogFileLayoutTemplate',
@ -33,35 +45,30 @@ define(
name : 'lastWriteTime',
label: 'Last Write Time',
cell : RelativeDateCell
},
{
name : 'filename',
label : '',
cell : DownloadLogCell,
sortable: false
}
],
initialize: function () {
this.collection = new LogFileCollection();
App.vent.on(App.Commands.ShowLogFile, this._showLogFile, this);
App.vent.on(App.Commands.ShowLogFile, this._fetchLogFileContents, this);
App.vent.on(App.Events.CommandComplete, this._commandComplete, this);
this.listenTo(this.collection, 'sync', this._collectionSynced);
this.collection.fetch();
},
onShow: function () {
this._fetchAndShow();
this._showToolbar();
this._showTable();
},
_fetchAndShow: function () {
var self = this;
this.contents.close();
var promise = this.collection.fetch();
promise.done(function () {
if (self.collection.length > 0) {
self._showLogFile({ model: self.collection.first() });
}
});
},
_showToolbar: function () {
var rightSideButtons = {
@ -104,31 +111,37 @@ define(
}));
},
_showLogFile: function (options) {
this.contents.show(new LoadingView());
if (!options.model) {
_collectionSynced: function () {
if (!this.collection.any()) {
return;
}
var self = this;
var filename = options.model.get('filename');
var model = this.collection.first();
this._fetchLogFileContents({ model: model });
},
$.ajax({
url: '/log/' + filename,
success: function (data) {
var model = new ContentsModel({
filename: filename,
contents: data
});
_fetchLogFileContents: function (options) {
this.contents.show(new LoadingView());
self.contents.show(new ContentsView({ model: model }));
}
var model = options.model;
var filename = model.get('filename');
var contentsModel = new ContentsModel({
filename: filename
});
this.listenToOnce(contentsModel, 'sync', this._showContents);
contentsModel.fetch({ dataType: 'text' });
},
_showContents: function (model) {
this.contents.show(new ContentsView({ model: model }));
},
_refreshLogs: function () {
this._fetchAndShow();
this.contents.close();
this.collection.fetch();
},
_commandComplete: function (options) {

Loading…
Cancel
Save