1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 02:07:41 +00:00

signalr-episodes

This commit is contained in:
Mark McDowall 2013-09-30 08:09:47 -07:00
parent 6a10382e7b
commit b6693a20a9
6 changed files with 44 additions and 12 deletions

View file

@ -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<EpisodeResource>
public class EpisodeModule : NzbDroneRestModuleWithSignalR<EpisodeResource, Episode>,
IHandle<EpisodeGrabbedEvent>,
IHandle<EpisodeDownloadedEvent>
{
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<EpisodeResource>();
}
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);
}
}
}
}

View file

@ -18,6 +18,12 @@ namespace NzbDrone.Api
_commandExecutor = commandExecutor;
}
protected NzbDroneRestModuleWithSignalR(ICommandExecutor commandExecutor, string resource)
: base(resource)
{
_commandExecutor = commandExecutor;
}
public void Handle(ModelEvent<TModel> message)
{
if (message.Action == ModelAction.Deleted || message.Action == ModelAction.Sync)

View file

@ -16,7 +16,7 @@ namespace NzbDrone.Core.Datastore.Events
public enum ModelAction
{
Unknow = 0,
Unknown = 0,
Created = 1,
Updated = 2,
Deleted = 3,

View file

@ -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 () {
}});
});

View file

@ -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 () {

View file

@ -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: