New: Scheduled tasks shwon in UI under System

This commit is contained in:
Mark McDowall
2014-09-11 23:06:11 -07:00
parent 879035b28a
commit 2b0ddb6131
14 changed files with 310 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ define(
'System/Logs/LogsLayout',
'System/Update/UpdateLayout',
'System/Backup/BackupLayout',
'System/Task/TaskLayout',
'Shared/Messenger'
], function ($,
Backbone,
@@ -16,6 +17,7 @@ define(
LogsLayout,
UpdateLayout,
BackupLayout,
TaskLayout,
Messenger) {
return Marionette.Layout.extend({
template: 'System/SystemLayoutTemplate',
@@ -24,23 +26,26 @@ define(
info : '#info',
logs : '#logs',
updates : '#updates',
backup : '#backup'
backup : '#backup',
tasks : '#tasks'
},
ui: {
infoTab : '.x-info-tab',
logsTab : '.x-logs-tab',
updatesTab : '.x-updates-tab',
backupTab : '.x-backup-tab'
backupTab : '.x-backup-tab',
tasksTab : '.x-tasks-tab'
},
events: {
'click .x-info-tab' : '_showInfo',
'click .x-logs-tab' : '_showLogs',
'click .x-updates-tab': '_showUpdates',
'click .x-backup-tab': '_showBackup',
'click .x-shutdown' : '_shutdown',
'click .x-restart' : '_restart'
'click .x-info-tab' : '_showInfo',
'click .x-logs-tab' : '_showLogs',
'click .x-updates-tab' : '_showUpdates',
'click .x-backup-tab' : '_showBackup',
'click .x-tasks-tab' : '_showTasks',
'click .x-shutdown' : '_shutdown',
'click .x-restart' : '_restart'
},
initialize: function (options) {
@@ -60,6 +65,9 @@ define(
case 'backup':
this._showBackup();
break;
case 'tasks':
this._showTasks();
break;
default:
this._showInfo();
}
@@ -109,6 +117,16 @@ define(
this._navigate('system/backup');
},
_showTasks: function (e) {
if (e) {
e.preventDefault();
}
this.tasks.show(new TaskLayout());
this.ui.tasksTab.tab('show');
this._navigate('system/tasks');
},
_shutdown: function () {
$.ajax({
url: window.NzbDrone.ApiRoot + '/system/shutdown',

View File

@@ -3,6 +3,7 @@
<li><a href="#logs" class="x-logs-tab no-router">Logs</a></li>
<li><a href="#updates" class="x-updates-tab no-router">Updates</a></li>
<li><a href="#backup" class="x-backup-tab no-router">Backup</a></li>
<li><a href="#tasks" class="x-tasks-tab no-router">Tasks</a></li>
<li class="lifecycle-controls pull-right">
<div class="btn-group">
<button class="btn btn-default btn-icon-only x-shutdown" title="Shutdown" data-container="body">
@@ -20,4 +21,5 @@
<div class="tab-pane" id="logs"></div>
<div class="tab-pane" id="updates"></div>
<div class="tab-pane" id="backup"></div>
<div class="tab-pane" id="tasks"></div>
</div>

View File

@@ -0,0 +1,41 @@
'use strict';
define(
[
'Cells/NzbDroneCell',
'Commands/CommandController'
], function (NzbDroneCell, CommandController) {
return NzbDroneCell.extend({
className: 'execute-task-cell',
events: {
'click .x-execute' : '_executeTask'
},
render: function () {
this.$el.empty();
var task = this.model.get('name');
this.$el.html(
'<i class="icon-cogs x-execute" title="Execute {0}"></i>'.format(task)
);
CommandController.bindToCommand({
element: this.$el.find('.x-execute'),
command: {
name : task
}
});
return this;
},
_executeTask: function () {
CommandController.Execute(this.model.get('name'), {
name : this.model.get('name')
});
}
});
});

View File

@@ -0,0 +1,19 @@
'use strict';
define(
[
'backbone.pageable',
'System/Task/TaskModel'
], function (PageableCollection, TaskModel) {
return PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/system/task',
model: TaskModel,
state: {
sortKey : 'name',
order : -1,
pageSize : 100000
},
mode: 'client'
});
});

View File

@@ -0,0 +1,25 @@
'use strict';
define(
[
'Cells/NzbDroneCell',
'moment'
], function (NzbDroneCell, moment) {
return NzbDroneCell.extend({
className: 'task-interval-cell',
render: function () {
this.$el.empty();
var interval = this.model.get('interval');
var duration = moment.duration(interval, 'minutes').humanize();
this.$el.html(
duration.replace(/an?(?=\s)/, '1')
);
return this;
}
});
});

View File

@@ -0,0 +1,73 @@
'use strict';
define(
[
'marionette',
'backgrid',
'System/Task/TaskCollection',
'Cells/RelativeTimeCell',
'System/Task/TaskIntervalCell',
'System/Task/ExecuteTaskCell',
'Shared/LoadingView'
], function (Marionette, Backgrid, BackupCollection, RelativeTimeCell, TaskIntervalCell, ExecuteTaskCell, LoadingView) {
return Marionette.Layout.extend({
template: 'System/Task/TaskLayoutTemplate',
regions: {
tasks : '#x-tasks'
},
columns: [
{
name : 'name',
label : 'Name',
sortable : true,
cell : 'string'
},
{
name : 'interval',
label : 'Interval',
sortable : true,
cell : TaskIntervalCell
},
{
name : 'lastExecution',
label : 'Last Execution',
sortable : true,
cell : RelativeTimeCell
},
{
name : 'nextExecution',
label : 'Next Execution',
sortable : true,
cell : RelativeTimeCell
},
{
name : 'this',
label : '',
sortable : false,
cell : ExecuteTaskCell
}
],
initialize: function () {
this.taskCollection = new BackupCollection();
this.listenTo(this.taskCollection, 'sync', this._showTasks);
},
onRender: function () {
this.tasks.show(new LoadingView());
this.taskCollection.fetch();
},
_showTasks: function () {
this.tasks.show(new Backgrid.Grid({
columns : this.columns,
collection: this.taskCollection,
className : 'table table-hover'
}));
}
});
});

View File

@@ -0,0 +1,5 @@
<div class="row">
<div class="col-md-12">
<div id="x-tasks" class="table-responsive"/>
</div>
</div>

View File

@@ -0,0 +1,9 @@
'use strict';
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
});
});