You've already forked Sonarr
							
							
				mirror of
				https://github.com/Sonarr/Sonarr.git
				synced 2025-10-31 00:07:55 +02:00 
			
		
		
		
	Look ma, history!
This commit is contained in:
		| @@ -389,12 +389,24 @@ namespace Marr.Data.QGen | ||||
|             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) | ||||
|         { | ||||
|             SortBuilder.OrderBy(sortExpression); | ||||
|             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) | ||||
|         { | ||||
|             SortBuilder.OrderByDescending(sortExpression); | ||||
|   | ||||
| @@ -45,9 +45,7 @@ namespace NzbDrone.Api | ||||
|             Mapper.CreateMap<PagingSpec<Episode>, PagingResource<EpisodeResource>>(); | ||||
|  | ||||
|             //History | ||||
|             Mapper.CreateMap<Core.History.History, HistoryResource>() | ||||
|                 .ForMember(dest => dest.Episode, opt => opt.Ignore()) | ||||
|                 .ForMember(dest => dest.Series, opt => opt.Ignore()); | ||||
|             Mapper.CreateMap<Core.History.History, HistoryResource>(); | ||||
|             Mapper.CreateMap<PagingSpec<Core.History.History>, PagingResource<HistoryResource>>(); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -44,7 +44,7 @@ namespace NzbDrone.Api.History | ||||
|                                                    ? SortDirection.Ascending | ||||
|                                                    : SortDirection.Descending; | ||||
|  | ||||
|             var pagingSpec = new PagingSpec<Episode> | ||||
|             var pagingSpec = new PagingSpec<Core.History.History> | ||||
|                                  { | ||||
|                                      Page = page, | ||||
|                                      PageSize = pageSize, | ||||
| @@ -52,44 +52,7 @@ namespace NzbDrone.Api.History | ||||
|                                      SortDirection = sortDirection | ||||
|                                  }; | ||||
|  | ||||
|             var series = new Core.Tv.Series { Title = "30 Rock", TitleSlug = "30-rock" }; | ||||
|             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; | ||||
|             var result = _historyService.Paged(pagingSpec); | ||||
|              | ||||
|             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<History.History>().RegisterModel("History") | ||||
|                   .Relationship() | ||||
|                   .HasOne(h => h.Episode, h => h.EpisodeId) | ||||
|                   .HasOne(h => h.Series, h => h.SeriesId); | ||||
|                   .Relationships | ||||
|                   .AutoMapICollectionOrComplexProperties(); | ||||
| //                  .Relationship(); | ||||
| //                  .HasOne(h => h.Episode, h => h.EpisodeId) | ||||
| //                  .HasOne(h => h.Series, h => h.SeriesId); | ||||
|  | ||||
|             Mapper.Entity<Series>().RegisterModel("Series") | ||||
|                   .Ignore(s => s.Path) | ||||
|   | ||||
| @@ -17,7 +17,10 @@ namespace NzbDrone.Core.History | ||||
|         public string NzbInfoUrl { get; set; } | ||||
|         public string ReleaseGroup { get; set; } | ||||
|  | ||||
|         public LazyLoaded<Episode> Episode { get; set; } | ||||
|         public LazyLoaded<Series> Series { get; set; }  | ||||
| //        public LazyLoaded<Episode> Episode { 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.Data; | ||||
| using System.Linq; | ||||
| using Marr.Data.QGen; | ||||
| using NzbDrone.Common.Messaging; | ||||
| using NzbDrone.Core.Datastore; | ||||
| using NzbDrone.Core.Tv; | ||||
| @@ -12,6 +13,7 @@ namespace NzbDrone.Core.History | ||||
|     { | ||||
|         void Trim(); | ||||
|         QualityModel GetBestQualityInHistory(int episodeId); | ||||
|         PagingSpec<History> Paged(PagingSpec<History> pagingSpec); | ||||
|     } | ||||
|  | ||||
|     public class HistoryRepository : BasicRepository<History>, IHistoryRepository | ||||
| @@ -41,6 +43,20 @@ namespace NzbDrone.Core.History | ||||
|             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 NLog; | ||||
| using NzbDrone.Common.Messaging; | ||||
| using NzbDrone.Core.Datastore; | ||||
| using NzbDrone.Core.Download; | ||||
| using NzbDrone.Core.Tv; | ||||
|  | ||||
| @@ -14,6 +15,7 @@ namespace NzbDrone.Core.History | ||||
|         void Purge(); | ||||
|         void Trim(); | ||||
|         QualityModel GetBestQualityInHistory(int episodeId); | ||||
|         PagingSpec<History> Paged(PagingSpec<History> pagingSpec); | ||||
|     } | ||||
|  | ||||
|     public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent> | ||||
| @@ -33,6 +35,11 @@ namespace NzbDrone.Core.History | ||||
|             return _historyRepository.All().ToList(); | ||||
|         } | ||||
|  | ||||
|         public PagingSpec<History> Paged(PagingSpec<History> pagingSpec) | ||||
|         { | ||||
|             return _historyRepository.Paged(pagingSpec); | ||||
|         } | ||||
|  | ||||
|         public void Purge() | ||||
|         { | ||||
|             _historyRepository.Purge(); | ||||
|   | ||||
| @@ -22,10 +22,6 @@ namespace NzbDrone.Core.Providers | ||||
|             _seriesRepository = seriesRepository; | ||||
|         } | ||||
|  | ||||
|         public XemProvider() | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public virtual void UpdateMappings() | ||||
|         { | ||||
|             _logger.Trace("Starting scene numbering update"); | ||||
|   | ||||
							
								
								
									
										1
									
								
								UI/History/EpisodeTitleTemplate.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								UI/History/EpisodeTitleTemplate.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| {{episode.title}} | ||||
| @@ -26,7 +26,7 @@ define([ | ||||
|                         headerCell: 'nzbDrone' | ||||
|                     }, | ||||
|                     { | ||||
|                         name      : 'seriesTitle', | ||||
|                         name      : 'Series.Title', | ||||
|                         label     : 'Series Title', | ||||
|                         editable  : false, | ||||
|                         cell      : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }), | ||||
| @@ -41,11 +41,11 @@ define([ | ||||
|                         headerCell: 'nzbDrone' | ||||
|                     }, | ||||
|                     { | ||||
|                         name      : 'episode.title', | ||||
|                         name      : 'Episode.Title', | ||||
|                         label     : 'Episode Title', | ||||
|                         editable  : false, | ||||
|                         sortable  : false, | ||||
|                         cell      : 'string', | ||||
|                         cell      : Backgrid.TemplateBackedCell.extend({ template: 'History/EpisodeTitleTemplate' }), | ||||
|                         headerCell: 'nzbDrone' | ||||
|                     }, | ||||
|                     { | ||||
|   | ||||
| @@ -1,6 +1,14 @@ | ||||
| "use strict"; | ||||
| define(['app'], function (app) { | ||||
|     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')); | ||||
|             }, | ||||
|             paddedEpisodeNumber: function () { | ||||
|                 return this.get('episodeNumber'); | ||||
|                 return this.get('episodeNumber').pad(2); | ||||
|             }, | ||||
|             day                : function () { | ||||
|                 return Date.create(this.get('airDate')).format('{dd}'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user