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
|
@ -3,17 +3,55 @@ define(
|
|||
[
|
||||
'Commands/CommandController',
|
||||
'Commands/CommandCollection',
|
||||
'Shared/Messenger'],
|
||||
function(CommandController, CommandCollection, Messenger) {
|
||||
'Shared/Messenger',
|
||||
'jQuery/jquery.spin'
|
||||
], function (CommandController, CommandCollection, Messenger) {
|
||||
|
||||
var actioneer = Marionette.AppRouter.extend({
|
||||
|
||||
initialize: function () {
|
||||
this.trackedCommands = [];
|
||||
this.trackedCommands =
|
||||
[
|
||||
];
|
||||
CommandCollection.fetch();
|
||||
this.listenTo(CommandCollection, 'sync', this._handleCommands);
|
||||
},
|
||||
|
||||
|
||||
bindToCommand: function (options) {
|
||||
|
||||
var self = this;
|
||||
options.idleIcon = this._getIconClass(options.element);
|
||||
|
||||
var existingCommand = CommandCollection.findCommand(options.command);
|
||||
|
||||
if (existingCommand) {
|
||||
this._bindToCommandModel.call(this, existingCommand, options);
|
||||
}
|
||||
|
||||
this.listenTo(CommandCollection, 'add sync', function (model) {
|
||||
if (model.isSameCommand(options.command)) {
|
||||
self._bindToCommandModel.call(self, model, options);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_bindToCommandModel: function bindToCommand(model, options) {
|
||||
|
||||
if (!model.isActive()) {
|
||||
options.element.stopSpin();
|
||||
return;
|
||||
}
|
||||
|
||||
this.listenTo(model, 'change:state', function (model) {
|
||||
if (!model.isActive()) {
|
||||
options.element.stopSpin();
|
||||
}
|
||||
});
|
||||
|
||||
options.element.startSpin();
|
||||
},
|
||||
|
||||
ExecuteCommand: function (options) {
|
||||
options.iconClass = this._getIconClass(options.element);
|
||||
|
||||
|
@ -62,7 +100,7 @@ define(
|
|||
_handleCommands: function () {
|
||||
var self = this;
|
||||
|
||||
_.each(this.trackedCommands, function (trackedCommand){
|
||||
_.each(this.trackedCommands, function (trackedCommand) {
|
||||
if (trackedCommand.completed === true) {
|
||||
return;
|
||||
}
|
||||
|
@ -95,12 +133,12 @@ define(
|
|||
});
|
||||
},
|
||||
|
||||
_getIconClass: function(element) {
|
||||
_getIconClass: function (element) {
|
||||
if (!element) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return element.attr('class').match(/(?:^|\s)icon\-.+?(?:$|\s)/)[0];
|
||||
return element.find('i').attr('class').match(/(?:^|\s)icon\-.+?(?:$|\s)/)[0];
|
||||
},
|
||||
|
||||
_setSpinnerOnElement: function (options) {
|
||||
|
@ -195,4 +233,4 @@ define(
|
|||
});
|
||||
|
||||
return new actioneer();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
'use strict';
|
||||
define(
|
||||
[
|
||||
'marionette'
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
'use strict';
|
||||
define(function () {
|
||||
return {
|
||||
|
||||
show: function (options) {
|
||||
|
||||
if (!options.type) {
|
||||
options.type = 'info';
|
||||
}
|
||||
|
||||
if (!options.hideAfter) {
|
||||
if (options.hideAfter === undefined) {
|
||||
switch (options.type) {
|
||||
case 'info':
|
||||
options.hideAfter = 5;
|
||||
|
@ -18,7 +19,7 @@ define(function () {
|
|||
break;
|
||||
|
||||
default :
|
||||
options.hideAfter = 0;
|
||||
options.hideAfter = 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +32,7 @@ define(function () {
|
|||
});
|
||||
},
|
||||
|
||||
|
||||
monitor: function (options) {
|
||||
|
||||
if (!options.promise) {
|
||||
|
|
51
UI/Shared/SignalRBroadcaster.js
Normal file
51
UI/Shared/SignalRBroadcaster.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'app',
|
||||
'signalR'
|
||||
], function () {
|
||||
return {
|
||||
|
||||
appInitializer: function () {
|
||||
console.log('starting signalR');
|
||||
|
||||
var getStatus = function (status) {
|
||||
switch (status) {
|
||||
case 0:
|
||||
return 'connecting';
|
||||
case 1:
|
||||
return 'connected';
|
||||
case 2:
|
||||
return 'reconnecting';
|
||||
case 4:
|
||||
return 'disconnected';
|
||||
default:
|
||||
throw 'invalid status ' + status;
|
||||
}
|
||||
};
|
||||
|
||||
this.signalRconnection = $.connection("/signalr");
|
||||
|
||||
this.signalRconnection.stateChanged(function (change) {
|
||||
console.debug('SignalR: [{0}]'.format(getStatus(change.newState)));
|
||||
});
|
||||
|
||||
this.signalRconnection.received(function (message) {
|
||||
require(
|
||||
[
|
||||
'app'
|
||||
], function (app) {
|
||||
app.vent.trigger('server:' + message.name, message.body);
|
||||
})
|
||||
});
|
||||
|
||||
this.signalRconnection.start({ transport:
|
||||
[
|
||||
'longPolling'
|
||||
] });
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -3,9 +3,9 @@ define(
|
|||
[
|
||||
'app',
|
||||
'marionette',
|
||||
'Shared/Actioneer',
|
||||
'Shared/Messenger'
|
||||
], function (App, Marionette, Actioneer, Messenger) {
|
||||
'Commands/CommandController',
|
||||
'Shared/Actioneer'
|
||||
], function (App, Marionette, CommandController, Actioneer) {
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
template : 'Shared/Toolbar/ButtonTemplate',
|
||||
|
@ -15,13 +15,8 @@ define(
|
|||
'click': 'onClick'
|
||||
},
|
||||
|
||||
ui: {
|
||||
icon: '.x-icon'
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key');
|
||||
this.idle = true;
|
||||
},
|
||||
|
||||
onRender: function () {
|
||||
|
@ -30,33 +25,34 @@ define(
|
|||
this.invokeCallback();
|
||||
}
|
||||
|
||||
if(!this.model.get('title')){
|
||||
if (!this.model.get('title')) {
|
||||
this.$el.addClass('btn-icon-only');
|
||||
}
|
||||
|
||||
var command = this.model.get('command');
|
||||
if (command) {
|
||||
Actioneer.bindToCommand({
|
||||
command: {name: command},
|
||||
element: this.$el
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onClick: function () {
|
||||
if (this.idle) {
|
||||
this.invokeCallback();
|
||||
this.invokeRoute();
|
||||
this.invokeCommand();
|
||||
|
||||
if (this.$el.hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.invokeCallback();
|
||||
this.invokeRoute();
|
||||
this.invokeCommand();
|
||||
},
|
||||
|
||||
invokeCommand: function () {
|
||||
var command = this.model.get('command');
|
||||
if (command) {
|
||||
this.idle = false;
|
||||
|
||||
Actioneer.ExecuteCommand({
|
||||
command : command,
|
||||
button : this.$el,
|
||||
element : this.ui.icon,
|
||||
errorMessage : this.model.get('errorMessage'),
|
||||
successMessage: this.model.get('successMessage'),
|
||||
always : this._commandAlways,
|
||||
context : this
|
||||
});
|
||||
CommandController.Execute(command);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -83,12 +79,6 @@ define(
|
|||
if (callback) {
|
||||
callback.call(this.model.ownerContext);
|
||||
}
|
||||
},
|
||||
|
||||
_commandAlways: function () {
|
||||
if (!this.isClosed) {
|
||||
this.idle = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue