diff --git a/NzbDrone.Api/Episodes/EpisodeModule.cs b/NzbDrone.Api/Episodes/EpisodeModule.cs index 3d6684d19..d057b3658 100644 --- a/NzbDrone.Api/Episodes/EpisodeModule.cs +++ b/NzbDrone.Api/Episodes/EpisodeModule.cs @@ -1,16 +1,25 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using NzbDrone.Api.Mapping; using NzbDrone.Api.REST; +using NzbDrone.Core.Datastore.Events; +using NzbDrone.Core.Download; +using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; namespace NzbDrone.Api.Episodes { - public class EpisodeModule : NzbDroneRestModule + public class EpisodeModule : NzbDroneRestModuleWithSignalR, + IHandle, + IHandle + { private readonly IEpisodeService _episodeService; - public EpisodeModule(IEpisodeService episodeService) - : base("/episodes") + public EpisodeModule(ICommandExecutor commandExecutor, IEpisodeService episodeService) + : base(commandExecutor, "episodes") { _episodeService = episodeService; @@ -40,5 +49,21 @@ namespace NzbDrone.Api.Episodes { return _episodeService.GetEpisode(id).InjectTo(); } + + public void Handle(EpisodeGrabbedEvent message) + { + foreach (var episode in message.Episode.Episodes) + { + BroadcastResourceChange(ModelAction.Updated, episode.Id); + } + } + + public void Handle(EpisodeDownloadedEvent message) + { + foreach (var episode in message.Episode.Episodes) + { + BroadcastResourceChange(ModelAction.Updated, episode.Id); + } + } } } \ No newline at end of file diff --git a/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs b/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs index 7cdfb3f53..2a70103b1 100644 --- a/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs +++ b/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs @@ -18,6 +18,12 @@ namespace NzbDrone.Api _commandExecutor = commandExecutor; } + protected NzbDroneRestModuleWithSignalR(ICommandExecutor commandExecutor, string resource) + : base(resource) + { + _commandExecutor = commandExecutor; + } + public void Handle(ModelEvent message) { if (message.Action == ModelAction.Deleted || message.Action == ModelAction.Sync) diff --git a/NzbDrone.Core/Datastore/Events/ModelEvent.cs b/NzbDrone.Core/Datastore/Events/ModelEvent.cs index 3cabd3a69..91f74887b 100644 --- a/NzbDrone.Core/Datastore/Events/ModelEvent.cs +++ b/NzbDrone.Core/Datastore/Events/ModelEvent.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Datastore.Events public enum ModelAction { - Unknow = 0, + Unknown = 0, Created = 1, Updated = 2, Deleted = 3, diff --git a/UI/Mixins/backbone.signalr.mixin.js b/UI/Mixins/backbone.signalr.mixin.js index 8f5c695ae..e0154e6af 100644 --- a/UI/Mixins/backbone.signalr.mixin.js +++ b/UI/Mixins/backbone.signalr.mixin.js @@ -1,8 +1,10 @@ 'use strict'; define( [ + 'underscore', + 'backbone', 'signalR' - ], function () { + ], function (_, Backbone) { _.extend(Backbone.Collection.prototype, { bindSignalR: function () { @@ -13,14 +15,14 @@ define( var model = new collection.model(options.resource, {parse: true}); collection.add(model, {merge: true}); - console.log(options.action + ": %O", options.resource); + console.log(options.action + ': {0}}'.format(options.resource)); }; require( [ 'app' ], function (app) { - collection.listenTo(app.vent, 'server:' + collection.url.replace('/api/', ''), processMessage) + collection.listenTo(app.vent, 'server:' + collection.url.replace('/api/', ''), processMessage); }); return this; @@ -28,7 +30,6 @@ define( unbindSignalR: function () { - }}); }); diff --git a/UI/Series/Details/SeriesDetailsLayout.js b/UI/Series/Details/SeriesDetailsLayout.js index d08abac58..ea4024675 100644 --- a/UI/Series/Details/SeriesDetailsLayout.js +++ b/UI/Series/Details/SeriesDetailsLayout.js @@ -171,7 +171,7 @@ define( this.seasons.show(new LoadingView()); this.seasonCollection = new SeasonCollection(this.model.get('seasons')); - this.episodeCollection = new EpisodeCollection({ seriesId: this.model.id }); + this.episodeCollection = new EpisodeCollection({ seriesId: this.model.id }).bindSignalR(); this.episodeFileCollection = new EpisodeFileCollection({ seriesId: this.model.id }); $.when(this.episodeCollection.fetch(), this.episodeFileCollection.fetch()).done(function () { diff --git a/UI/Shared/SignalRBroadcaster.js b/UI/Shared/SignalRBroadcaster.js index 5a58dcb1d..14f322fd1 100644 --- a/UI/Shared/SignalRBroadcaster.js +++ b/UI/Shared/SignalRBroadcaster.js @@ -24,7 +24,7 @@ define( } }; - this.signalRconnection = $.connection("/signalr"); + this.signalRconnection = $.connection('/signalr'); this.signalRconnection.stateChanged(function (change) { console.debug('SignalR: [{0}]'.format(getStatus(change.newState))); @@ -36,7 +36,7 @@ define( 'app' ], function (app) { app.vent.trigger('server:' + message.name, message.body); - }) + }); }); this.signalRconnection.start({ transport: