1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 23:42:33 +01:00

Fixed: Repaired Cutoff Unmet UI and added Cutoff Unmet status badge to History.

This commit is contained in:
Taloth Saldono 2014-08-27 02:25:35 +02:00
parent 0870afb425
commit 64ecaf5f6e
12 changed files with 130 additions and 60 deletions

View File

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

View File

@ -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<EpisodeResource>();
foreach (var episode in _episodeService.GetEpisodeBySeries(seriesId.Value))
{
var resource = episode.InjectTo<EpisodeResource>();
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;
}

View File

@ -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<EpisodeGrabbedEvent>,
IHandle<EpisodeDownloadedEvent>
{
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<EpisodeResource>();
return ToResource(episode);
}
protected override EpisodeResource ToResource<TModel>(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<EpisodeFileResource>();
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)

View File

@ -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<HistoryResource>
{
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>(TModel model)
{
var resource = base.ToResource<TModel>(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<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
{
var episodeId = Request.Query.EpisodeId;

View File

@ -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; }

View File

@ -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<TResource> ToListResource<TModel>(Func<IEnumerable<TModel>> function) where TModel : class
{
var modelList = function();
return modelList.InjectTo<List<TResource>>();
return ToListResource(modelList);
}
protected virtual List<TResource> ToListResource<TModel>(IEnumerable<TModel> modelList) where TModel : class
{
return modelList.Select(ToResource).ToList();
}
protected virtual TResource ToResource<TModel>(TModel model) where TModel : class
{
return model.InjectTo<TResource>();
}
protected PagingResource<TResource> ApplyToPage<TModel>(Func<PagingSpec<TModel>, PagingSpec<TModel>> function, PagingSpec<TModel> 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<List<TResource>>()
Records = ToListResource(pagingSpec.Records)
};
}
}

View File

@ -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<EpisodeResource> resource = ApplyToPage(_episodeCutoffService.EpisodesWhereCutoffUnmet, pagingSpec);
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();
return resource;
}
}

View File

@ -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<EpisodeResource> resource = ApplyToPage(v => _episodeService.EpisodesWithoutFiles(v), pagingSpec);
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();
return resource;
}
}

View File

@ -1,5 +1,5 @@
{{#if proper}}
<span class="badge badge-info" title="PROPER">{{quality.name}}</span>
{{else}}
<span class="badge badge-inverse">{{quality.name}}</span>
<span class="badge">{{quality.name}}</span>
{{/if}}

View File

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

View File

@ -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('<span class="badge badge-inverse" title="{0}">{1}</span>'.format(title, quality.quality.name));
}
else {
this.$el.html('<span class="badge" title="{0}">{1}</span>'.format(title, quality.quality.name));
}
return this;
}
});
});

View File

@ -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
},
{