Select type added for client schema

pull/3113/head
Mark McDowall 12 years ago
parent 954ac925d0
commit ca334ef664

@ -1,4 +1,6 @@
namespace NzbDrone.Api.ClientSchema using System.Collections.Generic;
namespace NzbDrone.Api.ClientSchema
{ {
public class Field public class Field
{ {
@ -8,5 +10,6 @@
public string HelpText { get; set; } public string HelpText { get; set; }
public object Value { get; set; } public object Value { get; set; }
public string Type { get; set; } public string Type { get; set; }
public List<SelectOption> SelectOptions { get; set; }
} }
} }

@ -1,4 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Reflection; using NzbDrone.Common.Reflection;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
@ -34,6 +36,11 @@ namespace NzbDrone.Api.ClientSchema
field.Value = value; field.Value = value;
} }
if (fieldAttribute.Type == FieldType.Select)
{
field.SelectOptions = GetSelectOptions(fieldAttribute.SelectOptions);
}
result.Add(field); result.Add(field);
} }
} }
@ -41,5 +48,13 @@ namespace NzbDrone.Api.ClientSchema
return result; return result;
} }
private static List<SelectOption> GetSelectOptions(Type selectOptions)
{
var options = from Enum e in Enum.GetValues(selectOptions)
select new SelectOption { Value = Convert.ToInt32(e), Name = e.ToString() };
return options.OrderBy(o => o.Value).ToList();
}
} }
} }

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Api.ClientSchema
{
public class SelectOption
{
public int Value { get; set; }
public string Name { get; set; }
}
}

@ -97,6 +97,7 @@
<Compile Include="ClientSchema\FieldDefinitionAttribute.cs" /> <Compile Include="ClientSchema\FieldDefinitionAttribute.cs" />
<Compile Include="ClientSchema\Field.cs" /> <Compile Include="ClientSchema\Field.cs" />
<Compile Include="ClientSchema\SchemaBuilder.cs" /> <Compile Include="ClientSchema\SchemaBuilder.cs" />
<Compile Include="ClientSchema\SelectOption.cs" />
<Compile Include="Commands\CommandModule.cs" /> <Compile Include="Commands\CommandModule.cs" />
<Compile Include="Commands\CommandResource.cs" /> <Compile Include="Commands\CommandResource.cs" />
<Compile Include="Directories\DirectoryModule.cs" /> <Compile Include="Directories\DirectoryModule.cs" />

@ -14,12 +14,14 @@ namespace NzbDrone.Core.Annotations
public string Label { get; set; } public string Label { get; set; }
public string HelpText { get; set; } public string HelpText { get; set; }
public FieldType Type { get; set; } public FieldType Type { get; set; }
public Type SelectOptions { get; set; }
} }
public enum FieldType public enum FieldType
{ {
Textbox, Textbox,
Password, Password,
Checkbox Checkbox,
Select
} }
} }

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Notifications.Prowl
{
public enum ProwlPriority
{
VeryLow = -2,
Low = -1,
Normal = 0,
High = 1,
Emergency = 2
}
}

@ -11,8 +11,8 @@ namespace NzbDrone.Core.Notifications.Prowl
[FieldDefinition(0, Label = "API Key", HelpText = "API Key for Prowl")] [FieldDefinition(0, Label = "API Key", HelpText = "API Key for Prowl")]
public String ApiKey { get; set; } public String ApiKey { get; set; }
[FieldDefinition(1, Label = "Priority", HelpText = "Priority to send messages at")] [FieldDefinition(1, Label = "Priority", HelpText = "Priority to send messages at", Type = FieldType.Select, SelectOptions= typeof(ProwlPriority) )]
public Nullable<Int32> Priority { get; set; } public Int32 Priority { get; set; }
public bool IsValid public bool IsValid
{ {

@ -332,6 +332,7 @@
<Compile Include="Notifications\Plex\PlexServerSettings.cs" /> <Compile Include="Notifications\Plex\PlexServerSettings.cs" />
<Compile Include="Notifications\Plex\TestPlexClientCommand.cs" /> <Compile Include="Notifications\Plex\TestPlexClientCommand.cs" />
<Compile Include="Notifications\Prowl\InvalidApiKeyException.cs" /> <Compile Include="Notifications\Prowl\InvalidApiKeyException.cs" />
<Compile Include="Notifications\Prowl\ProwlPriority.cs" />
<Compile Include="Notifications\Prowl\ProwlSettings.cs" /> <Compile Include="Notifications\Prowl\ProwlSettings.cs" />
<Compile Include="Notifications\Email\EmailSettings.cs" /> <Compile Include="Notifications\Email\EmailSettings.cs" />
<Compile Include="Notifications\Prowl\TestProwlCommand.cs" /> <Compile Include="Notifications\Prowl\TestProwlCommand.cs" />

@ -22,6 +22,10 @@ define(['app'], function () {
return Handlebars.helpers.partial.apply(field, ['Form/CheckboxTemplate']); return Handlebars.helpers.partial.apply(field, ['Form/CheckboxTemplate']);
} }
if (field.type === 'select') {
return Handlebars.helpers.partial.apply(field, ['Form/SelectTemplate']);
}
return Handlebars.helpers.partial.apply(field, ['Form/TextboxTemplate']); return Handlebars.helpers.partial.apply(field, ['Form/TextboxTemplate']);
}; };
}); });

@ -0,0 +1,16 @@
<div class="control-group">
<label class="control-label">{{label}}</label>
<div class="controls">
<select name="fields.{{order}}.value">
{{#each selectOptions}}
<option value="{{value}}">{{name}}</option>
{{/each}}
</select>
{{#if helpText}}
<span class="help-inline">
<i class="icon-question-sign" title="{{helpText}}"></i>
</span>
{{/if}}
</div>
</div>
Loading…
Cancel
Save