Started creating generated admin page
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public sealed class AdminBoldAttribute : Attribute;
|
||||
@@ -6,7 +6,6 @@ public interface IAdminPropertyGenerator {
|
||||
IAdminPropertyGenerator Editable(bool editable);
|
||||
IAdminPropertyGenerator DisplayValueWhileEditing(bool display);
|
||||
IAdminPropertyGenerator DisplayInListing(bool display = true);
|
||||
IAdminPropertyGenerator Bold(bool isBold = true);
|
||||
IAdminPropertyGenerator Ignore(bool ignore = true);
|
||||
IAdminPropertyGenerator Generated(bool generated = true);
|
||||
|
||||
|
||||
@@ -35,11 +35,6 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Bold(bool isBold = true) {
|
||||
_property.Bold = isBold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Ignore(bool ignore = false) {
|
||||
_property.Ignore = ignore;
|
||||
return this;
|
||||
@@ -73,7 +68,6 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
|
||||
public void ApplyConfigurationFromAttributes<T>(AdminPageGenerator<T> pageGenerator, object[] attributes, PropertyInfo property) {
|
||||
if (attributes.Any(a => a is KeyAttribute)) {
|
||||
pageGenerator.Page.DefaultSortPropertyName = property.Name;
|
||||
Bold();
|
||||
Editable(false);
|
||||
}
|
||||
|
||||
@@ -82,9 +76,6 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
|
||||
|
||||
if (attributes.Any(a => a is AdminUneditableAttribute))
|
||||
Editable(false);
|
||||
|
||||
if (attributes.Any(a => a is AdminBoldAttribute))
|
||||
Bold();
|
||||
|
||||
if (attributes.Any(a => a is AdminIgnoreAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminIgnoreAttribute) as AdminIgnoreAttribute;
|
||||
|
||||
@@ -13,7 +13,6 @@ public sealed class AdminPageProperty {
|
||||
public bool Editable { get; set; } = true;
|
||||
public bool EditDisplayValue { get; set; } = true;
|
||||
public bool Generated { get; set; }
|
||||
public bool Bold { get; set; }
|
||||
public bool Ignore { get; set; }
|
||||
[JsonIgnore]
|
||||
public Type Type { get; set; }
|
||||
|
||||
114
src/HopFrame.Web/Pages/Administration/AdminPageList.razor
Normal file
114
src/HopFrame.Web/Pages/Administration/AdminPageList.razor
Normal file
@@ -0,0 +1,114 @@
|
||||
@page "/administration/{url}"
|
||||
@layout AdminLayout
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@using System.ComponentModel
|
||||
@using BlazorStrap
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using HopFrame.Web.Admin.Models
|
||||
@using HopFrame.Web.Admin.Providers
|
||||
@using HopFrame.Web.Pages.Administration.Layout
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using HopFrame.Web.Components.Administration
|
||||
@using BlazorStrap.V5
|
||||
@using HopFrame.Web.Components
|
||||
|
||||
<PageTitle>@_pageData.Title</PageTitle>
|
||||
<AuthorizedView Permission="@_pageData.Permissions.View" RedirectIfUnauthorized="administration/login" />
|
||||
|
||||
<div class="title">
|
||||
<h3>
|
||||
@_pageData.Title administration
|
||||
<span class="reload" @onclick="Reload">
|
||||
<HopIconDisplay Type="HopIconDisplay.HopIcon.Reload"/>
|
||||
</span>
|
||||
</h3>
|
||||
|
||||
<div class="d-flex" role="search" id="search">
|
||||
<input class="form-control me-2 input-dark" type="search" placeholder="Search" aria-label="Search" @oninput="TriggerSearch">
|
||||
</div>
|
||||
<AuthorizedView Permission="@Security.AdminPermissions.AddGroup">
|
||||
<BSButton IsSubmit="false" Color="BSColor.Success" Target="add-user">Add Group</BSButton>
|
||||
</AuthorizedView>
|
||||
</div>
|
||||
|
||||
<BSTable IsStriped="true" IsHoverable="true" IsDark="true" Color="BSColor.Dark">
|
||||
<BSTHead>
|
||||
<BSTR>
|
||||
@foreach (var prop in GetListingProperties()) {
|
||||
<BSTD>
|
||||
@if (prop.Sortable) {
|
||||
<span class="sorter" @onclick="() => OrderBy(prop.Name)">@prop.DisplayName</span>
|
||||
@if (_currentSortProperty == prop.Name) {
|
||||
<HopIconDisplay Type="_currentSortDirection == ListSortDirection.Descending ? HopIconDisplay.HopIcon.ArrowDown : HopIconDisplay.HopIcon.ArrowUp"/>
|
||||
}
|
||||
}
|
||||
else {
|
||||
@prop.DisplayName
|
||||
}
|
||||
</BSTD>
|
||||
}
|
||||
</BSTR>
|
||||
</BSTHead>
|
||||
|
||||
<BSTBody>
|
||||
|
||||
</BSTBody>
|
||||
</BSTable>
|
||||
|
||||
@inject IAdminPagesProvider Pages
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string Url { get; set; }
|
||||
|
||||
private AdminPage _pageData;
|
||||
|
||||
private string _currentSortProperty;
|
||||
private ListSortDirection _currentSortDirection;
|
||||
private DateTime _lastSearch;
|
||||
|
||||
protected override void OnInitialized() {
|
||||
_pageData = Pages.LoadAdminPage(Url);
|
||||
|
||||
_currentSortProperty = _pageData.DefaultSortPropertyName;
|
||||
_currentSortDirection = _pageData.DefaultSortDirection;
|
||||
}
|
||||
|
||||
private IList<AdminPageProperty> GetListingProperties() {
|
||||
return _pageData.Properties
|
||||
.Where(p => p.Ignore == false)
|
||||
.Where(p => p.DisplayInListing)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void Reload() {
|
||||
|
||||
}
|
||||
|
||||
private void OrderBy(string property, bool changeDir = true) {
|
||||
if (_currentSortProperty == property && changeDir)
|
||||
_currentSortDirection = (ListSortDirection)(((int)_currentSortDirection + 1) % 2);
|
||||
if (_currentSortProperty != property)
|
||||
_currentSortDirection = ListSortDirection.Ascending;
|
||||
|
||||
//TODO: Handle ordering
|
||||
|
||||
_currentSortProperty = property;
|
||||
}
|
||||
|
||||
private void TriggerSearch(ChangeEventArgs e) {
|
||||
var search = ((string)e.Value)?.Trim();
|
||||
Search(search);
|
||||
}
|
||||
|
||||
private async void Search(string search) {
|
||||
_lastSearch = DateTime.Now;
|
||||
await Task.Delay(500);
|
||||
var timeSinceLastKeyPress = DateTime.Now - _lastSearch;
|
||||
if (timeSinceLastKeyPress < TimeSpan.FromMilliseconds(500)) return;
|
||||
|
||||
//TODO: Handle searching
|
||||
Console.WriteLine(search);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
.title {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#search {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
th, h3, .sorter {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.reload, .sorter {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
Reference in New Issue
Block a user