added metadata support for Module and Theme templates
This commit is contained in:
parent
276817c89d
commit
ddd657bfa7
|
@ -1,15 +1,13 @@
|
|||
@namespace Oqtane.Modules.Admin.ModuleCreator
|
||||
@inherits ModuleBase
|
||||
@using System.Text.RegularExpressions
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IModuleDefinitionService ModuleDefinitionService
|
||||
@inject IModuleService ModuleService
|
||||
@inject ISystemService SystemService
|
||||
@inject ISettingService SettingService
|
||||
@inject IStringLocalizer<Index> Localizer
|
||||
@using System.Text.RegularExpressions
|
||||
@using System.IO;
|
||||
|
||||
@if (string.IsNullOrEmpty(_moduledefinitionname) && _systeminfo != null && _templates != null)
|
||||
@if (string.IsNullOrEmpty(_moduledefinitionname) && _templates != null)
|
||||
{
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
|
@ -43,9 +41,9 @@
|
|||
<td>
|
||||
<select id="template" class="form-control" @onchange="(e => TemplateChanged(e))">
|
||||
<option value="-"><@Localizer["Select Template"]></option>
|
||||
@foreach (string template in _templates)
|
||||
@foreach (Template template in _templates)
|
||||
{
|
||||
<option value="@template">@template</option>
|
||||
<option value="@template.Name">@template.Name</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
|
@ -56,9 +54,9 @@
|
|||
</td>
|
||||
<td>
|
||||
<select id="reference" class="form-control" @bind="@_reference">
|
||||
@foreach (string version in Constants.ReleaseVersions.Split(','))
|
||||
@foreach (string version in _versions)
|
||||
{
|
||||
if (Version.Parse(version).CompareTo(Version.Parse("2.0.0")) >= 0)
|
||||
if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0)
|
||||
{
|
||||
<option value="@(version)">@(version)</option>
|
||||
}
|
||||
|
@ -91,13 +89,13 @@ else
|
|||
private string _owner = string.Empty;
|
||||
private string _module = string.Empty;
|
||||
private string _description = string.Empty;
|
||||
private List<Template> _templates;
|
||||
private string _template = "-";
|
||||
private string[] _versions;
|
||||
private string _reference = Constants.Version;
|
||||
private string _minversion = "2.0.0";
|
||||
private string _location = string.Empty;
|
||||
|
||||
private Dictionary<string, string> _systeminfo;
|
||||
private List<string> _templates;
|
||||
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
|
@ -105,8 +103,8 @@ else
|
|||
try
|
||||
{
|
||||
_moduledefinitionname = SettingService.GetSetting(ModuleState.Settings, "ModuleDefinitionName", "");
|
||||
_systeminfo = await SystemService.GetSystemInfoAsync();
|
||||
_templates = await ModuleDefinitionService.GetModuleDefinitionTemplatesAsync();
|
||||
_versions = Constants.ReleaseVersions.Split(',').Where(item => Version.Parse(item).CompareTo(Version.Parse("2.0.0")) >= 0).ToArray();
|
||||
|
||||
if (string.IsNullOrEmpty(_moduledefinitionname))
|
||||
{
|
||||
|
@ -178,17 +176,23 @@ else
|
|||
private void TemplateChanged(ChangeEventArgs e)
|
||||
{
|
||||
_template = (string)e.Value;
|
||||
_minversion = "2.0.0";
|
||||
if (_template != "-")
|
||||
{
|
||||
var template = _templates.FirstOrDefault(item => item.Name == _template);
|
||||
_minversion = template.Version;
|
||||
}
|
||||
GetLocation();
|
||||
}
|
||||
|
||||
private void GetLocation()
|
||||
{
|
||||
_location = string.Empty;
|
||||
if (_template != "-" && _systeminfo != null && _systeminfo.ContainsKey("serverpath"))
|
||||
if (_owner != "" && _module != "" && _template != "-")
|
||||
{
|
||||
string[] path = _systeminfo["serverpath"].Split(Path.DirectorySeparatorChar);
|
||||
_location = string.Join(Path.DirectorySeparatorChar, path, 0, path.Length - 2) +
|
||||
Path.DirectorySeparatorChar + _owner + "." + _module;
|
||||
var template = _templates.FirstOrDefault(item => item.Name == _template);
|
||||
_location = template.Location + _owner + "." + _module;
|
||||
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
@namespace Oqtane.Modules.Admin.ModuleDefinitions
|
||||
@inherits ModuleBase
|
||||
@using System.Text.RegularExpressions
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IModuleDefinitionService ModuleDefinitionService
|
||||
@inject IModuleService ModuleService
|
||||
@inject ISystemService SystemService
|
||||
@inject ISettingService SettingService
|
||||
@inject IStringLocalizer<Index> Localizer
|
||||
@using System.Text.RegularExpressions
|
||||
@using System.IO;
|
||||
|
||||
@if (_systeminfo != null && _templates != null)
|
||||
@if (_templates != null)
|
||||
{
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
|
@ -43,9 +41,9 @@
|
|||
<td>
|
||||
<select id="template" class="form-control" @onchange="(e => TemplateChanged(e))">
|
||||
<option value="-"><@Localizer["Select Template"]></option>
|
||||
@foreach (string template in _templates)
|
||||
@foreach (Template template in _templates)
|
||||
{
|
||||
<option value="@template">@template</option>
|
||||
<option value="@template.Name">@template.Name</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
|
@ -56,9 +54,9 @@
|
|||
</td>
|
||||
<td>
|
||||
<select id="reference" class="form-control" @bind="@_reference">
|
||||
@foreach (string version in Constants.ReleaseVersions.Split(','))
|
||||
@foreach (string version in _versions)
|
||||
{
|
||||
if (Version.Parse(version).CompareTo(Version.Parse("2.0.0")) >= 0)
|
||||
if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0)
|
||||
{
|
||||
<option value="@(version)">@(version)</option>
|
||||
}
|
||||
|
@ -87,21 +85,21 @@
|
|||
private string _owner = string.Empty;
|
||||
private string _module = string.Empty;
|
||||
private string _description = string.Empty;
|
||||
private List<Template> _templates;
|
||||
private string _template = "-";
|
||||
private string[] _versions;
|
||||
private string _reference = Constants.Version;
|
||||
private string _minversion = "2.0.0";
|
||||
private string _location = string.Empty;
|
||||
|
||||
private Dictionary<string, string> _systeminfo;
|
||||
private List<string> _templates;
|
||||
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_systeminfo = await SystemService.GetSystemInfoAsync();
|
||||
_templates = await ModuleDefinitionService.GetModuleDefinitionTemplatesAsync();
|
||||
_versions = Constants.ReleaseVersions.Split(',').Where(item => Version.Parse(item).CompareTo(Version.Parse("2.0.0")) >= 0).ToArray();
|
||||
AddModuleMessage(Localizer["Please Note That The Module Creator Is Only Intended To Be Used In A Development Environment"], MessageType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -141,17 +139,23 @@
|
|||
private void TemplateChanged(ChangeEventArgs e)
|
||||
{
|
||||
_template = (string)e.Value;
|
||||
_minversion = "2.0.0";
|
||||
if (_template != "-")
|
||||
{
|
||||
var template = _templates.FirstOrDefault(item => item.Name == _template);
|
||||
_minversion = template.Version;
|
||||
}
|
||||
GetLocation();
|
||||
}
|
||||
|
||||
private void GetLocation()
|
||||
{
|
||||
_location = string.Empty;
|
||||
if (_template != "-" && _systeminfo != null && _systeminfo.ContainsKey("serverpath"))
|
||||
if (_owner != "" && _module != "" && _template != "-")
|
||||
{
|
||||
string[] path = _systeminfo["serverpath"].Split(Path.DirectorySeparatorChar);
|
||||
_location = string.Join(Path.DirectorySeparatorChar, path, 0, path.Length - 2) +
|
||||
Path.DirectorySeparatorChar + _owner + "." + _module;
|
||||
var template = _templates.FirstOrDefault(item => item.Name == _template);
|
||||
_location = template.Location + _owner + "." + _module;
|
||||
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
@namespace Oqtane.Modules.Admin.Themes
|
||||
@inherits ModuleBase
|
||||
@using System.Text.RegularExpressions
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IThemeService ThemeService
|
||||
@inject IModuleService ModuleService
|
||||
@inject IPageModuleService PageModuleService
|
||||
@inject ISystemService SystemService
|
||||
@inject ISettingService SettingService
|
||||
@inject IStringLocalizer<Index> Localizer
|
||||
@using System.Text.RegularExpressions
|
||||
@using System.IO;
|
||||
|
||||
@if (_systeminfo != null && _templates != null)
|
||||
@if (_templates != null)
|
||||
{
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
|
@ -36,9 +34,9 @@
|
|||
<td>
|
||||
<select id="template" class="form-control" @onchange="(e => TemplateChanged(e))">
|
||||
<option value="-"><@Localizer["Select Template"]></option>
|
||||
@foreach (string template in _templates)
|
||||
@foreach (Template template in _templates)
|
||||
{
|
||||
<option value="@template">@template</option>
|
||||
<option value="@template.Name">@template.Name</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
|
@ -49,9 +47,9 @@
|
|||
</td>
|
||||
<td>
|
||||
<select id="reference" class="form-control" @bind="@_reference">
|
||||
@foreach (string version in Constants.ReleaseVersions.Split(','))
|
||||
@foreach (string version in _versions)
|
||||
{
|
||||
if (Version.Parse(version).CompareTo(Version.Parse("2.0.0")) >= 0)
|
||||
if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0)
|
||||
{
|
||||
<option value="@(version)">@(version)</option>
|
||||
}
|
||||
|
@ -79,21 +77,21 @@
|
|||
@code {
|
||||
private string _owner = string.Empty;
|
||||
private string _theme = string.Empty;
|
||||
private List<Template> _templates;
|
||||
private string _template = "-";
|
||||
private string[] _versions;
|
||||
private string _reference = Constants.Version;
|
||||
private string _minversion = "2.0.0";
|
||||
private string _location = string.Empty;
|
||||
|
||||
private Dictionary<string, string> _systeminfo;
|
||||
private List<string> _templates;
|
||||
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_systeminfo = await SystemService.GetSystemInfoAsync();
|
||||
_templates = await ThemeService.GetThemeTemplatesAsync();
|
||||
_versions = Constants.ReleaseVersions.Split(',').Where(item => Version.Parse(item).CompareTo(Version.Parse("2.0.0")) >= 0).ToArray();
|
||||
AddModuleMessage(Localizer["Please Note That The Theme Creator Is Only Intended To Be Used In A Development Environment"], MessageType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -111,7 +109,6 @@
|
|||
var theme = new Theme { Owner = _owner, Name = _theme, Template = _template, Version = _reference };
|
||||
theme = await ThemeService.CreateThemeAsync(theme);
|
||||
GetLocation();
|
||||
|
||||
AddModuleMessage(Localizer["The Source Code For Your Theme Has Been Created At The Location Specified Below And Must Be Compiled In Order To Make It Functional. Once It Has Been Compiled You Must <a href=\"{0}\">Restart</a> Your Application To Activate The Module.", NavigateUrl("admin/system")], MessageType.Success);
|
||||
}
|
||||
else
|
||||
|
@ -134,17 +131,23 @@
|
|||
private void TemplateChanged(ChangeEventArgs e)
|
||||
{
|
||||
_template = (string)e.Value;
|
||||
_minversion = "2.0.0";
|
||||
if (_template != "-")
|
||||
{
|
||||
var template = _templates.FirstOrDefault(item => item.Name == _template);
|
||||
_minversion = template.Version;
|
||||
}
|
||||
GetLocation();
|
||||
}
|
||||
|
||||
private void GetLocation()
|
||||
{
|
||||
_location = string.Empty;
|
||||
if (_template != "-" && _systeminfo != null && _systeminfo.ContainsKey("serverpath"))
|
||||
if (_owner != "" && _theme != "" && _template != "-")
|
||||
{
|
||||
string[] path = _systeminfo["serverpath"].Split(Path.DirectorySeparatorChar);
|
||||
_location = string.Join(Path.DirectorySeparatorChar, path, 0, path.Length - 2) +
|
||||
Path.DirectorySeparatorChar + _owner + "." + _theme;
|
||||
var template = _templates.FirstOrDefault(item => item.Name == _template);
|
||||
_location = template.Location + _owner + "." + _theme;
|
||||
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@ namespace Oqtane.Services
|
|||
Task InstallModuleDefinitionsAsync();
|
||||
Task DeleteModuleDefinitionAsync(int moduleDefinitionId, int siteId);
|
||||
Task<ModuleDefinition> CreateModuleDefinitionAsync(ModuleDefinition moduleDefinition);
|
||||
Task<List<string>> GetModuleDefinitionTemplatesAsync();
|
||||
Task<List<Template>> GetModuleDefinitionTemplatesAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@ namespace Oqtane.Services
|
|||
Task InstallThemesAsync();
|
||||
Task DeleteThemeAsync(string themeName);
|
||||
Task<Theme> CreateThemeAsync(Theme theme);
|
||||
Task<List<string>> GetThemeTemplatesAsync();
|
||||
Task<List<Template>> GetThemeTemplatesAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ namespace Oqtane.Services
|
|||
return await PostJsonAsync($"{Apiurl}", moduleDefinition);
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetModuleDefinitionTemplatesAsync()
|
||||
public async Task<List<Template>> GetModuleDefinitionTemplatesAsync()
|
||||
{
|
||||
List<string> templates = await GetJsonAsync<List<string>>($"{Apiurl}/templates");
|
||||
List<Template> templates = await GetJsonAsync<List<Template>>($"{Apiurl}/templates");
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,9 +58,9 @@ namespace Oqtane.Services
|
|||
return await PostJsonAsync($"{ApiUrl}", theme);
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetThemeTemplatesAsync()
|
||||
public async Task<List<Template>> GetThemeTemplatesAsync()
|
||||
{
|
||||
List<string> templates = await GetJsonAsync<List<string>>($"{ApiUrl}/templates");
|
||||
List<Template> templates = await GetJsonAsync<List<Template>>($"{ApiUrl}/templates");
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,13 +162,26 @@ namespace Oqtane.Controllers
|
|||
// GET: api/<controller>/templates
|
||||
[HttpGet("templates")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public List<string> GetTemplates()
|
||||
public List<Template> GetTemplates()
|
||||
{
|
||||
var templates = new List<string>();
|
||||
var templates = new List<Template>();
|
||||
var root = Directory.GetParent(_environment.ContentRootPath);
|
||||
string templatePath = Utilities.PathCombine(_environment.WebRootPath, "Modules", "Templates", Path.DirectorySeparatorChar.ToString());
|
||||
foreach (string directory in Directory.GetDirectories(templatePath))
|
||||
{
|
||||
templates.Add(directory.Replace(templatePath, ""));
|
||||
if (System.IO.File.Exists(Path.Combine(directory, "template.json")))
|
||||
{
|
||||
var template = JsonSerializer.Deserialize<Template>(System.IO.File.ReadAllText(Path.Combine(directory, "template.json")));
|
||||
if (template.Type.ToLower() != "internal")
|
||||
{
|
||||
template.Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString());
|
||||
}
|
||||
templates.Add(template);
|
||||
}
|
||||
else
|
||||
{
|
||||
templates.Add(new Template { Name = directory.Replace(templatePath, ""), Type = "External", Version = "", Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString()) });
|
||||
}
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
|
|
@ -89,13 +89,26 @@ namespace Oqtane.Controllers
|
|||
// GET: api/<controller>/templates
|
||||
[HttpGet("templates")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public List<string> GetTemplates()
|
||||
public List<Template> GetTemplates()
|
||||
{
|
||||
var templates = new List<string>();
|
||||
var templates = new List<Template>();
|
||||
var root = Directory.GetParent(_environment.ContentRootPath);
|
||||
string templatePath = Utilities.PathCombine(_environment.WebRootPath, "Themes", "Templates", Path.DirectorySeparatorChar.ToString());
|
||||
foreach (string directory in Directory.GetDirectories(templatePath))
|
||||
{
|
||||
templates.Add(directory.Replace(templatePath, ""));
|
||||
if (System.IO.File.Exists(Path.Combine(directory, "template.json")))
|
||||
{
|
||||
var template = JsonSerializer.Deserialize<Template>(System.IO.File.ReadAllText(Path.Combine(directory, "template.json")));
|
||||
if (template.Type.ToLower() != "internal")
|
||||
{
|
||||
template.Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString());
|
||||
}
|
||||
templates.Add(template);
|
||||
}
|
||||
else
|
||||
{
|
||||
templates.Add(new Template { Name = directory.Replace(templatePath, ""), Type = "External", Version = "", Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString()) });
|
||||
}
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
|
5
Oqtane.Server/wwwroot/Modules/Templates/External/template.json
vendored
Normal file
5
Oqtane.Server/wwwroot/Modules/Templates/External/template.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Name": "Default Module Template",
|
||||
"Type": "External",
|
||||
"Version": "2.1.0"
|
||||
}
|
5
Oqtane.Server/wwwroot/Themes/Templates/External/template.json
vendored
Normal file
5
Oqtane.Server/wwwroot/Themes/Templates/External/template.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Name": "Default Theme Template",
|
||||
"Type": "External",
|
||||
"Version": "2.1.0"
|
||||
}
|
28
Oqtane.Shared/Models/Template.cs
Normal file
28
Oqtane.Shared/Models/Template.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
namespace Oqtane.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// model for defining metadata for a Module or Theme template
|
||||
/// </summary>
|
||||
public class Template
|
||||
{
|
||||
/// <summary>
|
||||
/// name of template
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// type of template - Internal / External
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// minimum framework version dependency
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// location where template will be created (dynamically set)
|
||||
/// </summary>
|
||||
public string Location { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user