refactoring of #518 to simplify registration of scripts in modules and themes

This commit is contained in:
Shaun Walker
2020-06-14 12:07:16 -04:00
parent ea89cc1a64
commit 4e6b4a20ef
17 changed files with 106 additions and 207 deletions

View File

@ -4,6 +4,7 @@ using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.UI;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Oqtane.Themes
@ -22,6 +23,23 @@ namespace Oqtane.Themes
public virtual string Panes { get; set; }
public virtual List<Resource> Resources { get; set; }
// base lifecycle method for handling JSInterop script registration
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
if (Resources != null && Resources.Exists(item => item.ResourceType == ResourceType.Script))
{
var interop = new Interop(JSRuntime);
foreach (var resource in Resources.Where(item => item.ResourceType == ResourceType.Script))
{
await interop.LoadScript(resource.Url);
}
}
}
}
// path method
public string ThemePath()
@ -60,5 +78,10 @@ namespace Oqtane.Themes
{
return Utilities.EditUrl(PageState.Alias.Path, path, moduleid, action, parameters);
}
public string ContentUrl(int fileid)
{
return Utilities.ContentUrl(PageState.Alias, fileid);
}
}
}