diff --git a/src/NzbDrone.Core/Music/AlbumRepository.cs b/src/NzbDrone.Core/Music/AlbumRepository.cs index 4b6d03bcb..a79ab3a31 100644 --- a/src/NzbDrone.Core/Music/AlbumRepository.cs +++ b/src/NzbDrone.Core/Music/AlbumRepository.cs @@ -48,7 +48,9 @@ namespace NzbDrone.Core.Music { var currentTime = DateTime.UtcNow; - pagingSpec.TotalRecords = GetMissingAlbumsQuery(pagingSpec, currentTime).GetRowCount(); + //pagingSpec.TotalRecords = GetMissingAlbumsQuery(pagingSpec, currentTime).GetRowCount(); Cant Use GetRowCount with a Manual Query + + pagingSpec.TotalRecords = GetMissingAlbumsQueryCount(pagingSpec, currentTime); pagingSpec.Records = GetMissingAlbumsQuery(pagingSpec, currentTime).ToList(); return pagingSpec; @@ -70,21 +72,67 @@ namespace NzbDrone.Core.Music return query.ToList(); } - private SortBuilder GetMissingAlbumsQuery(PagingSpec pagingSpec, DateTime currentTime) + private QueryBuilder GetMissingAlbumsQuery(PagingSpec pagingSpec, DateTime currentTime) { - return Query.Join(JoinType.Inner, e => e.Artist, (e, s) => e.ArtistId == s.Id) - .Where(pagingSpec.FilterExpression) - - .AndWhere(BuildReleaseDateCutoffWhereClause(currentTime)) - //.Where(t => t.TrackFileId == 0) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) - .Skip(pagingSpec.PagingOffset()) - .Take(pagingSpec.PageSize); + string sortKey; + int monitored = 0; + + if (pagingSpec.FilterExpression.ToString().Contains("True")) + { + monitored = 1; + } + + if (pagingSpec.SortKey == "releaseDate") + { + sortKey = "[t0]." + pagingSpec.SortKey; + } + else if (pagingSpec.SortKey == "artist.sortName") + { + sortKey = "[t1]." + pagingSpec.SortKey.Split('.').Last(); + } + else + { + sortKey = "[t0].releaseDate"; + } + + string query = string.Format("SELECT * FROM Albums [t0] INNER JOIN Artists [t1] ON ([t0].[ArtistId] = [t1].[Id])" + + "WHERE (([t0].[Monitored] = {0}) AND ([t1].[Monitored] = {0})) AND {1}" + + " AND NOT EXISTS (SELECT 1 from Tracks [t2] WHERE [t2].albumId = [t0].id AND [t2].trackFileId <> 0) ORDER BY {2} {3} LIMIT {4} OFFSET {5}", + monitored, BuildReleaseDateCutoffWhereClause(currentTime), sortKey, pagingSpec.ToSortDirection(), pagingSpec.PageSize, pagingSpec.PagingOffset()); + + return Query.QueryText(query); + + //Use Manual Query until we find a way to "NOT EXIST(SELECT 1 from Tracks WHERE [t2].trackFileId <> 0)" + + //return Query.Join(JoinType.Inner, e => e.Artist, (e, s) => e.ArtistId == s.Id) + // .Where(pagingSpec.FilterExpression) + // .AndWhere(BuildReleaseDateCutoffWhereClause(currentTime)) + // //.Where(t => t.TrackFileId == 0) + // .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) + // .Skip(pagingSpec.PagingOffset()) + // .Take(pagingSpec.PageSize); + } + + private int GetMissingAlbumsQueryCount(PagingSpec pagingSpec, DateTime currentTime) + { + var monitored = 0; + + if (pagingSpec.FilterExpression.ToString().Contains("True")) + { + monitored = 1; + } + + string query = string.Format("SELECT * FROM Albums [t0] INNER JOIN Artists [t1] ON ([t0].[ArtistId] = [t1].[Id])" + + "WHERE (([t0].[Monitored] = {0}) AND ([t1].[Monitored] = {0})) AND {1}" + + " AND NOT EXISTS (SELECT 1 from Tracks [t2] WHERE [t2].albumId = [t0].id AND [t2].trackFileId <> 0)", + monitored, BuildReleaseDateCutoffWhereClause(currentTime)); + + return Query.QueryText(query).Count(); } private string BuildReleaseDateCutoffWhereClause(DateTime currentTime) { - return string.Format("WHERE datetime(strftime('%s', [t0].[ReleaseDate]), 'unixepoch') <= '{0}'", + return string.Format("datetime(strftime('%s', [t0].[ReleaseDate]), 'unixepoch') <= '{0}'", currentTime.ToString("yyyy-MM-dd HH:mm:ss")); } diff --git a/src/UI/Cells/AlbumTitleCell.js b/src/UI/Cells/AlbumTitleCell.js new file mode 100644 index 000000000..ca3d1cc48 --- /dev/null +++ b/src/UI/Cells/AlbumTitleCell.js @@ -0,0 +1,29 @@ +var vent = require('vent'); +var NzbDroneCell = require('./NzbDroneCell'); + +module.exports = NzbDroneCell.extend({ + className : 'album-title-cell', + + events : { + 'click' : '_showDetails' + }, + + render : function() { + var title = this.cellValue.get('title'); + + if (!title || title === '') { + title = 'TBA'; + } + + this.$el.html(title); + return this; + }, + + _showDetails : function() { + var hideArtistLink = this.column.get('hideArtistLink'); + vent.trigger(vent.Commands.ShowAlbumDetails, { + album : this.cellValue, + hideArtistLink : hideArtistLink + }); + } +}); \ No newline at end of file diff --git a/src/UI/Wanted/Missing/MissingLayout.js b/src/UI/Wanted/Missing/MissingLayout.js index 114b8a850..61772deaf 100644 --- a/src/UI/Wanted/Missing/MissingLayout.js +++ b/src/UI/Wanted/Missing/MissingLayout.js @@ -7,7 +7,7 @@ var MissingCollection = require('./MissingCollection'); var SelectAllCell = require('../../Cells/SelectAllCell'); var ArtistTitleCell = require('../../Cells/ArtistTitleCell'); var EpisodeNumberCell = require('../../Cells/EpisodeNumberCell'); -var EpisodeTitleCell = require('../../Cells/EpisodeTitleCell'); +var AlbumTitleCell = require('../../Cells/AlbumTitleCell'); var RelativeDateCell = require('../../Cells/RelativeDateCell'); var EpisodeStatusCell = require('../../Cells/EpisodeStatusCell'); var GridPager = require('../../Shared/Grid/Pager'); @@ -53,8 +53,8 @@ module.exports = Marionette.Layout.extend({ // }, { name : 'this', - label : 'Track Title', - cell : EpisodeTitleCell, + label : 'Album Title', + cell : AlbumTitleCell, sortable : false }, {