Merge pull request #564 from sbwalker/master
addressed consistency between theme loading and moduledefinition loading, added theme detailed UI view
This commit is contained in:
commit
64b0c2f128
@ -1,4 +1,5 @@
|
|||||||
@namespace Oqtane.Modules.Admin.Themes
|
@namespace Oqtane.Modules.Admin.Themes
|
||||||
|
@using System.Net
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject IThemeService ThemeService
|
@inject IThemeService ThemeService
|
||||||
@ -14,25 +15,27 @@ else
|
|||||||
|
|
||||||
<Pager Items="@_themes">
|
<Pager Items="@_themes">
|
||||||
<Header>
|
<Header>
|
||||||
|
<th> </th>
|
||||||
<th> </th>
|
<th> </th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Version</th>
|
<th>Version</th>
|
||||||
<th> </th>
|
<th> </th>
|
||||||
</Header>
|
</Header>
|
||||||
<Row>
|
<Row>
|
||||||
|
<td><ActionLink Action="View" Parameters="@($"name=" + WebUtility.UrlEncode(context.ThemeName))" /></td>
|
||||||
<td>
|
<td>
|
||||||
@if (context.AssemblyName != "Oqtane.Client")
|
@if (context.AssemblyName != "Oqtane.Client")
|
||||||
{
|
{
|
||||||
<ActionDialog Header="Delete Theme" Message="@("Are You Sure You Wish To Delete The " + context.Name + " Theme?")" Action="Delete" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteTheme(context))" />
|
<ActionDialog Header="Delete Theme" Message="@("Are You Sure You Wish To Delete The " + context.Name + " Theme?")" Action="Delete" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteTheme(context))" />
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
<td>@context.Name</td>
|
<td>@context.Name</td>
|
||||||
<td>@context.Version</td>
|
<td>@context.Version</td>
|
||||||
<td>
|
<td>
|
||||||
@if (UpgradeAvailable(context.ThemeName, context.Version))
|
@if (UpgradeAvailable(context.ThemeName, context.Version))
|
||||||
{
|
{
|
||||||
<button type="button" class="btn btn-success" @onclick=@(async () => await DownloadTheme(context.ThemeName, context.Version))>Upgrade</button>
|
<button type="button" class="btn btn-success" @onclick=@(async () => await DownloadTheme(context.ThemeName, context.Version))>Upgrade</button>
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
</Row>
|
</Row>
|
||||||
</Pager>
|
</Pager>
|
||||||
|
101
Oqtane.Client/Modules/Admin/Themes/View.razor
Normal file
101
Oqtane.Client/Modules/Admin/Themes/View.razor
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
@namespace Oqtane.Modules.Admin.Themes
|
||||||
|
@using System.Net
|
||||||
|
@inherits ModuleBase
|
||||||
|
@inject IThemeService ThemeService
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="name" HelpText="The name of the theme">Name: </Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="name" class="form-control" @bind="@_name" disabled />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="themename" HelpText="The internal name of the module">Internal Name: </Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="themename" class="form-control" @bind="@_themeName" disabled />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="version" HelpText="The version of the thene">Version: </Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="version" class="form-control" @bind="@_version" disabled />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="owner" HelpText="The owner or creator of the theme">Owner: </Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="owner" class="form-control" @bind="@_owner" disabled />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="url" HelpText="The reference url of the theme">Reference Url: </Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="url" class="form-control" @bind="@_url" disabled />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="contact" HelpText="The contact for the theme">Contact: </Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="contact" class="form-control" @bind="@_contact" disabled />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="license" HelpText="The license of the theme">License: </Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<textarea id="license" class="form-control" @bind="@_license" rows="5" disabled></textarea>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private string _themeName = "";
|
||||||
|
private string _name;
|
||||||
|
private string _version;
|
||||||
|
private string _owner = "";
|
||||||
|
private string _url = "";
|
||||||
|
private string _contact = "";
|
||||||
|
private string _license = "";
|
||||||
|
|
||||||
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_themeName = WebUtility.UrlDecode(PageState.QueryString["name"]);
|
||||||
|
var themes = await ThemeService.GetThemesAsync();
|
||||||
|
var theme = themes.FirstOrDefault(item => item.ThemeName == _themeName);
|
||||||
|
if (theme != null)
|
||||||
|
{
|
||||||
|
_name = theme.Name;
|
||||||
|
_version = theme.Version;
|
||||||
|
_owner = theme.Owner;
|
||||||
|
_url = theme.Url;
|
||||||
|
_contact = theme.Contact;
|
||||||
|
_license = theme.License;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await logger.LogError(ex, "Error Loading Theme {ThemeName} {Error}", _themeName, ex.Message);
|
||||||
|
AddModuleMessage("Error Loading Theme", MessageType.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -188,6 +188,7 @@ namespace Oqtane.Repository
|
|||||||
private List<ModuleDefinition> LoadModuleDefinitionsFromAssembly(List<ModuleDefinition> moduledefinitions, Assembly assembly)
|
private List<ModuleDefinition> LoadModuleDefinitionsFromAssembly(List<ModuleDefinition> moduledefinitions, Assembly assembly)
|
||||||
{
|
{
|
||||||
ModuleDefinition moduledefinition;
|
ModuleDefinition moduledefinition;
|
||||||
|
|
||||||
Type[] modulecontroltypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IModuleControl))).ToArray();
|
Type[] modulecontroltypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IModuleControl))).ToArray();
|
||||||
foreach (Type modulecontroltype in modulecontroltypes)
|
foreach (Type modulecontroltype in modulecontroltypes)
|
||||||
{
|
{
|
||||||
@ -198,8 +199,8 @@ namespace Oqtane.Repository
|
|||||||
|| modulecontroltype.IsOqtaneIgnore()
|
|| modulecontroltype.IsOqtaneIgnore()
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
string moduleNamespace = modulecontroltype.Namespace;
|
// create namespace root typename
|
||||||
string qualifiedModuleType = moduleNamespace + ", " + modulecontroltype.Assembly.GetName().Name;
|
string qualifiedModuleType = modulecontroltype.Namespace + ", " + modulecontroltype.Assembly.GetName().Name;
|
||||||
|
|
||||||
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
@ -208,7 +209,7 @@ namespace Oqtane.Repository
|
|||||||
Type moduletype = assembly
|
Type moduletype = assembly
|
||||||
.GetTypes()
|
.GetTypes()
|
||||||
.Where(item => item.Namespace != null)
|
.Where(item => item.Namespace != null)
|
||||||
.Where(item => item.Namespace.StartsWith(moduleNamespace))
|
.Where(item => item.Namespace == modulecontroltype.Namespace || item.Namespace.StartsWith(modulecontroltype.Namespace + "."))
|
||||||
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(IModule)));
|
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(IModule)));
|
||||||
if (moduletype != null)
|
if (moduletype != null)
|
||||||
{
|
{
|
||||||
@ -221,8 +222,8 @@ namespace Oqtane.Repository
|
|||||||
// set default property values
|
// set default property values
|
||||||
moduledefinition = new ModuleDefinition
|
moduledefinition = new ModuleDefinition
|
||||||
{
|
{
|
||||||
Name = moduleNamespace.Substring(moduleNamespace.LastIndexOf(".") + 1),
|
Name = Utilities.GetTypeNameLastSegment(modulecontroltype.Namespace, 0),
|
||||||
Description = "Manage " + moduleNamespace.Substring(moduleNamespace.LastIndexOf(".") + 1),
|
Description = "Manage " + Utilities.GetTypeNameLastSegment(modulecontroltype.Namespace, 0),
|
||||||
Categories = ((qualifiedModuleType.StartsWith("Oqtane.Modules.Admin.")) ? "Admin" : "")
|
Categories = ((qualifiedModuleType.StartsWith("Oqtane.Modules.Admin.")) ? "Admin" : "")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -230,7 +231,7 @@ namespace Oqtane.Repository
|
|||||||
// set internal properties
|
// set internal properties
|
||||||
moduledefinition.ModuleDefinitionName = qualifiedModuleType;
|
moduledefinition.ModuleDefinitionName = qualifiedModuleType;
|
||||||
moduledefinition.Version = ""; // will be populated from database
|
moduledefinition.Version = ""; // will be populated from database
|
||||||
moduledefinition.ControlTypeTemplate = moduleNamespace + "." + Constants.ActionToken + ", " + modulecontroltype.Assembly.GetName().Name;
|
moduledefinition.ControlTypeTemplate = modulecontroltype.Namespace + "." + Constants.ActionToken + ", " + modulecontroltype.Assembly.GetName().Name;
|
||||||
moduledefinition.AssemblyName = assembly.GetName().Name;
|
moduledefinition.AssemblyName = assembly.GetName().Name;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(moduledefinition.Categories))
|
if (string.IsNullOrEmpty(moduledefinition.Categories))
|
||||||
|
@ -44,36 +44,33 @@ namespace Oqtane.Repository
|
|||||||
private List<Theme> LoadThemesFromAssembly(List<Theme> themes, Assembly assembly)
|
private List<Theme> LoadThemesFromAssembly(List<Theme> themes, Assembly assembly)
|
||||||
{
|
{
|
||||||
Theme theme;
|
Theme theme;
|
||||||
|
List<Type> themeTypes = new List<Type>();
|
||||||
|
|
||||||
Type[] themeControlTypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IThemeControl))).ToArray();
|
Type[] themeControlTypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IThemeControl))).ToArray();
|
||||||
foreach (Type themeControlType in themeControlTypes)
|
foreach (Type themeControlType in themeControlTypes)
|
||||||
{
|
{
|
||||||
// Check if type should be ignored
|
// Check if type should be ignored
|
||||||
if (themeControlType.Name == "ThemeBase"
|
if (themeControlType.Name == "ThemeBase"
|
||||||
|| themeControlType.IsGenericType
|
|| themeControlType.IsGenericType
|
||||||
|
|| themeControlType.IsAbstract
|
||||||
|| themeControlType.IsOqtaneIgnore()
|
|| themeControlType.IsOqtaneIgnore()
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
string themeNamespace = themeControlType.Namespace;
|
// create namespace root typename
|
||||||
// 2dm disabled - not used anywhere in code
|
string qualifiedThemeType = themeControlType.Namespace + ", " + themeControlType.Assembly.GetName().Name;
|
||||||
//string qualifiedModuleType = themeNamespace + ", " + themeControlType.Assembly.GetName().Name;
|
|
||||||
|
|
||||||
int index = themes.FindIndex(item => item.ThemeName == themeNamespace);
|
|
||||||
|
|
||||||
// Find all types in the assembly which have the same namespace-root as the theme file
|
|
||||||
// Check with "." in the end to
|
|
||||||
List<Type> typesInTheme = assembly.GetTypes()
|
|
||||||
.Where(item=>!item.IsOqtaneIgnore())
|
|
||||||
.Where(item => item.Namespace != null)
|
|
||||||
// Namespace must be the same or start with "xxx." to ensure that
|
|
||||||
// similar namespaces like "MyTheme" and "MyTheme2" don't match in StartsWith(...)
|
|
||||||
.Where(item => item.Namespace == themeNamespace
|
|
||||||
|| item.Namespace.StartsWith(themeNamespace + "."))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
|
int index = themes.FindIndex(item => item.ThemeName == qualifiedThemeType);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
|
// Find all types in the assembly with the same namespace root
|
||||||
|
themeTypes = assembly.GetTypes()
|
||||||
|
.Where(item => !item.IsOqtaneIgnore())
|
||||||
|
.Where(item => item.Namespace != null)
|
||||||
|
.Where(item => item.Namespace == themeControlType.Namespace || item.Namespace.StartsWith(themeControlType.Namespace + "."))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
// determine if this theme implements ITheme
|
// determine if this theme implements ITheme
|
||||||
Type themetype = typesInTheme
|
Type themetype = themeTypes
|
||||||
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(ITheme)));
|
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(ITheme)));
|
||||||
if (themetype != null)
|
if (themetype != null)
|
||||||
{
|
{
|
||||||
@ -89,19 +86,19 @@ namespace Oqtane.Repository
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
// set internal properties
|
// set internal properties
|
||||||
theme.ThemeName = themeNamespace;
|
theme.ThemeName = qualifiedThemeType;
|
||||||
theme.ThemeControls = "";
|
theme.ThemeControls = "";
|
||||||
theme.PaneLayouts = "";
|
theme.PaneLayouts = "";
|
||||||
theme.ContainerControls = "";
|
theme.ContainerControls = "";
|
||||||
theme.AssemblyName = assembly.FullName.Split(",")[0];
|
theme.AssemblyName = assembly.FullName.Split(",")[0];
|
||||||
themes.Add(theme);
|
themes.Add(theme);
|
||||||
index = themes.FindIndex(item => item.ThemeName == themeNamespace);
|
index = themes.FindIndex(item => item.ThemeName == qualifiedThemeType);
|
||||||
}
|
}
|
||||||
theme = themes[index];
|
theme = themes[index];
|
||||||
theme.ThemeControls += (themeControlType.FullName + ", " + themeControlType.Assembly.GetName().Name + ";");
|
theme.ThemeControls += (themeControlType.FullName + ", " + themeControlType.Assembly.GetName().Name + ";");
|
||||||
|
|
||||||
// layouts
|
// layouts
|
||||||
Type[] layouttypes = typesInTheme
|
Type[] layouttypes = themeTypes
|
||||||
.Where(item => item.GetInterfaces().Contains(typeof(ILayoutControl))).ToArray();
|
.Where(item => item.GetInterfaces().Contains(typeof(ILayoutControl))).ToArray();
|
||||||
foreach (Type layouttype in layouttypes)
|
foreach (Type layouttype in layouttypes)
|
||||||
{
|
{
|
||||||
@ -113,7 +110,7 @@ namespace Oqtane.Repository
|
|||||||
}
|
}
|
||||||
|
|
||||||
// containers
|
// containers
|
||||||
Type[] containertypes = typesInTheme
|
Type[] containertypes = themeTypes
|
||||||
.Where(item => item.GetInterfaces().Contains(typeof(IContainerControl))).ToArray();
|
.Where(item => item.GetInterfaces().Contains(typeof(IContainerControl))).ToArray();
|
||||||
foreach (Type containertype in containertypes)
|
foreach (Type containertype in containertypes)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user