allow users to modify default module names, descriptions, and categories and improve control panel behavior
This commit is contained in:
parent
f56d1fe543
commit
62987ca72f
|
@ -16,10 +16,10 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<Label For="version" HelpText="The version of the module">Version: </Label>
|
||||
<Label For="description" HelpText="The description of the module">Description: </Label>
|
||||
</td>
|
||||
<td>
|
||||
<input id="version" class="form-control" @bind="@_version" disabled />
|
||||
<textarea id="description" class="form-control" @bind="@_description" rows="2"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -43,10 +43,10 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<Label For="description" HelpText="The description of the module">Description: </Label>
|
||||
<Label For="version" HelpText="The version of the module">Version: </Label>
|
||||
</td>
|
||||
<td>
|
||||
<textarea id="description" class="form-control" @bind="@_description" rows="2" disabled></textarea>
|
||||
<input id="version" class="form-control" @bind="@_version" disabled />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -158,6 +158,18 @@
|
|||
try
|
||||
{
|
||||
var moduledefinition = await ModuleDefinitionService.GetModuleDefinitionAsync(_moduleDefinitionId, ModuleState.SiteId);
|
||||
if (moduledefinition.Name != _name)
|
||||
{
|
||||
moduledefinition.Name = _name;
|
||||
}
|
||||
if (moduledefinition.Description != _description)
|
||||
{
|
||||
moduledefinition.Description = _description;
|
||||
}
|
||||
if (moduledefinition.Categories != _categories)
|
||||
{
|
||||
moduledefinition.Categories = _categories;
|
||||
}
|
||||
moduledefinition.Permissions = _permissionGrid.GetPermissions();
|
||||
await ModuleDefinitionService.UpdateModuleDefinitionAsync(moduledefinition);
|
||||
await logger.LogInformation("ModuleDefinition Saved {ModuleDefinition}", moduledefinition);
|
||||
|
|
|
@ -87,22 +87,36 @@
|
|||
@if (_moduleDefinitions != null)
|
||||
{
|
||||
<select class="form-control" @onchange="(e => CategoryChanged(e))">
|
||||
<option value="-"><Common Modules></option>
|
||||
@foreach (var category in _categories)
|
||||
{
|
||||
<option value="@category">@category</option>
|
||||
if (category == _category)
|
||||
{
|
||||
<option value="@category" selected>@category Modules</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="@category">@category Modules</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
<select class="form-control" @bind="@_moduleDefinitionName">
|
||||
<option value="-"><Select Module></option>
|
||||
<select class="form-control" @onchange="(e => ModuleChanged(e))">
|
||||
@if (_moduleDefinitionName == "-")
|
||||
{
|
||||
<option value="-" selected><Select Module></option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="-"><Select Module></option>
|
||||
}
|
||||
@foreach (var moduledefinition in _moduleDefinitions)
|
||||
{
|
||||
if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Utilize, moduledefinition.Permissions))
|
||||
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Utilize, moduledefinition.Permissions))
|
||||
{
|
||||
<option value="@moduledefinition.ModuleDefinitionName">@moduledefinition.Name</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
@((MarkupString)@_description)
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -207,6 +221,8 @@
|
|||
private List<Module> _modules = new List<Module>();
|
||||
private Dictionary<string, string> _containers = new Dictionary<string, string>();
|
||||
private string _moduleDefinitionName = "-";
|
||||
private string _category = "Common";
|
||||
private string _description = "";
|
||||
private string _pane = "";
|
||||
private string _title = "";
|
||||
private string _containerType = "";
|
||||
|
@ -267,6 +283,7 @@
|
|||
|
||||
_allModuleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
|
||||
|
||||
_categories = new List<string>();
|
||||
foreach (ModuleDefinition moduledefinition in _allModuleDefinitions)
|
||||
{
|
||||
if (moduledefinition.Categories != "")
|
||||
|
@ -281,23 +298,34 @@
|
|||
}
|
||||
}
|
||||
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories == "").ToList();
|
||||
_category = "Common";
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(_category)).ToList();
|
||||
_moduleDefinitionName = "-";
|
||||
_description = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void CategoryChanged(ChangeEventArgs e)
|
||||
{
|
||||
var category = (string) e.Value;
|
||||
if (category == "-")
|
||||
_category = (string) e.Value;
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(_category)).ToList();
|
||||
_moduleDefinitionName = "-";
|
||||
_description = "";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void ModuleChanged(ChangeEventArgs e)
|
||||
{
|
||||
_moduleDefinitionName = (string)e.Value;
|
||||
if (_moduleDefinitionName != "-")
|
||||
{
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories == "").ToList();
|
||||
var moduleDefinition = _moduleDefinitions.FirstOrDefault(item => item.ModuleDefinitionName == _moduleDefinitionName);
|
||||
_description = "<br /><div class=\"alert alert-info\" role=\"alert\">" + moduleDefinition.Description + "</div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(category)).ToList();
|
||||
_description = "";
|
||||
}
|
||||
|
||||
_moduleDefinitionName = "-";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
|
@ -371,6 +399,7 @@
|
|||
_message = "<br /><div class=\"alert alert-success\" role=\"alert\">Module Added To Page</div>";
|
||||
|
||||
_moduleDefinitionName = "-";
|
||||
_description = "";
|
||||
_pane = "";
|
||||
_title = "";
|
||||
_containerType = "";
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
using Oqtane.Models;
|
||||
using Oqtane.Infrastructure;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.SiteTemplates
|
||||
{
|
||||
public class EmptySiteTemplate : ISiteTemplate
|
||||
{
|
||||
private readonly IPermissionRepository _permissionRepository;
|
||||
|
||||
public EmptySiteTemplate(IPermissionRepository permissionRepository)
|
||||
{
|
||||
_permissionRepository = permissionRepository;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Empty Site Template"; }
|
||||
}
|
||||
|
||||
public List<PageTemplate> CreateSite(Site site)
|
||||
{
|
||||
List<PageTemplate> _pageTemplates = new List<PageTemplate>();
|
||||
|
||||
_pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Home",
|
||||
Parent = "",
|
||||
Path = "",
|
||||
Icon = "home",
|
||||
IsNavigation = true,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = _permissionRepository.EncodePermissions( new List<Permission> {
|
||||
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
|
||||
}),
|
||||
PageTemplateModules = new List<PageTemplateModule>()
|
||||
});
|
||||
|
||||
return _pageTemplates;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Models;
|
||||
|
@ -37,6 +38,8 @@ namespace Oqtane.Repository
|
|||
|
||||
public void UpdateModuleDefinition(ModuleDefinition moduleDefinition)
|
||||
{
|
||||
_db.Entry(moduleDefinition).State = EntityState.Modified;
|
||||
_db.SaveChanges();
|
||||
_permissions.UpdatePermissions(moduleDefinition.SiteId, EntityNames.ModuleDefinition, moduleDefinition.ModuleDefinitionId, moduleDefinition.Permissions);
|
||||
_cache.Remove("moduledefinitions:" + moduleDefinition.SiteId.ToString());
|
||||
}
|
||||
|
@ -90,6 +93,18 @@ namespace Oqtane.Repository
|
|||
else
|
||||
{
|
||||
// existing module definition
|
||||
if (!string.IsNullOrEmpty(moduledef.Name))
|
||||
{
|
||||
moduledefinition.Name = moduledef.Name;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(moduledef.Description))
|
||||
{
|
||||
moduledefinition.Description = moduledef.Description;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(moduledef.Categories))
|
||||
{
|
||||
moduledefinition.Categories = moduledef.Categories;
|
||||
}
|
||||
if (permissions.Count == 0)
|
||||
{
|
||||
_permissions.UpdatePermissions(siteId, EntityNames.ModuleDefinition, moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
||||
|
@ -166,7 +181,7 @@ namespace Oqtane.Repository
|
|||
moduledefinition = new ModuleDefinition
|
||||
{
|
||||
Name = moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
||||
Description = moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
||||
Description = "Manage " + moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
||||
Categories = ((qualifiedModuleType.StartsWith("Oqtane.Modules.Admin.")) ? "Admin" : ""),
|
||||
Version = new Version(1, 0, 0).ToString()
|
||||
};
|
||||
|
@ -175,6 +190,10 @@ namespace Oqtane.Repository
|
|||
moduledefinition.ModuleDefinitionName = qualifiedModuleType;
|
||||
moduledefinition.ControlTypeTemplate = moduleType + "." + Constants.ActionToken + ", " + typename[1];
|
||||
moduledefinition.AssemblyName = assembly.FullName.Split(",")[0];
|
||||
if (string.IsNullOrEmpty(moduledefinition.Categories))
|
||||
{
|
||||
moduledefinition.Categories = "Common";
|
||||
}
|
||||
if (moduledefinition.Categories == "Admin")
|
||||
{
|
||||
moduledefinition.Permissions = new List<Permission>
|
||||
|
|
|
@ -40,6 +40,9 @@ GO
|
|||
CREATE TABLE [dbo].[ModuleDefinition](
|
||||
[ModuleDefinitionId] [int] IDENTITY(1,1) NOT NULL,
|
||||
[ModuleDefinitionName] [nvarchar](200) NOT NULL,
|
||||
[Name] [nvarchar](200) NULL,
|
||||
[Description] [nvarchar](2000) NULL,
|
||||
[Categories] [nvarchar](200) NULL,
|
||||
[CreatedBy] [nvarchar](256) NOT NULL,
|
||||
[CreatedOn] [datetime] NOT NULL,
|
||||
[ModifiedBy] [nvarchar](256) NOT NULL,
|
||||
|
|
|
@ -24,6 +24,9 @@ namespace Oqtane.Models
|
|||
|
||||
public int ModuleDefinitionId { get; set; }
|
||||
public string ModuleDefinitionName { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Categories { get; set; }
|
||||
|
||||
public string CreatedBy { get; set; }
|
||||
public DateTime CreatedOn { get; set; }
|
||||
|
@ -33,12 +36,6 @@ namespace Oqtane.Models
|
|||
[NotMapped]
|
||||
public int SiteId { get; set; }
|
||||
[NotMapped]
|
||||
public string Name { get; set; }
|
||||
[NotMapped]
|
||||
public string Description { get; set; }
|
||||
[NotMapped]
|
||||
public string Categories { get; set; }
|
||||
[NotMapped]
|
||||
public string Version { get; set; }
|
||||
[NotMapped]
|
||||
public string Owner { get; set; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user