@using BLAIzor.Models @using BLAIzor.Services @using Microsoft.AspNetCore.Components.Authorization @inherits EditorUIComponentBase @inject ContentEditorService contentEditorService @inject NavigationManager navigation @inject NotificationService notificationService @inject DialogService dialogService @attribute [Authorize] @if (isLoading) {

Loading content groups...

} else { @foreach (var group in groups) { if (selectedGroupId == group.Id) { } else {
@group.Name
@group.Type
} } } @code { [Parameter] public int SiteInfoId { get; set; } [Parameter] public Func OnManageContentItemClicked { get; set; } private List groups = new(); private bool isLoading = true; private int? selectedGroupId = null; private async Task SelectGroup(int groupId) { selectedGroupId = groupId; var group = groups.FirstOrDefault(g => g.Id == groupId); if (group != null) { await NotifyContentEditStartedAsync(group); } } private async Task DeselectGroup() { selectedGroupId = null; StateHasChanged(); } protected override async Task OnInitializedAsync() { isLoading = true; groups = (await contentEditorService.GetContentGroupsBySiteInfoIdAsync(SiteInfoId)) .Where(g => g.SiteInfoId == SiteInfoId) .OrderByDescending(g => g.LastUpdated) .ToList(); isLoading = false; } private void EditGroup(ContentGroup group) { navigation.NavigateTo($"/content-group/{group.Id}/items"); } private async Task Rechunk(ContentGroup group) { var confirmationResult = await dialogService.Confirm("Are you sure?", "Rechunk group", new ConfirmOptions() { OkButtonText = "Rechunk", CancelButtonText = "Oops, no" }); if (confirmationResult == true) { await ReallyRechunk(group); } else { //do nothing? } } private async Task ReallyRechunk(ContentGroup group) { group.LastUpdated = DateTime.UtcNow; var siteInfo = await contentEditorService.GetSiteInfoByIdAsync(group.SiteInfoId); var result = await contentEditorService.ForceRechunkContentGroupAsync(group.Id, siteInfo.VectorCollectionName); if (result != null) { await NotifyContentUpdatedAsync(group); // This triggers the base class logic await DeselectGroup(); } } private async Task SaveGroup(ContentGroup group) { group.LastUpdated = DateTime.UtcNow; group.Version = group.Version + 1; var result = await contentEditorService.UpdateContentGroupByIdAsync(group); if (result != null) { await NotifyContentUpdatedAsync(group); // This triggers the base class logic await DeselectGroup(); } } private async Task DeleteGroup(ContentGroup group) { var confirmationResult = await dialogService.Confirm("Are you sure?", "Delete group", new ConfirmOptions() { OkButtonText = "Delete", CancelButtonText = "Oops, no" }); if (confirmationResult == true) { await ReallyDeleteGroup(group); } else { //do nothing? } } private async Task ReallyDeleteGroup(ContentGroup group) { var result = await contentEditorService.DeleteContentGroupByIdAsync(group.Id); ; groups.Remove(group); var message = NotificationHelper.CreateNotificationMessage("Group deleted", 2, "Success", "ContentGroup deleted"); ShowNotification(message); StateHasChanged(); } private async Task AddNewGroup() { var newGroup = new ContentGroup { SiteInfoId = SiteInfoId, Name = "New Group", Slug = $"group-{DateTime.UtcNow.Ticks}", Type = "manual", VectorSize = 384, EmbeddingModel = "default", CreatedAt = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, Version = 1 }; var result = await contentEditorService.CreateContentGroupAsync(newGroup); if (result != null) { var message = NotificationHelper.CreateNotificationMessage("Group created", 2, "Success", "ContentGroup created"); ShowNotification(message); groups.Insert(0, newGroup); selectedGroupId = newGroup.Id; } } private async Task ContentItemManagedCallback(string method, int itemId) { if (OnManageContentItemClicked != null) await OnManageContentItemClicked.Invoke(method, itemId); } public void ShowNotification(NotificationMessage message) { notificationService.Notify(message); } RenderFragment GetMessage() { return __builder => { Are you sure? }; } }