@using Microsoft.AspNetCore.Components.Routing @using Oqtane.Services @using Oqtane.Models @using Oqtane.Modules @using Oqtane.Shared @using Oqtane.Security @using Oqtane.Modules.Controls @namespace Oqtane.Modules.Admin.ModuleSettings @inherits ModuleBase @inject NavigationManager NavigationManager @inject IThemeService ThemeService @inject IModuleService ModuleService @inject IPageModuleService PageModuleService
@DynamicComponent Cancel @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } } public override string Title { get { return "Module Settings"; } } Dictionary containers = new Dictionary(); string title; string containertype; string permissions; string pageid; PermissionGrid permissiongrid; RenderFragment DynamicComponent { get; set; } object settings; protected override async Task OnInitializedAsync() { title = ModuleState.Title; containers = ThemeService.GetContainerTypes(await ThemeService.GetThemesAsync()); containertype = ModuleState.ContainerType; permissions = ModuleState.Permissions; pageid = ModuleState.PageId.ToString(); DynamicComponent = builder => { Type moduleType = Type.GetType(ModuleState.ModuleType); if (moduleType != null) { builder.OpenComponent(0, moduleType); builder.AddComponentReferenceCapture(1, inst => { settings = Convert.ChangeType(inst, moduleType); }); builder.CloseComponent(); } }; } private async Task SaveModule() { Module module = ModuleState; module.Permissions = permissiongrid.GetPermissions(); await ModuleService.UpdateModuleAsync(module); PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); pagemodule.Title = title; pagemodule.ContainerType = containertype; await PageModuleService.UpdatePageModuleAsync(pagemodule); Type moduleType = Type.GetType(ModuleState.ModuleType); if (moduleType != null) { moduleType.GetMethod("UpdateSettings").Invoke(settings, null); // method must be public in settings component } PageState.Reload = Constants.ReloadPage; NavigationManager.NavigateTo(NavigateUrl()); } }