Merge pull request #1425 from sbwalker/dev
added metadata support for Module and Theme templates
This commit is contained in:
@ -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"
|
||||
}
|
Reference in New Issue
Block a user