mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 06:00:50 -07:00
Added the settings for #925 but need to apply the settings to the UI
This commit is contained in:
parent
32f044b4da
commit
bef6e036f7
10 changed files with 335 additions and 36 deletions
|
@ -1,4 +1,5 @@
|
|||
#region Copyright
|
||||
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: CustomizationModule.cs
|
||||
|
@ -23,43 +24,94 @@
|
|||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy;
|
||||
using Nancy.ModelBinding;
|
||||
using Nancy.Responses.Negotiation;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Helpers.Permissions;
|
||||
using Ombi.UI.Models;
|
||||
using Ombi.UI.Models.Admin;
|
||||
using Ombi.UI.Models.UI;
|
||||
using TMDbLib.Utilities;
|
||||
using ISecurityExtensions = Ombi.Core.ISecurityExtensions;
|
||||
|
||||
namespace Ombi.UI.Modules.Admin
|
||||
{
|
||||
public class CustomizationModule : BaseModule
|
||||
{
|
||||
public CustomizationModule(ISettingsService<PlexRequestSettings> settingsService, ISettingsService<CustomizationSettings> cust, ISecurityExtensions security) : base("admin", settingsService, security)
|
||||
public CustomizationModule(ISettingsService<PlexRequestSettings> settingsService,
|
||||
ISettingsService<CustomizationSettings> cust, ISecurityExtensions security)
|
||||
: base("admin", settingsService, security)
|
||||
{
|
||||
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
|
||||
|
||||
Settings = cust;
|
||||
|
||||
Get["/customization", true] = async (x,ct) => await Index();
|
||||
Post["/customization", true] = async (x,ct) => await Save();
|
||||
Get["/customization", true] = async (x, ct) => await Index();
|
||||
Post["/customization", true] = async (x, ct) => await Save();
|
||||
}
|
||||
|
||||
|
||||
private ISettingsService<CustomizationSettings> Settings { get; }
|
||||
|
||||
private async Task<Negotiator> Index()
|
||||
{
|
||||
var model = await Settings.GetSettingsAsync();
|
||||
|
||||
return View["customization", model];
|
||||
var viewModel = new CustomizationViewModel
|
||||
{
|
||||
Settings = model,
|
||||
SortOptions = new List<Dropdown<SortOptions>>()
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
foreach (var value in EnumHelper<SortOptions>.GetValues(SortOptions.LatestRelease))
|
||||
{
|
||||
viewModel.SortOptions.Add(new Dropdown<SortOptions>
|
||||
{
|
||||
Value = value,
|
||||
Name = EnumHelper<SortOptions>.GetDisplayDescription(value),
|
||||
Selected = model.DefaultSort == (int) value
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var value in EnumHelper<FilterOptions>.GetValues(FilterOptions.Available))
|
||||
{
|
||||
viewModel.FilterOptions.Add(new Dropdown<FilterOptions>
|
||||
{
|
||||
Value = value,
|
||||
Name = EnumHelper<FilterOptions>.GetDisplayDescription(value),
|
||||
Selected = model.DefaultFilter == (int) value
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var value in EnumHelper<Languages>.GetValues(Languages.en))
|
||||
{
|
||||
viewModel.LanguageDropdown.Add(new Dropdown<Languages>
|
||||
{
|
||||
Value = value,
|
||||
Name = EnumHelper<Languages>.GetDisplayValue(value),
|
||||
Selected = model.DefaultLang == (int) value
|
||||
});
|
||||
}
|
||||
|
||||
return View["customization", viewModel];
|
||||
}
|
||||
|
||||
private async Task<Response> Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var model = this.Bind<CustomizationSettings>();
|
||||
|
||||
var result = await Settings.SaveSettingsAsync(model);
|
||||
|
@ -67,6 +119,12 @@ namespace Ombi.UI.Modules.Admin
|
|||
return Response.AsJson(result
|
||||
? new JsonResponseModel { Result = true }
|
||||
: new JsonResponseModel { Result = false, Message = "We could not save to the database, please try again" });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue