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
pull/85/head
Mark McDowall 10 years ago
commit bd0392a376

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

@ -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")

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

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

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

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

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

@ -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()
{

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

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

@ -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" />

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

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

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

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

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

@ -38,7 +38,7 @@ define(
name : 'series',
label : 'Series',
cell : SeriesTitleCell,
sortValue: 'series.title'
sortValue : 'series.sortTitle'
},
{
name : 'sourceTitle',

@ -40,19 +40,20 @@ define(
{
name : 'series',
label : 'Series',
cell : SeriesTitleCell
cell : SeriesTitleCell,
sortable : false
},
{
name : 'episode',
label : 'Episode',
sortable: false,
cell : EpisodeNumberCell
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'episode',
label : 'Episode Title',
sortable: false,
cell : EpisodeTitleCell
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'quality',

@ -48,19 +48,19 @@ define(
name : 'series',
label : 'Series',
cell : SeriesTitleCell,
sortValue: 'series.title'
sortValue : 'series.sortTitle'
},
{
name : 'episode',
label : 'Episode',
sortable: false,
cell : EpisodeNumberCell
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'episode',
label : 'Episode Title',
sortable: false,
cell : EpisodeTitleCell
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'quality',

@ -60,7 +60,8 @@ define(
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue: 'this'
cellValue : 'this',
sortValue : 'sortTitle'
},
{
name : 'qualityProfileId',

@ -56,7 +56,8 @@ define(
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue: 'this'
cellValue : 'this',
sortValue : 'sortTitle'
},
{
name : 'seasonCount',

@ -60,11 +60,17 @@ define(
nextAiring: function (model, attr) {
var nextAiring = model.get(attr);
if (!nextAiring) {
return Number.MAX_VALUE;
if (nextAiring) {
return Moment(nextAiring).unix();
}
return Moment(nextAiring).unix();
var previousAiring = model.get(attr.replace('nextAiring', 'previousAiring'));
if (previousAiring) {
return 10000000000 - Moment(previousAiring).unix();
}
return Number.MAX_VALUE;
}
});

@ -53,20 +53,20 @@ define([
{
name : 'series',
label : 'Series Title',
sortable : false,
cell : SeriesTitleCell
cell : SeriesTitleCell,
sortValue : 'series.sortTitle'
},
{
name : 'this',
label : 'Episode',
sortable : false,
cell : EpisodeNumberCell
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'this',
label : 'Episode Title',
sortable : false,
cell : EpisodeTitleCell
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'airDateUtc',

@ -53,20 +53,20 @@ define([
{
name : 'series',
label : 'Series Title',
sortable : false,
cell : SeriesTitleCell
cell : SeriesTitleCell,
sortValue : 'series.sortTitle'
},
{
name : 'this',
label : 'Episode',
sortable : false,
cell : EpisodeNumberCell
cell : EpisodeNumberCell,
sortable : false
},
{
name : 'this',
label : 'Episode Title',
sortable : false,
cell : EpisodeTitleCell
cell : EpisodeTitleCell,
sortable : false
},
{
name : 'airDateUtc',

Loading…
Cancel
Save