Promptauswahl + Undo/Redo in EditVM
This commit is contained in:
@@ -104,6 +104,13 @@ namespace BeWo.ViewModel.ListViewModel
|
||||
public ICommand UndoAiActionCommand { get; set; }
|
||||
public ICommand RedoAiActionCommand { get; set; }
|
||||
|
||||
private List<string> _EditAiActionHistory;
|
||||
private int _EditAiActionHistoryIndex;
|
||||
|
||||
public ICommand OpenEditAiPromptSelectionCommand { get; set; }
|
||||
public ICommand UndoEditAiActionCommand { get; set; }
|
||||
public ICommand RedoEditAiActionCommand { get; set; }
|
||||
|
||||
public IList<ServiceRecordVM> VisibleSerivceRecords { get; set; }
|
||||
|
||||
public ServiceRecordListVM(
|
||||
@@ -186,6 +193,21 @@ namespace BeWo.ViewModel.ListViewModel
|
||||
UndoAiActionCommand = new DelegateCommand(UndoAiAction);
|
||||
RedoAiActionCommand = new DelegateCommand(RedoAiAction);
|
||||
|
||||
var vm_edit_doku = new AiPromptbausteinSelectionComplexViewModel(AiActionType.ServiceRecordDocumentation);
|
||||
|
||||
vm_edit_doku.PromptAccepted += EditPromptAccepted;
|
||||
|
||||
OpenEditAiPromptSelectionCommand = new DelegateCommand(() =>
|
||||
{
|
||||
_EditAiActionHistory = new List<string>();
|
||||
_EditAiActionHistory.Add(AktuellerEditDokutext);
|
||||
_EditAiActionHistoryIndex = 0;
|
||||
BeWoApp.MainControl.WindowService.Show(vm_edit_doku);
|
||||
}, () => !string.IsNullOrWhiteSpace(AktuellerEditDokutext));
|
||||
|
||||
UndoEditAiActionCommand = new DelegateCommand(UndoEditAiAction);
|
||||
RedoEditAiActionCommand = new DelegateCommand(RedoEditAiAction);
|
||||
|
||||
_AiActionHistory = new List<string>();
|
||||
_AiActionHistory.Add(AktuellerDokutext);
|
||||
_AiActionHistoryIndex = 0;
|
||||
@@ -202,11 +224,24 @@ namespace BeWo.ViewModel.ListViewModel
|
||||
FirePropertyChanged(nameof(IsUndoButtonVisible));
|
||||
}
|
||||
}
|
||||
public string AktuellerEditDokutext
|
||||
{
|
||||
get => EditVM.Notice;
|
||||
set
|
||||
{
|
||||
EditVM.Notice = value;
|
||||
FirePropertyChanged(nameof(IsEditUndoButtonVisible));
|
||||
FirePropertyChanged(nameof(IsEditRedoButtonVisible));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAiButtonVisible => SelectedCustomerNode is object;
|
||||
public bool IsUndoButtonVisible => _AiActionHistoryIndex > 0;
|
||||
public bool IsRedoButtonVisible => _AiActionHistoryIndex < _AiActionHistory.Count - 1;
|
||||
|
||||
public bool IsEditUndoButtonVisible => _AiActionHistoryIndex > 0;
|
||||
public bool IsEditRedoButtonVisible => _AiActionHistoryIndex < _AiActionHistory.Count - 1;
|
||||
|
||||
private void PromptAccepted(object sender, AiPromptbausteinPromptVM prompt)
|
||||
{
|
||||
if (prompt is null)
|
||||
@@ -271,7 +306,7 @@ namespace BeWo.ViewModel.ListViewModel
|
||||
_AiActionHistory.RemoveRange(idx + 1, count - idx - 1);
|
||||
}
|
||||
|
||||
if(AktuellerDokutext != _AiActionHistory[_AiActionHistoryIndex])
|
||||
if (AktuellerDokutext != _AiActionHistory[_AiActionHistoryIndex])
|
||||
{
|
||||
_AiActionHistory.Add(AktuellerDokutext);
|
||||
_AiActionHistoryIndex++;
|
||||
@@ -314,6 +349,113 @@ namespace BeWo.ViewModel.ListViewModel
|
||||
);
|
||||
}
|
||||
|
||||
private void EditPromptAccepted(object sender, AiPromptbausteinPromptVM prompt)
|
||||
{
|
||||
if (prompt is null)
|
||||
throw new NotImplementedException();
|
||||
|
||||
// 1. Information aufbereiten
|
||||
// 1.1 Prompt
|
||||
var prompt_oid = prompt.DataContract.Oid.Value;
|
||||
var prompt_version = prompt.DataContract.Version;
|
||||
|
||||
// 1.2 Hilfeplan
|
||||
var support_concept = SelectedCustomerNode.SupportConceptTreeNodeDC.SupportConcept;
|
||||
var support_concept_oid = support_concept.SupportConceptOid;
|
||||
var support_concept_version = support_concept.SupportConceptVersion;
|
||||
|
||||
// 1.3 Aktuelles Doku Feld
|
||||
var doku_feld = AktuellerEditDokutext;
|
||||
|
||||
// 1.4 Sichtbaren Zeiterfassungseinträge
|
||||
var service_records = CurrentVisibleVMs;
|
||||
var sr_refs = service_records.Select(x => new BeWoRefDC(x.DataContract.ServiceRecordOid.Value, x.DataContract.ServiceRecordVersion));
|
||||
|
||||
// 1.5 Costbearer
|
||||
var costbearer = SelectedCustomerNode.SupportConceptTreeNodeDC.CostBearer;
|
||||
var cb_oid = costbearer.CostBearerOid.Value;
|
||||
var cb_ver = costbearer.CostBearerVersion;
|
||||
|
||||
// Service Aufruf
|
||||
var req = new AiFunctionDocRequest()
|
||||
{
|
||||
AiPromptbausteinPrompt = new BeWoRefDC(prompt_oid, prompt_version),
|
||||
SupportConcept = new BeWoRefDC(support_concept_oid, support_concept_version),
|
||||
ServiceRecords = sr_refs,
|
||||
CostBearer = new BeWoRefDC(cb_oid, cb_ver),
|
||||
Dokumentation = doku_feld,
|
||||
};
|
||||
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.ExecuteAiFunctionServiceRecordDocumentation(req),
|
||||
callback =>
|
||||
{
|
||||
var viewModel = new AiPromptbausteinActionResultViewModel();
|
||||
|
||||
viewModel.Result = callback.Result;
|
||||
|
||||
viewModel.Accept_Button_Clicked += (s, e) =>
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine("AI Antwort:");
|
||||
sb.AppendLine(viewModel.Result);
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("Original:");
|
||||
sb.AppendLine(AktuellerEditDokutext);
|
||||
|
||||
var str = sb.ToString();
|
||||
var idx = _EditAiActionHistoryIndex;
|
||||
var count = _EditAiActionHistory.Count;
|
||||
|
||||
if (count - 1 > idx)
|
||||
{
|
||||
_EditAiActionHistory.RemoveRange(idx + 1, count - idx - 1);
|
||||
}
|
||||
|
||||
if (AktuellerEditDokutext != _EditAiActionHistory[_EditAiActionHistoryIndex])
|
||||
{
|
||||
_EditAiActionHistory.Add(AktuellerEditDokutext);
|
||||
_EditAiActionHistoryIndex++;
|
||||
}
|
||||
|
||||
_EditAiActionHistory.Add(str);
|
||||
_EditAiActionHistoryIndex++;
|
||||
|
||||
AktuellerEditDokutext = str;
|
||||
};
|
||||
viewModel.Replace_Button_Clicked += (s, e) =>
|
||||
{
|
||||
var str = viewModel.Result;
|
||||
var idx = _EditAiActionHistoryIndex;
|
||||
var count = _EditAiActionHistory.Count;
|
||||
|
||||
if (count - 1 > idx)
|
||||
{
|
||||
_EditAiActionHistory.RemoveRange(idx + 1, count - idx - 1);
|
||||
}
|
||||
|
||||
if (AktuellerEditDokutext != _EditAiActionHistory[_EditAiActionHistoryIndex])
|
||||
{
|
||||
_EditAiActionHistory.Add(AktuellerEditDokutext);
|
||||
_EditAiActionHistoryIndex++;
|
||||
}
|
||||
|
||||
_EditAiActionHistory.Add(str);
|
||||
_EditAiActionHistoryIndex++;
|
||||
|
||||
AktuellerEditDokutext = str;
|
||||
};
|
||||
viewModel.Retry_Button_Clicked += (s, e) =>
|
||||
{
|
||||
PromptAccepted(sender, prompt);
|
||||
};
|
||||
|
||||
BeWoApp.MainControl.WindowService.Show(viewModel);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public Dictionary<TableID, long[]> GetVisibleInformationReferences(IEnumerable<ServiceRecordVM> selected_records)
|
||||
{
|
||||
var current = SelectedCustomerNode;
|
||||
@@ -768,6 +910,24 @@ namespace BeWo.ViewModel.ListViewModel
|
||||
_AiActionHistoryIndex++;
|
||||
AktuellerDokutext = _AiActionHistory[_AiActionHistoryIndex];
|
||||
}
|
||||
|
||||
public void UndoEditAiAction()
|
||||
{
|
||||
if (_EditAiActionHistoryIndex <= 0)
|
||||
return;
|
||||
|
||||
_EditAiActionHistoryIndex--;
|
||||
AktuellerEditDokutext = _EditAiActionHistory[_EditAiActionHistoryIndex];
|
||||
}
|
||||
|
||||
public void RedoEditAiAction()
|
||||
{
|
||||
if (_EditAiActionHistoryIndex >= _EditAiActionHistory.Count - 1)
|
||||
return;
|
||||
|
||||
_EditAiActionHistoryIndex++;
|
||||
AktuellerEditDokutext = _EditAiActionHistory[_EditAiActionHistoryIndex];
|
||||
}
|
||||
|
||||
public List<ServiceRecordVM> CreateFromPrototype()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user