107 lines
4.0 KiB
Plaintext
107 lines
4.0 KiB
Plaintext
@namespace Oqtane.Modules.Admin.ModuleDefinitions
|
|
@inherits ModuleBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject IFileService FileService
|
|
@inject IModuleDefinitionService ModuleDefinitionService
|
|
@inject IPackageService PackageService
|
|
|
|
@if (_packages != null)
|
|
{
|
|
<TabStrip>
|
|
@if (_packages.Count > 0)
|
|
{
|
|
<TabPanel Name="Download" ResourceKey="Download">
|
|
<ModuleMessage Type="MessageType.Info" Message="Download one or more modules from the list below. Once you are ready click Install to complete the installation."></ModuleMessage>
|
|
<Pager Items="@_packages">
|
|
<Header>
|
|
<th>Name</th>
|
|
<th>Version</th>
|
|
<th style="width: 1px"></th>
|
|
</Header>
|
|
<Row>
|
|
<td>@context.Name</td>
|
|
<td>@context.Version</td>
|
|
<td>
|
|
<button type="button" class="btn btn-primary" @onclick=@(async () => await DownloadModule(context.PackageId, context.Version))>Download</button>
|
|
</td>
|
|
</Row>
|
|
</Pager>
|
|
</TabPanel>
|
|
}
|
|
<TabPanel Name="Upload" ResourceKey="Upload">
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<Label HelpText="Upload one or more module packages. Once they are uploaded click Install to complete the installation." ResourceKey="Module">Module: </Label>
|
|
</td>
|
|
<td>
|
|
<FileManager Filter="nupkg" ShowFiles="false" Folder="Modules" UploadMultiple="true" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</TabPanel>
|
|
</TabStrip>
|
|
|
|
<button type="button" class="btn btn-success" @onclick="InstallModules">Install</button>
|
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
|
}
|
|
|
|
@code {
|
|
private List<Package> _packages;
|
|
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
|
|
_packages = await PackageService.GetPackagesAsync("module");
|
|
|
|
foreach (Package package in _packages.ToArray())
|
|
{
|
|
if (moduledefinitions.Exists(item => Utilities.GetTypeName(item.ModuleDefinitionName) == package.PackageId))
|
|
{
|
|
_packages.Remove(package);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading Packages {Error}", ex.Message);
|
|
AddModuleMessage("Error Loading Packages", MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task InstallModules()
|
|
{
|
|
try
|
|
{
|
|
ShowProgressIndicator();
|
|
var interop = new Interop(JSRuntime);
|
|
await interop.RedirectBrowser(NavigateUrl(), 10);
|
|
await ModuleDefinitionService.InstallModuleDefinitionsAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Installating Module");
|
|
}
|
|
}
|
|
|
|
private async Task DownloadModule(string packageid, string version)
|
|
{
|
|
try
|
|
{
|
|
await PackageService.DownloadPackageAsync(packageid, version, "Modules");
|
|
await logger.LogInformation("Module {ModuleDefinitionName} {Version} Downloaded Successfully", packageid, version);
|
|
AddModuleMessage("Modules Downloaded Successfully. Click Install To Complete Installation.", MessageType.Success);
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Downloading Module {ModuleDefinitionName} {Version}", packageid, version);
|
|
AddModuleMessage("Error Downloading Module", MessageType.Error);
|
|
}
|
|
}
|
|
}
|