module installer
This commit is contained in:
@ -2,9 +2,11 @@
|
||||
@using Oqtane.Client.Modules.Controls
|
||||
@using Oqtane.Modules
|
||||
@using Oqtane.Services
|
||||
@using Oqtane.Shared
|
||||
@inherits ModuleBase
|
||||
@inject IUriHelper UriHelper
|
||||
@inject IFileService FileService
|
||||
@inject IModuleDefinitionService ModuleDefinitionService
|
||||
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
@ -16,15 +18,32 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<button type="button" class="btn btn-success" @onclick="UploadFile">Upload</button>
|
||||
@if (uploaded)
|
||||
{
|
||||
<button type="button" class="btn btn-success" @onclick="InstallFile">Install</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-success" @onclick="UploadFile">Upload</button>
|
||||
}
|
||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||
|
||||
@code {
|
||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
||||
|
||||
bool uploaded = false;
|
||||
|
||||
private async Task UploadFile()
|
||||
{
|
||||
await FileService.UploadFilesAsync("/Sites/Modules");
|
||||
await FileService.UploadFilesAsync("Modules");
|
||||
uploaded = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InstallFile()
|
||||
{
|
||||
await ModuleDefinitionService.InstallModulesAsync();
|
||||
PageState.Reload = Constants.ReloadApplication;
|
||||
UriHelper.NavigateTo(NavigateUrl());
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<ActionLink Action="Add" Text="Upload Module" />
|
||||
<ActionLink Action="Add" Text="Install Module" />
|
||||
<table class="table table-borderless">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -7,5 +7,6 @@ namespace Oqtane.Services
|
||||
public interface IModuleDefinitionService
|
||||
{
|
||||
Task<List<ModuleDefinition>> GetModuleDefinitionsAsync();
|
||||
}
|
||||
Task InstallModulesAsync();
|
||||
}
|
||||
}
|
||||
|
@ -63,5 +63,10 @@ namespace Oqtane.Services
|
||||
|
||||
return moduledefinitions.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task InstallModulesAsync()
|
||||
{
|
||||
await http.GetJsonAsync<List<string>>(apiurl + "/install");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
{
|
||||
if (PageState.Site.Logo != "")
|
||||
{
|
||||
logo = "<a href=\"" + PageState.Alias.Url + "\"><img src=\"/Sites/" + PageState.Site.SiteId.ToString() + "/" + PageState.Site.Logo + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
|
||||
logo = "<a href=\"" + PageState.Alias.Url + "\"><img src=\"" + PageState.Alias.SiteRootUrl + PageState.Site.Logo + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 7.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.8 KiB |
@ -55,5 +55,61 @@ window.interop = {
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
},
|
||||
uploadFiles: function (posturl, folder, name) {
|
||||
var files = document.getElementById(name + 'FileInput').files;
|
||||
var progressinfo = document.getElementById(name + 'ProgressInfo');
|
||||
var progressbar = document.getElementById(name + 'ProgressBar');
|
||||
var filename = '';
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var FileChunk = [];
|
||||
var file = files[i];
|
||||
var MaxFileSizeMB = 1;
|
||||
var BufferChunkSize = MaxFileSizeMB * (1024 * 1024);
|
||||
var FileStreamPos = 0;
|
||||
var EndPos = BufferChunkSize;
|
||||
var Size = file.size;
|
||||
|
||||
progressbar.setAttribute("style", "visibility: visible;");
|
||||
|
||||
if (files.length > 1) {
|
||||
filename = file.name;
|
||||
}
|
||||
|
||||
while (FileStreamPos < Size) {
|
||||
FileChunk.push(file.slice(FileStreamPos, EndPos));
|
||||
FileStreamPos = EndPos;
|
||||
EndPos = FileStreamPos + BufferChunkSize;
|
||||
}
|
||||
|
||||
var TotalParts = FileChunk.length;
|
||||
var PartCount = 0;
|
||||
|
||||
while (Chunk = FileChunk.shift()) {
|
||||
PartCount++;
|
||||
var FileName = file.name + ".part_" + PartCount + "_" + TotalParts;
|
||||
|
||||
var data = new FormData();
|
||||
data.append('folder', folder);
|
||||
data.append('file', Chunk, FileName);
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('POST', posturl, true);
|
||||
request.upload.onloadstart = function (e) {
|
||||
progressbar.value = 0;
|
||||
progressinfo.innerHTML = filename + ' 0%';
|
||||
};
|
||||
request.upload.onprogress = function (e) {
|
||||
var percent = Math.ceil((e.loaded / e.total) * 100);
|
||||
progressbar.value = (percent / 100);
|
||||
progressinfo.innerHTML = filename + '[' + PartCount + '] ' + percent + '%';
|
||||
};
|
||||
request.upload.onloadend = function (e) {
|
||||
progressbar.value = 1;
|
||||
progressinfo.innerHTML = filename + ' 100%';
|
||||
};
|
||||
request.send(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user