From d105d1a7ec709ddb6240a286bbd7be292a9acd1c Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 21 Sep 2025 16:03:44 +0200 Subject: Various fixes --- .../PolicyListCategoryComponent.razor | 55 +++++++------ .../PolicyListEditorHeader.razor | 47 ++++++++--- .../PolicyListRowComponent.razor | 92 +++++++++++++++------- 3 files changed, 130 insertions(+), 64 deletions(-) (limited to 'MatrixUtils.Web/Pages/Rooms/PolicyListComponents') diff --git a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor index b52e03f..932e0fe 100644 --- a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor +++ b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListCategoryComponent.razor @@ -10,43 +10,45 @@ + @foreach (var name in PolicyCollection.PropertiesToDisplay!.Keys) { } - @foreach (var policy in PolicyCollection.ActivePolicies.Values.OrderBy(x => x.Policy.RawContent?["entity"]?.GetValue())) { - + }
Actions@nameActions
-
- - - @("Invalid " + PolicyCollection.Name.ToLower()) - - - - - - - - - - - @foreach (var policy in PolicyCollection.RemovedPolicies.Values) { + @if (RenderInvalidSection) { +
+ + + @("Invalid " + PolicyCollection.Name.ToLower()) + + +
State keyJson contents
+ - - + + - } - -
@policy.Policy.StateKey -
@policy.Policy.RawContent.ToJson(true, false)
-
State keyJson contents
-
+ + + @foreach (var policy in PolicyCollection.RemovedPolicies.Values) { + + @policy.Policy.StateKey + +
@policy.Policy.RawContent.ToJson(true, false)
+ + + } + + + + } @code { @@ -60,6 +62,9 @@ [Parameter] public bool RenderEventInfo { get; set; } + [Parameter] + public bool RenderInvalidSection { get; set; } = true; + protected override bool ShouldRender() { // if (PolicyCollection is null) return false; diff --git a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor index e82f17d..8585561 100644 --- a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor +++ b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListEditorHeader.razor @@ -12,14 +12,14 @@
@* *@ Create new policy + CurrentlyEditingEvent = new() { Type = "", RawContent = new() }; + return Task.CompletedTask; + })">Create new policy Create many new policies + MassCreatePolicies = true; + return Task.CompletedTask; + })">Create many new policies Refresh @@ -33,20 +33,43 @@ // _ = LoadStatesAsync(); })"> } +
+ + Render event info @code { + [Parameter] public required GenericRoom Room { get; set; } - + [Parameter] public required Func ReloadStateAsync { get; set; } + [Parameter] + public required bool RenderEventInfo { get; set; } + + [Parameter] + public required EventCallback RenderEventInfoChanged { get; set; } + private string? RoomName { get; set; } private string? RoomAlias { get; set; } private string? DraupnirShortcode { get; set; } - - private StateEventResponse? CurrentlyEditingEvent { get; set { field = value; StateHasChanged(); } } - private bool MassCreatePolicies { get; set { field = value; StateHasChanged(); } } + + private StateEventResponse? CurrentlyEditingEvent { + get; + set { + field = value; + StateHasChanged(); + } + } + + private bool MassCreatePolicies { + get; + set { + field = value; + StateHasChanged(); + } + } protected override async Task OnInitializedAsync() { await Task.WhenAll( @@ -54,12 +77,12 @@ Task.Run(async () => { RoomAlias = (await Room.GetCanonicalAliasAsync())?.Alias; }), Task.Run(async () => { RoomName = await Room.GetNameOrFallbackAsync(); }) ); - + StateHasChanged(); } private async Task UpdatePolicyAsync(StateEventResponse evt) { - Console.WriteLine("UpdatePolicyAsync in PolicyListEditorHeader not yet implementeD!"); + Console.WriteLine("UpdatePolicyAsync in PolicyListEditorHeader not yet implemented!"); } } \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor index 9ac5077..cd432c9 100644 --- a/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor +++ b/MatrixUtils.Web/Pages/Rooms/PolicyListComponents/PolicyListRowComponent.razor @@ -1,4 +1,5 @@ @using System.Reflection +@using ArcaneLibs.Extensions @using LibMatrix @using LibMatrix.EventTypes.Spec.State.Policy @using LibMatrix.RoomTypes @@ -6,30 +7,6 @@ @if (_isInitialized && IsVisible) { - @foreach (var prop in PolicyCollection.PropertiesToDisplay.Values) { - if (prop.Name == "Entity") { - - @TruncateMxid(TypedContent.Entity) - @foreach (var dup in PolicyInfo.DuplicatedBy) { -
- Duplicated by @dup.FriendlyTypeName.ToLower() @TruncateMxid(dup.RawContent["entity"]?.GetValue()) - } - @foreach (var dup in PolicyInfo.MadeRedundantBy) { -
- Also matched by @dup.FriendlyTypeName.ToLower() @TruncateMxid(dup.RawContent["entity"]?.GetValue()) - } - @if (RenderEventInfo) { -
-
-                            @PolicyInfo.Policy.Type/@PolicyInfo.Policy.StateKey by @PolicyInfo.Policy.Sender at @PolicyInfo.Policy.OriginServerTs 
-                        
- } - - } - else { - @prop.GetGetMethod()?.Invoke(TypedContent, null) - } - }
@* @if (PowerLevels.UserHasStatePermission(Homeserver.WhoAmI.UserId, Policy.Type)) { *@ @@ -41,7 +18,7 @@ Remove @if (Policy.IsLegacyType) { - Update policy type + Update type } @if (TypedContent.Entity?.StartsWith("@*:", StringComparison.Ordinal) == true) { @@ -66,6 +43,30 @@ }
+ @foreach (var prop in PolicyCollection.PropertiesToDisplay.Values) { + if (prop.Name == "Entity") { + + @TruncateMxid(TypedContent.Entity) + @foreach (var dup in PolicyInfo.DuplicatedBy) { +
+ Duplicated by @dup.FriendlyTypeName.ToLower() @TruncateMxid(dup.RawContent["entity"]?.GetValue()) + } + @foreach (var dup in PolicyInfo.MadeRedundantBy) { +
+ Also matched by @dup.FriendlyTypeName.ToLower() @TruncateMxid(dup.RawContent["entity"]?.GetValue()) + } + @if (RenderEventInfo) { +
+
+                            @PolicyInfo.Policy.Type/@PolicyInfo.Policy.StateKey by @PolicyInfo.Policy.Sender at @PolicyInfo.Policy.OriginServerTimestamp
+                        
+ } + + } + else { + @prop.GetGetMethod()?.Invoke(TypedContent, null) + } + } @if (IsEditing) { @@ -95,6 +96,9 @@ [Parameter] public bool RenderEventInfo { get; set; } + [Parameter] + public required Action PolicyCollectionStateHasChanged { get; set; } + private StateEventResponse Policy => PolicyInfo.Policy; private bool IsEditing { @@ -142,8 +146,42 @@ private async Task RemovePolicyAsync() { await Room.SendStateEventAsync(Policy.Type, Policy.StateKey, new { }); - IsVisible = false; - StateHasChanged(); + bool shouldUpdateVisibility = true; + PolicyCollection.ActivePolicies.Remove((Policy.Type, Policy.StateKey)); + PolicyCollection.RemovedPolicies.Add((Policy.Type, Policy.StateKey), PolicyInfo); + if (PolicyInfo.DuplicatedBy.Count > 0) { + foreach (var evt in PolicyInfo.DuplicatedBy) { + var matchingEntry = PolicyCollection.ActivePolicies + .FirstOrDefault(x => StateEvent.Equals(x.Value.Policy, evt)).Value; + var removals = matchingEntry.DuplicatedBy.RemoveAll(x => StateEvent.Equals(x, Policy)); + Console.WriteLine($"Removed {removals} duplicates from {evt.EventId}, matching entry: {matchingEntry.ToJson()}"); + if (PolicyCollection.ViewType == PolicyList.PolicyCollection.SpecialViewType.Duplicates && matchingEntry.DuplicatedBy.Count == 0) { + PolicyCollection.ActivePolicies.Remove((matchingEntry.Policy.Type, matchingEntry.Policy.StateKey)); + PolicyCollection.RemovedPolicies.Add((matchingEntry.Policy.Type, matchingEntry.Policy.StateKey), matchingEntry); + Console.WriteLine($"Also removed {matchingEntry.Policy.EventId} as it is now redundant"); + } + } + + PolicyCollectionStateHasChanged(); + shouldUpdateVisibility = false; + } + + if (PolicyInfo.MadeRedundantBy.Count > 0) { + foreach (var evt in PolicyInfo.MadeRedundantBy) { + var matchingEntry = PolicyCollection.ActivePolicies + .FirstOrDefault(x => StateEvent.Equals(x.Value.Policy, evt)).Value; + var removals = matchingEntry.MadeRedundantBy.RemoveAll(x => StateEvent.Equals(x, Policy)); + Console.WriteLine($"Removed {removals} redundants from {evt.EventId}, matching entry: {matchingEntry.ToJson()}"); + } + + PolicyCollectionStateHasChanged(); + shouldUpdateVisibility = false; + } + + if (shouldUpdateVisibility) { + IsVisible = false; + StateHasChanged(); + } // PolicyEventsByType[policyEvent.MappedType].Remove(policyEvent); // await LoadStatesAsync(); } -- cgit 1.5.1