Refactored IModule and ITheme interfaces for future compatibility scenarios. Added Permissions property to IModule interface to allow for explicit ordering and custom module permissions.
This commit is contained in:
parent
838b48f91e
commit
8351ec2d71
|
@ -81,9 +81,7 @@
|
|||
[Parameter]
|
||||
public string Permissions { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string PermissionNames { get; set; } // optional - can be used to specify permissions order or add custom permissions
|
||||
|
||||
string permissionnames = "";
|
||||
List<Role> roles;
|
||||
List<PermissionString> permissions = new List<PermissionString>();
|
||||
List<User> users = new List<User>();
|
||||
|
@ -92,14 +90,15 @@
|
|||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(PermissionNames))
|
||||
permissionnames = PageState.ModuleDefinitions.Find(item => item.ModuleDefinitionName == ModuleState.ModuleDefinitionName).Permissions;
|
||||
if (string.IsNullOrEmpty(permissionnames))
|
||||
{
|
||||
PermissionNames = "View,Edit";
|
||||
permissionnames = "View,Edit";
|
||||
}
|
||||
roles = await RoleService.GetRolesAsync(ModuleState.SiteId);
|
||||
roles.Insert(0, new Role { Name = Constants.AllUsersRole });
|
||||
|
||||
foreach (string permissionname in PermissionNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
foreach (string permissionname in permissionnames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
permissions.Add(new PermissionString { PermissionName = permissionname, Permissions = "" });
|
||||
}
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
using Oqtane.Modules;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Client.Modules.Counter
|
||||
{
|
||||
public class Module : IModule
|
||||
{
|
||||
public string Name { get { return "Counter"; } }
|
||||
public string Description { get { return "Increments a counter"; } }
|
||||
public string Version { get { return "1.0.0"; } }
|
||||
public string Owner { get { return ""; } }
|
||||
public string Url { get { return ""; } }
|
||||
public string Contact { get { return ""; } }
|
||||
public string License { get { return ""; } }
|
||||
public string Dependencies { get { return ""; } }
|
||||
public Dictionary<string, string> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, string> properties = new Dictionary<string, string>
|
||||
{
|
||||
{ "Name", "Counter" },
|
||||
{ "Description", "Increments a counter" },
|
||||
{ "Version", "1.0.0" }
|
||||
};
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
using Oqtane.Modules;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Client.Modules.HtmlText
|
||||
{
|
||||
public class Module : IModule
|
||||
{
|
||||
public string Name { get { return "HtmlText"; } }
|
||||
public string Description { get { return "Renders HTML or Text"; } }
|
||||
public string Version { get { return "1.0.0"; } }
|
||||
public string Owner { get { return ""; } }
|
||||
public string Url { get { return ""; } }
|
||||
public string Contact { get { return ""; } }
|
||||
public string License { get { return ""; } }
|
||||
public string Dependencies { get { return ""; } }
|
||||
public Dictionary<string, string> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, string> properties = new Dictionary<string, string>
|
||||
{
|
||||
{ "Name", "HtmlText" },
|
||||
{ "Description", "Renders HTML or Text" },
|
||||
{ "Version", "1.0.0" }
|
||||
};
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
namespace Oqtane.Modules
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Modules
|
||||
{
|
||||
public interface IModule
|
||||
{
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
string Version { get; }
|
||||
string Owner { get; }
|
||||
string Url { get; }
|
||||
string Contact { get; }
|
||||
string License { get; }
|
||||
string Dependencies { get; }
|
||||
Dictionary<string, string> Properties { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
using Oqtane.Modules;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Client.Modules.Weather
|
||||
{
|
||||
public class Module : IModule
|
||||
{
|
||||
public string Name { get { return "Weather"; } }
|
||||
public string Description { get { return "Displays random weather using a service"; } }
|
||||
public string Version { get { return "1.0.0"; } }
|
||||
public string Owner { get { return ""; } }
|
||||
public string Url { get { return ""; } }
|
||||
public string Contact { get { return ""; } }
|
||||
public string License { get { return ""; } }
|
||||
public string Dependencies { get { return ""; } }
|
||||
public Dictionary<string, string> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, string> properties = new Dictionary<string, string>
|
||||
{
|
||||
{ "Name", "Weather" },
|
||||
{ "Description", "Displays random weather using a service" },
|
||||
{ "Version", "1.0.0" }
|
||||
};
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Themes
|
||||
{
|
||||
public interface ITheme
|
||||
{
|
||||
string Name { get; }
|
||||
string Version { get; }
|
||||
string Owner { get; }
|
||||
string Url { get; }
|
||||
string Contact { get; }
|
||||
string License { get; }
|
||||
string Dependencies { get; }
|
||||
Dictionary<string, string> Properties { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
namespace Oqtane.Themes.Theme1
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Themes.Theme1
|
||||
{
|
||||
public class Theme : ITheme
|
||||
{
|
||||
public string Name { get { return "Theme1"; } }
|
||||
public string Version { get { return "1.0.0"; } }
|
||||
public string Owner { get { return ""; } }
|
||||
public string Url { get { return ""; } }
|
||||
public string Contact { get { return ""; } }
|
||||
public string License { get { return ""; } }
|
||||
public string Dependencies { get { return ""; } }
|
||||
public Dictionary<string, string> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, string> properties = new Dictionary<string, string>
|
||||
{
|
||||
{ "Name", "Theme1" },
|
||||
{ "Version", "1.0.0" }
|
||||
};
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
namespace Oqtane.Themes.Theme2
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Themes.Theme2
|
||||
{
|
||||
public class Theme : ITheme
|
||||
{
|
||||
public string Name { get { return "Theme2"; } }
|
||||
public string Version { get { return "1.0.0"; } }
|
||||
public string Owner { get { return ""; } }
|
||||
public string Url { get { return ""; } }
|
||||
public string Contact { get { return ""; } }
|
||||
public string License { get { return ""; } }
|
||||
public string Dependencies { get { return ""; } }
|
||||
public Dictionary<string, string> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, string> properties = new Dictionary<string, string>
|
||||
{
|
||||
{ "Name", "Theme2" },
|
||||
{ "Version", "1.0.0" }
|
||||
};
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
namespace Oqtane.Themes.Theme3
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Themes.Theme3
|
||||
{
|
||||
public class Theme : ITheme
|
||||
{
|
||||
public string Name { get { return "Theme3"; } }
|
||||
public string Version { get { return "1.0.0"; } }
|
||||
public string Owner { get { return ""; } }
|
||||
public string Url { get { return ""; } }
|
||||
public string Contact { get { return ""; } }
|
||||
public string License { get { return ""; } }
|
||||
public string Dependencies { get { return ""; } }
|
||||
public Dictionary<string, string> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, string> properties = new Dictionary<string, string>
|
||||
{
|
||||
{ "Name", "Theme3" },
|
||||
{ "Version", "1.0.0" }
|
||||
};
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,24 +51,26 @@ namespace Oqtane.Repository
|
|||
{
|
||||
/// determine if this module implements IModule
|
||||
Type moduletype = assembly.GetTypes()
|
||||
.Where(item => item.Namespace != null)
|
||||
.Where(item => item.Namespace.StartsWith(ModuleType))
|
||||
.Where(item => item.GetInterfaces().Contains(typeof(IModule)))
|
||||
.FirstOrDefault();
|
||||
.Where(item => item.Namespace != null)
|
||||
.Where(item => item.Namespace.StartsWith(ModuleType))
|
||||
.Where(item => item.GetInterfaces().Contains(typeof(IModule)))
|
||||
.FirstOrDefault();
|
||||
if (moduletype != null)
|
||||
{
|
||||
var moduleobject = Activator.CreateInstance(moduletype);
|
||||
Dictionary<string, string> properties = (Dictionary<string, string>)moduletype.GetProperty("Properties").GetValue(moduleobject);
|
||||
moduledefinition = new ModuleDefinition
|
||||
{
|
||||
ModuleDefinitionName = QualifiedModuleType,
|
||||
Name = (string)moduletype.GetProperty("Name").GetValue(moduleobject),
|
||||
Description = (string)moduletype.GetProperty("Description").GetValue(moduleobject),
|
||||
Version = (string)moduletype.GetProperty("Version").GetValue(moduleobject),
|
||||
Owner = (string)moduletype.GetProperty("Owner").GetValue(moduleobject),
|
||||
Url = (string)moduletype.GetProperty("Url").GetValue(moduleobject),
|
||||
Contact = (string)moduletype.GetProperty("Contact").GetValue(moduleobject),
|
||||
License = (string)moduletype.GetProperty("License").GetValue(moduleobject),
|
||||
Dependencies = (string)moduletype.GetProperty("Dependencies").GetValue(moduleobject),
|
||||
Name = GetProperty(properties, "Name"),
|
||||
Description = GetProperty(properties, "Description"),
|
||||
Version = GetProperty(properties, "Version"),
|
||||
Owner = GetProperty(properties, "Owner"),
|
||||
Url = GetProperty(properties, "Url"),
|
||||
Contact = GetProperty(properties, "Contact"),
|
||||
License = GetProperty(properties, "License"),
|
||||
Dependencies = GetProperty(properties, "Dependencies"),
|
||||
Permissions = GetProperty(properties, "Permissions"),
|
||||
ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1],
|
||||
ControlTypeRoutes = "",
|
||||
AssemblyName = assembly.FullName.Split(",")[0]
|
||||
|
@ -87,6 +89,7 @@ namespace Oqtane.Repository
|
|||
Contact = "",
|
||||
License = "",
|
||||
Dependencies = "",
|
||||
Permissions = "",
|
||||
ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1],
|
||||
ControlTypeRoutes = "",
|
||||
AssemblyName = assembly.FullName.Split(",")[0]
|
||||
|
@ -118,5 +121,14 @@ namespace Oqtane.Repository
|
|||
return ModuleDefinitions;
|
||||
}
|
||||
|
||||
private string GetProperty(Dictionary<string, string> Properties, string Key)
|
||||
{
|
||||
string Value = "";
|
||||
if (Properties.ContainsKey(Key))
|
||||
{
|
||||
Value = Properties[Key];
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,23 +49,24 @@ namespace Oqtane.Repository
|
|||
if (index == -1)
|
||||
{
|
||||
/// determine if this theme implements ITheme
|
||||
Type themeType = assembly.GetTypes()
|
||||
Type themetype = assembly.GetTypes()
|
||||
.Where(item => item.Namespace != null)
|
||||
.Where(item => item.Namespace.StartsWith(Namespace))
|
||||
.Where(item => item.GetInterfaces().Contains(typeof(ITheme))).FirstOrDefault();
|
||||
if (themeType != null)
|
||||
if (themetype != null)
|
||||
{
|
||||
var themeObject = Activator.CreateInstance(themeType);
|
||||
var themeobject = Activator.CreateInstance(themetype);
|
||||
Dictionary<string, string> properties = (Dictionary<string, string>)themetype.GetProperty("Properties").GetValue(themeobject);
|
||||
theme = new Theme
|
||||
{
|
||||
ThemeName = Namespace,
|
||||
Name = (string)themeType.GetProperty("Name").GetValue(themeObject),
|
||||
Version = (string)themeType.GetProperty("Version").GetValue(themeObject),
|
||||
Owner = (string)themeType.GetProperty("Owner").GetValue(themeObject),
|
||||
Url = (string)themeType.GetProperty("Url").GetValue(themeObject),
|
||||
Contact = (string)themeType.GetProperty("Contact").GetValue(themeObject),
|
||||
License = (string)themeType.GetProperty("License").GetValue(themeObject),
|
||||
Dependencies = (string)themeType.GetProperty("Dependencies").GetValue(themeObject),
|
||||
Name = GetProperty(properties, "Name"),
|
||||
Version = GetProperty(properties, "Version"),
|
||||
Owner = GetProperty(properties, "Owner"),
|
||||
Url = GetProperty(properties, "Url"),
|
||||
Contact = GetProperty(properties, "Contact"),
|
||||
License = GetProperty(properties, "License"),
|
||||
Dependencies = GetProperty(properties, "Dependencies"),
|
||||
ThemeControls = "",
|
||||
PaneLayouts = "",
|
||||
ContainerControls = "",
|
||||
|
@ -122,5 +123,15 @@ namespace Oqtane.Repository
|
|||
{
|
||||
return Themes;
|
||||
}
|
||||
|
||||
private string GetProperty(Dictionary<string, string> Properties, string Key)
|
||||
{
|
||||
string Value = "";
|
||||
if (Properties.ContainsKey(Key))
|
||||
{
|
||||
Value = Properties[Key];
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
public string Contact { get; set; }
|
||||
public string License { get; set; }
|
||||
public string Dependencies { get; set; }
|
||||
public string Permissions { get; set; }
|
||||
public string ControlTypeTemplate { get; set; }
|
||||
public string ControlTypeRoutes { get; set; }
|
||||
public string AssemblyName { get; set; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user