From fded4cf7f3e11e9b6f818728c18841c3a12765af Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 11 Aug 2013 17:42:11 -0700 Subject: [PATCH] Added examples to naming settings --- NzbDrone.Api/Naming/NamingModule.cs | 71 +++++++++++++++++++ NzbDrone.Api/Naming/NamingResource.cs | 19 +++++ NzbDrone.Api/NzbDrone.Api.csproj | 2 + NzbDrone.Core/Organizer/FileNameBuilder.cs | 6 ++ UI/Settings/MediaManagement/Naming/View.js | 25 ++++++- .../MediaManagement/Naming/ViewTemplate.html | 16 +++++ .../MediaManagement/Sorting/ViewTemplate.html | 6 +- UI/Settings/settings.less | 5 ++ 8 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 NzbDrone.Api/Naming/NamingModule.cs create mode 100644 NzbDrone.Api/Naming/NamingResource.cs diff --git a/NzbDrone.Api/Naming/NamingModule.cs b/NzbDrone.Api/Naming/NamingModule.cs new file mode 100644 index 000000000..6f9e814ca --- /dev/null +++ b/NzbDrone.Api/Naming/NamingModule.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using NzbDrone.Api.Commands; +using NzbDrone.Api.Extensions; +using NzbDrone.Common.Messaging; +using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Tv; +using Omu.ValueInjecter; + +namespace NzbDrone.Api.Naming +{ + public class NamingModule : NzbDroneRestModule + { + private readonly IBuildFileNames _buildFileNames; + + public NamingModule(IBuildFileNames buildFileNames) + :base("naming") + { + _buildFileNames = buildFileNames; + CreateResource = GetExamples; + } + + private NamingResource GetExamples(NamingResource resource) + { + var nameSpec = new NamingConfig(); + nameSpec.InjectFrom(resource); + + var series = new Core.Tv.Series + { + SeriesType = SeriesTypes.Standard, + Title = "Series Title" + }; + + var episode1 = new Episode + { + SeasonNumber = 1, + EpisodeNumber = 1, + Title = "Episode Title (1)" + }; + + var episode2 = new Episode + { + SeasonNumber = 1, + EpisodeNumber = 2, + Title = "Episode Title (2)" + }; + + var episodeFile = new EpisodeFile + { + Quality = new QualityModel(Quality.HDTV720p), + Path = @"C:\Test\Series.Title.S01E01.hdtv.avi" + }; + + resource.SingleEpisodeExample = _buildFileNames.BuildFilename(new List { episode1 }, + series, + episodeFile, + nameSpec); + + episodeFile.Path = @"C:\Test\Series.Title.S01E01-E02.hdtv.avi"; + + resource.MultiEpisodeExample = _buildFileNames.BuildFilename(new List { episode1, episode2 }, + series, + episodeFile, + nameSpec); + + return resource; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/Naming/NamingResource.cs b/NzbDrone.Api/Naming/NamingResource.cs new file mode 100644 index 000000000..b7cd0612d --- /dev/null +++ b/NzbDrone.Api/Naming/NamingResource.cs @@ -0,0 +1,19 @@ +using NzbDrone.Api.REST; + +namespace NzbDrone.Api.Naming +{ + public class NamingResource : RestResource + { + public bool RenameEpisodes { get; set; } + public string Separator { get; set; } + public int NumberStyle { get; set; } + public bool IncludeSeriesTitle { get; set; } + public bool IncludeEpisodeTitle { get; set; } + public bool IncludeQuality { get; set; } + public int MultiEpisodeStyle { get; set; } + public bool ReplaceSpaces { get; set; } + + public string SingleEpisodeExample { get; set; } + public string MultiEpisodeExample { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 6e67dd73d..2b4f23503 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -117,6 +117,8 @@ + + diff --git a/NzbDrone.Core/Organizer/FileNameBuilder.cs b/NzbDrone.Core/Organizer/FileNameBuilder.cs index fa762947e..cab26aa10 100644 --- a/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Core.Organizer public interface IBuildFileNames { string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile); + string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile, NamingConfig namingConfig); string BuildFilePath(Series series, int seasonNumber, string fileName, string extension); } @@ -67,6 +68,11 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile { var nameSpec = _namingConfigService.GetConfig(); + return BuildFilename(episodes, series, episodeFile, nameSpec); + } + + public string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile, NamingConfig nameSpec) + { if (!nameSpec.RenameEpisodes) { if (String.IsNullOrWhiteSpace(episodeFile.SceneName)) diff --git a/UI/Settings/MediaManagement/Naming/View.js b/UI/Settings/MediaManagement/Naming/View.js index 96c5fee14..87f299522 100644 --- a/UI/Settings/MediaManagement/Naming/View.js +++ b/UI/Settings/MediaManagement/Naming/View.js @@ -10,7 +10,9 @@ define( ui: { namingOptions : '.x-naming-options', - renameEpisodesCheckbox: '.x-rename-episodes' + renameEpisodesCheckbox: '.x-rename-episodes', + singleEpisodeExample : '.x-single-episode-example', + multiEpisodeExample : '.x-multi-episode-example' }, events: { @@ -21,6 +23,9 @@ define( if(!this.model.get('renameEpisodes')){ this.ui.namingOptions.hide(); } + + this.listenTo(this.model, 'change', this._buildExamples); + this._buildExamples(); }, _setNamingOptionsVisibility: function () { @@ -32,6 +37,24 @@ define( else { this.ui.namingOptions.slideUp(); } + }, + + _buildExamples: function () { + var self = this; + + var data = this.model.toJSON(); + data.id = 0; + + var promise = $.ajax({ + type: 'POST', + url : window.ApiRoot + '/naming', + data: JSON.stringify(data) + }); + + promise.done(function (result) { + self.ui.singleEpisodeExample.html(result.singleEpisodeExample); + self.ui.multiEpisodeExample.html(result.multiEpisodeExample); + }); } }); diff --git a/UI/Settings/MediaManagement/Naming/ViewTemplate.html b/UI/Settings/MediaManagement/Naming/ViewTemplate.html index 58b530f62..50b732d1c 100644 --- a/UI/Settings/MediaManagement/Naming/ViewTemplate.html +++ b/UI/Settings/MediaManagement/Naming/ViewTemplate.html @@ -129,4 +129,20 @@ + +
+ + +
+ +
+
+ +
+ + +
+ +
+
diff --git a/UI/Settings/MediaManagement/Sorting/ViewTemplate.html b/UI/Settings/MediaManagement/Sorting/ViewTemplate.html index c18b0af57..e44141004 100644 --- a/UI/Settings/MediaManagement/Sorting/ViewTemplate.html +++ b/UI/Settings/MediaManagement/Sorting/ViewTemplate.html @@ -24,9 +24,9 @@
- - - + + +
diff --git a/UI/Settings/settings.less b/UI/Settings/settings.less index 007ca201c..e1d594cc2 100644 --- a/UI/Settings/settings.less +++ b/UI/Settings/settings.less @@ -38,4 +38,9 @@ li.save-and-add:hover { i { .clickable; } +} + +.naming-example { + display: inline-block; + margin-top: 5px; } \ No newline at end of file