mirror of https://github.com/lidarr/Lidarr
UI Cleanup - Updated Commands subtree.
This commit is contained in:
parent
7b5c0a952b
commit
7b7f199587
|
@ -2,17 +2,19 @@ var Backbone = require('backbone');
|
||||||
var CommandModel = require('./CommandModel');
|
var CommandModel = require('./CommandModel');
|
||||||
require('../Mixins/backbone.signalr.mixin');
|
require('../Mixins/backbone.signalr.mixin');
|
||||||
|
|
||||||
module.exports = (function(){
|
var CommandCollection = Backbone.Collection.extend({
|
||||||
var CommandCollection = Backbone.Collection.extend({
|
url : window.NzbDrone.ApiRoot + '/command',
|
||||||
url : window.NzbDrone.ApiRoot + '/command',
|
model : CommandModel,
|
||||||
model : CommandModel,
|
|
||||||
findCommand : function(command){
|
findCommand : function(command) {
|
||||||
return this.find(function(model){
|
return this.find(function(model) {
|
||||||
return model.isSameCommand(command);
|
return model.isSameCommand(command);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var collection = new CommandCollection().bindSignalR();
|
|
||||||
collection.fetch();
|
var collection = new CommandCollection().bindSignalR();
|
||||||
return collection;
|
|
||||||
}).call(this);
|
collection.fetch();
|
||||||
|
|
||||||
|
module.exports = collection;
|
|
@ -7,69 +7,88 @@ var moment = require('moment');
|
||||||
var Messenger = require('../Shared/Messenger');
|
var Messenger = require('../Shared/Messenger');
|
||||||
require('../jQuery/jquery.spin');
|
require('../jQuery/jquery.spin');
|
||||||
|
|
||||||
module.exports = (function(){
|
CommandMessengerCollectionView.render();
|
||||||
CommandMessengerCollectionView.render();
|
|
||||||
var singleton = function(){
|
var singleton = function() {
|
||||||
return {
|
|
||||||
_lastCommand : {},
|
return {
|
||||||
Execute : function(name, properties){
|
|
||||||
var attr = _.extend({name : name.toLocaleLowerCase()}, properties);
|
_lastCommand : {},
|
||||||
var commandModel = new CommandModel(attr);
|
|
||||||
if(this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) {
|
Execute : function(name, properties) {
|
||||||
Messenger.show({
|
|
||||||
message : 'Please wait at least 5 seconds before running this command again',
|
var attr = _.extend({ name : name.toLocaleLowerCase() }, properties);
|
||||||
hideAfter : 5,
|
var commandModel = new CommandModel(attr);
|
||||||
type : 'error'
|
|
||||||
});
|
if (this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) {
|
||||||
return this._lastCommand.promise;
|
|
||||||
}
|
Messenger.show({
|
||||||
var promise = commandModel.save().success(function(){
|
message : 'Please wait at least 5 seconds before running this command again',
|
||||||
CommandCollection.add(commandModel);
|
hideAfter : 5,
|
||||||
|
type : 'error'
|
||||||
});
|
});
|
||||||
this._lastCommand = {
|
|
||||||
command : commandModel,
|
return this._lastCommand.promise;
|
||||||
promise : promise,
|
|
||||||
time : moment()
|
|
||||||
};
|
|
||||||
return promise;
|
|
||||||
},
|
|
||||||
bindToCommand : function(options){
|
|
||||||
var self = this;
|
|
||||||
var existingCommand = CommandCollection.findCommand(options.command);
|
|
||||||
if(existingCommand) {
|
|
||||||
this._bindToCommandModel.call(this, existingCommand, options);
|
|
||||||
}
|
|
||||||
CommandCollection.bind('add', function(model){
|
|
||||||
if(model.isSameCommand(options.command)) {
|
|
||||||
self._bindToCommandModel.call(self, model, options);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
CommandCollection.bind('sync', function(){
|
|
||||||
var command = CommandCollection.findCommand(options.command);
|
|
||||||
if(command) {
|
|
||||||
self._bindToCommandModel.call(self, command, options);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
_bindToCommandModel : function bindToCommand (model, options){
|
|
||||||
if(!model.isActive()) {
|
|
||||||
options.element.stopSpin();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
model.bind('change:state', function(model){
|
|
||||||
if(!model.isActive()) {
|
|
||||||
options.element.stopSpin();
|
|
||||||
if(model.isComplete()) {
|
|
||||||
vent.trigger(vent.Events.CommandComplete, {
|
|
||||||
command : model,
|
|
||||||
model : options.model
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
options.element.startSpin();
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
var promise = commandModel.save().success(function() {
|
||||||
|
CommandCollection.add(commandModel);
|
||||||
|
});
|
||||||
|
|
||||||
|
this._lastCommand = {
|
||||||
|
command : commandModel,
|
||||||
|
promise : promise,
|
||||||
|
time : moment()
|
||||||
|
};
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
},
|
||||||
|
|
||||||
|
bindToCommand : function(options) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
var existingCommand = CommandCollection.findCommand(options.command);
|
||||||
|
|
||||||
|
if (existingCommand) {
|
||||||
|
this._bindToCommandModel.call(this, existingCommand, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandCollection.bind('add', function(model) {
|
||||||
|
if (model.isSameCommand(options.command)) {
|
||||||
|
self._bindToCommandModel.call(self, model, options);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CommandCollection.bind('sync', function() {
|
||||||
|
var command = CommandCollection.findCommand(options.command);
|
||||||
|
if (command) {
|
||||||
|
self._bindToCommandModel.call(self, command, options);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_bindToCommandModel : function bindToCommand (model, options) {
|
||||||
|
|
||||||
|
if (!model.isActive()) {
|
||||||
|
options.element.stopSpin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
model.bind('change:state', function(model) {
|
||||||
|
if (!model.isActive()) {
|
||||||
|
options.element.stopSpin();
|
||||||
|
|
||||||
|
if (model.isComplete()) {
|
||||||
|
vent.trigger(vent.Events.CommandComplete, {
|
||||||
|
command : model,
|
||||||
|
model : options.model
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
options.element.startSpin();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return singleton();
|
};
|
||||||
}).call(this);
|
module.exports = singleton();
|
||||||
|
|
|
@ -2,7 +2,10 @@ var Marionette = require('marionette');
|
||||||
var commandCollection = require('./CommandCollection');
|
var commandCollection = require('./CommandCollection');
|
||||||
var CommandMessengerItemView = require('./CommandMessengerItemView');
|
var CommandMessengerItemView = require('./CommandMessengerItemView');
|
||||||
|
|
||||||
module.exports = (function(){
|
var CollectionView = Marionette.CollectionView.extend({
|
||||||
var CollectionView = Marionette.CollectionView.extend({itemView : CommandMessengerItemView});
|
itemView : CommandMessengerItemView
|
||||||
return new CollectionView({collection : commandCollection});
|
});
|
||||||
}).call(this);
|
|
||||||
|
module.exports = new CollectionView({
|
||||||
|
collection : commandCollection
|
||||||
|
});
|
||||||
|
|
|
@ -2,13 +2,15 @@ var Marionette = require('marionette');
|
||||||
var Messenger = require('../Shared/Messenger');
|
var Messenger = require('../Shared/Messenger');
|
||||||
|
|
||||||
module.exports = Marionette.ItemView.extend({
|
module.exports = Marionette.ItemView.extend({
|
||||||
initialize : function(){
|
initialize : function() {
|
||||||
this.listenTo(this.model, 'change', this.render);
|
this.listenTo(this.model, 'change', this.render);
|
||||||
},
|
},
|
||||||
render : function(){
|
|
||||||
if(!this.model.get('message') || !this.model.get('sendUpdatesToClient')) {
|
render : function() {
|
||||||
|
if (!this.model.get('message') || !this.model.get('sendUpdatesToClient')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
type : 'info',
|
type : 'info',
|
||||||
message : '[{0}] {1}'.format(this.model.get('name'), this.model.get('message')),
|
message : '[{0}] {1}'.format(this.model.get('name'), this.model.get('message')),
|
||||||
|
@ -26,15 +28,18 @@ module.exports = Marionette.ItemView.extend({
|
||||||
message.hideAfter = isManual ? 10 : 4;
|
message.hideAfter = isManual ? 10 : 4;
|
||||||
message.type = 'error';
|
message.type = 'error';
|
||||||
break;
|
break;
|
||||||
default:
|
default :
|
||||||
message.hideAfter = 0;
|
message.hideAfter = 0;
|
||||||
}
|
}
|
||||||
if(this.messenger) {
|
|
||||||
|
if (this.messenger) {
|
||||||
this.messenger.update(message);
|
this.messenger.update(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
this.messenger = Messenger.show(message);
|
this.messenger = Messenger.show(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(message.message);
|
console.log(message.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -2,33 +2,41 @@ var _ = require('underscore');
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
|
|
||||||
module.exports = Backbone.Model.extend({
|
module.exports = Backbone.Model.extend({
|
||||||
url : window.NzbDrone.ApiRoot + '/command',
|
url : window.NzbDrone.ApiRoot + '/command',
|
||||||
parse : function(response){
|
|
||||||
|
parse : function(response) {
|
||||||
response.name = response.name.toLocaleLowerCase();
|
response.name = response.name.toLocaleLowerCase();
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
isSameCommand : function(command){
|
|
||||||
if(command.name.toLocaleLowerCase() !== this.get('name').toLocaleLowerCase()) {
|
isSameCommand : function(command) {
|
||||||
|
|
||||||
|
if (command.name.toLocaleLowerCase() !== this.get('name').toLocaleLowerCase()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var key in command) {
|
for (var key in command) {
|
||||||
if(key !== 'name') {
|
if (key !== 'name') {
|
||||||
if(Array.isArray(command[key])) {
|
if (Array.isArray(command[key])) {
|
||||||
if(_.difference(command[key], this.get(key)).length > 0) {
|
if (_.difference(command[key], this.get(key)).length > 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(command[key] !== this.get(key)) {
|
|
||||||
|
else if (command[key] !== this.get(key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
isActive : function(){
|
|
||||||
|
isActive : function() {
|
||||||
return this.get('state') !== 'completed' && this.get('state') !== 'failed';
|
return this.get('state') !== 'completed' && this.get('state') !== 'failed';
|
||||||
},
|
},
|
||||||
isComplete : function(){
|
|
||||||
|
isComplete : function() {
|
||||||
return this.get('state') === 'completed';
|
return this.get('state') === 'completed';
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue