season list is properly populated in series details.

pull/23/head
kay.one 12 years ago
parent 6447b78a5a
commit 62f15d4d96

@ -125,6 +125,7 @@
<Compile Include="Resolvers\NullableDatetimeToString.cs" />
<Compile Include="RootFolders\RootFolderModule.cs" />
<Compile Include="Extensions\RootPathProvider.cs" />
<Compile Include="Seasons\SeasonModule.cs" />
<Compile Include="Series\SeriesResource.cs" />
<Compile Include="Series\SeriesModule.cs" />
<Compile Include="Series\SeriesLookupModule.cs" />

@ -0,0 +1,29 @@
using System.Linq;
using Nancy;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Tv;
namespace NzbDrone.Api.Seasons
{
public class SeasonModule : NzbDroneApiModule
{
private readonly ISeasonService _seasonService;
public SeasonModule(ISeasonService seasonService)
: base("/Season")
{
_seasonService = seasonService;
Get["/"] = x => GetSeasons();
}
private Response GetSeasons()
{
var seriesId = Request.Query.SeriesId;
return JsonExtensions.AsResponse(_seasonService.GetSeasonsBySeries(seriesId));
}
}
}

@ -122,10 +122,14 @@
<Content Include="Routing.js" />
<Content Include="Series\Delete\DeleteSeriesTemplate.html" />
<Content Include="Series\Delete\DeleteSeriesView.js" />
<Content Include="Series\Details\EpisodeCollection.js" />
<Content Include="Series\Details\EpisodeItemTemplate.html" />
<Content Include="Series\Details\EpisodeItemView.js" />
<Content Include="Series\Details\EpisodeModel.js" />
<Content Include="Series\Details\SeasonCollection.js" />
<Content Include="Series\Details\SeasonCollectionTemplate.html" />
<Content Include="Series\Details\SeasonCollectionView.js" />
<Content Include="Series\Details\SeasonCompositeTemplate.html" />
<Content Include="Series\Details\SeasonCompositeView.js" />
<Content Include="Series\Details\SeasonModel.js" />
<Content Include="Series\Details\SeriesDetailsTemplate.html" />
<Content Include="Series\Details\SeriesDetailsView.js" />
<Content Include="Series\Edit\EditSeriesTemplate.html" />

@ -1,5 +1,6 @@
define(['app','Series/Details/SeasonModel'], function () {
NzbDrone.Series.Details.SeasonCollection = Backbone.Collection.extend({
url: NzbDrone.Constants.ApiRoot + '/season'
url: NzbDrone.Constants.ApiRoot + '/season',
model: NzbDrone.Series.Details.SeasonModel
});
});

@ -1,4 +1,4 @@
<h3>Season {{seasonNumber}}</h3>
<h3>{{seasonTitle}}</h3>
<table class="table table-hover x-season-table">
<thead>
<tr>

@ -6,9 +6,7 @@ define(['app', 'Series/Details/EpisodeItemView'], function () {
template: 'Series/Details/SeasonCompositeTemplate',
initialize: function() {
var episodes = this.model.get('episodes');
var test = 1;
//this.collection
}
});
});

@ -1,4 +1,21 @@
define(['app', 'Series/Details/SeasonCollection'], function (app) {
define(['app'], function () {
NzbDrone.Series.Details.SeasonModel = Backbone.Model.extend({
mutators: {
seasonTitle: function () {
var seasonNumber = this.get('seasonNumber');
if (seasonNumber === 0) {
return "Specials"
}
return "Season " + seasonNumber;
}
},
defaults: {
seasonNumber: 0
}
});
});
});

@ -1,4 +1,6 @@
<div>
<div class="x-series-details"></div>
<div class="x-series-details">
{{overview}}
</div>
<div class="x-series-seasons"></div>
</div>

@ -1,4 +1,4 @@
define(['app', 'Quality/QualityProfileCollection', 'Series/Details/SeasonCompositeView'], function () {
define(['app', 'Quality/QualityProfileCollection', 'Series/Details/SeasonCompositeView', 'Series/Details/SeasonCollection'], function () {
NzbDrone.Series.Details.SeriesDetailsView = Backbone.Marionette.CompositeView.extend({
itemView: NzbDrone.Series.Details.SeasonCompositeView,
@ -6,6 +6,8 @@ define(['app', 'Quality/QualityProfileCollection', 'Series/Details/SeasonComposi
template: 'Series/Details/SeriesDetailsTemplate',
initialize: function () {
this.collection = new NzbDrone.Series.Details.SeasonCollection();
this.collection.fetch({data: { seriesId: this.model.get('id') }});
}
});
});

@ -17,7 +17,7 @@ namespace NzbDrone.Common.Test.EventingTests
var intHandler = new Mock<IHandle<EventA>>();
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object });
var aggregator = new EventAggregator(TestLogger, () => new List<IHandle> { intHandler.Object });
aggregator.Publish(eventA);
intHandler.Verify(c => c.Handle(eventA), Times.Once());
@ -30,7 +30,7 @@ namespace NzbDrone.Common.Test.EventingTests
var intHandler1 = new Mock<IHandle<EventA>>();
var intHandler2 = new Mock<IHandle<EventA>>();
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler1.Object, intHandler2.Object });
var aggregator = new EventAggregator(TestLogger, () => new List<IHandle> { intHandler1.Object, intHandler2.Object });
aggregator.Publish(eventA);
intHandler1.Verify(c => c.Handle(eventA), Times.Once());
@ -44,7 +44,7 @@ namespace NzbDrone.Common.Test.EventingTests
var aHandler = new Mock<IHandle<EventA>>();
var bHandler = new Mock<IHandle<EventB>>();
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { aHandler.Object, bHandler.Object });
var aggregator = new EventAggregator(TestLogger, () => new List<IHandle> { aHandler.Object, bHandler.Object });
aggregator.Publish(eventA);

@ -1,18 +1,17 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.EnsureThat;
namespace NzbDrone.Common.Eventing
{
public class EventAggregator : IEventAggregator
{
private readonly Logger _logger;
private readonly IEnumerable<IHandle> _handlers;
private readonly Func<IEnumerable<IHandle>> _handlers;
public EventAggregator(Logger logger, IEnumerable<IHandle> handlers)
public EventAggregator(Logger logger, Func<IEnumerable<IHandle>> handlers)
{
Ensure.That(() => handlers).HasItems();
_logger = logger;
_handlers = handlers;
}
@ -21,7 +20,7 @@ namespace NzbDrone.Common.Eventing
{
_logger.Trace("Publishing {0}", message.GetType().Name);
foreach (var handler in _handlers.OfType<IHandle<TEvent>>())
foreach (var handler in _handlers().OfType<IHandle<TEvent>>())
{
_logger.Trace("{0} => {1}", message.GetType().Name, handler.GetType().Name);
handler.Handle(message);

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace NzbDrone.Common.Eventing

@ -1,10 +1,12 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Autofac;
using Autofac.Core;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.ExternalNotification;
using NzbDrone.Core.Indexers;
@ -25,6 +27,7 @@ namespace NzbDrone.Core
containerBuilder.InitDatabase();
containerBuilder.RegisterModule<LogInjectionModule>();
}

@ -261,6 +261,8 @@
<Compile Include="ReferenceData\SceneMappingProxy.cs" />
<Compile Include="ReferenceData\SceneMappingRepository.cs" />
<Compile Include="Tv\EpisodeService.cs" />
<Compile Include="Tv\Events\EpisodeInfoUpdatedEvent.cs" />
<Compile Include="Tv\Events\EpisodeInfoAddedEvent.cs" />
<Compile Include="Tv\Events\SeriesAddedEvent.cs" />
<Compile Include="Tv\SeasonRepository.cs" />
<Compile Include="Tv\SeriesRepository.cs" />

@ -7,6 +7,7 @@ using NzbDrone.Core.Datastore;
using NzbDrone.Core.Download;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Tv.Events;
namespace NzbDrone.Core.Tv
{
@ -41,12 +42,14 @@ namespace NzbDrone.Core.Tv
private readonly TvDbProvider _tvDbProvider;
private readonly ISeasonRepository _seasonRepository;
private readonly IEpisodeRepository _episodeRepository;
private readonly IEventAggregator _eventAggregator;
public EpisodeService(TvDbProvider tvDbProviderProvider, ISeasonRepository seasonRepository, IEpisodeRepository episodeRepository)
public EpisodeService(TvDbProvider tvDbProviderProvider, ISeasonRepository seasonRepository, IEpisodeRepository episodeRepository, IEventAggregator eventAggregator)
{
_tvDbProvider = tvDbProviderProvider;
_seasonRepository = seasonRepository;
_episodeRepository = episodeRepository;
_eventAggregator = eventAggregator;
}
public void AddEpisode(Episode episode)
@ -240,7 +243,7 @@ namespace NzbDrone.Core.Tv
episodeToUpdate.Overview = episode.Overview;
episodeToUpdate.AirDate = episode.AirDate;
if(!String.IsNullOrWhiteSpace(series.AirTime) && episodeToUpdate.AirDate.HasValue)
if (!String.IsNullOrWhiteSpace(series.AirTime) && episodeToUpdate.AirDate.HasValue)
{
episodeToUpdate.AirDate = episodeToUpdate.AirDate.Value.Add(Convert.ToDateTime(series.AirTime).TimeOfDay)
.AddHours(series.UtcOffset * -1);
@ -258,6 +261,16 @@ namespace NzbDrone.Core.Tv
_episodeRepository.InsertMany(newList);
_episodeRepository.UpdateMany(updateList);
if (newList.Any())
{
_eventAggregator.Publish(new EpisodeInfoAddedEvent(newList));
}
if (updateList.Any())
{
_eventAggregator.Publish(new EpisodeInfoUpdatedEvent(updateList));
}
if (failCount != 0)
{
logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ",

@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using NzbDrone.Common.Eventing;
namespace NzbDrone.Core.Tv.Events
{
public class EpisodeInfoAddedEvent : IEvent
{
public ReadOnlyCollection<Episode> Episodes { get; private set; }
public EpisodeInfoAddedEvent(IList<Episode> episodes)
{
Episodes = new ReadOnlyCollection<Episode>(episodes);
}
}
}

@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using NzbDrone.Common.Eventing;
namespace NzbDrone.Core.Tv.Events
{
public class EpisodeInfoUpdatedEvent : IEvent
{
public ReadOnlyCollection<Episode> Episodes { get; private set; }
public EpisodeInfoUpdatedEvent(IList<Episode> episodes)
{
Episodes = new ReadOnlyCollection<Episode>(episodes);
}
}
}

Binary file not shown.
Loading…
Cancel
Save