Added examples to naming settings

This commit is contained in:
Mark McDowall 2013-08-11 17:42:11 -07:00
parent a5e8452840
commit fded4cf7f3
8 changed files with 146 additions and 4 deletions

View File

@ -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<NamingResource>
{
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<Episode> { episode1 },
series,
episodeFile,
nameSpec);
episodeFile.Path = @"C:\Test\Series.Title.S01E01-E02.hdtv.avi";
resource.MultiEpisodeExample = _buildFileNames.BuildFilename(new List<Episode> { episode1, episode2 },
series,
episodeFile,
nameSpec);
return resource;
}
}
}

View File

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

View File

@ -117,6 +117,8 @@
<Compile Include="Mapping\ResourceMappingException.cs" />
<Compile Include="Mapping\ValueInjectorExtensions.cs" />
<Compile Include="Missing\MissingModule.cs" />
<Compile Include="Naming\NamingResource.cs" />
<Compile Include="Naming\NamingModule.cs" />
<Compile Include="Notifications\NotificationSchemaModule.cs" />
<Compile Include="Notifications\NotificationModule.cs" />
<Compile Include="Notifications\NotificationResource.cs" />

View File

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Organizer
public interface IBuildFileNames
{
string BuildFilename(IList<Episode> episodes, Series series, EpisodeFile episodeFile);
string BuildFilename(IList<Episode> episodes, Series series, EpisodeFile episodeFile, NamingConfig namingConfig);
string BuildFilePath(Series series, int seasonNumber, string fileName, string extension);
}
@ -67,6 +68,11 @@ namespace NzbDrone.Core.Organizer
{
var nameSpec = _namingConfigService.GetConfig();
return BuildFilename(episodes, series, episodeFile, nameSpec);
}
public string BuildFilename(IList<Episode> episodes, Series series, EpisodeFile episodeFile, NamingConfig nameSpec)
{
if (!nameSpec.RenameEpisodes)
{
if (String.IsNullOrWhiteSpace(episodeFile.SceneName))

View File

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

View File

@ -129,4 +129,20 @@
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">Single Episode Example</label>
<div class="controls">
<span class="x-single-episode-example naming-example"></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Multi-Episode Example</label>
<div class="controls">
<span class="x-multi-episode-example naming-example"></span>
</div>
</div>
</fieldset>

View File

@ -24,9 +24,9 @@
<div class="controls">
<input type="text" placeholder="Season %s" name="seasonFolderFormat"/>
<span class="help-inline">
<i class="icon-question-sign" title="How should season folders be named? (Use %0s to pad to two digits, %sn for Series Name)"/>
</span>
<span class="help-inline">
<i class="icon-question-sign" title="How should season folders be named? (Use %0s to pad to two digits, %sn for Series Name)"/>
</span>
</div>
</div>
</fieldset>

View File

@ -38,4 +38,9 @@ li.save-and-add:hover {
i {
.clickable;
}
}
.naming-example {
display: inline-block;
margin-top: 5px;
}