Conversation List Reorder
This commit is contained in:
@@ -13,7 +13,7 @@ namespace BeWo.Converter
|
||||
if (value is null)
|
||||
return null;
|
||||
|
||||
var t = ((DelegateCommand)value).CanExecute(null);
|
||||
//var t = ((DelegateCommand)value).CanExecute(null);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@
|
||||
x:Name="listbox_messages"
|
||||
Grid.Row="1"
|
||||
Background="Transparent"
|
||||
ItemsSource="{Binding SelectedVM.Messages.VMList, Converter={StaticResource TestDebugConverter}}">
|
||||
ItemsSource="{Binding SelectedVM.Messages.VMList}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:Name="messages_datatemplate" DataType="viewmodel:AiConversationMessageVM">
|
||||
<TextBlock Text="{Binding Json}" />
|
||||
|
||||
@@ -933,8 +933,6 @@ namespace BeWo.ViewModel
|
||||
{
|
||||
var list = ServiceFacade.DoAiEnhancedServiceSnyc(s => s.GetAiConversations(actionType, reference_oid));
|
||||
|
||||
list.Reverse();
|
||||
|
||||
return new AiConversationListVM(list);
|
||||
}
|
||||
|
||||
|
||||
@@ -307,6 +307,8 @@ namespace BeWo.ViewModel.View.AI
|
||||
{
|
||||
MessageInput = string.Empty;
|
||||
|
||||
ReloadConversations(ListVM.VMList);
|
||||
|
||||
EndSending();
|
||||
|
||||
SendNewMessageSuccess?.Invoke(this, EventArgs.Empty);
|
||||
@@ -357,7 +359,21 @@ namespace BeWo.ViewModel.View.AI
|
||||
|
||||
var list = VMFactory.CreateAiConversationListVM(ui_context, reference);
|
||||
|
||||
ListVM.VMList.MakeEqualTo(list.VMList);
|
||||
ReloadConversations(list.VMList);
|
||||
}
|
||||
private void ReloadConversations(IEnumerable<AiConversationVM> aiConversations)
|
||||
{
|
||||
if(aiConversations is null)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(aiConversations));
|
||||
}
|
||||
|
||||
var sorted = aiConversations.OrderByDescending(vm => vm.Updated).ToList();
|
||||
|
||||
var t0 = ListVM.SelectedVM;
|
||||
ListVM.VMList.UpdateBy(sorted);
|
||||
ListVM.SelectedVM = t0;
|
||||
ListVM.VMList.ResetBindings();
|
||||
}
|
||||
|
||||
private void OpenSetting()
|
||||
@@ -540,6 +556,8 @@ namespace BeWo.ViewModel.View.AI
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.ExecuteAiConversationWithPrompt(cb.Oid.Value, ViewContext, prompt.DataContract.Oid.Value),
|
||||
cb2 =>
|
||||
{
|
||||
vm.Updated = DateTime.Now;
|
||||
|
||||
FinishSending();
|
||||
|
||||
ServiceFacade.EndManuelWaiting();
|
||||
@@ -594,8 +612,12 @@ namespace BeWo.ViewModel.View.AI
|
||||
|
||||
private void ExecuteChain(AiPromptbausteinRoutineVM routine, int step, Action<Exception> error)
|
||||
{
|
||||
var conv = ListVM.SelectedVM;
|
||||
|
||||
if (step >= routine.Steps.Count)
|
||||
{
|
||||
conv.Updated = DateTime.Now;
|
||||
|
||||
FinishSending();
|
||||
|
||||
ServiceFacade.EndManuelWaiting();
|
||||
@@ -603,8 +625,6 @@ namespace BeWo.ViewModel.View.AI
|
||||
return;
|
||||
}
|
||||
|
||||
var conv = ListVM.SelectedVM;
|
||||
|
||||
var custom_viewContext = new AiViewContextDC
|
||||
{
|
||||
References = ViewContext.References,
|
||||
|
||||
@@ -272,8 +272,6 @@ namespace BeWo.Service.Plugins
|
||||
var toadd = request_models.Except(current_prompts, comparer);
|
||||
var toremove = current_prompts_actives.Except(request_models, comparer);
|
||||
var toreadd = current_prompts_deactives.Intersect(request_models, comparer);
|
||||
//var tocheckupdate = request_models.Union(current_prompts, comparer);
|
||||
//var toupdate = tocheckupdate.;
|
||||
|
||||
foreach (var a in current_prompts)
|
||||
{
|
||||
|
||||
@@ -66,6 +66,39 @@ namespace BS.Shared.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateBy<T>(this IList<T> a_list, IList<T> b_list)
|
||||
{
|
||||
// Elemente entfernen, die in der Zielliste nicht mehr vorkommen.
|
||||
// Rückwärts iterieren, damit RemoveAt die noch zu prüfenden Indizes nicht verschiebt.
|
||||
for (int i = a_list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (!b_list.Contains(a_list[i]))
|
||||
a_list.RemoveAt(i);
|
||||
}
|
||||
|
||||
// Reihenfolge angleichen und fehlende Elemente einfügen.
|
||||
// Bewusst über Insert/RemoveAt statt über den Indexer (a_list[i] = ...),
|
||||
// da BindingList<T> beim Indexer nur ItemChanged meldet und WPF die
|
||||
// ListView dann nicht neu anordnet. Insert/RemoveAt melden ItemAdded/ItemDeleted.
|
||||
for (int i = 0; i < b_list.Count; i++)
|
||||
{
|
||||
var item = b_list[i];
|
||||
|
||||
if (i < a_list.Count && a_list[i].Equals(item))
|
||||
continue;
|
||||
|
||||
var currentIndex = a_list.IndexOf(item);
|
||||
if (currentIndex >= 0)
|
||||
a_list.RemoveAt(currentIndex);
|
||||
|
||||
a_list.Insert(i, item);
|
||||
}
|
||||
|
||||
// Eventuelle überzählige Elemente am Ende entfernen.
|
||||
while (a_list.Count > b_list.Count)
|
||||
a_list.RemoveAt(a_list.Count - 1);
|
||||
}
|
||||
|
||||
public static void RemoveRange<T>(this IList<T> pList, IEnumerable<T> pToRemove)
|
||||
{
|
||||
foreach (T iItem in pToRemove.ToList())
|
||||
|
||||
Reference in New Issue
Block a user