improve support for internal module/theme templates

This commit is contained in:
sbwalker
2025-10-14 13:37:39 -04:00
parent 83b56966f4
commit 7cf325f4f6
2 changed files with 66 additions and 48 deletions

View File

@@ -42,29 +42,32 @@
</select> </select>
</div> </div>
</div> </div>
<div class="row mb-1 align-items-center"> @if (_type == "External")
<Label Class="col-sm-3" For="reference" HelpText="Select a framework reference version" ResourceKey="FrameworkReference">Framework Reference: </Label>
<div class="col-sm-9">
<select id="reference" class="form-select" @bind="@_reference" required>
@foreach (string version in _versions)
{
if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0)
{
<option value="@(version)">@(version)</option>
}
}
<option value="local">@SharedLocalizer["LocalVersion"]</option>
</select>
</div>
</div>
@if (!string.IsNullOrEmpty(_location))
{ {
<div class="row mb-1 align-items-center"> <div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="location" HelpText="Location where the module will be created" ResourceKey="Location">Location: </Label> <Label Class="col-sm-3" For="reference" HelpText="Select a framework reference version" ResourceKey="FrameworkReference">Framework Reference: </Label>
<div class="col-sm-9"> <div class="col-sm-9">
<input id="module" class="form-control" @bind="@_location" readonly /> <select id="reference" class="form-select" @bind="@_reference" required>
@foreach (string version in _versions)
{
if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0)
{
<option value="@(version)">@(version)</option>
}
}
<option value="local">@SharedLocalizer["LocalVersion"]</option>
</select>
</div> </div>
</div> </div>
@if (!string.IsNullOrEmpty(_location))
{
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="location" HelpText="Location where the module will be created" ResourceKey="Location">Location: </Label>
<div class="col-sm-9">
<input id="module" class="form-control" @bind="@_location" readonly />
</div>
</div>
}
} }
</div> </div>
<button type="button" class="btn btn-success" @onclick="CreateModule">@Localizer["CreateModule"]</button> <button type="button" class="btn btn-success" @onclick="CreateModule">@Localizer["CreateModule"]</button>
@@ -80,9 +83,10 @@
private string _description = string.Empty; private string _description = string.Empty;
private List<Template> _templates; private List<Template> _templates;
private string _template = "-"; private string _template = "-";
private string _minversion = "2.0.0";
private string _type = "External";
private string[] _versions; private string[] _versions;
private string _reference = "local"; private string _reference = "local";
private string _minversion = "2.0.0";
private string _location = string.Empty; private string _location = string.Empty;
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
@@ -153,7 +157,7 @@
private bool IsValid(string name) private bool IsValid(string name)
{ {
// must contain letters, underscores and digits and first character must be letter or underscore // must contain letters, underscores and digits and first character must be letter or underscore
return !string.IsNullOrEmpty(name) && name.ToLower() != "module" && !name.ToLower().Contains("oqtane") && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$"); return !string.IsNullOrEmpty(name) && name.ToLower() != "module" && !name.ToLower().Contains("oqtane") && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_.]*$");
} }
private bool IsValidXML(string description) private bool IsValidXML(string description)
@@ -165,11 +169,16 @@
private void TemplateChanged(ChangeEventArgs e) private void TemplateChanged(ChangeEventArgs e)
{ {
_template = (string)e.Value; _template = (string)e.Value;
_minversion = "2.0.0";
if (_template != "-") if (_template != "-")
{ {
var template = _templates.FirstOrDefault(item => item.Name == _template); var template = _templates.FirstOrDefault(item => item.Name == _template);
_minversion = template.Version; _minversion = template.Version;
_type = template.Type;
}
else
{
_minversion = "2.0.0";
_type = "External";
} }
GetLocation(); GetLocation();
} }

View File

@@ -36,30 +36,33 @@
</select> </select>
</div> </div>
</div> </div>
<div class="row mb-1 align-items-center"> @if (_type == "External")
<Label Class="col-sm-3" For="reference" HelpText="Select a framework reference version" ResourceKey="FrameworkReference">Framework Reference: </Label> {
<div class="col-sm-9"> <div class="row mb-1 align-items-center">
<select id="reference" class="form-select" @bind="@_reference"> <Label Class="col-sm-3" For="reference" HelpText="Select a framework reference version" ResourceKey="FrameworkReference">Framework Reference: </Label>
@foreach (string version in _versions) <div class="col-sm-9">
{ <select id="reference" class="form-select" @bind="@_reference">
if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0) @foreach (string version in _versions)
{ {
<option value="@(version)">@(version)</option> if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0)
} {
} <option value="@(version)">@(version)</option>
<option value="local">@SharedLocalizer["LocalVersion"]</option> }
</select> }
</div> <option value="local">@SharedLocalizer["LocalVersion"]</option>
</div> </select>
@if (!string.IsNullOrEmpty(_location)) </div>
{ </div>
<div class="row mb-1 align-items-center"> @if (!string.IsNullOrEmpty(_location))
<Label Class="col-sm-3" For="location" HelpText="Location where the theme will be created" ResourceKey="Location">Location: </Label> {
<div class="col-sm-9"> <div class="row mb-1 align-items-center">
<input id="module" class="form-control" @bind="@_location" readonly /> <Label Class="col-sm-3" For="location" HelpText="Location where the theme will be created" ResourceKey="Location">Location: </Label>
</div> <div class="col-sm-9">
</div> <input id="module" class="form-control" @bind="@_location" readonly />
} </div>
</div>
}
}
</div> </div>
<br /> <br />
<button type="button" class="btn btn-success" @onclick="CreateTheme">@Localizer["Theme.Create"]</button> <button type="button" class="btn btn-success" @onclick="CreateTheme">@Localizer["Theme.Create"]</button>
@@ -71,9 +74,10 @@
private string _theme = string.Empty; private string _theme = string.Empty;
private List<Template> _templates; private List<Template> _templates;
private string _template = "-"; private string _template = "-";
private string _minversion = "2.0.0";
private string _type = "External";
private string[] _versions; private string[] _versions;
private string _reference = "local"; private string _reference = "local";
private string _minversion = "2.0.0";
private string _location = string.Empty; private string _location = string.Empty;
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
@@ -125,17 +129,22 @@
private bool IsValid(string name) private bool IsValid(string name)
{ {
// must contain letters, underscores and digits and first character must be letter or underscore // must contain letters, underscores and digits and first character must be letter or underscore
return !string.IsNullOrEmpty(name) && name.ToLower() != "theme" && !name.ToLower().Contains("oqtane") && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$"); return !string.IsNullOrEmpty(name) && name.ToLower() != "theme" && !name.ToLower().Contains("oqtane") && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_.]*$");
} }
private void TemplateChanged(ChangeEventArgs e) private void TemplateChanged(ChangeEventArgs e)
{ {
_template = (string)e.Value; _template = (string)e.Value;
_minversion = "2.0.0";
if (_template != "-") if (_template != "-")
{ {
var template = _templates.FirstOrDefault(item => item.Name == _template); var template = _templates.FirstOrDefault(item => item.Name == _template);
_minversion = template.Version; _minversion = template.Version;
_type = template.Type;
}
else
{
_minversion = "2.0.0";
_type = "External";
} }
GetLocation(); GetLocation();
} }