mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
signalr cleanup
This commit is contained in:
parent
feda4a9b67
commit
25e2c98c45
219 changed files with 2035 additions and 1495 deletions
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
'use strict';
|
||||
define(
|
||||
[
|
||||
'backbone',
|
||||
|
@ -8,10 +8,19 @@ define(
|
|||
|
||||
var CommandCollection = Backbone.Collection.extend({
|
||||
url : window.ApiRoot + '/command',
|
||||
model: CommandModel
|
||||
model: CommandModel,
|
||||
|
||||
findCommand: function (command) {
|
||||
return this.find(function (model) {
|
||||
return model.isSameCommand(command);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var collection = new CommandCollection().bindSignalR();
|
||||
|
||||
collection.fetch();
|
||||
|
||||
return collection;
|
||||
});
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
'use strict';
|
||||
define({
|
||||
Execute: function (name, properties) {
|
||||
var data = { command: name };
|
||||
define(
|
||||
[
|
||||
'Commands/CommandModel',
|
||||
'Commands/CommandCollection',
|
||||
'underscore'
|
||||
], function (CommandModel, CommandCollection, _) {
|
||||
|
||||
if (properties) {
|
||||
$.extend(data, properties);
|
||||
return{
|
||||
Execute: function (name, properties) {
|
||||
|
||||
var attr = _.extend({name: name.toLocaleLowerCase()}, properties);
|
||||
|
||||
var commandModel = new CommandModel(attr);
|
||||
|
||||
return commandModel.save().success(function () {
|
||||
CommandCollection.add(commandModel);
|
||||
});
|
||||
}
|
||||
|
||||
return $.ajax({
|
||||
type: 'POST',
|
||||
url : window.ApiRoot + '/command',
|
||||
data: JSON.stringify(data)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
15
UI/Commands/CommandMessengerCollectionView.js
Normal file
15
UI/Commands/CommandMessengerCollectionView.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'app',
|
||||
'marionette',
|
||||
'Commands/CommandCollection',
|
||||
'Commands/CommandMessengerItemView'
|
||||
], function (App, Marionette, commandCollection, CommandMessengerItemView) {
|
||||
|
||||
var CollectionView = Marionette.CollectionView.extend({
|
||||
itemView : CommandMessengerItemView
|
||||
});
|
||||
|
||||
new CollectionView({collection: commandCollection});
|
||||
});
|
48
UI/Commands/CommandMessengerItemView.js
Normal file
48
UI/Commands/CommandMessengerItemView.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'app',
|
||||
'marionette',
|
||||
'Shared/Messenger'
|
||||
], function (App, Marionette, Messenger) {
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
|
||||
|
||||
initialize: function () {
|
||||
this.listenTo(this.model, 'change', this.render);
|
||||
},
|
||||
|
||||
|
||||
render: function () {
|
||||
if (!this.model.get('message')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var message = {
|
||||
type : 'info',
|
||||
message : '[{0}] {1}'.format(this.model.get('name'), this.model.get('message')),
|
||||
id : this.model.id,
|
||||
hideAfter: 0
|
||||
};
|
||||
|
||||
switch (this.model.get('state')) {
|
||||
case 'completed':
|
||||
message.hideAfter = 4;
|
||||
break;
|
||||
case 'failed':
|
||||
message.hideAfter = 4;
|
||||
message.type = 'error';
|
||||
break;
|
||||
default :
|
||||
message.hideAfter = 0;
|
||||
}
|
||||
|
||||
Messenger.show(message);
|
||||
|
||||
console.log(message.message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -4,5 +4,30 @@ define(
|
|||
'backbone'
|
||||
], function (Backbone) {
|
||||
return Backbone.Model.extend({
|
||||
url: window.ApiRoot + '/command',
|
||||
|
||||
parse: function (response) {
|
||||
response.name = response.name.toLocaleLowerCase();
|
||||
return response;
|
||||
},
|
||||
|
||||
isActive: function () {
|
||||
return this.get('state') !== 'completed' && this.get('state') !== 'failed';
|
||||
},
|
||||
|
||||
isSameCommand: function (command) {
|
||||
|
||||
if (command.name.toLocaleLowerCase() != this.get('name').toLocaleLowerCase()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var key in command) {
|
||||
if (key !== 'name' && command[key] !== this.get(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue