修改了添加触发器的对话框界面
This commit is contained in:
@@ -52,6 +52,7 @@ public class InitializeRepository : IInitializeRepository
|
||||
_db.CodeFirst.InitTables<DbEmailTemplate>();
|
||||
_db.CodeFirst.InitTables<DbEmailLog>();
|
||||
_db.CodeFirst.InitTables<DbTriggerDefinition>();
|
||||
_db.CodeFirst.InitTables<DbTriggerVariable>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace DMS.Infrastructure.Repositories
|
||||
VariableId = variableId
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.GetInstance().Insertable(triggerVariables).ExecuteCommandAsync();
|
||||
await _dbContext.GetInstance().Insertable<DbTriggerVariable>(triggerVariables).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
return _mapper.Map(dbTrigger, trigger);
|
||||
|
||||
35
DMS.WPF/Converters/IntToVisibilityConverter.cs
Normal file
35
DMS.WPF/Converters/IntToVisibilityConverter.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DMS.WPF.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// 将整数值转换为Visibility的转换器。
|
||||
/// 当值等于参数时,返回Visibility.Collapsed;否则返回Visibility.Visible。
|
||||
/// </summary>
|
||||
public class IntToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is int intValue && parameter is string paramString && int.TryParse(paramString, out int paramValue))
|
||||
{
|
||||
return intValue == paramValue ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
// 默认情况下,如果值为0则隐藏,否则显示
|
||||
if (value is int intValueDefault)
|
||||
{
|
||||
return intValueDefault == 0 ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -30,10 +31,13 @@ namespace DMS.WPF.ViewModels.Dialogs
|
||||
private TriggerDefinitionDto _trigger = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private List<VariableDto> _availableVariables = new();
|
||||
private List<VariableItemViewModel> _availableVariables = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<VariableItemViewModel> _selectedVariables = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<VariableItemViewModel> _filteredVariables = new();
|
||||
|
||||
// Properties for easier binding in XAML for SendEmail action config
|
||||
[ObservableProperty]
|
||||
@@ -59,17 +63,65 @@ namespace DMS.WPF.ViewModels.Dialogs
|
||||
|
||||
partial void OnSearchTextChanged(string searchText)
|
||||
{
|
||||
SelectedVariables.Clear();
|
||||
foreach (var variableKv in _dataStorageService.Variables)
|
||||
UpdateFilteredVariables();
|
||||
}
|
||||
|
||||
private void UpdateFilteredVariables()
|
||||
{
|
||||
FilteredVariables.Clear();
|
||||
|
||||
// 如果没有搜索文本,显示所有可用变量
|
||||
if (string.IsNullOrEmpty(SearchText))
|
||||
{
|
||||
if (variableKv.Value.Name.Contains(SearchText))
|
||||
foreach (var variable in AvailableVariables)
|
||||
{
|
||||
SelectedVariables.Add(variableKv.Value);
|
||||
// 只显示未被选中的变量
|
||||
if (!SelectedVariables.Contains(variable))
|
||||
{
|
||||
FilteredVariables.Add(variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 根据搜索文本过滤变量
|
||||
foreach (var variable in AvailableVariables)
|
||||
{
|
||||
// 只显示未被选中的变量且名称包含搜索文本的变量
|
||||
if (!SelectedVariables.Contains(variable) &&
|
||||
variable.Name.Contains(SearchText, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
FilteredVariables.Add(variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将变量添加到选中列表
|
||||
/// </summary>
|
||||
/// <param name="variable">要添加的变量</param>
|
||||
public void AddVariable(VariableItemViewModel variable)
|
||||
{
|
||||
if (!SelectedVariables.Contains(variable))
|
||||
{
|
||||
SelectedVariables.Add(variable);
|
||||
UpdateFilteredVariables();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从选中列表中移除变量
|
||||
/// </summary>
|
||||
/// <param name="variable">要移除的变量</param>
|
||||
public void RemoveVariable(VariableItemViewModel variable)
|
||||
{
|
||||
if (SelectedVariables.Contains(variable))
|
||||
{
|
||||
SelectedVariables.Remove(variable);
|
||||
UpdateFilteredVariables();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化视图模型(传入待编辑的触发器)
|
||||
@@ -94,10 +146,13 @@ namespace DMS.WPF.ViewModels.Dialogs
|
||||
var variable = AvailableVariables.FirstOrDefault(v => v.Id == variableId);
|
||||
if (variable != null)
|
||||
{
|
||||
// SelectedVariables.Add(variable);
|
||||
SelectedVariables.Add(variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化过滤后的变量列表
|
||||
UpdateFilteredVariables();
|
||||
|
||||
// Parse action configuration if it's SendEmail
|
||||
if (Trigger.Action == ActionType.SendEmail && !string.IsNullOrEmpty(Trigger.ActionConfigurationJson))
|
||||
@@ -131,13 +186,14 @@ namespace DMS.WPF.ViewModels.Dialogs
|
||||
{
|
||||
try
|
||||
{
|
||||
var variables = await _variableAppService.GetAllVariablesAsync();
|
||||
AvailableVariables = variables ?? new List<VariableDto>();
|
||||
// 使用数据存储服务中的变量列表
|
||||
AvailableVariables = new List<VariableItemViewModel>(_dataStorageService.Variables.Select(kvp => kvp.Value));
|
||||
UpdateFilteredVariables();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_notificationService.ShowError($"加载变量列表失败: {ex.Message}");
|
||||
AvailableVariables = new List<VariableDto>();
|
||||
AvailableVariables = new List<VariableItemViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,14 @@
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:ex="clr-namespace:DMS.Extensions"
|
||||
xmlns:converters="clr-namespace:DMS.WPF.Converters"
|
||||
xmlns:items="clr-namespace:DMS.WPF.ViewModels.Items"
|
||||
Title="{Binding Title}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600"
|
||||
d:DesignHeight="700"
|
||||
d:DesignWidth="600"
|
||||
d:DataContext="{d:DesignInstance vmd:TriggerDialogViewModel}"
|
||||
MinWidth="500"
|
||||
MinHeight="500"
|
||||
MinHeight="600"
|
||||
PrimaryButtonText="{Binding PrimaryButText}"
|
||||
CloseButtonText="取消"
|
||||
PrimaryButtonCommand="{Binding SaveCommand}"
|
||||
@@ -24,6 +25,7 @@
|
||||
|
||||
<ui:ContentDialog.Resources>
|
||||
<converters:EnumToVisibilityConverter x:Key="LocalEnumToVisibilityConverter" />
|
||||
<converters:IntToVisibilityConverter x:Key="IntToVisibilityConverter" />
|
||||
<ex:EnumBindingSource x:Key="ConditionTypeEnum"
|
||||
EnumType="{x:Type enums:ConditionType}" />
|
||||
<ex:EnumBindingSource x:Key="ActionTypeEnum"
|
||||
@@ -36,24 +38,6 @@
|
||||
<GroupBox Header="基本信息"
|
||||
Padding="5">
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel>
|
||||
<hc:TextBox hc:InfoElement.Title="搜索变量:"
|
||||
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged }">
|
||||
</hc:TextBox>
|
||||
<DataGrid
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="False"
|
||||
ItemsSource="{Binding SelectedVariables}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Name}" Header="变量名"></DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<DockPanel Margin="0,0,0,5">
|
||||
<Label Content="描述:"
|
||||
Width="100"
|
||||
@@ -65,7 +49,81 @@
|
||||
|
||||
<CheckBox Content="激活"
|
||||
IsChecked="{Binding Trigger.IsActive}"
|
||||
Margin="0,0,0,5" />
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<!-- Selected Variables Section -->
|
||||
<Label Content="已选择的变量:"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,5"/>
|
||||
<Border BorderBrush="LightGray" BorderThickness="1"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10"
|
||||
Background="WhiteSmoke">
|
||||
<WrapPanel x:Name="SelectedVariablesPanel">
|
||||
<ItemsControl ItemsSource="{Binding SelectedVariables}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type items:VariableItemViewModel}">
|
||||
<Border Background="LightBlue"
|
||||
CornerRadius="3"
|
||||
Margin="2"
|
||||
Padding="5,2">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Name}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,5,0"/>
|
||||
<Button Content="×"
|
||||
FontSize="12"
|
||||
FontWeight="Bold"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Padding="2"
|
||||
Click="RemoveVariableButton_Click"
|
||||
Tag="{Binding}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<TextBlock Text="暂无选择的变量"
|
||||
FontStyle="Italic"
|
||||
Foreground="Gray"
|
||||
Visibility="{Binding SelectedVariables.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=0}"/>
|
||||
</WrapPanel>
|
||||
</Border>
|
||||
|
||||
<!-- Variable Search Section -->
|
||||
<Label Content="搜索变量:"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,5"/>
|
||||
<TextBox x:Name="SearchTextBox"
|
||||
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="0,0,0,5"
|
||||
ui:ControlHelper.PlaceholderText="输入变量名称进行搜索"/>
|
||||
|
||||
<Border BorderBrush="LightGray"
|
||||
BorderThickness="1"
|
||||
Height="150"
|
||||
Margin="0,0,0,10">
|
||||
<ListBox x:Name="VariableListBox"
|
||||
ItemsSource="{Binding FilteredVariables}"
|
||||
SelectionMode="Single"
|
||||
MouseDoubleClick="VariableListBox_MouseDoubleClick">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type items:VariableItemViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
|
||||
<TextBlock Text=" - " />
|
||||
<TextBlock Text="{Binding Description}" FontStyle="Italic" Foreground="Gray"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using DMS.WPF.Helper;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
|
||||
namespace DMS.WPF.Views.Dialogs
|
||||
@@ -28,5 +30,29 @@ namespace DMS.WPF.Views.Dialogs
|
||||
backgroundElementBorder.MaxHeight = ContentAreaMaxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理变量列表双击事件,将选中的变量添加到已选择列表
|
||||
/// </summary>
|
||||
private void VariableListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (VariableListBox.SelectedItem is VariableItemViewModel selectedVariable)
|
||||
{
|
||||
var viewModel = DataContext as ViewModels.Dialogs.TriggerDialogViewModel;
|
||||
viewModel?.AddVariable(selectedVariable);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理移除变量按钮点击事件
|
||||
/// </summary>
|
||||
private void RemoveVariableButton_Click(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
if (sender is System.Windows.Controls.Button button && button.Tag is VariableItemViewModel variable)
|
||||
{
|
||||
var viewModel = DataContext as ViewModels.Dialogs.TriggerDialogViewModel;
|
||||
viewModel?.RemoveVariable(variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user