Merge pull request #11 from mitchelsellers/ThemeServiceChanges

ThemeService Improvements
This commit is contained in:
Shaun Walker 2019-05-20 08:57:21 -04:00 committed by GitHub
commit 068399f1f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 62 deletions

View File

@ -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.GetContainerTypes(await ThemeService.GetThemesAsync());
containertype = ModuleState.ContainerType;
viewpermissions = ModuleState.ViewPermissions;
editpermissions = ModuleState.EditPermissions;

View File

@ -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.GetThemeTypes(Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(Themes);
}
private async Task SavePage()

View File

@ -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.GetThemeTypes(Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();

View File

@ -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.GetThemeTypes(Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();

View File

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

View 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> GetThemeTypes(List<Theme> themes);
Dictionary<string, string> GetPaneLayoutTypes(List<Theme> themes);
Dictionary<string, string> GetContainerTypes(List<Theme> themes);
}
}

View File

@ -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> GetThemeTypes(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> GetPaneLayoutTypes(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> GetContainerTypes(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;
}
}
}

View File

@ -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.GetContainerTypes(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))