Browse Source

avalonia: Added employee selector to DFMultisignature; implemented "Clear" button

Kenric Nugteren 2 weeks ago
parent
commit
d0f8d7b9aa

+ 1 - 0
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/DigitalFormViewer.axaml.cs

@@ -4,6 +4,7 @@ using Avalonia.Layout;
 using Avalonia.Markup.Xaml;
 using Avalonia.Media;
 using InABox.Core;
+using PRS.Avalonia.Modules;
 using System;
 using System.Collections.Generic;
 using System.Drawing;

+ 66 - 1
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFMultiSignatureFieldControl.cs

@@ -4,12 +4,15 @@ using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Templates;
 using Avalonia.Layout;
 using Avalonia.Media;
+using Comal.Classes;
 using Comal.Classes.SecurityDescriptors;
 using CommunityToolkit.Mvvm.Input;
 using InABox.Avalonia;
+using InABox.Avalonia.Components;
 using InABox.Avalonia.Converters;
 using InABox.Avalonia.Dialogs;
 using InABox.Core;
+using PRS.Avalonia.Components;
 using ReactiveUI;
 using System;
 using System.Collections.Generic;
@@ -81,6 +84,7 @@ internal partial class DFMultiSignatureFieldControl : DigitalFormFieldControl<DF
                     CommandParameter = value.Key,
                     Command = DeleteSignatureCommand
                 };
+                button.IsVisible = _isEnabled;
                 button.Classes.Add("Standard");
 
                 grid.AddChild(image, 0, 0, colSpan: 2);
@@ -198,9 +202,70 @@ internal partial class DFMultiSignatureFieldControl : DigitalFormFieldControl<DF
     }
 
     [RelayCommand]
-    private void Select()
+    private async Task Select()
     {
+        var model = new EmployeeDetailModel(ViewModelBase.Repositories.Data, LookupFactory.DefineFilter<Employee>);
+        SelectionViewModel.Execute<EmployeeDetailShell>(model =>
+        {
+            model.Columns.BeginUpdate()
+                .Add(new AvaloniaDataGridTextColumn<EmployeeDetailShell>
+                {
+                    Column = x => x.Code,
+                    Width = GridLength.Auto
+                })
+                .Add(new AvaloniaDataGridTextColumn<EmployeeDetailShell>
+                {
+                    Column = x => x.Name,
+                    Width = GridLength.Star
+                })
+                .EndUpdate();
+            model.SelectionPageMode = SelectionPageMode.MultiSelect;
+        }, args =>
+        {
+            model.SelectFilter(args.Filter);
+            return model.Refresh(args.Force);
+        }, employees =>
+        {
+            AddEmployees(employees).ContinueWith(task =>
+            {
+                if(task.Exception is not null)
+                {
+                    _ = MessageDialog.ShowError(task.Exception);
+                    MobileLogging.Log(task.Exception);
+                }
+            }, TaskScheduler.FromCurrentSynchronizationContext());
+        });
+    }
+    private async Task AddEmployees(EmployeeDetailShell[] employees)
+    {
+        var withoutSignature = new List<string>();
+        var changed = false;
+        foreach(var employee in employees)
+        {
+            if (!_value.ContainsKey(employee.Name))
+            {
+                if(employee.Signature is not null && employee.Signature.Length > 0)
+                {
+                    _value.Add(employee.Name.ToUpper(), employee.Signature);
+                    changed = true;
+                }
+                else
+                {
+                    withoutSignature.Add(employee.Name);
+                }
+            }
+        }
 
+        if(withoutSignature.Count > 0)
+        {
+            await MessageDialog.ShowMessage($"The following people do not have a signature saved in the system, and will have to be added manually:\n{string.Join(',', withoutSignature)}");
+        }
+
+        if (changed)
+        {
+            Update();
+            ChangeField();
+        }
     }
 
     [RelayCommand]

+ 5 - 2
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFSignaturePadEditorView.axaml

@@ -9,12 +9,15 @@
              x:DataType="forms:DFSignaturePadEditorViewModel">
     <Grid RowDefinitions="200,Auto"
           ColumnDefinitions="*,Auto">
-        <components:InkCanvas Name="Canvas" Grid.Row="0" Grid.ColumnSpan="2"/>
+        <Border Classes="Standard" Grid.Row="0" Grid.ColumnSpan="2">
+            <components:InkCanvas Name="Canvas"/>
+        </Border>
         <TextBox Grid.Row="1" Grid.Column="0"
                  Watermark="Name"
                  Text="{Binding SignatureName}"/>
         <Button Classes="Standard"
-                Grid.Row="1" Grid.Column="1">
+                Grid.Row="1" Grid.Column="1"
+                Click="Clear_Click">
             <Image Classes="Small" Source="{SvgImage /Images/cross.svg}"/>
         </Button>
     </Grid>

+ 6 - 0
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFSignaturePadEditorView.axaml.cs

@@ -1,5 +1,6 @@
 using Avalonia;
 using Avalonia.Controls;
+using Avalonia.Interactivity;
 using Avalonia.Markup.Xaml;
 using System;
 
@@ -24,6 +25,11 @@ public partial class DFSignaturePadEditorView : UserControl
         model.GetImage = GetImage;
     }
 
+    private void Clear_Click(object sender, RoutedEventArgs e)
+    {
+        Canvas.Clear();
+    }
+
     private byte[]? GetImage()
     {
         return Canvas.SaveImage();

+ 3 - 1
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFSignaturePadEditorViewModel.cs

@@ -1,4 +1,6 @@
-using CommunityToolkit.Mvvm.ComponentModel;
+using Avalonia.Controls;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
 using InABox.Avalonia;
 using PRS.Avalonia.Modules;
 using System;