1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-04-23 12:18:56 +02:00
Sonarr/src/UI/System/Logs/Table/LogsTableLayout.js

136 lines
4.3 KiB
JavaScript
Raw Normal View History

2013-06-21 23:24:24 -07:00
'use strict';
2013-07-13 19:40:47 -07:00
define(
[
2013-10-08 18:43:41 -07:00
'vent',
2013-07-13 19:40:47 -07:00
'marionette',
'backgrid',
'System/Logs/Table/LogTimeCell',
'System/Logs/Table/LogLevelCell',
'System/Logs/Table/LogRow',
2013-07-13 19:40:47 -07:00
'Shared/Grid/Pager',
'System/Logs/LogsCollection',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView'
], function (vent, Marionette, Backgrid, LogTimeCell, LogLevelCell, LogRow, GridPager, LogCollection, ToolbarLayout, LoadingView) {
return Marionette.Layout.extend({
template: 'System/Logs/Table/LogsTableLayoutTemplate',
2013-06-04 17:49:53 -07:00
regions: {
grid : '#x-grid',
toolbar: '#x-toolbar',
pager : '#x-pager'
},
2013-07-13 19:40:47 -07:00
attributes: {
id: 'logs-screen'
},
columns:
[
{
name : 'level',
label : '',
sortable: true,
cell : LogLevelCell
},
{
name : 'logger',
label : 'Component',
sortable: true,
cell : Backgrid.StringCell.extend({
className: 'log-logger-cell'
})
},
{
name : 'message',
label : 'Message',
sortable: false,
cell : Backgrid.StringCell.extend({
className: 'log-message-cell'
})
},
{
name : 'time',
label: 'Time',
cell : LogTimeCell
}
],
2013-06-04 17:49:53 -07:00
2013-07-28 16:13:14 -07:00
initialize: function () {
this.collection = new LogCollection();
this.collectionPromise = this.collection.fetch();
2013-10-08 18:43:41 -07:00
vent.on(vent.Events.CommandComplete, this._commandComplete, this);
},
onRender: function () {
this.grid.show(new LoadingView());
2013-07-28 16:13:14 -07:00
},
onShow: function () {
var self = this;
2013-07-28 16:13:14 -07:00
this._showToolbar();
this.collectionPromise.done(function () {
self._showTable();
});
2013-07-28 16:13:14 -07:00
},
_showTable: function () {
2013-07-13 19:40:47 -07:00
this.grid.show(new Backgrid.Grid({
row : LogRow,
2013-07-13 19:40:47 -07:00
columns : this.columns,
collection: this.collection,
className : 'table table-hover'
}));
2013-06-04 17:49:53 -07:00
this.pager.show(new GridPager({
2013-06-04 17:49:53 -07:00
columns : this.columns,
collection: this.collection
}));
},
2013-07-28 16:13:14 -07:00
_showToolbar: function () {
var rightSideButtons = {
type : 'default',
storeState: false,
items :
[
{
title : 'Refresh',
icon : 'icon-refresh',
ownerContext : this,
callback : this._refreshLogs
},
{
title : 'Clear Logs',
icon : 'icon-trash',
command : 'clearLog'
}
]
};
2013-07-28 16:13:14 -07:00
this.toolbar.show(new ToolbarLayout({
right :
2013-07-28 16:13:14 -07:00
[
rightSideButtons
2013-07-28 16:13:14 -07:00
],
context: this
}));
},
_refreshLogs: function () {
this.collection.state.currentPage = 1;
this.collection.fetch({ reset: true });
this._showTable();
},
_commandComplete: function (options) {
if (options.command.get('name') === 'clearlog') {
this._refreshLogs();
}
2013-06-04 17:49:53 -07:00
}
2013-07-13 19:40:47 -07:00
});
});