|
|
@ -1,4 +1,5 @@
|
|
|
|
#region Copyright
|
|
|
|
#region Copyright
|
|
|
|
|
|
|
|
|
|
|
|
// /************************************************************************
|
|
|
|
// /************************************************************************
|
|
|
|
// Copyright (c) 2016 Jamie Rees
|
|
|
|
// Copyright (c) 2016 Jamie Rees
|
|
|
|
// File: CustomizationModule.cs
|
|
|
|
// File: CustomizationModule.cs
|
|
|
@ -23,30 +24,39 @@
|
|
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
// ************************************************************************/
|
|
|
|
// ************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Nancy;
|
|
|
|
using Nancy;
|
|
|
|
using Nancy.ModelBinding;
|
|
|
|
using Nancy.ModelBinding;
|
|
|
|
using Nancy.Responses.Negotiation;
|
|
|
|
using Nancy.Responses.Negotiation;
|
|
|
|
using Ombi.Core;
|
|
|
|
using Ombi.Core;
|
|
|
|
using Ombi.Core.SettingModels;
|
|
|
|
using Ombi.Core.SettingModels;
|
|
|
|
|
|
|
|
using Ombi.Helpers;
|
|
|
|
using Ombi.Helpers.Permissions;
|
|
|
|
using Ombi.Helpers.Permissions;
|
|
|
|
using Ombi.UI.Models;
|
|
|
|
using Ombi.UI.Models;
|
|
|
|
|
|
|
|
using Ombi.UI.Models.Admin;
|
|
|
|
|
|
|
|
using Ombi.UI.Models.UI;
|
|
|
|
|
|
|
|
using TMDbLib.Utilities;
|
|
|
|
using ISecurityExtensions = Ombi.Core.ISecurityExtensions;
|
|
|
|
using ISecurityExtensions = Ombi.Core.ISecurityExtensions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ombi.UI.Modules.Admin
|
|
|
|
namespace Ombi.UI.Modules.Admin
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class CustomizationModule : BaseModule
|
|
|
|
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);
|
|
|
|
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
|
|
|
|
|
|
|
|
|
|
|
|
Settings = cust;
|
|
|
|
Settings = cust;
|
|
|
|
|
|
|
|
|
|
|
|
Get["/customization", true] = async (x,ct) => await Index();
|
|
|
|
Get["/customization", true] = async (x, ct) => await Index();
|
|
|
|
Post["/customization", true] = async (x,ct) => await Save();
|
|
|
|
Post["/customization", true] = async (x, ct) => await Save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ISettingsService<CustomizationSettings> Settings { get; }
|
|
|
|
private ISettingsService<CustomizationSettings> Settings { get; }
|
|
|
@ -55,11 +65,53 @@ namespace Ombi.UI.Modules.Admin
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var model = await Settings.GetSettingsAsync();
|
|
|
|
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()
|
|
|
|
private async Task<Response> Save()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var model = this.Bind<CustomizationSettings>();
|
|
|
|
var model = this.Bind<CustomizationSettings>();
|
|
|
|
|
|
|
|
|
|
|
|
var result = await Settings.SaveSettingsAsync(model);
|
|
|
|
var result = await Settings.SaveSettingsAsync(model);
|
|
|
@ -67,6 +119,12 @@ namespace Ombi.UI.Modules.Admin
|
|
|
|
return Response.AsJson(result
|
|
|
|
return Response.AsJson(result
|
|
|
|
? new JsonResponseModel { Result = true }
|
|
|
|
? new JsonResponseModel { Result = true }
|
|
|
|
: new JsonResponseModel { Result = false, Message = "We could not save to the database, please try again" });
|
|
|
|
: new JsonResponseModel { Result = false, Message = "We could not save to the database, please try again" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|