Select type added for client schema

This commit is contained in:
Mark McDowall 2013-06-13 00:20:33 -07:00
parent 954ac925d0
commit ca334ef664
10 changed files with 76 additions and 5 deletions

View File

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

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.Annotations;
@ -34,6 +36,11 @@ namespace NzbDrone.Api.ClientSchema
field.Value = value;
}
if (fieldAttribute.Type == FieldType.Select)
{
field.SelectOptions = GetSelectOptions(fieldAttribute.SelectOptions);
}
result.Add(field);
}
}
@ -41,5 +48,13 @@ namespace NzbDrone.Api.ClientSchema
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();
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,6 +22,10 @@ define(['app'], function () {
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']);
};
});

View File

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