ThemeService Improvements
Centralized the code used to determine the available themes, panes, and containers. This isn't the most "ideal" way to handle this. However, it does improve the management of the code by centralizing the logic for theme selection. Future PR's development might improve this more.
This commit is contained in:
parent
1e5df43e84
commit
86adae19c1
@ -80,14 +80,7 @@
|
||||
protected override async Task OnInitAsync()
|
||||
{
|
||||
title = ModuleState.Title;
|
||||
List<Theme> Themes = await ThemeService.GetThemesAsync();
|
||||
foreach (Theme theme in Themes)
|
||||
{
|
||||
foreach (string container in theme.ContainerControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
containers.Add(container, theme.Name + " - " + @Utilities.GetTypeNameClass(container));
|
||||
}
|
||||
}
|
||||
containers = ThemeService.CalculateSelectableContainers(await ThemeService.GetThemesAsync());
|
||||
containertype = ModuleState.ContainerType;
|
||||
viewpermissions = ModuleState.ViewPermissions;
|
||||
editpermissions = ModuleState.EditPermissions;
|
||||
|
@ -134,18 +134,9 @@
|
||||
|
||||
protected override async Task OnInitAsync()
|
||||
{
|
||||
List<Theme> Themes = await ThemeService.GetThemesAsync();
|
||||
foreach (Theme theme in Themes)
|
||||
{
|
||||
foreach (string themecontrol in theme.ThemeControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
themes.Add(themecontrol, theme.Name + " - " + @Utilities.GetTypeNameClass(themecontrol));
|
||||
}
|
||||
foreach (string panelayout in theme.PaneLayouts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
panelayouts.Add(panelayout, theme.Name + " - " + @Utilities.GetTypeNameClass(panelayout));
|
||||
}
|
||||
}
|
||||
var Themes = await ThemeService.GetThemesAsync();
|
||||
themes = ThemeService.CalculateSelectableThemes(Themes);
|
||||
panelayouts = ThemeService.CalculateSelectablePaneLayouts(Themes);
|
||||
}
|
||||
|
||||
private async Task SavePage()
|
||||
|
@ -136,17 +136,8 @@
|
||||
protected override async Task OnInitAsync()
|
||||
{
|
||||
List<Theme> Themes = await ThemeService.GetThemesAsync();
|
||||
foreach (Theme theme in Themes)
|
||||
{
|
||||
foreach (string themecontrol in theme.ThemeControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
themes.Add(themecontrol, theme.Name + " - " + @Utilities.GetTypeNameClass(themecontrol));
|
||||
}
|
||||
foreach (string panelayout in theme.PaneLayouts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
panelayouts.Add(panelayout, theme.Name + " - " + @Utilities.GetTypeNameClass(panelayout));
|
||||
}
|
||||
}
|
||||
themes = ThemeService.CalculateSelectableThemes(Themes);
|
||||
panelayouts = ThemeService.CalculateSelectablePaneLayouts(Themes);
|
||||
|
||||
PageId = Int32.Parse(PageState.QueryString["id"]);
|
||||
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
|
||||
|
@ -136,17 +136,8 @@
|
||||
protected override async Task OnInitAsync()
|
||||
{
|
||||
List<Theme> Themes = await ThemeService.GetThemesAsync();
|
||||
foreach (Theme theme in Themes)
|
||||
{
|
||||
foreach (string themeControl in theme.ThemeControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
themes.Add(themeControl, theme.Name + " - " + @Utilities.GetTypeNameClass(themeControl));
|
||||
}
|
||||
foreach (string panelayout in theme.PaneLayouts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
panelayouts.Add(panelayout, theme.Name + " - " + @Utilities.GetTypeNameClass(panelayout));
|
||||
}
|
||||
}
|
||||
themes = ThemeService.CalculateSelectableThemes(Themes);
|
||||
panelayouts = ThemeService.CalculateSelectablePaneLayouts(Themes);
|
||||
|
||||
PageId = Int32.Parse(PageState.QueryString["id"]);
|
||||
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
|
||||
|
@ -1,11 +0,0 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IThemeService
|
||||
{
|
||||
Task<List<Theme>> GetThemesAsync();
|
||||
}
|
||||
}
|
14
Oqtane.Client/Services/IthemeService.cs
Normal file
14
Oqtane.Client/Services/IthemeService.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IThemeService
|
||||
{
|
||||
Task<List<Theme>> GetThemesAsync();
|
||||
Dictionary<string, string> CalculateSelectableThemes(List<Theme> themes);
|
||||
Dictionary<string, string> CalculateSelectablePaneLayouts(List<Theme> themes);
|
||||
Dictionary<string, string> CalculateSelectableContainers(List<Theme> themes);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
@ -21,7 +22,7 @@ namespace Oqtane.Services
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "Theme");
|
||||
}
|
||||
|
||||
//TODO: Implement Caching or otherwise on this, and other calls within this class
|
||||
public async Task<List<Theme>> GetThemesAsync()
|
||||
{
|
||||
if (themes == null)
|
||||
@ -56,5 +57,44 @@ namespace Oqtane.Services
|
||||
}
|
||||
return themes.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public Dictionary<string, string> CalculateSelectableThemes(List<Theme> themes)
|
||||
{
|
||||
var selectableThemes = new Dictionary<string, string>();
|
||||
foreach (Theme theme in themes)
|
||||
{
|
||||
foreach (string themecontrol in theme.ThemeControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
selectableThemes.Add(themecontrol, theme.Name + " - " + Utilities.GetTypeNameClass(themecontrol));
|
||||
}
|
||||
}
|
||||
return selectableThemes;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> CalculateSelectablePaneLayouts(List<Theme> themes)
|
||||
{
|
||||
var selectablePaneLayouts = new Dictionary<string, string>();
|
||||
foreach (Theme theme in themes)
|
||||
{
|
||||
foreach (string panelayout in theme.PaneLayouts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
selectablePaneLayouts.Add(panelayout, theme.Name + " - " + @Utilities.GetTypeNameClass(panelayout));
|
||||
}
|
||||
}
|
||||
return selectablePaneLayouts;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> CalculateSelectableContainers(List<Theme> themes)
|
||||
{
|
||||
var selectableContainers = new Dictionary<string, string>();
|
||||
foreach (Theme theme in themes)
|
||||
{
|
||||
foreach (string container in theme.ContainerControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
selectableContainers.Add(container, theme.Name + " - " + @Utilities.GetTypeNameClass(container));
|
||||
}
|
||||
}
|
||||
return selectableContainers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,14 +84,7 @@
|
||||
{
|
||||
//TODO: Move this to shared component. This is used in this control Add, Edit, and Delete controls as well
|
||||
moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync();
|
||||
List<Theme> themes = await ThemeService.GetThemesAsync();
|
||||
foreach (Theme theme in themes)
|
||||
{
|
||||
foreach (string container in theme.ContainerControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
containers.Add(container, theme.Name + " - " + @Utilities.GetTypeNameClass(container));
|
||||
}
|
||||
}
|
||||
containers = ThemeService.CalculateSelectableContainers(await ThemeService.GetThemesAsync());
|
||||
List<Module> modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId, Constants.PageManagementModule);
|
||||
pagemanagementmoduleid = modules.FirstOrDefault().ModuleId;
|
||||
if (UserService.IsAuthorized(PageState.User, PageState.Page.EditPermissions))
|
||||
|
Loading…
x
Reference in New Issue
Block a user