modified all admin UIs to position action buttons on the left side of grids and implemented ActionDialog throughout rather than dedicated delete components

This commit is contained in:
Shaun Walker
2019-11-04 23:29:35 -05:00
parent 156f5b5f94
commit ab564f7244
32 changed files with 737 additions and 732 deletions

View File

@ -1,94 +0,0 @@
@namespace Oqtane.Modules.Admin.Roles
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject IRoleService RoleService
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@name" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Description: </label>
</td>
<td>
<textarea class="form-control" @bind="@description" rows="5" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Auto Assigned? </label>
</td>
<td>
<select class="form-control" @bind="@isautoassigned" readonly>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">System Role? </label>
</td>
<td>
<select class="form-control" @bind="@issystem" readonly>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="DeleteRole">Delete</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int roleid;
string name = "";
string description = "";
string isautoassigned = "False";
string issystem = "False";
protected override async Task OnInitializedAsync()
{
try
{
roleid = Int32.Parse(PageState.QueryString["id"]);
Role role = await RoleService.GetRoleAsync(roleid);
if (role != null)
{
name = role.Name;
description = role.Description;
isautoassigned = role.IsAutoAssigned.ToString();
issystem = role.IsSystem.ToString();
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", roleid, ex.Message);
AddModuleMessage("Error Loading Role", MessageType.Error);
}
}
private async Task DeleteRole()
{
try
{
await RoleService.DeleteRoleAsync(roleid);
await logger.LogInformation("Role Deleted {RoleId}", roleid);
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Role {RoleId} {Error}", roleid, ex.Message);
AddModuleMessage("Error Deleting Role", MessageType.Error);
}
}
}

View File

@ -8,18 +8,18 @@
}
else
{
<ActionLink Action="Add" Text="Add Role" Style="float: right; margin: 10px;" />
<ActionLink Action="Add" Text="Add Role" />
<Pager Items="@Roles">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Name</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</Header>
<Row>
<td>@context.Name</td>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.RoleId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + context.RoleId.ToString())" Class="btn btn-danger" /></td>
<td><ActionDialog Header="Delete Role" Message="@("Are You Sure You Wish To Delete The " + context.Name + " Role?")" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteRole(context))" /></td>
<td>@context.Name</td>
</Row>
</Pager>
}
@ -29,8 +29,23 @@ else
List<Role> Roles;
protected override async Task OnInitializedAsync()
protected override async Task OnParametersSetAsync()
{
Roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
}
private async Task DeleteRole(Role Role)
{
try
{
await RoleService.DeleteRoleAsync(Role.RoleId);
await logger.LogInformation("Role Deleted {Role}", Role);
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Role {Role} {Error}", Role, ex.Message);
AddModuleMessage("Error Deleting Role", MessageType.Error);
}
}
}