Added the settings for #925 but need to apply the settings to the UI

pull/927/head
Jamie.Rees 8 years ago
parent 32f044b4da
commit bef6e036f7

@ -35,5 +35,23 @@ namespace Ombi.Core.SettingModels
/// The CSS name of the theme we want /// The CSS name of the theme we want
/// </summary> /// </summary>
public string ThemeName { get; set; } public string ThemeName { get; set; }
/// <summary>
/// Admin Only.
/// </summary>
/// <value>
/// The default filter.
/// </value>
public int DefaultFilter { get; set; }
/// <summary>
/// Admin only.
/// </summary>
/// <value>
/// The default sort.
/// </value>
public int DefaultSort { get; set; }
public int DefaultLang { get; set; }
} }
} }

@ -82,6 +82,19 @@ namespace Ombi.Helpers
if (descriptionAttributes == null) return string.Empty; if (descriptionAttributes == null) return string.Empty;
return (descriptionAttributes.Length > 0) ? descriptionAttributes[0].Name : value.ToString(); return (descriptionAttributes.Length > 0) ? descriptionAttributes[0].Name : value.ToString();
} }
public static string GetDisplayDescription(T value)
{
var fieldInfo = value.GetType().GetField(value.ToString());
var descriptionAttributes = fieldInfo.GetCustomAttributes(
typeof(DisplayAttribute), false) as DisplayAttribute[];
if (descriptionAttributes[0].ResourceType != null)
return LookupResource(descriptionAttributes[0].ResourceType, descriptionAttributes[0].Description);
if (descriptionAttributes == null) return string.Empty;
return (descriptionAttributes.Length > 0) ? descriptionAttributes[0].Description : value.ToString();
}
public static T GetValueFromName(string name) public static T GetValueFromName(string name)
{ {

@ -17,8 +17,26 @@ var tvLoaded = false;
var albumLoaded = false; var albumLoaded = false;
var isAdmin = $('#isAdmin').text(); var isAdmin = $('#isAdmin').text();
var defaultFiler = isAdmin == 'True' ? '.approved-fase' : 'all'; var defaultFiler = isAdmin == 'True' ? '.approved-fase' : 'all';
var url = createBaseUrl(base, '/requests/UpdateFilters');
$.ajax({
type: 'GET',
url: url,
dataType: "json",
success: function (response) {
mixItUpDefault.load.filter = response.defaultFilter;
mixItUpDefault.load.sort = response.defaultSort;
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong saving your filter!", "danger");
}
});
var mixItUpDefault = { var mixItUpDefault = {
animation: { enable: true }, animation: { enable: true },
load: { load: {
@ -30,26 +48,6 @@ var mixItUpDefault = {
}, },
callbacks: { callbacks: {
onMixStart: function (state, futureState) { onMixStart: function (state, futureState) {
//futureState.activeSort // sort
//futureState.activeFilter // next filter
// The below is TODO for saving the users filter and sort order
//var url = createBaseUrl(base, '/requests/UpdateFilters');
//$.ajax({
// type: 'post',
// url: url,
// data: {sort:futureState.activeSort, filter:futureState.activeFilte},
// dataType: "json",
// success: function (response) {
// console.log("saved filter and sort order");
// },
// error: function (e) {
// console.log(e);
// generateNotify("Something went wrong saving your filter!", "danger");
// }
//});
$('.mix', this).removeAttr('data-bound').removeData('bound'); // fix for animation issues in other tabs $('.mix', this).removeAttr('data-bound').removeData('bound'); // fix for animation issues in other tabs
} }
} }

@ -0,0 +1,91 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: CustomizationViewModel.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Ombi.Core.SettingModels;
using Ombi.UI.Models.UI;
namespace Ombi.UI.Models.Admin
{
public class CustomizationViewModel
{
public CustomizationSettings Settings { get; set; }
public List<Dropdown<Languages>> LanguageDropdown { get; set; } = new List<Dropdown<Languages>>();
public List<Dropdown<FilterOptions>> FilterOptions { get; set; } = new List<Dropdown<FilterOptions>>();
public List<Dropdown<SortOptions>> SortOptions { get; set; } = new List<Dropdown<SortOptions>>();
}
public enum FilterOptions
{
[Display(Name = ".available-true", Description = "Available")]
Available,
[Display(Name = ".available-false", Description = "Not Available")]
NotAvailable,
[Display(Name = ".released-true", Description = "Released")]
Released,
[Display(Name = ".released-false", Description = "Not Released")]
NotReleased
}
public enum SortOptions
{
[Display(Name = "requestorder:desc", Description = "Latest Requests")]
LatestRequests,
[Display(Name = "requestorder:asc", Description = "Oldest Requests")]
OldestRequests,
[Display(Name = "releaseorder:desc", Description = "Latest Releases")]
LatestRelease,
[Display(Name = "releaseorder:asc", Description = "Oldest Releases")]
OldestRelease
}
public enum Languages
{
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_English")]
en,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_French")]
fr,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_Dutch")]
nl,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_Spanish")]
es,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_German")]
de,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_Danish")]
da,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_Portuguese")]
pt,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_Swedish")]
sv,
[Display(ResourceType = typeof(Resources.UI), Name = "Layout_Italian")]
it
}
}

@ -0,0 +1,35 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: Dropdown.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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
namespace Ombi.UI.Models.UI
{
public class Dropdown<T>
{
public bool Selected { get; set; }
public string Name { get; set; }
public T Value { get; set; }
}
}

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

@ -43,6 +43,7 @@ using Ombi.Services.Interfaces;
using Ombi.Services.Notification; using Ombi.Services.Notification;
using Ombi.Store; using Ombi.Store;
using Ombi.UI.Models; using Ombi.UI.Models;
using Ombi.UI.Models.Admin;
using Action = Ombi.Helpers.Analytics.Action; using Action = Ombi.Helpers.Analytics.Action;
using ISecurityExtensions = Ombi.Core.ISecurityExtensions; using ISecurityExtensions = Ombi.Core.ISecurityExtensions;
@ -64,7 +65,8 @@ namespace Ombi.UI.Modules
ICacheProvider cache, ICacheProvider cache,
IAnalytics an, IAnalytics an,
INotificationEngine engine, INotificationEngine engine,
ISecurityExtensions security) : base("requests", prSettings, security) ISecurityExtensions security,
ISettingsService<CustomizationSettings> customSettings) : base("requests", prSettings, security)
{ {
Service = service; Service = service;
PrSettings = prSettings; PrSettings = prSettings;
@ -79,6 +81,7 @@ namespace Ombi.UI.Modules
Cache = cache; Cache = cache;
Analytics = an; Analytics = an;
NotificationEngine = engine; NotificationEngine = engine;
CustomizationSettings = customSettings;
Get["/", true] = async (x, ct) => await LoadRequests(); Get["/", true] = async (x, ct) => await LoadRequests();
Get["/movies", true] = async (x, ct) => await GetMovies(); Get["/movies", true] = async (x, ct) => await GetMovies();
@ -92,7 +95,7 @@ namespace Ombi.UI.Modules
Post["/changeavailability", true] = async (x, ct) => await ChangeRequestAvailability((int)Request.Form.Id, (bool)Request.Form.Available); Post["/changeavailability", true] = async (x, ct) => await ChangeRequestAvailability((int)Request.Form.Id, (bool)Request.Form.Available);
Post["/UpdateFilters", true] = async (x, ct) => await UpdateFilters(); Get["/UpdateFilters", true] = async (x, ct) => await GetFilterAndSortSettings();
} }
private static Logger Log = LogManager.GetCurrentClassLogger(); private static Logger Log = LogManager.GetCurrentClassLogger();
@ -104,6 +107,7 @@ namespace Ombi.UI.Modules
private ISettingsService<SonarrSettings> SonarrSettings { get; } private ISettingsService<SonarrSettings> SonarrSettings { get; }
private ISettingsService<SickRageSettings> SickRageSettings { get; } private ISettingsService<SickRageSettings> SickRageSettings { get; }
private ISettingsService<CouchPotatoSettings> CpSettings { get; } private ISettingsService<CouchPotatoSettings> CpSettings { get; }
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
private ISonarrApi SonarrApi { get; } private ISonarrApi SonarrApi { get; }
private ISickRageApi SickRageApi { get; } private ISickRageApi SickRageApi { get; }
private ICouchPotatoApi CpApi { get; } private ICouchPotatoApi CpApi { get; }
@ -408,11 +412,20 @@ namespace Ombi.UI.Modules
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" }); : new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });
} }
private async Task<Response> UpdateFilters() private async Task<Response> GetFilterAndSortSettings()
{ {
var s = await CustomizationSettings.GetSettingsAsync();
var sortVal = EnumHelper<SortOptions>.GetDisplayValue((SortOptions)s.DefaultSort);
var filterVal = EnumHelper<FilterOptions>.GetDisplayValue((FilterOptions)s.DefaultFilter);
return Response.AsJson(""); var vm = new
{
DefaultSort = sortVal,
DefaultFilter = filterVal
};
return Response.AsJson(vm);
} }
} }
} }

@ -118,6 +118,7 @@
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
@ -233,6 +234,7 @@
<Compile Include="ModelDataProviders\UserUpdateViewModelDataProvider.cs" /> <Compile Include="ModelDataProviders\UserUpdateViewModelDataProvider.cs" />
<Compile Include="ModelDataProviders\RequestedModelDataProvider.cs" /> <Compile Include="ModelDataProviders\RequestedModelDataProvider.cs" />
<Compile Include="Models\AboutAdminViewModel.cs" /> <Compile Include="Models\AboutAdminViewModel.cs" />
<Compile Include="Models\Admin\CustomizationViewModel.cs" />
<Compile Include="Models\DatatablesModel.cs" /> <Compile Include="Models\DatatablesModel.cs" />
<Compile Include="Models\EpisodeListViewModel.cs" /> <Compile Include="Models\EpisodeListViewModel.cs" />
<Compile Include="Models\EpisodeRequestModel.cs" /> <Compile Include="Models\EpisodeRequestModel.cs" />
@ -247,6 +249,7 @@
<Compile Include="Models\SearchViewModel.cs" /> <Compile Include="Models\SearchViewModel.cs" />
<Compile Include="Models\SearchMusicViewModel.cs" /> <Compile Include="Models\SearchMusicViewModel.cs" />
<Compile Include="Models\SearchMovieViewModel.cs" /> <Compile Include="Models\SearchMovieViewModel.cs" />
<Compile Include="Models\UI\Dropdown.cs" />
<Compile Include="Models\UserManagement\DeleteUserViewModel.cs" /> <Compile Include="Models\UserManagement\DeleteUserViewModel.cs" />
<Compile Include="Models\UserManagement\UserUpdateViewModel.cs" /> <Compile Include="Models\UserManagement\UserUpdateViewModel.cs" />
<Compile Include="Modules\Admin\AboutModule.cs" /> <Compile Include="Modules\Admin\AboutModule.cs" />

@ -1,14 +1,14 @@
@using Ombi.UI.Helpers @using Ombi.UI.Helpers
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<Ombi.Core.SettingModels.CustomizationSettings> @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<Ombi.UI.Models.Admin.CustomizationViewModel>
@Html.Partial("Shared/Partial/_Sidebar") @Html.Partial("Shared/Partial/_Sidebar")
@{ @{
var plexTheme = string.Empty; var plexTheme = string.Empty;
var originalTheme = string.Empty; var originalTheme = string.Empty;
if (!string.IsNullOrEmpty(Model.ThemeName)) if (!string.IsNullOrEmpty(Model.Settings.ThemeName))
{ {
plexTheme = Model.ThemeName.Equals(Themes.PlexTheme) ? "selected=\"selected\"" : string.Empty; plexTheme = Model.Settings.ThemeName.Equals(Themes.PlexTheme) ? "selected=\"selected\"" : string.Empty;
originalTheme = Model.ThemeName.Equals(Themes.OriginalTheme) ? "selected=\"selected\"" : string.Empty; originalTheme = Model.Settings.ThemeName.Equals(Themes.OriginalTheme) ? "selected=\"selected\"" : string.Empty;
} }
else else
{ {
@ -26,7 +26,7 @@
<label for="ApplicationName" class="control-label">Application Name</label> <label for="ApplicationName" class="control-label">Application Name</label>
<div> <div>
<input type="text" class="form-control form-control-custom " id="ApplicationName" name="ApplicationName" placeholder="Application Name" value="@Model.ApplicationName"> <input type="text" class="form-control form-control-custom " id="ApplicationName" name="ApplicationName" placeholder="Application Name" value="@Model.Settings.ApplicationName">
</div> </div>
</div> </div>
@ -40,6 +40,69 @@
</div> </div>
</div> </div>
<div class="form-group">
<label for="lang" class="control-label">Default Language</label>
<div id="langSelect">
<select class="form-control form-control-custom" id="lang">
@foreach (var l in Model.LanguageDropdown)
{
var enumVal = (int)l.Value;
if (l.Selected)
{
<option selected="selected" class="form-control form-control-custom" value="@enumVal">@l.Name</option>
}
else
{
<option class="form-control form-control-custom" value="@enumVal">@l.Name</option>
}
}
</select>
</div>
</div>
<div class="form-group">
<label for="sort" class="control-label">Default Admin Sort Order</label>
<div id="sortSelect">
<select class="form-control form-control-custom" id="sort">
@foreach (var l in Model.SortOptions)
{
var enumVal = (int) l.Value;
if (l.Selected)
{
<option selected="selected" class="form-control form-control-custom" value="@enumVal">@l.Name</option>
}
else
{
<option class="form-control form-control-custom" value="@enumVal">@l.Name</option>
}
}
</select>
</div>
</div>
<div class="form-group">
<label for="filter" class="control-label">Default Admin Filter</label>
<div id="filterSelect">
<select class="form-control form-control-custom" id="filter">
@foreach (var l in Model.FilterOptions)
{
var enumVal = (int)l.Value;
if (l.Selected)
{
<option selected="selected" class="form-control form-control-custom" value="@enumVal">@l.Name</option>
}
else
{
<option class="form-control form-control-custom" value="@enumVal">@l.Name</option>
}
}
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<div> <div>
<button type="submit" id="save" class="btn btn-primary-outline">Submit</button> <button type="submit" id="save" class="btn btn-primary-outline">Submit</button>
@ -60,10 +123,17 @@
e.preventDefault(); e.preventDefault();
var theme = $("#themes option:selected").val(); var theme = $("#themes option:selected").val();
var lang = $('#langSelect option:selected').val();
var sort = $('#sortSelect option:selected').val();
var filter = $('#filterSelect option:selected').val();
var $form = $("#mainForm"); var $form = $("#mainForm");
var data = $form.serialize(); var data = $form.serialize();
data = data + "&themeName=" + theme; data = data +
"&themeName=" + theme +
"&DefaultLang=" + lang +
"&DefaultSort=" + sort +
"&DefaultFilter=" + filter;
$.ajax({ $.ajax({
type: $form.prop("method"), type: $form.prop("method"),

@ -1,4 +1,4 @@
ab@using Nancy.Security @using Nancy.Security
@using Nancy.Session @using Nancy.Session
@using Nancy; @using Nancy;
@using Ombi.Helpers @using Ombi.Helpers

Loading…
Cancel
Save