200 lines
6.4 KiB
C#
200 lines
6.4 KiB
C#
using BeWo.ServiceProxy;
|
|
using BeWo.View.Detail.AI;
|
|
using BeWo.ViewModel;
|
|
using BeWo.ViewModel.View.AI;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts.Feature.AI;
|
|
using DevExpress.Mvvm;
|
|
using DevExpress.Pdf.Native.BouncyCastle.Asn1.BC;
|
|
using DevExpress.Web.Internal.XmlProcessor;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace BeWo.View.Controls.AI
|
|
{
|
|
public enum AiConversationButtonState
|
|
{
|
|
Hidden,
|
|
Normal,
|
|
Loading,
|
|
Warning,
|
|
Disabled
|
|
}
|
|
|
|
/// <summary>
|
|
/// Interaktionslogik für AIConversationButton.xaml
|
|
/// </summary>
|
|
public partial class AiConversationButton : UserControl
|
|
{
|
|
public static readonly DependencyProperty StateProperty =
|
|
DependencyProperty.Register("State", typeof(AiConversationButtonState), typeof(AiConversationButton), new PropertyMetadata(AiConversationButtonState.Normal, OnStateChanged));
|
|
|
|
public static readonly DependencyProperty ActionTypeProperty =
|
|
DependencyProperty.Register("ActionType", typeof(AiActionType), typeof(AiConversationButton), new PropertyMetadata(AiActionType.ServiceRecord, OnActionTypeChanged));
|
|
|
|
|
|
public event RoutedEventHandler OpenAiWindowClick;
|
|
|
|
public event EventHandler<AiPromptbausteinPromptVM> PromptAccepted;
|
|
|
|
public AiConversationButton()
|
|
{
|
|
InitializeComponent();
|
|
|
|
UpdateState();
|
|
}
|
|
|
|
public AiConversationButtonState State
|
|
{
|
|
get { return (AiConversationButtonState)GetValue(StateProperty); }
|
|
set { SetValue(StateProperty, value); }
|
|
}
|
|
public AiActionType ActionType
|
|
{
|
|
get { return (AiActionType)GetValue(ActionTypeProperty); }
|
|
set { SetValue(ActionTypeProperty, value); }
|
|
}
|
|
|
|
public AiPromptbausteinSelectionComplexViewModel AllPromptsViewModel { get; set; }
|
|
|
|
public ICommand AiPromptOpenAllCommand { get; set; }
|
|
public ICommand AiPromptOpenFavoriteCommand { get; set; }
|
|
|
|
public string Tooltip { get; set; }
|
|
public bool IsButtonEnabled { get; set; }
|
|
public bool IsButton2Enabled { get; set; }
|
|
public bool IsButtonVisible { get; set; }
|
|
public bool IsButton2Visible { get; set; }
|
|
public bool IsWarningSignVisible { get; set; }
|
|
|
|
public void AiPromptOpenAll()
|
|
{
|
|
//popup_promptbaustein_all.IsOpen = true;
|
|
//OpenAiPromptClick?.Invoke(this, e);
|
|
BeWoApp.MainControl.WindowService.Show(AllPromptsViewModel);
|
|
}
|
|
public void AiPromptOpenFavorite()
|
|
{
|
|
popup_promptbaustein_favoriten.IsOpen = true;
|
|
}
|
|
|
|
private void UpdateState()
|
|
{
|
|
switch (State)
|
|
{
|
|
case AiConversationButtonState.Hidden:
|
|
Tooltip = string.Empty;
|
|
IsButtonEnabled = false;
|
|
IsButton2Enabled = false;
|
|
IsButtonVisible = false;
|
|
IsButton2Visible = false;
|
|
IsWarningSignVisible = false;
|
|
break;
|
|
case AiConversationButtonState.Normal:
|
|
Tooltip = string.Empty;
|
|
IsButtonEnabled = true;
|
|
IsButton2Enabled = true;
|
|
IsButtonVisible = true;
|
|
IsButton2Visible = true;
|
|
IsWarningSignVisible = false;
|
|
break;
|
|
case AiConversationButtonState.Loading:
|
|
Tooltip = "Lädt";
|
|
IsButtonEnabled = false;
|
|
IsButton2Enabled = false;
|
|
IsButtonVisible = true;
|
|
IsButton2Visible = true;
|
|
IsWarningSignVisible = false;
|
|
break;
|
|
case AiConversationButtonState.Warning:
|
|
Tooltip = string.Empty;
|
|
IsButtonEnabled = true;
|
|
IsButton2Enabled = false;
|
|
IsButtonVisible = true;
|
|
IsButton2Visible = false;
|
|
IsWarningSignVisible = true;
|
|
break;
|
|
case AiConversationButtonState.Disabled:
|
|
Tooltip = string.Empty;
|
|
IsButtonEnabled = false;
|
|
IsButton2Enabled = false;
|
|
IsButtonVisible = true;
|
|
IsButton2Visible = true;
|
|
IsWarningSignVisible = false;
|
|
break;
|
|
}
|
|
|
|
btnOpenAi5.ToolTip = btnOpenAi4.ToolTip = ToolTip;
|
|
btnOpenAi4.IsEnabled = IsButtonEnabled;
|
|
btnOpenAi5.IsEnabled = IsButton2Enabled;
|
|
btnOpenAi4.Visibility = IsButtonVisible ? Visibility.Visible : Visibility.Collapsed;
|
|
btnOpenAi5.Visibility = IsButton2Visible ? Visibility.Visible : Visibility.Collapsed;
|
|
imgWarning.Visibility = IsWarningSignVisible ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
private static void OnActionTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
var control = (AiConversationButton)d;
|
|
var actionType = (AiActionType)e.NewValue;
|
|
if (BeWoApp.AppSettings.ShowAI && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModulePromptbausteineView))
|
|
{
|
|
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiPromptbausteinFolder(actionType), folders => control.InitPromptbausteine(actionType, folders));
|
|
}
|
|
|
|
}
|
|
private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
var control = (AiConversationButton)d;
|
|
control.UpdateState();
|
|
}
|
|
private void btnOpenAi4_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
OpenAiWindowClick?.Invoke(this, e);
|
|
}
|
|
private void btnOpenAi5_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
AiPromptOpenAll();
|
|
}
|
|
private void btnOpenAi5_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
AiPromptOpenFavorite();
|
|
}
|
|
private void InitPromptbausteine(AiActionType actionType, List<AiPromptbausteinFolderDC> folders)
|
|
{
|
|
VMFactory.CreateAiPromptbausteinFolderListVM(folders, (listvm) =>
|
|
{
|
|
var viewmodel = new AiPromptbausteinSelectionComplexViewModel(actionType, listvm);
|
|
viewmodel.PromptAccepted += PromptAccepted;
|
|
viewmodel.RequestClose += (s, e) => viewmodel.ResetSelection();
|
|
AllPromptsViewModel = viewmodel;
|
|
|
|
var viewmodel2 = new AiPromptbausteinSelectionComplexViewModel(actionType, listvm, true);
|
|
viewmodel2.PromptAccepted += PromptAccepted;
|
|
popup_promptbaustein_favoriten.Closed += (s, e) => viewmodel2.ResetSelection();
|
|
var view2 = new AiPromptbausteinComplexSelectionFavoritenView(viewmodel2);
|
|
viewmodel2.SelectedFolder = viewmodel2.Folders.VMList[0];
|
|
view2.Padding = new Thickness(3);
|
|
view2.Background = FindResource("ObjectEditBackgroundBrush") as System.Windows.Media.Brush;
|
|
border_promptbaustein_favoriten.Child = view2;
|
|
|
|
viewmodel.VMListReloaded += (s, e) => viewmodel2.ReloadVMList(false);
|
|
|
|
AiPromptOpenAllCommand = new DelegateCommand(AiPromptOpenAll);
|
|
AiPromptOpenFavoriteCommand = new DelegateCommand(AiPromptOpenFavorite);
|
|
});
|
|
}
|
|
}
|
|
}
|