From cde8b4dd97420fae81f4fe02ec2acec6796e8f4b Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Tue, 10 Jan 2017 20:06:09 +0100 Subject: [PATCH] Added MovieFileResource. This allows the UI to interact with movie files better. Downloaded Quality is now shown in the table. --- src/NzbDrone.Api/NzbDrone.Api.csproj | 1 + src/NzbDrone.Api/Series/MovieFileResource.cs | 85 +++++++++++++++++++ src/NzbDrone.Api/Series/MovieResource.cs | 6 +- src/UI/Cells/MovieDownloadStatusTemplate.hbs | 2 +- src/UI/Handlebars/Helpers/Series.js | 8 ++ src/UI/Movies/Details/InfoViewTemplate.hbs | 2 +- .../SeriesOverviewItemViewTemplate.hbs | 2 +- 7 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/NzbDrone.Api/Series/MovieFileResource.cs diff --git a/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index 5486fe715..f92541404 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -232,6 +232,7 @@ + diff --git a/src/NzbDrone.Api/Series/MovieFileResource.cs b/src/NzbDrone.Api/Series/MovieFileResource.cs new file mode 100644 index 000000000..62ad7832f --- /dev/null +++ b/src/NzbDrone.Api/Series/MovieFileResource.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NzbDrone.Api.REST; +using NzbDrone.Core.MediaCover; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Qualities; +using NzbDrone.Api.Series; +using NzbDrone.Core.MediaFiles; + +namespace NzbDrone.Api.Movie +{ + public class MovieFileResource : RestResource + { + public MovieFileResource() + { + + } + + //Todo: Sorters should be done completely on the client + //Todo: Is there an easy way to keep IgnoreArticlesWhenSorting in sync between, Series, History, Missing? + //Todo: We should get the entire Profile instead of ID and Name separately + + public int MovieId { get; set; } + public string RelativePath { get; set; } + public string Path { get; set; } + public long Size { get; set; } + public DateTime DateAdded { get; set; } + public string SceneName { get; set; } + public string ReleaseGroup { get; set; } + public QualityModel Quality { get; set; } + public MovieResource Movie { get; set; } + + + + //TODO: Add series statistics as a property of the series (instead of individual properties) + } + + public static class MovieFileResourceMapper + { + public static MovieFileResource ToResource(this MovieFile model) + { + if (model == null) return null; + + MovieResource movie = null; + + if (model.Movie != null) + { + model.Movie.LazyLoad(); + if (model.Movie.Value != null) + { + //movie = model.Movie.Value.ToResource(); + } + } + + return new MovieFileResource + { + Id = model.Id, + RelativePath = model.RelativePath, + Path = model.Path, + Size = model.Size, + DateAdded = model.DateAdded, + ReleaseGroup = model.ReleaseGroup, + Quality = model.Quality, + Movie = movie, + + }; + } + + public static MovieFile ToModel(this MovieFileResource resource) + { + if (resource == null) return null; + + return new MovieFile + { + + }; + } + + public static List ToResource(this IEnumerable movies) + { + return movies.Select(ToResource).ToList(); + } + } +} diff --git a/src/NzbDrone.Api/Series/MovieResource.cs b/src/NzbDrone.Api/Series/MovieResource.cs index 70a585086..c0cc8d623 100644 --- a/src/NzbDrone.Api/Series/MovieResource.cs +++ b/src/NzbDrone.Api/Series/MovieResource.cs @@ -55,6 +55,7 @@ namespace NzbDrone.Api.Movie public AddMovieOptions AddOptions { get; set; } public Ratings Ratings { get; set; } public List AlternativeTitles { get; set; } + public MovieFileResource MovieFile { get; set; } //TODO: Add series statistics as a property of the series (instead of individual properties) @@ -84,6 +85,7 @@ namespace NzbDrone.Api.Movie long size = 0; bool downloaded = false; + MovieFileResource movieFile = null; if(model.MovieFile != null) @@ -95,6 +97,7 @@ namespace NzbDrone.Api.Movie { size = model.MovieFile.Value.Size; downloaded = true; + movieFile = model.MovieFile.Value.ToResource(); } return new MovieResource @@ -140,7 +143,8 @@ namespace NzbDrone.Api.Movie Added = model.Added, AddOptions = model.AddOptions, AlternativeTitles = model.AlternativeTitles, - Ratings = model.Ratings + Ratings = model.Ratings, + MovieFile = movieFile }; } diff --git a/src/UI/Cells/MovieDownloadStatusTemplate.hbs b/src/UI/Cells/MovieDownloadStatusTemplate.hbs index 002a9fdc6..93a88fdf1 100644 --- a/src/UI/Cells/MovieDownloadStatusTemplate.hbs +++ b/src/UI/Cells/MovieDownloadStatusTemplate.hbs @@ -1 +1 @@ -{{DownloadedStatus}} +{{DownloadedStatus}} diff --git a/src/UI/Handlebars/Helpers/Series.js b/src/UI/Handlebars/Helpers/Series.js index fa642e39f..b33e192b0 100644 --- a/src/UI/Handlebars/Helpers/Series.js +++ b/src/UI/Handlebars/Helpers/Series.js @@ -161,6 +161,14 @@ Handlebars.registerHelper('DownloadedStatus', function() { return "Missing"; }); +Handlebars.registerHelper("DownloadedQuality", function() { + if (this.movieFile) { + return this.movieFile.quality.quality.name; + } + + return ""; +}) + Handlebars.registerHelper('inCinemas', function() { var monthNames = ["January", "February", "March", "April", "May", "June", diff --git a/src/UI/Movies/Details/InfoViewTemplate.hbs b/src/UI/Movies/Details/InfoViewTemplate.hbs index 602a13e72..35652f838 100644 --- a/src/UI/Movies/Details/InfoViewTemplate.hbs +++ b/src/UI/Movies/Details/InfoViewTemplate.hbs @@ -26,7 +26,7 @@ {{else}} Announced {{/if_eq}} - {{DownloadedStatus}} + {{DownloadedStatus}}
diff --git a/src/UI/Movies/Index/Overview/SeriesOverviewItemViewTemplate.hbs b/src/UI/Movies/Index/Overview/SeriesOverviewItemViewTemplate.hbs index 302d431ca..b1181c07d 100644 --- a/src/UI/Movies/Index/Overview/SeriesOverviewItemViewTemplate.hbs +++ b/src/UI/Movies/Index/Overview/SeriesOverviewItemViewTemplate.hbs @@ -41,7 +41,7 @@ {{profile profileId}} - {{DownloadedStatus}} + {{DownloadedStatus}}