From ca334ef6641c04e93a23a4c73793e66ee7436e35 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 13 Jun 2013 00:20:33 -0700 Subject: [PATCH] Select type added for client schema --- NzbDrone.Api/ClientSchema/Field.cs | 5 ++++- NzbDrone.Api/ClientSchema/SchemaBuilder.cs | 17 ++++++++++++++++- NzbDrone.Api/ClientSchema/SelectOption.cs | 13 +++++++++++++ NzbDrone.Api/NzbDrone.Api.csproj | 1 + .../Annotations/FieldDefinitionAttribute.cs | 4 +++- .../Notifications/Prowl/ProwlPriority.cs | 16 ++++++++++++++++ .../Notifications/Prowl/ProwlSettings.cs | 4 ++-- NzbDrone.Core/NzbDrone.Core.csproj | 1 + UI/Form/FormBuilder.js | 4 ++++ UI/Form/SelectTemplate.html | 16 ++++++++++++++++ 10 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 NzbDrone.Api/ClientSchema/SelectOption.cs create mode 100644 NzbDrone.Core/Notifications/Prowl/ProwlPriority.cs create mode 100644 UI/Form/SelectTemplate.html diff --git a/NzbDrone.Api/ClientSchema/Field.cs b/NzbDrone.Api/ClientSchema/Field.cs index 00ac78618..858c51de0 100644 --- a/NzbDrone.Api/ClientSchema/Field.cs +++ b/NzbDrone.Api/ClientSchema/Field.cs @@ -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 SelectOptions { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs index f4847f45c..13f61885b 100644 --- a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs +++ b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs @@ -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 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(); + } } } \ No newline at end of file diff --git a/NzbDrone.Api/ClientSchema/SelectOption.cs b/NzbDrone.Api/ClientSchema/SelectOption.cs new file mode 100644 index 000000000..9be74c865 --- /dev/null +++ b/NzbDrone.Api/ClientSchema/SelectOption.cs @@ -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; } + } +} diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 24ab92ec1..83e5fd8fa 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -97,6 +97,7 @@ + diff --git a/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs b/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs index 3c5728879..9a795c728 100644 --- a/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs +++ b/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs @@ -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 } } \ No newline at end of file diff --git a/NzbDrone.Core/Notifications/Prowl/ProwlPriority.cs b/NzbDrone.Core/Notifications/Prowl/ProwlPriority.cs new file mode 100644 index 000000000..6a8187b76 --- /dev/null +++ b/NzbDrone.Core/Notifications/Prowl/ProwlPriority.cs @@ -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 + } +} diff --git a/NzbDrone.Core/Notifications/Prowl/ProwlSettings.cs b/NzbDrone.Core/Notifications/Prowl/ProwlSettings.cs index 0fb9150d8..f224b4672 100644 --- a/NzbDrone.Core/Notifications/Prowl/ProwlSettings.cs +++ b/NzbDrone.Core/Notifications/Prowl/ProwlSettings.cs @@ -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 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 { diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 0b7c893f9..0c62441ed 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -332,6 +332,7 @@ + diff --git a/UI/Form/FormBuilder.js b/UI/Form/FormBuilder.js index 512b5b9de..266b66566 100644 --- a/UI/Form/FormBuilder.js +++ b/UI/Form/FormBuilder.js @@ -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']); }; }); diff --git a/UI/Form/SelectTemplate.html b/UI/Form/SelectTemplate.html new file mode 100644 index 000000000..f917a5fee --- /dev/null +++ b/UI/Form/SelectTemplate.html @@ -0,0 +1,16 @@ +
+ + +
+ + {{#if helpText}} + + + + {{/if}} +
+
\ No newline at end of file