Merge branch 'series-sorttitle' of https://github.com/Taloth/NzbDrone into develop

Conflicts:
	src/NzbDrone.Api/Series/SeriesResource.cs
	src/NzbDrone.Core/Tv/SeriesService.cs
This commit is contained in:
Mark McDowall 2014-07-02 07:42:04 -07:00
commit bd0392a376
24 changed files with 301 additions and 154 deletions

View File

@ -28,7 +28,7 @@ namespace NzbDrone.Api.Blacklist
//This is a hack to deal with backgrid setting the sortKey to the column name instead of sortValue
if (pagingSpec.SortKey.Equals("series", StringComparison.InvariantCultureIgnoreCase))
{
pagingSpec.SortKey = "series.title";
pagingSpec.SortKey = "series.sortTitle";
}
return ApplyToPage(_blacklistService.Paged, pagingSpec);

View File

@ -36,7 +36,7 @@ namespace NzbDrone.Api.History
//This is a hack to deal with backgrid setting the sortKey to the column name instead of sortValue
if (pagingSpec.SortKey.Equals("series", StringComparison.InvariantCultureIgnoreCase))
{
pagingSpec.SortKey = "series.title";
pagingSpec.SortKey = "series.sortTitle";
}
if (pagingResource.FilterKey == "eventType")

View File

@ -163,6 +163,7 @@ namespace NzbDrone.Api.Series
resource.EpisodeCount = seriesStatistics.EpisodeCount;
resource.EpisodeFileCount = seriesStatistics.EpisodeFileCount;
resource.NextAiring = seriesStatistics.NextAiring;
resource.PreviousAiring = seriesStatistics.PreviousAiring;
}
private void PopulateAlternateTitles(List<SeriesResource> resources)

View File

@ -16,6 +16,7 @@ namespace NzbDrone.Api.Series
//View Only
public String Title { get; set; }
public List<AlternateTitleResource> AlternateTitles { get; set; }
public String SortTitle { get; set; }
public Int32 SeasonCount
{
@ -33,6 +34,7 @@ namespace NzbDrone.Api.Series
public String QualityProfileName { get; set; }
public String Overview { get; set; }
public DateTime? NextAiring { get; set; }
public DateTime? PreviousAiring { get; set; }
public String Network { get; set; }
public String AirTime { get; set; }
public List<MediaCover> Images { get; set; }

View File

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using NzbDrone.Api.Episodes;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Datastore;
@ -30,6 +31,12 @@ namespace NzbDrone.Api.Wanted
SortDirection = pagingResource.SortDirection
};
//This is a hack to deal with backgrid setting the sortKey to the column name instead of sortValue
if (pagingSpec.SortKey.Equals("series", StringComparison.InvariantCultureIgnoreCase))
{
pagingSpec.SortKey = "series.sortTitle";
}
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
{
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;

View File

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using NzbDrone.Api.Episodes;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Datastore;
@ -30,6 +31,12 @@ namespace NzbDrone.Api.Wanted
SortDirection = pagingResource.SortDirection
};
//This is a hack to deal with backgrid setting the sortKey to the column name instead of sortValue
if (pagingSpec.SortKey.Equals("series", StringComparison.InvariantCultureIgnoreCase))
{
pagingSpec.SortKey = "series.sortTitle";
}
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
{
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;

View File

@ -40,6 +40,7 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
[TestCase(75978)]
[TestCase(83462)]
[TestCase(266189)]
public void should_be_able_to_get_series_detail(int tvdbId)
{
var details = Subject.GetSeriesInfo(tvdbId);
@ -69,6 +70,7 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
series.Should().NotBeNull();
series.Title.Should().NotBeBlank();
series.CleanTitle.Should().Be(Parser.Parser.CleanSeriesTitle(series.Title));
series.SortTitle.Should().Be(Parser.Parser.NormalizeEpisodeTitle(series.Title));
series.Overview.Should().NotBeBlank();
series.AirTime.Should().NotBeBlank();
series.FirstAired.Should().HaveValue();

View File

@ -39,6 +39,11 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
_episode.EpisodeFileId = 1;
}
private void GivenOldEpisode()
{
_episode.AirDateUtc = DateTime.Now.AddSeconds(-10);
}
private void GivenMonitoredEpisode()
{
_episode.Monitored = true;
@ -59,6 +64,7 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().Be(_episode.AirDateUtc);
stats.First().PreviousAiring.Should().NotHaveValue();
}
[Test]
@ -73,6 +79,47 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
stats.First().NextAiring.Should().NotHaveValue();
}
[Test]
public void should_have_previous_airing_for_old_episode_with_file()
{
GivenEpisodeWithFile();
GivenOldEpisode();
GivenFile();
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().NotHaveValue();
stats.First().PreviousAiring.Should().Be(_episode.AirDateUtc);
}
[Test]
public void should_have_previous_airing_for_old_episode_without_file_monitored()
{
GivenMonitoredEpisode();
GivenOldEpisode();
GivenFile();
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().NotHaveValue();
stats.First().PreviousAiring.Should().Be(_episode.AirDateUtc);
}
[Test]
public void should_not_have_previous_airing_for_old_episode_without_file_unmonitored()
{
GivenOldEpisode();
GivenFile();
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().NotHaveValue();
stats.First().PreviousAiring.Should().NotHaveValue();
}
[Test]
public void should_not_include_unmonitored_episode_in_episode_count()
{

View File

@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using FluentMigrator;
using Newtonsoft.Json;
using NzbDrone.Common;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(53)]
public class add_series_sorttitle : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.Column("SortTitle").OnTable("Series").AsString().Nullable();
Execute.WithConnection(SetSortTitles);
}
private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand getSeriesCmd = conn.CreateCommand())
{
getSeriesCmd.Transaction = tran;
getSeriesCmd.CommandText = @"SELECT Id, Title FROM Series";
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
{
while (seriesReader.Read())
{
var id = seriesReader.GetInt32(0);
var title = seriesReader.GetString(1);
var sortTitle = Parser.Parser.NormalizeEpisodeTitle(title).ToLower();
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE Series SET SortTitle = ? WHERE Id = ?";
updateCmd.AddParameter(sortTitle);
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}

View File

@ -105,6 +105,7 @@ namespace NzbDrone.Core.MetadataSource
series.ImdbId = show.imdb_id;
series.Title = show.title;
series.CleanTitle = Parser.Parser.CleanSeriesTitle(show.title);
series.SortTitle = Parser.Parser.NormalizeEpisodeTitle(show.title).ToLower();
series.Year = GetYear(show.year, show.first_aired);
series.FirstAired = FromIso(show.first_aired_iso);
series.Overview = show.overview;

View File

@ -201,6 +201,7 @@
<Compile Include="Datastore\Migration\050_add_hash_to_metadata_files.cs" />
<Compile Include="Datastore\Migration\051_download_client_import.cs" />
<Compile Include="Datastore\Migration\052_add_columns_for_anime.cs" />
<Compile Include="Datastore\Migration\053_add_series_sorttitle.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />

View File

@ -7,6 +7,7 @@ namespace NzbDrone.Core.SeriesStats
{
public int SeriesId { get; set; }
public string NextAiringString { get; set; }
public string PreviousAiringString { get; set; }
public int EpisodeFileCount { get; set; }
public int EpisodeCount { get; set; }
@ -21,5 +22,17 @@ namespace NzbDrone.Core.SeriesStats
return nextAiring;
}
}
public DateTime? PreviousAiring
{
get
{
DateTime previousAiring;
if (!DateTime.TryParse(PreviousAiringString, out previousAiring)) return null;
return previousAiring;
}
}
}
}

View File

@ -56,7 +56,8 @@ namespace NzbDrone.Core.SeriesStats
SeriesId,
SUM(CASE WHEN (Monitored = 1 AND AirdateUtc <= @currentDate) OR EpisodeFileId > 0 THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN EpisodeFileId > 0 THEN 1 ELSE 0 END) AS EpisodeFileCount,
MIN(CASE WHEN AirDateUtc < @currentDate OR EpisodeFileId > 0 OR Monitored = 0 THEN NULL ELSE AirDateUtc END) AS NextAiringString
MIN(CASE WHEN AirDateUtc < @currentDate OR EpisodeFileId > 0 OR Monitored = 0 THEN NULL ELSE AirDateUtc END) AS NextAiringString,
MAX(CASE WHEN AirDateUtc >= @currentDate OR EpisodeFileId = 0 AND Monitored = 0 THEN NULL ELSE AirDateUtc END) AS PreviousAiringString
FROM Episodes";
}

View File

@ -59,6 +59,7 @@ namespace NzbDrone.Core.Tv
series.Overview = seriesInfo.Overview;
series.Status = seriesInfo.Status;
series.CleanTitle = seriesInfo.CleanTitle;
series.SortTitle = seriesInfo.SortTitle;
series.LastInfoSync = DateTime.UtcNow;
series.Runtime = seriesInfo.Runtime;
series.Images = seriesInfo.Images;

View File

@ -22,6 +22,7 @@ namespace NzbDrone.Core.Tv
public string ImdbId { get; set; }
public string Title { get; set; }
public string CleanTitle { get; set; }
public string SortTitle { get; set; }
public SeriesStatusType Status { get; set; }
public string Overview { get; set; }
public String AirTime { get; set; }

View File

@ -79,6 +79,7 @@ namespace NzbDrone.Core.Tv
newSeries.Monitored = true;
newSeries.CleanTitle = newSeries.Title.CleanSeriesTitle();
newSeries.SortTitle = Parser.Parser.NormalizeEpisodeTitle(newSeries.Title).ToLower();
_seriesRepository.Insert(newSeries);
_eventAggregator.PublishEvent(new SeriesAddedEvent(GetSeries(newSeries.Id)));

View File

@ -35,33 +35,33 @@ define(
columns:
[
{
name : 'series',
label: 'Series',
cell : SeriesTitleCell,
sortValue: 'series.title'
name : 'series',
label : 'Series',
cell : SeriesTitleCell,
sortValue : 'series.sortTitle'
},
{
name : 'sourceTitle',
label: 'Source Title',
cell : 'string',
sortValue: 'sourceTitle'
name : 'sourceTitle',
label : 'Source Title',
cell : 'string',
sortValue : 'sourceTitle'
},
{
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable: false
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable : false
},
{
name : 'date',
label: 'Date',
cell : RelativeDateCell
name : 'date',
label : 'Date',
cell : RelativeDateCell
},
{
name : 'this',
label : '',
cell : BlacklistActionsCell,
sortable: false
name : 'this',
label : '',
cell : BlacklistActionsCell,
sortable : false
}
],

View File

@ -32,33 +32,34 @@ define(
columns:
[
{
name : 'status',
label: '',
cell : QueueStatusCell,
cellValue: 'this'
name : 'status',
label : '',
cell : QueueStatusCell,
cellValue : 'this'
},
{
name : 'series',
label: 'Series',
cell : SeriesTitleCell
name : 'series',
label : 'Series',
cell : SeriesTitleCell,
sortable : false
},
{
name : 'episode',
label : 'Episode',
sortable: false,
cell : EpisodeNumberCell
name : 'episode',
label : 'Episode',
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'episode',
label : 'Episode Title',
sortable: false,
cell : EpisodeTitleCell
name : 'episode',
label : 'Episode Title',
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable: false
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable : false
},
{
name : 'timeleft',

View File

@ -39,45 +39,45 @@ define(
columns:
[
{
name : 'eventType',
label : '',
cell : EventTypeCell,
cellValue: 'this'
name : 'eventType',
label : '',
cell : EventTypeCell,
cellValue : 'this'
},
{
name : 'series',
label: 'Series',
cell : SeriesTitleCell,
sortValue: 'series.title'
name : 'series',
label : 'Series',
cell : SeriesTitleCell,
sortValue : 'series.sortTitle'
},
{
name : 'episode',
label : 'Episode',
sortable: false,
cell : EpisodeNumberCell
name : 'episode',
label : 'Episode',
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'episode',
label : 'Episode Title',
sortable: false,
cell : EpisodeTitleCell
name : 'episode',
label : 'Episode Title',
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable: false
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable : false
},
{
name : 'date',
label: 'Date',
cell : RelativeDateCell
name : 'date',
label : 'Date',
cell : RelativeDateCell
},
{
name : 'this',
label : '',
cell : HistoryDetailsCell,
sortable: false
name : 'this',
label : '',
cell : HistoryDetailsCell,
sortable : false
}
],

View File

@ -57,25 +57,26 @@ define(
cell : SeriesStatusCell
},
{
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue: 'this'
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue : 'this',
sortValue : 'sortTitle'
},
{
name : 'qualityProfileId',
label: 'Quality',
cell : QualityProfileCell
name : 'qualityProfileId',
label : 'Quality',
cell : QualityProfileCell
},
{
name : 'seasonFolder',
label: 'Season Folder',
cell : SeasonFolderCell
name : 'seasonFolder',
label : 'Season Folder',
cell : SeasonFolderCell
},
{
name : 'path',
label: 'Path',
cell : 'string'
name : 'path',
label : 'Path',
cell : 'string'
}
],

View File

@ -53,25 +53,26 @@ define(
cell : SeriesStatusCell
},
{
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue: 'this'
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue : 'this',
sortValue : 'sortTitle'
},
{
name : 'seasonCount',
label: 'Seasons',
cell : 'integer'
name : 'seasonCount',
label : 'Seasons',
cell : 'integer'
},
{
name : 'qualityProfileId',
label: 'Quality',
cell : QualityProfileCell
name : 'qualityProfileId',
label : 'Quality',
cell : QualityProfileCell
},
{
name : 'network',
label: 'Network',
cell : 'string'
name : 'network',
label : 'Network',
cell : 'string'
},
{
name : 'nextAiring',
@ -80,16 +81,16 @@ define(
sortValue : SeriesCollection.nextAiring
},
{
name : 'percentOfEpisodes',
label : 'Episodes',
cell : EpisodeProgressCell,
className: 'episode-progress-cell'
name : 'percentOfEpisodes',
label : 'Episodes',
cell : EpisodeProgressCell,
className : 'episode-progress-cell'
},
{
name : 'this',
label : '',
sortable: false,
cell : SeriesActionsCell
name : 'this',
label : '',
sortable : false,
cell : SeriesActionsCell
}
],

View File

@ -59,12 +59,18 @@ define(
//Sorters
nextAiring: function (model, attr) {
var nextAiring = model.get(attr);
if (!nextAiring) {
return Number.MAX_VALUE;
if (nextAiring) {
return Moment(nextAiring).unix();
}
var previousAiring = model.get(attr.replace('nextAiring', 'previousAiring'));
if (previousAiring) {
return 10000000000 - Moment(previousAiring).unix();
}
return Moment(nextAiring).unix();
return Number.MAX_VALUE;
}
});

View File

@ -45,39 +45,39 @@ define([
columns : [
{
name : '',
cell : 'select-row',
headerCell : 'select-all',
sortable : false
name : '',
cell : 'select-row',
headerCell: 'select-all',
sortable : false
},
{
name : 'series',
label : 'Series Title',
sortable : false,
cell : SeriesTitleCell
name : 'series',
label : 'Series Title',
cell : SeriesTitleCell,
sortValue : 'series.sortTitle'
},
{
name : 'this',
label : 'Episode',
sortable : false,
cell : EpisodeNumberCell
name : 'this',
label : 'Episode',
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'this',
label : 'Episode Title',
sortable : false,
cell : EpisodeTitleCell
name : 'this',
label : 'Episode Title',
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'airDateUtc',
label : 'Air Date',
cell : RelativeDateCell
name : 'airDateUtc',
label : 'Air Date',
cell : RelativeDateCell
},
{
name : 'status',
label : 'Status',
cell : EpisodeStatusCell,
sortable : false
name : 'status',
label : 'Status',
cell : EpisodeStatusCell,
sortable : false
}
],

View File

@ -45,39 +45,39 @@ define([
columns : [
{
name : '',
cell : 'select-row',
headerCell : 'select-all',
sortable : false
name : '',
cell : 'select-row',
headerCell: 'select-all',
sortable : false
},
{
name : 'series',
label : 'Series Title',
sortable : false,
cell : SeriesTitleCell
name : 'series',
label : 'Series Title',
cell : SeriesTitleCell,
sortValue : 'series.sortTitle'
},
{
name : 'this',
label : 'Episode',
sortable : false,
cell : EpisodeNumberCell
name : 'this',
label : 'Episode',
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'this',
label : 'Episode Title',
sortable : false,
cell : EpisodeTitleCell
name : 'this',
label : 'Episode Title',
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'airDateUtc',
label : 'Air Date',
cell : RelativeDateCell
name : 'airDateUtc',
label : 'Air Date',
cell : RelativeDateCell
},
{
name : 'status',
label : 'Status',
cell : EpisodeStatusCell,
sortable : false
name : 'status',
label : 'Status',
cell : EpisodeStatusCell,
sortable : false
}
],