Verwaltung2 update

This commit is contained in:
2025-12-12 14:15:58 +01:00
parent a655219996
commit 49492a27ed
22 changed files with 534 additions and 189 deletions

View File

@@ -1,6 +1,8 @@
using BeWo.Services;
using BeWo.ServiceProxy;
using BeWo.Services;
using BeWo.ViewModel.ListViewModel;
using BS.Shared;
using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.Extensions.CustomInterfaces;
using System;
using System.Collections.Generic;
@@ -24,7 +26,7 @@ namespace BeWo.ViewModel.View.Administration
}
Func<bool> canAddPrompt = () => SelectedNode.IsOrdner() || SelectedNode.IsKette();
Func<bool> canAddOrdner = () => SelectedNode.IsOrdner();
Func<bool> canAddOrdner = () => SelectedNode.IsOrdner() || true;
Func<bool> canAddKette = () => SelectedNode.IsOrdner() && false;
Func<bool> canEdit = () => SelectedNode is object;
Func<bool> canCopy = () => SelectedNode.IsKette() || SelectedNode.IsOrdner();
@@ -81,9 +83,43 @@ namespace BeWo.ViewModel.View.Administration
public void SaveVMList()
{
// BFS -> 1. Sobald Knoten gefunden wird mit IsNew=true: Teilbaum als neu markieren
if (!IsDirty)
return;
// DFS -> 1. Sobald Knoten gefunden wird mit IsNew=true: Teilbaum als neu markieren
// 2. Sobald Knoten gefunden wird mit IsNew=false && IsDirty=true: Knoten als update markieren
// 3. Checken, welche Knoten gelöscht wurden
var toadd = new List<AiPromptbausteinTreeVM>();
var toupdate = new List<AiPromptbausteinTreeVM>();
DFS_Search_AddUpdate(ListVM, ref toadd, ref toupdate);
var todelete = new List<AiPromptbausteinTreeDC>();
DFS_Search_Delete(ListVM, ref todelete);
var toadd_dcs = toadd.Select(x => x.CommitToDataContract());
var toupdate_dcs = toupdate.Select(x => x.CommitToDataContract());
var actions = new List<Action<IAiEnhancedService>>();
if (toadd_dcs.Any())
actions.Add(x => x.CreateAiPromptbausteineTree(toadd_dcs.ToList()));
if (toupdate_dcs.Any())
actions.Add(x => x.UpdateAiPromptbausteineTree(toupdate_dcs.ToList()));
if (todelete.Any())
actions.Add(x => x.DeleteAiPromptbausteineTree(todelete.ToDictionary(x1 => x1.Oid.Value, x2 => x2.Version.Value)));
ServiceFacade.DoMultipleAiEnhancedServicesAsync(actions, () =>
{
ReloadVMList();
});
}
internal void ReloadVMList()
{
VMFactory.CreateAiPromptbausteinTreeListAsync(vm => UpdateVMList(vm));
}
public void UpdateVMList(AiPromptbausteinTreeListVM new_list)
{
@@ -165,5 +201,40 @@ namespace BeWo.ViewModel.View.Administration
return false;
}
private void DFS_Search_AddUpdate(AiPromptbausteinTreeListVM search, ref List<AiPromptbausteinTreeVM> toAdd, ref List<AiPromptbausteinTreeVM> toUpdate)
{
foreach (var node in search.VMList)
{
if (node.IsNew)
{
toAdd.Add(node);
}
else
{
if (node.IsDirty)
toUpdate.Add(node);
if (node.HasChildren)
DFS_Search_AddUpdate(node.Children, ref toAdd, ref toUpdate);
}
}
}
private void DFS_Search_Delete(AiPromptbausteinTreeListVM search, ref List<AiPromptbausteinTreeDC> toDelete)
{
foreach(var node_dc in search.DCBackup)
{
if (search.VMList.FirstOrDefault(vm => vm.DataContract == node_dc) is AiPromptbausteinTreeVM node_vm)
{
if (node_vm.Children.DCBackup is object && node_vm.Children.DCBackup.Count > 0)
DFS_Search_Delete(node_vm.Children, ref toDelete);
}
else
{
toDelete.Add(node_dc);
}
}
}
}
}