Look ma, history!

pull/4/head
Mark McDowall 12 years ago
parent 3602822572
commit d320c2b6a9

@ -389,12 +389,24 @@ namespace Marr.Data.QGen
return SortBuilder; return SortBuilder;
} }
public virtual SortBuilder<T> OrderBy(Expression<Func<T, object>> sortExpression, SortDirection sortDirection)
{
SortBuilder.OrderBy(sortExpression, sortDirection);
return SortBuilder;
}
public virtual SortBuilder<T> ThenBy(Expression<Func<T, object>> sortExpression) public virtual SortBuilder<T> ThenBy(Expression<Func<T, object>> sortExpression)
{ {
SortBuilder.OrderBy(sortExpression); SortBuilder.OrderBy(sortExpression);
return SortBuilder; return SortBuilder;
} }
public virtual SortBuilder<T> ThenBy(Expression<Func<T, object>> sortExpression, SortDirection sortDirection)
{
SortBuilder.OrderBy(sortExpression, sortDirection);
return SortBuilder;
}
public virtual SortBuilder<T> OrderByDescending(Expression<Func<T, object>> sortExpression) public virtual SortBuilder<T> OrderByDescending(Expression<Func<T, object>> sortExpression)
{ {
SortBuilder.OrderByDescending(sortExpression); SortBuilder.OrderByDescending(sortExpression);

@ -45,9 +45,7 @@ namespace NzbDrone.Api
Mapper.CreateMap<PagingSpec<Episode>, PagingResource<EpisodeResource>>(); Mapper.CreateMap<PagingSpec<Episode>, PagingResource<EpisodeResource>>();
//History //History
Mapper.CreateMap<Core.History.History, HistoryResource>() Mapper.CreateMap<Core.History.History, HistoryResource>();
.ForMember(dest => dest.Episode, opt => opt.Ignore())
.ForMember(dest => dest.Series, opt => opt.Ignore());
Mapper.CreateMap<PagingSpec<Core.History.History>, PagingResource<HistoryResource>>(); Mapper.CreateMap<PagingSpec<Core.History.History>, PagingResource<HistoryResource>>();
} }
} }

@ -44,7 +44,7 @@ namespace NzbDrone.Api.History
? SortDirection.Ascending ? SortDirection.Ascending
: SortDirection.Descending; : SortDirection.Descending;
var pagingSpec = new PagingSpec<Episode> var pagingSpec = new PagingSpec<Core.History.History>
{ {
Page = page, Page = page,
PageSize = pageSize, PageSize = pageSize,
@ -52,44 +52,7 @@ namespace NzbDrone.Api.History
SortDirection = sortDirection SortDirection = sortDirection
}; };
var series = new Core.Tv.Series { Title = "30 Rock", TitleSlug = "30-rock" }; var result = _historyService.Paged(pagingSpec);
var episode = new Episode { Title = "Test", SeasonNumber = 1, EpisodeNumber = 5 };
var result = new PagingSpec<Core.History.History>
{
Records = new List<Core.History.History>
{
new Core.History.History
{
Id = 1,
Date = DateTime.UtcNow.AddHours(-5),
// Episode = episode,
// Series = series,
Indexer = "nzbs.org",
Quality = new QualityModel(Quality.HDTV720p)
},
new Core.History.History
{
Id = 2,
Date = DateTime.UtcNow.AddDays(-1),
// Episode = episode,
// Series = series,
Indexer = "nzbs.org",
Quality = new QualityModel(Quality.SDTV, true)
},
new Core.History.History
{
Id = 3,
Date = DateTime.UtcNow.AddDays(-5),
// Episode = episode,
// Series = series,
Indexer = "nzbs.org",
Quality = new QualityModel(Quality.WEBDL1080p)
}
}
};
result.TotalRecords = result.Records.Count;
return Mapper.Map<PagingSpec<Core.History.History>, PagingResource<HistoryResource>>(result).AsResponse(); return Mapper.Map<PagingSpec<Core.History.History>, PagingResource<HistoryResource>>(result).AsResponse();
} }

@ -39,9 +39,11 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings"); Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings");
Mapper.Entity<History.History>().RegisterModel("History") Mapper.Entity<History.History>().RegisterModel("History")
.Relationship() .Relationships
.HasOne(h => h.Episode, h => h.EpisodeId) .AutoMapICollectionOrComplexProperties();
.HasOne(h => h.Series, h => h.SeriesId); // .Relationship();
// .HasOne(h => h.Episode, h => h.EpisodeId)
// .HasOne(h => h.Series, h => h.SeriesId);
Mapper.Entity<Series>().RegisterModel("Series") Mapper.Entity<Series>().RegisterModel("Series")
.Ignore(s => s.Path) .Ignore(s => s.Path)

@ -17,7 +17,10 @@ namespace NzbDrone.Core.History
public string NzbInfoUrl { get; set; } public string NzbInfoUrl { get; set; }
public string ReleaseGroup { get; set; } public string ReleaseGroup { get; set; }
public LazyLoaded<Episode> Episode { get; set; } // public LazyLoaded<Episode> Episode { get; set; }
public LazyLoaded<Series> Series { get; set; } // public LazyLoaded<Series> Series { get; set; }
public Episode Episode { get; set; }
public Series Series { get; set; }
} }
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using Marr.Data.QGen;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
@ -12,6 +13,7 @@ namespace NzbDrone.Core.History
{ {
void Trim(); void Trim();
QualityModel GetBestQualityInHistory(int episodeId); QualityModel GetBestQualityInHistory(int episodeId);
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
} }
public class HistoryRepository : BasicRepository<History>, IHistoryRepository public class HistoryRepository : BasicRepository<History>, IHistoryRepository
@ -41,6 +43,20 @@ namespace NzbDrone.Core.History
return null; return null;
} }
//public List<History> GetPagedHistory() public PagingSpec<History> Paged(PagingSpec<History> pagingSpec)
{
var pagingQuery = Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
.Join<History, Episode>(JoinType.Inner, h => h.Episode, (h, e) => h.EpisodeId == e.Id)
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
.Skip(pagingSpec.PagingOffset())
.Take(pagingSpec.PageSize);
pagingSpec.Records = pagingQuery.ToList();
//TODO: Use the same query for count and records
pagingSpec.TotalRecords = Count();
return pagingSpec;
}
} }
} }

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
@ -14,6 +15,7 @@ namespace NzbDrone.Core.History
void Purge(); void Purge();
void Trim(); void Trim();
QualityModel GetBestQualityInHistory(int episodeId); QualityModel GetBestQualityInHistory(int episodeId);
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
} }
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent> public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>
@ -33,6 +35,11 @@ namespace NzbDrone.Core.History
return _historyRepository.All().ToList(); return _historyRepository.All().ToList();
} }
public PagingSpec<History> Paged(PagingSpec<History> pagingSpec)
{
return _historyRepository.Paged(pagingSpec);
}
public void Purge() public void Purge()
{ {
_historyRepository.Purge(); _historyRepository.Purge();

@ -22,10 +22,6 @@ namespace NzbDrone.Core.Providers
_seriesRepository = seriesRepository; _seriesRepository = seriesRepository;
} }
public XemProvider()
{
}
public virtual void UpdateMappings() public virtual void UpdateMappings()
{ {
_logger.Trace("Starting scene numbering update"); _logger.Trace("Starting scene numbering update");

@ -0,0 +1 @@
{{episode.title}}

@ -26,7 +26,7 @@ define([
headerCell: 'nzbDrone' headerCell: 'nzbDrone'
}, },
{ {
name : 'seriesTitle', name : 'Series.Title',
label : 'Series Title', label : 'Series Title',
editable : false, editable : false,
cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }), cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }),
@ -41,11 +41,11 @@ define([
headerCell: 'nzbDrone' headerCell: 'nzbDrone'
}, },
{ {
name : 'episode.title', name : 'Episode.Title',
label : 'Episode Title', label : 'Episode Title',
editable : false, editable : false,
sortable : false, sortable : false,
cell : 'string', cell : Backgrid.TemplateBackedCell.extend({ template: 'History/EpisodeTitleTemplate' }),
headerCell: 'nzbDrone' headerCell: 'nzbDrone'
}, },
{ {

@ -1,6 +1,14 @@
"use strict"; "use strict";
define(['app'], function (app) { define(['app'], function (app) {
NzbDrone.History.Model = Backbone.Model.extend({ NzbDrone.History.Model = Backbone.Model.extend({
mutators: {
seasonNumber: function () {
return this.get('episode').seasonNumber;
},
paddedEpisodeNumber: function () {
return this.get('episode').episodeNumber.pad(2);
}
}
}); });
}); });

@ -7,7 +7,7 @@ define(['app'], function () {
return bestDateString(this.get('airDate')); return bestDateString(this.get('airDate'));
}, },
paddedEpisodeNumber: function () { paddedEpisodeNumber: function () {
return this.get('episodeNumber'); return this.get('episodeNumber').pad(2);
}, },
day : function () { day : function () {
return Date.create(this.get('airDate')).format('{dd}'); return Date.create(this.get('airDate')).format('{dd}');

Loading…
Cancel
Save