diff --git a/src/NzbDrone.Api/Calendar/CalendarModule.cs b/src/NzbDrone.Api/Calendar/CalendarModule.cs index 484d3a52b..372515e64 100644 --- a/src/NzbDrone.Api/Calendar/CalendarModule.cs +++ b/src/NzbDrone.Api/Calendar/CalendarModule.cs @@ -4,18 +4,12 @@ using System.Linq; using NzbDrone.Api.Episodes; using NzbDrone.Api.Extensions; using NzbDrone.Api.Mapping; -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.Calendar { - public class CalendarModule : NzbDroneRestModuleWithSignalR, - IHandle, - IHandle + public class CalendarModule : EpisodeModuleWithSignalR { private readonly IEpisodeService _episodeService; private readonly SeriesRepository _seriesRepository; @@ -53,24 +47,5 @@ namespace NzbDrone.Api.Calendar return resources.OrderBy(e => e.AirDateUtc).ToList(); } - - public void Handle(EpisodeGrabbedEvent message) - { - foreach (var episode in message.Episode.Episodes) - { - var resource = episode.InjectTo(); - resource.Grabbed = true; - - BroadcastResourceChange(ModelAction.Updated, resource); - } - } - - public void Handle(EpisodeDownloadedEvent message) - { - foreach (var episode in message.Episode.Episodes) - { - BroadcastResourceChange(ModelAction.Updated, episode.Id); - } - } } } diff --git a/src/NzbDrone.Api/Episodes/EpisodeModule.cs b/src/NzbDrone.Api/Episodes/EpisodeModule.cs index 4e24cb78f..0fc9fb59b 100644 --- a/src/NzbDrone.Api/Episodes/EpisodeModule.cs +++ b/src/NzbDrone.Api/Episodes/EpisodeModule.cs @@ -5,14 +5,11 @@ 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 : NzbDroneRestModuleWithSignalR, - IHandle, - IHandle + public class EpisodeModule : EpisodeModuleWithSignalR { private readonly IEpisodeService _episodeService; diff --git a/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs b/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs new file mode 100644 index 000000000..8a305eb1b --- /dev/null +++ b/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs @@ -0,0 +1,46 @@ +using NzbDrone.Api.Mapping; +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 abstract class EpisodeModuleWithSignalR : NzbDroneRestModuleWithSignalR, + IHandle, + IHandle + where TResource : EpisodeResource, new() + where TModel : Episode + { + protected EpisodeModuleWithSignalR(ICommandExecutor commandExecutor) + : base(commandExecutor) + { + } + + protected EpisodeModuleWithSignalR(ICommandExecutor commandExecutor, string resource) + : base(commandExecutor, resource) + { + } + + public void Handle(EpisodeGrabbedEvent message) + { + foreach (var episode in message.Episode.Episodes) + { + var resource = episode.InjectTo(); + resource.Grabbed = true; + + BroadcastResourceChange(ModelAction.Updated, resource); + } + } + + 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/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index fa1038d38..21a84886e 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -117,6 +117,7 @@ + diff --git a/src/NzbDrone.Api/Wanted/CutoffModule.cs b/src/NzbDrone.Api/Wanted/CutoffModule.cs index ee0b9f219..a9ab765e2 100644 --- a/src/NzbDrone.Api/Wanted/CutoffModule.cs +++ b/src/NzbDrone.Api/Wanted/CutoffModule.cs @@ -2,17 +2,18 @@ using NzbDrone.Api.Episodes; using NzbDrone.Api.Extensions; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; namespace NzbDrone.Api.Wanted { - public class CutoffModule : NzbDroneRestModule + public class CutoffModule : EpisodeModuleWithSignalR { private readonly IEpisodeCutoffService _episodeCutoffService; - private readonly SeriesRepository _seriesRepository; + private readonly ISeriesRepository _seriesRepository; - public CutoffModule(IEpisodeCutoffService episodeCutoffService, SeriesRepository seriesRepository) - :base("wanted/cutoff") + public CutoffModule(IEpisodeCutoffService episodeCutoffService, ISeriesRepository seriesRepository, ICommandExecutor commandExecutor) + :base(commandExecutor, "wanted/cutoff") { _episodeCutoffService = episodeCutoffService; _seriesRepository = seriesRepository; diff --git a/src/NzbDrone.Api/Wanted/MissingModule.cs b/src/NzbDrone.Api/Wanted/MissingModule.cs index dd4d97f69..81b8d17cf 100644 --- a/src/NzbDrone.Api/Wanted/MissingModule.cs +++ b/src/NzbDrone.Api/Wanted/MissingModule.cs @@ -2,17 +2,18 @@ using NzbDrone.Api.Episodes; using NzbDrone.Api.Extensions; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; namespace NzbDrone.Api.Wanted { - public class MissingModule : NzbDroneRestModule + public class MissingModule : EpisodeModuleWithSignalR { private readonly IEpisodeService _episodeService; - private readonly SeriesRepository _seriesRepository; + private readonly ISeriesRepository _seriesRepository; - public MissingModule(IEpisodeService episodeService, SeriesRepository seriesRepository) - :base("wanted/missing") + public MissingModule(IEpisodeService episodeService, ISeriesRepository seriesRepository, ICommandExecutor commandExecutor) + :base(commandExecutor, "wanted/missing") { _episodeService = episodeService; _seriesRepository = seriesRepository; diff --git a/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js b/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js index d01397bd4..df889f4f5 100644 --- a/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js +++ b/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js @@ -14,7 +14,8 @@ define([ 'Shared/LoadingView', 'Shared/Messenger', 'Commands/CommandController', - 'backgrid.selectall' + 'backgrid.selectall', + 'Mixins/backbone.signalr.mixin' ], function (_, Marionette, Backgrid, @@ -81,7 +82,7 @@ define([ ], initialize : function () { - this.collection = new CutoffUnmetCollection(); + this.collection = new CutoffUnmetCollection().bindSignalR({ updateOnly: true }); this.listenTo(this.collection, 'sync', this._showTable); }, diff --git a/src/UI/Wanted/Missing/MissingLayout.js b/src/UI/Wanted/Missing/MissingLayout.js index 45bfb9d4e..7e1cf6ae2 100644 --- a/src/UI/Wanted/Missing/MissingLayout.js +++ b/src/UI/Wanted/Missing/MissingLayout.js @@ -14,7 +14,8 @@ define([ 'Shared/LoadingView', 'Shared/Messenger', 'Commands/CommandController', - 'backgrid.selectall' + 'backgrid.selectall', + 'Mixins/backbone.signalr.mixin' ], function (_, Marionette, Backgrid, @@ -81,7 +82,7 @@ define([ ], initialize : function () { - this.collection = new MissingCollection(); + this.collection = new MissingCollection().bindSignalR({ updateOnly: true }); this.listenTo(this.collection, 'sync', this._showTable); },