From 64ecaf5f6e98401846fe92c9486a56538b8eed73 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 27 Aug 2014 02:25:35 +0200 Subject: [PATCH] Fixed: Repaired Cutoff Unmet UI and added Cutoff Unmet status badge to History. --- src/NzbDrone.Api/Calendar/CalendarModule.cs | 18 +++------ src/NzbDrone.Api/Episodes/EpisodeModule.cs | 26 ++++-------- .../Episodes/EpisodeModuleWithSignalR.cs | 40 ++++++++++++++++--- src/NzbDrone.Api/History/HistoryModule.cs | 21 +++++++++- src/NzbDrone.Api/History/HistoryResource.cs | 1 + src/NzbDrone.Api/NzbDroneRestModule.cs | 15 ++++++- src/NzbDrone.Api/Wanted/CutoffModule.cs | 12 +++--- src/NzbDrone.Api/Wanted/MissingModule.cs | 14 +++---- src/UI/Cells/QualityCellTemplate.html | 2 +- src/UI/Cells/cells.less | 2 +- src/UI/History/Table/HistoryQualityCell.js | 31 ++++++++++++++ src/UI/History/Table/HistoryTableLayout.js | 8 ++-- 12 files changed, 130 insertions(+), 60 deletions(-) create mode 100644 src/UI/History/Table/HistoryQualityCell.js diff --git a/src/NzbDrone.Api/Calendar/CalendarModule.cs b/src/NzbDrone.Api/Calendar/CalendarModule.cs index a97e55e8b..4f089e0d3 100644 --- a/src/NzbDrone.Api/Calendar/CalendarModule.cs +++ b/src/NzbDrone.Api/Calendar/CalendarModule.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Api.Episodes; using NzbDrone.Api.Extensions; +using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; using NzbDrone.SignalR; @@ -11,17 +12,11 @@ namespace NzbDrone.Api.Calendar { public class CalendarModule : EpisodeModuleWithSignalR { - private readonly IEpisodeService _episodeService; - private readonly SeriesRepository _seriesRepository; - - public CalendarModule(IBroadcastSignalRMessage signalRBroadcaster, - IEpisodeService episodeService, - SeriesRepository seriesRepository) - : base(episodeService, signalRBroadcaster, "calendar") + public CalendarModule(IEpisodeService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster) + : base(episodeService, qualityUpgradableSpecification, signalRBroadcaster, "calendar") { - _episodeService = episodeService; - _seriesRepository = seriesRepository; - GetResourceAll = GetCalendar; } @@ -36,8 +31,7 @@ namespace NzbDrone.Api.Calendar if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value); if (queryEnd.HasValue) end = DateTime.Parse(queryEnd.Value); - var resources = ToListResource(() => _episodeService.EpisodesBetweenDates(start, end)) - .LoadSubtype(e => e.SeriesId, _seriesRepository); + var resources = ToListResource(() => _episodeService.EpisodesBetweenDates(start, end)); return resources.OrderBy(e => e.AirDateUtc).ToList(); } diff --git a/src/NzbDrone.Api/Episodes/EpisodeModule.cs b/src/NzbDrone.Api/Episodes/EpisodeModule.cs index 4a5a649e5..ee56fb00b 100644 --- a/src/NzbDrone.Api/Episodes/EpisodeModule.cs +++ b/src/NzbDrone.Api/Episodes/EpisodeModule.cs @@ -10,17 +10,15 @@ namespace NzbDrone.Api.Episodes { public class EpisodeModule : EpisodeModuleWithSignalR { - private readonly ISeriesService _seriesService; - private readonly IEpisodeService _episodeService; - private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification; + protected readonly ISeriesService _seriesService; - public EpisodeModule(IBroadcastSignalRMessage signalRBroadcaster, ISeriesService seriesService, IEpisodeService episodeService, - IQualityUpgradableSpecification qualityUpgradableSpecification) - : base(episodeService, signalRBroadcaster) + public EpisodeModule(ISeriesService seriesService, + IEpisodeService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster) + : base(episodeService, qualityUpgradableSpecification, signalRBroadcaster) { _seriesService = seriesService; - _episodeService = episodeService; - _qualityUpgradableSpecification = qualityUpgradableSpecification; GetResourceAll = GetEpisodes; UpdateResource = SetMonitored; @@ -37,17 +35,7 @@ namespace NzbDrone.Api.Episodes var series = _seriesService.GetSeries(seriesId.Value); - var resources = new List(); - foreach (var episode in _episodeService.GetEpisodeBySeries(seriesId.Value)) - { - var resource = episode.InjectTo(); - if (episode.EpisodeFile.IsLoaded) - { - resource.EpisodeFile.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(series.Profile.Value, episode.EpisodeFile.Value.Quality); - } - - resources.Add(resource); - } + var resources = ToListResource(_episodeService.GetEpisodeBySeries(seriesId.Value)); return resources; } diff --git a/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs b/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs index 7976767f8..6f3b7c7fc 100644 --- a/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs +++ b/src/NzbDrone.Api/Episodes/EpisodeModuleWithSignalR.cs @@ -1,5 +1,9 @@ -using NzbDrone.Api.Mapping; +using System; +using System.IO; +using NzbDrone.Api.EpisodeFiles; +using NzbDrone.Api.Mapping; using NzbDrone.Core.Datastore.Events; +using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging.Events; @@ -12,20 +16,28 @@ namespace NzbDrone.Api.Episodes IHandle, IHandle { - private readonly IEpisodeService _episodeService; + protected readonly IEpisodeService _episodeService; + protected readonly IQualityUpgradableSpecification _qualityUpgradableSpecification; - protected EpisodeModuleWithSignalR(IEpisodeService episodeService, IBroadcastSignalRMessage signalRBroadcaster) + protected EpisodeModuleWithSignalR(IEpisodeService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster) : base(signalRBroadcaster) { _episodeService = episodeService; + _qualityUpgradableSpecification = qualityUpgradableSpecification; GetResourceById = GetEpisode; } - protected EpisodeModuleWithSignalR(IEpisodeService episodeService, IBroadcastSignalRMessage signalRBroadcaster, string resource) + protected EpisodeModuleWithSignalR(IEpisodeService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster, + String resource) : base(signalRBroadcaster, resource) { _episodeService = episodeService; + _qualityUpgradableSpecification = qualityUpgradableSpecification; GetResourceById = GetEpisode; } @@ -34,7 +46,25 @@ namespace NzbDrone.Api.Episodes { var episode = _episodeService.GetEpisode(id); episode.EpisodeFile.LazyLoad(); - return episode.InjectTo(); + return ToResource(episode); + } + + protected override EpisodeResource ToResource(TModel model) + { + var resource = base.ToResource(model); + + var episode = model as Episode; + if (episode != null) + { + if (episode.EpisodeFile.IsLoaded && episode.EpisodeFile.Value != null) + { + resource.EpisodeFile = episode.EpisodeFile.Value.InjectTo(); + resource.EpisodeFile.Path = Path.Combine(episode.Series.Path, episode.EpisodeFile.Value.RelativePath); + resource.EpisodeFile.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(episode.Series.Profile.Value, episode.EpisodeFile.Value.Quality); + } + } + + return resource; } public void Handle(EpisodeGrabbedEvent message) diff --git a/src/NzbDrone.Api/History/HistoryModule.cs b/src/NzbDrone.Api/History/HistoryModule.cs index 232edfd79..9a9984566 100644 --- a/src/NzbDrone.Api/History/HistoryModule.cs +++ b/src/NzbDrone.Api/History/HistoryModule.cs @@ -2,6 +2,7 @@ using Nancy; using NzbDrone.Api.Extensions; using NzbDrone.Core.Datastore; +using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; using NzbDrone.Core.History; @@ -10,17 +11,35 @@ namespace NzbDrone.Api.History public class HistoryModule : NzbDroneRestModule { private readonly IHistoryService _historyService; + private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification; private readonly IDownloadTrackingService _downloadTrackingService; - public HistoryModule(IHistoryService historyService, IDownloadTrackingService downloadTrackingService) + public HistoryModule(IHistoryService historyService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IDownloadTrackingService downloadTrackingService) { _historyService = historyService; + _qualityUpgradableSpecification = qualityUpgradableSpecification; _downloadTrackingService = downloadTrackingService; GetResourcePaged = GetHistory; Post["/failed"] = x => MarkAsFailed(); } + protected override HistoryResource ToResource(TModel model) + { + var resource = base.ToResource(model); + + var history = model as NzbDrone.Core.History.History; + + if (history != null && history.Series != null) + { + resource.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(history.Series.Profile.Value, history.Quality); + } + + return resource; + } + private PagingResource GetHistory(PagingResource pagingResource) { var episodeId = Request.Query.EpisodeId; diff --git a/src/NzbDrone.Api/History/HistoryResource.cs b/src/NzbDrone.Api/History/HistoryResource.cs index 2d9d0a07d..48093f685 100644 --- a/src/NzbDrone.Api/History/HistoryResource.cs +++ b/src/NzbDrone.Api/History/HistoryResource.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Api.History public int SeriesId { get; set; } public string SourceTitle { get; set; } public QualityModel Quality { get; set; } + public Boolean QualityCutoffNotMet { get; set; } public DateTime Date { get; set; } public string Indexer { get; set; } public string NzbInfoUrl { get; set; } diff --git a/src/NzbDrone.Api/NzbDroneRestModule.cs b/src/NzbDrone.Api/NzbDroneRestModule.cs index 5c297e331..e3c043ef5 100644 --- a/src/NzbDrone.Api/NzbDroneRestModule.cs +++ b/src/NzbDrone.Api/NzbDroneRestModule.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using NzbDrone.Api.REST; using NzbDrone.Api.Validation; @@ -34,7 +35,17 @@ namespace NzbDrone.Api protected List ToListResource(Func> function) where TModel : class { var modelList = function(); - return modelList.InjectTo>(); + return ToListResource(modelList); + } + + protected virtual List ToListResource(IEnumerable modelList) where TModel : class + { + return modelList.Select(ToResource).ToList(); + } + + protected virtual TResource ToResource(TModel model) where TModel : class + { + return model.InjectTo(); } protected PagingResource ApplyToPage(Func, PagingSpec> function, PagingSpec pagingSpec) where TModel : ModelBase, new() @@ -48,7 +59,7 @@ namespace NzbDrone.Api SortDirection = pagingSpec.SortDirection, SortKey = pagingSpec.SortKey, TotalRecords = pagingSpec.TotalRecords, - Records = pagingSpec.Records.InjectTo>() + Records = ToListResource(pagingSpec.Records) }; } } diff --git a/src/NzbDrone.Api/Wanted/CutoffModule.cs b/src/NzbDrone.Api/Wanted/CutoffModule.cs index eb7514798..c6092c863 100644 --- a/src/NzbDrone.Api/Wanted/CutoffModule.cs +++ b/src/NzbDrone.Api/Wanted/CutoffModule.cs @@ -2,6 +2,7 @@ using NzbDrone.Api.Episodes; using NzbDrone.Api.Extensions; using NzbDrone.Core.Datastore; +using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Tv; using NzbDrone.SignalR; @@ -10,13 +11,14 @@ namespace NzbDrone.Api.Wanted public class CutoffModule : EpisodeModuleWithSignalR { private readonly IEpisodeCutoffService _episodeCutoffService; - private readonly ISeriesRepository _seriesRepository; - public CutoffModule(IEpisodeService episodeService, IEpisodeCutoffService episodeCutoffService, ISeriesRepository seriesRepository, IBroadcastSignalRMessage signalRBroadcaster) - : base(episodeService, signalRBroadcaster, "wanted/cutoff") + public CutoffModule(IEpisodeCutoffService episodeCutoffService, + IEpisodeService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster) + : base(episodeService, qualityUpgradableSpecification, signalRBroadcaster, "wanted/cutoff") { _episodeCutoffService = episodeCutoffService; - _seriesRepository = seriesRepository; GetResourcePaged = GetCutoffUnmetEpisodes; } @@ -41,8 +43,6 @@ namespace NzbDrone.Api.Wanted PagingResource resource = ApplyToPage(_episodeCutoffService.EpisodesWhereCutoffUnmet, pagingSpec); - resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList(); - return resource; } } diff --git a/src/NzbDrone.Api/Wanted/MissingModule.cs b/src/NzbDrone.Api/Wanted/MissingModule.cs index 78e4c4495..e4f03d555 100644 --- a/src/NzbDrone.Api/Wanted/MissingModule.cs +++ b/src/NzbDrone.Api/Wanted/MissingModule.cs @@ -3,6 +3,7 @@ using System.Linq; using NzbDrone.Api.Episodes; using NzbDrone.Api.Extensions; using NzbDrone.Core.Datastore; +using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; using NzbDrone.SignalR; @@ -11,14 +12,11 @@ namespace NzbDrone.Api.Wanted { public class MissingModule : EpisodeModuleWithSignalR { - private readonly IEpisodeService _episodeService; - private readonly ISeriesRepository _seriesRepository; - - public MissingModule(IEpisodeService episodeService, ISeriesRepository seriesRepository, IBroadcastSignalRMessage signalRBroadcaster) - : base(episodeService, signalRBroadcaster, "wanted/missing") + public MissingModule(IEpisodeService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster) + : base(episodeService, qualityUpgradableSpecification, signalRBroadcaster, "wanted/missing") { - _episodeService = episodeService; - _seriesRepository = seriesRepository; GetResourcePaged = GetMissingEpisodes; } @@ -43,8 +41,6 @@ namespace NzbDrone.Api.Wanted PagingResource resource = ApplyToPage(v => _episodeService.EpisodesWithoutFiles(v), pagingSpec); - resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList(); - return resource; } } diff --git a/src/UI/Cells/QualityCellTemplate.html b/src/UI/Cells/QualityCellTemplate.html index 429ef0c0f..28b8c83a2 100644 --- a/src/UI/Cells/QualityCellTemplate.html +++ b/src/UI/Cells/QualityCellTemplate.html @@ -1,5 +1,5 @@ {{#if proper}} {{quality.name}} {{else}} - {{quality.name}} + {{quality.name}} {{/if}} \ No newline at end of file diff --git a/src/UI/Cells/cells.less b/src/UI/Cells/cells.less index 0f915fc94..0eb6b6f30 100644 --- a/src/UI/Cells/cells.less +++ b/src/UI/Cells/cells.less @@ -78,7 +78,7 @@ } } -td.episode-status-cell, td.quality-cell { +td.episode-status-cell, td.quality-cell, td.history-quality-cell { text-align: center; width: 80px; diff --git a/src/UI/History/Table/HistoryQualityCell.js b/src/UI/History/Table/HistoryQualityCell.js new file mode 100644 index 000000000..f580f529a --- /dev/null +++ b/src/UI/History/Table/HistoryQualityCell.js @@ -0,0 +1,31 @@ +'use strict'; +define( + [ + 'Cells/NzbDroneCell' + ], function (NzbDroneCell) { + return NzbDroneCell.extend({ + + className: 'history-quality-cell', + + render: function () { + + var title = ''; + var quality = this.model.get('quality'); + + if (quality.proper) { + title = 'PROPER'; + } + + if (this.model.get('qualityCutoffNotMet')) { + this.$el.html('{1}'.format(title, quality.quality.name)); + } + else { + this.$el.html('{1}'.format(title, quality.quality.name)); + } + + return this; + } + + + }); + }); diff --git a/src/UI/History/Table/HistoryTableLayout.js b/src/UI/History/Table/HistoryTableLayout.js index d4df0fc71..336deaccd 100644 --- a/src/UI/History/Table/HistoryTableLayout.js +++ b/src/UI/History/Table/HistoryTableLayout.js @@ -8,7 +8,7 @@ define( 'Cells/SeriesTitleCell', 'Cells/EpisodeNumberCell', 'Cells/EpisodeTitleCell', - 'Cells/QualityCell', + 'History/Table/HistoryQualityCell', 'Cells/RelativeDateCell', 'History/Table/HistoryDetailsCell', 'Shared/Grid/Pager', @@ -21,7 +21,7 @@ define( SeriesTitleCell, EpisodeNumberCell, EpisodeTitleCell, - QualityCell, + HistoryQualityCell, RelativeDateCell, HistoryDetailsCell, GridPager, @@ -62,9 +62,9 @@ define( sortable : false }, { - name : 'quality', + name : 'this', label : 'Quality', - cell : QualityCell, + cell : HistoryQualityCell, sortable : false }, {