61 lines
2.0 KiB
Plaintext
61 lines
2.0 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Files
|
|
@inherits ModuleBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject IFileService FileService
|
|
|
|
@if (Files == null)
|
|
{
|
|
<p><em>Loading...</em></p>
|
|
}
|
|
else
|
|
{
|
|
<ActionLink Action="Add" Text="Add Files" />
|
|
|
|
<Pager Items="@Files">
|
|
<Header>
|
|
<th> </th>
|
|
<th>Name</th>
|
|
</Header>
|
|
<Row>
|
|
<td><ConfirmationDialog Header="Delete File" Message="@("Are You Sure You Wish To Delete " + context + "?")" Action="Delete" Class="btn btn-danger" OnClick="@(async () => await DeleteFile(context))" /></td>
|
|
<td><a href="@(uri.Scheme + "://" + uri.Authority + "/" + PageState.Site.SiteRootPath + context)" target="_new">@context</a></td>
|
|
</Row>
|
|
</Pager>
|
|
}
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
|
|
|
|
List<string> Files;
|
|
Uri uri;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
try
|
|
{
|
|
Files = await FileService.GetFilesAsync(PageState.Site.SiteRootPath);
|
|
uri = new Uri(NavigationManager.Uri);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading Files {Error}", ex.Message);
|
|
AddModuleMessage("Error Loading Files", MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task DeleteFile(string filename)
|
|
{
|
|
try
|
|
{
|
|
await FileService.DeleteFileAsync(PageState.Site.SiteRootPath, filename);
|
|
Files = await FileService.GetFilesAsync(PageState.Site.SiteRootPath);
|
|
await logger.LogInformation("File Deleted {File}", filename);
|
|
AddModuleMessage("File " + filename + " Deleted", MessageType.Success);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Deleting File {File} {Error}", filename, ex.Message);
|
|
AddModuleMessage("Error Deleting File " + filename, MessageType.Error);
|
|
}
|
|
}
|
|
} |