Bladeren bron

Added LogikalInitializationRequest/Response
Fixed Fluent LogikalResponse Handling
Created List-style Dictionary editor component
Added ObjectToBooleanConverter
Fixed error in DynmaicMenuColumn

frankvandenbos 2 maanden geleden
bovenliggende
commit
f346bae777

+ 11 - 10
InABox.Integration.Logikal/LogikalMethod.cs

@@ -3,16 +3,17 @@ namespace InABox.Integration.Logikal
     public enum LogikalMethod
     {
         Error = -1,
-        Connect = 0,
-        Login = 1,
-        ProjectCentres = 2,
-        Projects = 3,
-        Project = 4,
-        Phases = 5,
-        ElevationSummary = 6,
-        BOM = 7,
-        ElevationDetail = 8,
+        Initialize = 0,
+        Connect = 1,
+        Login = 2,
+        ProjectCentres = 3,
+        Projects = 4,
+        Project = 5,
+        Phases = 6,
+        ElevationSummary = 7,
+        BOM = 8,
+        ElevationDetail = 9,
         Logout = 998,
-        Disconnect = 999
+        Disconnect = 999,
     }
 }

+ 2 - 8
InABox.Integration.Logikal/LogikalResponse.cs

@@ -19,21 +19,15 @@ namespace InABox.Integration.Logikal
         public LogikalResponse Error(Action<LogikalErrorResponse> handler, LogikalStatus status = LogikalStatus.IsError)
         {
             if (this is LogikalErrorResponse error && status.HasFlag(error.Status))
-            {
                 handler?.Invoke(error);
-                return null;
-            }
             return this;
         }
 
-        public T Success<T>(Action<T> handler) where T : LogikalResponse
+        public LogikalResponse Success<T>(Action<T> handler) where T : LogikalResponse
         {
             if (this is T response)
-            {
                 handler?.Invoke(response);
-                return response;
-            }
-            return null;
+            return this;
         }
 
 

+ 5 - 0
InABox.Integration.Logikal/Requests/System/LogikalConnectRequest.cs

@@ -6,6 +6,11 @@ namespace InABox.Integration.Logikal
         
         public string Path { get; set; }
         
+        public LogikalConnectRequest(string path)
+        {
+            Path = path;
+        }
+        
     }
     
     

+ 0 - 2
InABox.Integration.Logikal/Requests/System/LogikalErrorRequest.cs

@@ -22,6 +22,4 @@ namespace InABox.Integration.Logikal
         }
 
     }
-
-
 }

+ 0 - 2
InABox.Integration.Logikal/Requests/System/LogikalErrorResponse.cs

@@ -13,6 +13,4 @@ namespace InABox.Integration.Logikal
         public override string ToString() => $"{Status}: {Message}";
 
     }
-
-
 }

+ 15 - 0
InABox.Integration.Logikal/Requests/System/LogikalInitializeRequest.cs

@@ -0,0 +1,15 @@
+namespace InABox.Integration.Logikal
+{
+    public class LogikalInitializeRequest : LogikalRequest
+    {
+        public override LogikalMethod Method() => LogikalMethod.Initialize;
+
+        public override string ToString() => "Initialize";
+
+        public LogikalInitializeRequest()
+        {
+        }
+
+
+    }
+}

+ 12 - 0
InABox.Integration.Logikal/Requests/System/LogikalInitializeResponse.cs

@@ -0,0 +1,12 @@
+namespace InABox.Integration.Logikal
+{
+    public class LogikalInitializeResponse : LogikalResponse
+    {
+        public override LogikalMethod Method() => LogikalMethod.Initialize;
+        
+        public string Path { get; set; }
+
+        public override string ToString() => Path;
+
+    }
+}

+ 14 - 0
inabox.wpf/Converters/ObjectToBooleanConverter.cs

@@ -0,0 +1,14 @@
+namespace InABox.WPF;
+
+public class ObjectToBooleanConverter : AbstractConverter<object?, bool>
+{
+
+    public bool Value { get; set; } = true;
+    
+    public override bool Convert(object? value)
+    {
+        return value == null
+            ? !Value
+            : Value;
+    }
+}

+ 1 - 1
inabox.wpf/DigitalForms/DigitalFormGrid.cs

@@ -442,7 +442,7 @@ namespace InABox.DynamicGrid
                 String appliesto = "";
                 String code = "";
                 var lookups = new DigitalFormCategoryLookups(null).Lookups();
-                if (!DictionaryEdit.Execute<String>(lookups, ref appliesto, "Applies To", "Select Form Type") || String.IsNullOrWhiteSpace(appliesto))
+                if (!DictionaryComboEdit.Execute<String>(lookups, ref appliesto, "Applies To", "Select Form Type") || String.IsNullOrWhiteSpace(appliesto))
                     return;
                 Progress.ShowModal("Creating Form", (progress) =>
                 {

+ 1 - 1
inabox.wpf/DynamicGrid/Columns/DynamicMenuColumn.cs

@@ -55,7 +55,7 @@ namespace InABox.DynamicGrid
                 
             Action = r =>
             {
-                if (_status?.Invoke(r)== DynamicMenuStatus.Enabled)
+                if ((_status == null) || _status.Invoke(r)== DynamicMenuStatus.Enabled)
                 {
                     _menu.Tag = r;
                     _menu.Items.Clear();

+ 9 - 2
inabox.wpf/Editors/DictionaryEdit.xaml → inabox.wpf/Editors/DictionaryComboEdit.xaml

@@ -1,4 +1,4 @@
-<wpf:ThemableWindow x:Class="InABox.WPF.DictionaryEdit"
+<wpf:ThemableWindow x:Class="InABox.WPF.DictionaryComboEdit"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -20,7 +20,14 @@
         <Label x:Name="Label" Grid.Row="0" Grid.Column="0" Margin="10,0,10,0" HorizontalAlignment="Left"
                HorizontalContentAlignment="Left" VerticalAlignment="Stretch" VerticalContentAlignment="Center"
                Content="Select Value" />
-        <ComboBox x:Name="Combo" Grid.Row="0" Grid.Column="1" Margin="0,0,5,0" Grid.ColumnSpan="3"
+        <ItemsControl Grid.Row="0" Grid.Column="1">
+            <ItemsControl.ItemTemplate>
+                <DataTemplate>
+                    
+                </DataTemplate>
+            </ItemsControl.ItemTemplate>
+        </ItemsControl>
+        <ComboBox Visibility="Collapsed" x:Name="Combo" Grid.Row="0" Grid.Column="1" Margin="0,0,5,0" Grid.ColumnSpan="3"
                   HorizontalAlignment="Stretch" VerticalAlignment="Center" SelectionChanged="Combo_SelectionChanged" />
         <Button x:Name="OK" Grid.Row="1" Grid.Column="2" Margin="5" Content="OK" Click="OK_Click" IsEnabled="False" />
         <Button x:Name="Cancel" Grid.Row="1" Grid.Column="3" Margin="5" Content="Cancel" Click="Cancel_Click" />

+ 3 - 3
inabox.wpf/Editors/DictionaryEdit.xaml.cs → inabox.wpf/Editors/DictionaryComboEdit.xaml.cs

@@ -9,7 +9,7 @@ namespace InABox.WPF
     /// <summary>
     ///     Interaction logic for PrinterSelection.xaml
     /// </summary>
-    public partial class DictionaryEdit : ThemableWindow
+    public partial class DictionaryComboEdit : ThemableWindow
     {
 
         public string Description
@@ -18,7 +18,7 @@ namespace InABox.WPF
             set => Label.Content = value;
         }
         
-        public DictionaryEdit(string[] values, ref int index)
+        public DictionaryComboEdit(string[] values, ref int index)
         {
             InitializeComponent();
             Combo.Items.Clear();
@@ -49,7 +49,7 @@ namespace InABox.WPF
         public static bool Execute<T>(Dictionary<T, string> values, ref T value, string? title = null, string? description = null) where T : notnull
         {
             var index = values.Keys.ToList().IndexOf(value);
-            var edit = new DictionaryEdit(values.Values.ToArray(), ref index);
+            var edit = new DictionaryComboEdit(values.Values.ToArray(), ref index);
             edit.Title = title ?? "Value Selection";
             edit.Description = description ?? "Select Value";
             if (edit.ShowDialog() == true)

+ 73 - 0
inabox.wpf/Editors/DictionaryRadioEdit.xaml

@@ -0,0 +1,73 @@
+<wpf:ThemableWindow x:Class="InABox.Wpf.DictionaryRadioEdit"
+                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+                    xmlns:wpf="clr-namespace:InABox.Wpf"
+                    xmlns:wpf1="clr-namespace:InABox.WPF"
+                    mc:Ignorable="d"
+                    Title="{Binding Title}" 
+                    SizeToContent="WidthAndHeight" 
+                    MinWidth="300" 
+                    MinHeight="120"
+                    WindowStartupLocation="CenterScreen">
+    
+    <wpf:ThemableWindow.DataContext>
+        <wpf:DictionaryRadioEditViewModel x:Name="ViewModel" />
+    </wpf:ThemableWindow.DataContext>
+    <wpf:ThemableWindow.Resources>
+        <wpf1:StringToVisibilityConverter x:Key="StringToVisibilityConverter" />
+        <wpf1:ObjectToBooleanConverter x:Key="ObjectToBooleanConverter" />
+    </wpf:ThemableWindow.Resources>
+    
+    <DockPanel Margin="5">
+
+        <Label 
+            DockPanel.Dock="Top"
+            Margin="5" 
+            HorizontalContentAlignment="Center" 
+            Content="{Binding Description}"
+               Visibility="{Binding Description, Converter={StaticResource StringToVisibilityConverter}}" />
+        
+        <StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Center" Orientation="Horizontal" Margin="5">
+            <Button 
+                MinWidth="80" 
+                MinHeight="30" 
+                Padding="10,5" 
+                Margin="0,0,2.5,0" 
+                Content="OK" 
+                Click="OK_Click" 
+                IsEnabled="{Binding List.Selected, Converter={StaticResource ObjectToBooleanConverter}}" />
+            <Button 
+                MinWidth="80" 
+                MinHeight="30" 
+                Padding="10,5" 
+                Margin="2.5,0,0,0" 
+                Content="Cancel" 
+                Click="Cancel_Click" />
+        </StackPanel>
+        
+        <Border 
+            DockPanel.Dock="Top"
+            Margin="5" 
+            BorderBrush="Gray"
+            BorderThickness="0.75"
+            Padding="10"
+            CornerRadius="5">
+            
+            <ItemsControl ItemsSource="{Binding List.Items}">
+                <ItemsControl.ItemTemplate>
+                    <DataTemplate DataType="{x:Type wpf:DictionaryRadioItem}">
+                        <DockPanel>
+                            <CheckBox DockPanel.Dock="Left" IsChecked="{Binding Checked}"  Padding="10" VerticalContentAlignment="Center" />
+                            <Label DockPanel.Dock="Right" Content="{Binding Value}" Padding="0,10,10,10" VerticalContentAlignment="Center" />
+                        </DockPanel>
+                    </DataTemplate>
+                </ItemsControl.ItemTemplate>
+            </ItemsControl>
+            
+        </Border>
+        
+    </DockPanel>
+    
+</wpf:ThemableWindow>

+ 200 - 0
inabox.wpf/Editors/DictionaryRadioEdit.xaml.cs

@@ -0,0 +1,200 @@
+using InABox.Wpf;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using FastReport.Data;
+using InABox.Core;
+
+namespace InABox.Wpf
+{
+
+    public class DictionaryRadioItem(DictionaryRadioList parent) : DependencyObject
+    {
+
+        public DictionaryRadioList Parent => parent;
+
+        private static readonly DependencyProperty CheckedProperty = DependencyProperty.Register(
+            nameof(Checked), 
+            typeof(bool), 
+            typeof(DictionaryRadioItem),
+            new FrameworkPropertyMetadata(
+                false, 
+                FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
+                propertyChangedCallback: CheckedChanged
+            )
+        );
+
+        private static bool _isChanging = false;
+        
+        private static void CheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            if (d is not DictionaryRadioItem item || e.NewValue is not bool isChecked || _isChanging)
+                return;
+            _isChanging = true;
+            item.Parent.Selected = isChecked ? item : null;
+            _isChanging = false;
+        }
+
+        public bool Checked
+        {
+            get => (bool)GetValue(CheckedProperty);
+            set => SetValue(CheckedProperty, value);
+        } 
+        
+        private static readonly DependencyProperty KeyProperty = DependencyProperty.Register(
+            nameof(Key), 
+            typeof(object), 
+            typeof(DictionaryRadioItem)
+        );
+
+        public object Key
+        {
+            get => GetValue(KeyProperty);
+            set => SetValue(KeyProperty, value);
+        } 
+        
+        private static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
+            nameof(Value), 
+            typeof(string), 
+            typeof(DictionaryRadioItem)
+        );
+
+        public string? Value
+        {
+            get => GetValue(ValueProperty) as string;
+            set => SetValue(ValueProperty, value);
+        } 
+    }
+
+    public class DictionaryRadioList : DependencyObject
+    {
+        private void Select(DictionaryRadioItem? selected)
+        {
+            var others = Items.Where(x => !Equals(x, selected)).ToArray();
+            foreach (var item in others)
+                item.Checked = false;
+        }
+
+        private static readonly DependencyProperty SelectedProperty = DependencyProperty.Register(
+            nameof(Selected), 
+            typeof(DictionaryRadioItem), 
+            typeof(DictionaryRadioList)
+        );
+
+        public DictionaryRadioItem? Selected
+        {
+            get => GetValue(SelectedProperty) as DictionaryRadioItem;
+            set
+            {
+                SetValue(SelectedProperty, value);
+                Select(Items.FirstOrDefault(x=>Equals(x,value)));
+            }
+        } 
+        
+        private static readonly DependencyProperty ItemsProperty = DependencyProperty.Register(
+            nameof(Items), 
+            typeof(CoreObservableCollection<DictionaryRadioItem>), 
+            typeof(DictionaryRadioList)
+        );
+
+        public CoreObservableCollection<DictionaryRadioItem> Items
+        {
+            get => (CoreObservableCollection<DictionaryRadioItem>)GetValue(ItemsProperty);
+            set => SetValue(ItemsProperty, value);
+        }
+
+        public DictionaryRadioList()
+        {
+            Items = new CoreObservableCollection<DictionaryRadioItem>();
+        }
+    }
+
+    public class DictionaryRadioEditViewModel : DependencyObject
+    {
+        private static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
+            nameof(Title), 
+            typeof(string), 
+            typeof(DictionaryRadioEditViewModel)
+        );
+
+        public string? Title
+        {
+            get => GetValue(TitleProperty) as string;
+            set => SetValue(TitleProperty, value);
+        } 
+        
+        private static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
+            nameof(Description), 
+            typeof(string), 
+            typeof(DictionaryRadioEditViewModel)
+        );
+
+        public string? Description
+        {
+            get => GetValue(DescriptionProperty) as string;
+            set => SetValue(DescriptionProperty, value);
+        } 
+        
+        private static readonly DependencyProperty ListProperty = DependencyProperty.Register(
+            nameof(List), 
+            typeof(DictionaryRadioList), 
+            typeof(DictionaryRadioEditViewModel)
+        );
+
+        public DictionaryRadioList List
+        {
+            get => (DictionaryRadioList)GetValue(ListProperty);
+            set => SetValue(ListProperty, value);
+        } 
+    }
+    
+    /// <summary>
+    ///     Interaction logic for PrinterSelection.xaml
+    /// </summary>
+    public partial class DictionaryRadioEdit : ThemableWindow
+    {
+        
+       
+        public DictionaryRadioEdit(DictionaryRadioList list, string title, string? description )
+        {
+            InitializeComponent();
+            ViewModel.Title = title;
+            ViewModel.Description = description;
+            ViewModel.List = list;
+        }
+        
+        private void OK_Click(object sender, RoutedEventArgs e)
+        {
+            DialogResult = true;
+            Close();
+        }
+
+        private void Cancel_Click(object sender, RoutedEventArgs e)
+        {
+            DialogResult = false;
+            Close();
+        }
+
+        public static bool Execute<T>(Dictionary<T, string> values, string title, string? description, ref T? result) where T : notnull
+        {
+            var list = new DictionaryRadioList();
+            foreach (var key in values.Keys)
+                list.Items.Add(new DictionaryRadioItem(list) { Key = key, Value = values[key], Checked = Equals(result,key)});
+
+            var edit = new DictionaryRadioEdit(
+                list,
+                title,
+                description);
+            
+            if (edit.ShowDialog() == true)
+            {
+                result = list.Selected != null ? (T)list.Selected.Key : default;
+                return result is not null;
+            }
+
+            return false;
+        }
+        
+    }
+}