created generic confirmation dialog control and implemented in File Management module

This commit is contained in:
Shaun Walker 2019-10-24 14:59:15 -04:00
parent 414935dc58
commit b3e010d5e2
7 changed files with 88 additions and 21 deletions

View File

@ -9,18 +9,16 @@
} }
else else
{ {
<ActionLink Action="Add" Text="Add Files" Style="float: right; margin: 10px;" /> <ActionLink Action="Add" Text="Add Files" />
<Pager Items="@Files"> <Pager Items="@Files">
<Header> <Header>
<th>Name</th>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>Name</th>
</Header> </Header>
<Row> <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> <td><a href="@(uri.Scheme + "://" + uri.Authority + "/" + PageState.Site.SiteRootPath + context)" target="_new">@context</a></td>
<td>
<button type="button" class="btn btn-danger" @onclick=@(async () => await DeleteFile(context))>Delete</button>
</td>
</Row> </Row>
</Pager> </Pager>
} }
@ -40,7 +38,7 @@ else
} }
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError("Error Loading Files {Error}", ex.Message); await logger.LogError(ex, "Error Loading Files {Error}", ex.Message);
AddModuleMessage("Error Loading Files", MessageType.Error); AddModuleMessage("Error Loading Files", MessageType.Error);
} }
} }
@ -51,13 +49,13 @@ else
{ {
await FileService.DeleteFileAsync(PageState.Site.SiteRootPath, filename); await FileService.DeleteFileAsync(PageState.Site.SiteRootPath, filename);
Files = await FileService.GetFilesAsync(PageState.Site.SiteRootPath); Files = await FileService.GetFilesAsync(PageState.Site.SiteRootPath);
await logger.LogInformation("File Deleted"); await logger.LogInformation("File Deleted {File}", filename);
AddModuleMessage("File Deleted", MessageType.Success); AddModuleMessage("File " + filename + " Deleted", MessageType.Success);
} }
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError("Error Deleting File {Error}", ex.Message); await logger.LogError(ex, "Error Deleting File {File} {Error}", filename, ex.Message);
AddModuleMessage("Error Deleting File", MessageType.Error); AddModuleMessage("Error Deleting File " + filename, MessageType.Error);
} }
} }
} }

View File

@ -0,0 +1,69 @@
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
@if (visible)
{
<div class="app-admin-modal">
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@Header</h5>
<button type="button" class="close" @onclick="DisplayModal" aria-label="Close">&times;</button>
</div>
<div class="modal-body">
<p>@Message</p>
</div>
<div class="modal-footer">
<button type="button" class="@Class" @onclick="Confirm">@Action</button>
<button type="button" class="btn btn-secondary" @onclick="DisplayModal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
}
<button class="@Class" @onclick="DisplayModal">@Action</button>
@code {
[Parameter]
public string Header { get; set; }
[Parameter]
public string Message { get; set; }
[Parameter]
public string Action { get; set; }
[Parameter]
public string Class { get; set; }
[Parameter]
public Action OnClick { get; set; }
bool visible = false;
protected override void OnParametersSet()
{
if (string.IsNullOrEmpty(Action))
{
Action = "Ok";
}
if (string.IsNullOrEmpty(Class))
{
Class = "btn btn-success";
}
}
private void DisplayModal()
{
visible = !visible;
StateHasChanged();
}
private void Confirm()
{
DisplayModal();
OnClick();
}
}

View File

@ -3,14 +3,12 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<div class="app-admin-modal"> <div class="app-admin-modal">
<div class="modal" style="display: block"> <div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title"><ModuleTitle /></h5> <h5 class="modal-title"><ModuleTitle /></h5>
<button type="button" class="close" @onclick="CloseModal" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" @onclick="CloseModal" aria-label="Close">&times;</button>
<span aria-hidden="true">&times;</span>
</button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<ModuleInstance /> <ModuleInstance />

View File

@ -44,6 +44,7 @@ app {
z-index: 9999; /* Sit on top */ z-index: 9999; /* Sit on top */
left: 0; left: 0;
top: 0; top: 0;
display: block;
width: 100%; /* Full width */ width: 100%; /* Full width */
height: 100%; /* Full height */ height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */ overflow: auto; /* Enable scroll if needed */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

View File

@ -44,6 +44,7 @@ app {
z-index: 9999; /* Sit on top */ z-index: 9999; /* Sit on top */
left: 0; left: 0;
top: 0; top: 0;
display: block;
width: 100%; /* Full width */ width: 100%; /* Full width */
height: 100%; /* Full height */ height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */ overflow: auto; /* Enable scroll if needed */