Merge pull request #1431 from sbwalker/dev

fix issue in theme creator
This commit is contained in:
Shaun Walker 2021-06-01 15:45:09 -04:00 committed by GitHub
commit 1b4934d623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 11 deletions

View File

@ -43,7 +43,7 @@
<option value="-">&lt;@Localizer["Select Template"]&gt;</option>
@foreach (Template template in _templates)
{
<option value="@template.Name">@template.Name</option>
<option value="@template.Name">@template.Title</option>
}
</select>
</td>
@ -170,7 +170,7 @@ else
private bool IsValid(string name)
{
// must contain letters, underscores and digits and first character must be letter or underscore
return !string.IsNullOrEmpty(name) && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$");
return !string.IsNullOrEmpty(name) && name.ToLower() != "module" && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$");
}
private void TemplateChanged(ChangeEventArgs e)

View File

@ -43,7 +43,7 @@
<option value="-">&lt;@Localizer["Select Template"]&gt;</option>
@foreach (Template template in _templates)
{
<option value="@template.Name">@template.Name</option>
<option value="@template.Name">@template.Title</option>
}
</select>
</td>
@ -133,7 +133,7 @@
private bool IsValid(string name)
{
// must contain letters, underscores and digits and first character must be letter or underscore
return !string.IsNullOrEmpty(name) && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$");
return !string.IsNullOrEmpty(name) && name.ToLower() != "module" && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$");
}
private void TemplateChanged(ChangeEventArgs e)

View File

@ -36,7 +36,7 @@
<option value="-">&lt;@Localizer["Select Template"]&gt;</option>
@foreach (Template template in _templates)
{
<option value="@template.Name">@template.Name</option>
<option value="@template.Name">@template.Title</option>
}
</select>
</td>
@ -125,7 +125,7 @@
private bool IsValid(string name)
{
// must contain letters, underscores and digits and first character must be letter or underscore
return !string.IsNullOrEmpty(name) && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$");
return !string.IsNullOrEmpty(name) && name.ToLower() != "theme" && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$");
}
private void TemplateChanged(ChangeEventArgs e)

View File

@ -169,9 +169,12 @@ namespace Oqtane.Controllers
string templatePath = Utilities.PathCombine(_environment.WebRootPath, "Modules", "Templates", Path.DirectorySeparatorChar.ToString());
foreach (string directory in Directory.GetDirectories(templatePath))
{
string name = 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")));
template.Name = name;
template.Location = "";
if (template.Type.ToLower() != "internal")
{
template.Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString());
@ -180,7 +183,7 @@ namespace Oqtane.Controllers
}
else
{
templates.Add(new Template { Name = directory.Replace(templatePath, ""), Type = "External", Version = "", Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString()) });
templates.Add(new Template { Name = name, Title = name, Type = "External", Version = "", Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString()) });
}
}
return templates;

View File

@ -96,9 +96,12 @@ namespace Oqtane.Controllers
string templatePath = Utilities.PathCombine(_environment.WebRootPath, "Themes", "Templates", Path.DirectorySeparatorChar.ToString());
foreach (string directory in Directory.GetDirectories(templatePath))
{
string name = 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")));
template.Name = name;
template.Location = "";
if (template.Type.ToLower() != "internal")
{
template.Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString());
@ -107,7 +110,7 @@ namespace Oqtane.Controllers
}
else
{
templates.Add(new Template { Name = directory.Replace(templatePath, ""), Type = "External", Version = "", Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString()) });
templates.Add(new Template { Name = name, Title = name, Type = "External", Version = "", Location = Utilities.PathCombine(root.Parent.ToString(), Path.DirectorySeparatorChar.ToString()) });
}
}
return templates;

View File

@ -1,5 +1,5 @@
{
"Name": "Default Module Template",
"Title": "Default Module Template",
"Type": "External",
"Version": "2.1.0"
}

View File

@ -1,5 +1,5 @@
{
"Name": "Default Theme Template",
"Title": "Default Theme Template",
"Type": "External",
"Version": "2.1.0"
}

View File

@ -6,10 +6,15 @@ namespace Oqtane.Models
public class Template
{
/// <summary>
/// name of template
/// name of template (folder name)
/// </summary>
public string Name { get; set; }
/// <summary>
/// title of template
/// </summary>
public string Title { get; set; }
/// <summary>
/// type of template - Internal / External
/// </summary>