From 03313562d21d5db9bf6a14ebbeab80e06c883d3a Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 24 Jan 2024 02:31:56 +0100 Subject: MRU->RMU, fixes, cleanup --- .../PolicyEditorComponents/PolicyEditorModal.razor | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 MatrixUtils.Web/Shared/PolicyEditorComponents/PolicyEditorModal.razor (limited to 'MatrixUtils.Web/Shared/PolicyEditorComponents') diff --git a/MatrixUtils.Web/Shared/PolicyEditorComponents/PolicyEditorModal.razor b/MatrixUtils.Web/Shared/PolicyEditorComponents/PolicyEditorModal.razor new file mode 100644 index 0000000..4fd151d --- /dev/null +++ b/MatrixUtils.Web/Shared/PolicyEditorComponents/PolicyEditorModal.razor @@ -0,0 +1,92 @@ +@using LibMatrix.EventTypes.Spec.State.Policy +@using System.Reflection +@using ArcaneLibs.Attributes +@using ArcaneLibs.Extensions +@using LibMatrix +@using System.Collections.Frozen +@using LibMatrix.EventTypes + + @{ + var policyData = (PolicyEvent.TypedContent as PolicyRuleEventContent)!; + } + @if (string.IsNullOrWhiteSpace(PolicyEvent.EventId)) { + Policy type: + + } + + + @{ + // enumerate all properties with friendly name + var props = PolicyEvent.MappedType.GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(x => (x.GetFriendlyNameOrNull() ?? x.GetJsonPropertyNameOrNull()) is not null) + .Where(x => x.GetCustomAttribute() is null) + .ToFrozenSet(); + var propNames = props.Select(x => x.GetFriendlyNameOrNull() ?? x.GetJsonPropertyName()!).ToFrozenSet(); + } + + + + + + + + + @foreach (var prop in props) { + + + @{ + var getter = prop.GetGetMethod(); + var setter = prop.GetSetMethod(); + } + @switch (Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType) { + case Type t when t == typeof(string): + {e}"); setter?.Invoke(policyData, [e]); StateHasChanged(); })"> + break; + default: +

Unsupported type: @prop.PropertyType

+ break; + } + + } + +
PropertyValue
+ @prop.GetFriendlyName() + @if (Nullable.GetUnderlyingType(prop.PropertyType) is not null) { + * + } +
+
+
+        @PolicyEvent.ToJson(true, false)
+    
+ Cancel + Save + @* Target entity: *@ + @*
*@ + @* Reason: *@ + @* *@ +
+ +@code { + + [Parameter] + public StateEventResponse? PolicyEvent { get; set; } + + [Parameter] + public required Action OnClose { get; set; } + + [Parameter] + public required Action OnSave { get; set; } + + private static FrozenSet KnownPolicyTypes = StateEvent.KnownStateEventTypes.Where(x => x.IsAssignableTo(typeof(PolicyRuleEventContent))).ToFrozenSet(); + + private static Dictionary PolicyTypes = KnownPolicyTypes + .ToDictionary(x => x.GetCustomAttributes().First(y => !string.IsNullOrWhiteSpace(y.EventName)).EventName, x => x); + +} \ No newline at end of file -- cgit 1.5.1