Browse Source

avalonia: Added EmployeeForms screen

Kenric Nugteren 1 month ago
parent
commit
123a9ebeed

+ 28 - 0
PRS.Avalonia/PRS.Avalonia/Components/FormsList/FormsList.axaml.cs

@@ -207,4 +207,32 @@ public partial class FormsList : UserControl
         await Model.RefreshAsync(true);
         return true;
     }
+
+    public static async Task<DigitalFormShell?> SelectForm<TForm, TParent, TLink>(DigitalFormModel formModel)
+        where TForm : EntityForm<TParent, TLink, TForm>
+        where TParent : Entity, new()
+        where TLink : EntityLink<TParent>, new()
+    {
+        return (await SelectionViewModel.ExecutePopup<DigitalFormShell>(model =>
+        {
+            model.AddFilters(formModel.AvailableFilters.Select(x => x.Name).NotNull());
+            model.Columns.BeginUpdate()
+                .Add(new AvaloniaDataGridTextColumn<DigitalFormShell>
+                {
+                    Column = x => x.Code,
+                    Width = GridLength.Auto
+                })
+                .Add(new AvaloniaDataGridTextColumn<DigitalFormShell>
+                {
+                    Column = x => x.Description,
+                    Width = GridLength.Star
+                })
+                .EndUpdate();
+        }, args =>
+        {
+            formModel.SelectFilter(args.Filter);
+            formModel.Search(x => x.AppliesTo == typeof(TForm).Name);
+            return formModel.Refresh(args.Force);
+        }))?.FirstOrDefault();
+    }
 }

+ 2 - 26
PRS.Avalonia/PRS.Avalonia/Modules/DigitalForms/FormsViewModel.cs

@@ -42,38 +42,14 @@ public partial class FormsViewModel : ModuleViewModel
                     .Or(x => x.FormCompleted).IsGreaterThanOrEqualTo(DateTime.Today.AddDays(-7))),
             () => DefaultCacheFileName<KanbanFormShell>());
 
-        DigitalForms = new DigitalFormModel(DataAccess,
-            () => new Filter<DigitalForm>(x => x.ID).InQuery(new Filter<EmployeeDigitalForm>(x => x.Employee.ID).IsEqualTo(Repositories.Me.ID), x => x.Form.ID)
-                .And(x => x.Active).IsEqualTo(true)
-                .And(x => x.ID).InQuery(new Filter<DigitalFormLayout>(x => x.Active).IsEqualTo(true), x => x.Form.ID),
-            () => DefaultCacheFileName<DigitalFormShell>());
+        DigitalForms = Repositories.DigitalForms();
 
         PrimaryMenu.Add(new AvaloniaMenuItem(Images.plus, AddForm));
     }
 
     private async Task<bool> AddForm()
     {
-        var form = (await SelectionViewModel.ExecutePopup<DigitalFormShell>(model =>
-        {
-            model.AddFilters(DigitalForms.AvailableFilters.Select(x => x.Name).NotNull());
-            model.Columns.BeginUpdate()
-                .Add(new AvaloniaDataGridTextColumn<DigitalFormShell>
-                {
-                    Column = x => x.Code,
-                    Width = GridLength.Auto
-                })
-                .Add(new AvaloniaDataGridTextColumn<DigitalFormShell>
-                {
-                    Column = x => x.Description,
-                    Width = GridLength.Star
-                })
-                .EndUpdate();
-        }, args =>
-        {
-            DigitalForms.SelectFilter(args.Filter);
-            DigitalForms.Search(x => x.AppliesTo == nameof(Kanban));
-            return DigitalForms.Refresh(args.Force);
-        }))?.FirstOrDefault();
+        var form = await FormsList.SelectForm<KanbanForm, Kanban, KanbanLink>(DigitalForms);
         if (form is null) return true;
         
         var kanban = Kanbans.CreateItem();

+ 12 - 0
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRDigitalForms/MyHRDigitalFormsView.axaml

@@ -0,0 +1,12 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             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:avComponents="using:PRS.Avalonia.Components"
+			 xmlns:myHR="using:PRS.Avalonia.Modules.MyHR"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+             x:Class="PRS.Avalonia.Modules.MyHR.MyHRDigitalFormsView"
+			 x:DataType="myHR:MyHRDigitalFormsViewModel">
+	<avComponents:FormsList Model="{Binding Forms}"
+							FormClicked="{Binding FormClickedCommand}"/>
+</UserControl>

+ 13 - 0
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRDigitalForms/MyHRDigitalFormsView.axaml.cs

@@ -0,0 +1,13 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace PRS.Avalonia.Modules.MyHR;
+
+public partial class MyHRDigitalFormsView : UserControl
+{
+    public MyHRDigitalFormsView()
+    {
+        InitializeComponent();
+    }
+}

+ 62 - 2
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRDigitalForms/MyHRDigitalFormsViewModel.cs

@@ -1,6 +1,66 @@
+using Avalonia.Controls;
+using Comal.Classes;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using InABox.Avalonia.Components;
+using InABox.Core;
+using PRS.Avalonia.Components;
+using PRS.Avalonia.DigitalForms;
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+
 namespace PRS.Avalonia.Modules.MyHR;
 
-public class MyHRDigitalFormsViewModel : ModuleViewModel
+public partial class MyHRDigitalFormsViewModel : ModuleViewModel
 {
-    public override string Title => "Digital Forms";
+    public override string Title => "My Forms";
+
+    [ObservableProperty]
+    private EmployeeFormModel _forms;
+
+    [ObservableProperty]
+    private DigitalFormModel _digitalForms;
+
+    public MyHRDigitalFormsViewModel()
+    {
+        Forms = new EmployeeFormModel(DataAccess,
+            () => new Filter<EmployeeForm>(x => x.Parent.ID).IsEqualTo(Repositories.Me.ID),
+            () => DefaultCacheFileName<EmployeeFormShell>());
+
+        DigitalForms = Repositories.DigitalForms();
+
+        PrimaryMenu.Add(new AvaloniaMenuItem(Images.plus, AddForm));
+    }
+
+    private async Task<bool> AddForm()
+    {
+        var form = await FormsList.SelectForm<EmployeeForm, Employee, EmployeeLink>(DigitalForms);
+        if (form is null) return true;
+
+        var employeeForm = Forms.CreateItem();
+        employeeForm.ParentID = Repositories.Me.ID;
+        employeeForm.FormID = form.ID;
+        employeeForm.FormCode = form.Code;
+        employeeForm.FormDescription = form.Description;
+        employeeForm.FormDescriptionExpression = form.DescriptionExpression;
+
+        DigitalFormsHostViewModel<EmployeeFormModel, EmployeeFormShell, Employee, EmployeeLink, EmployeeForm>
+            .EditForm(Forms, employeeForm, Repositories.Me.Entity);
+
+        return true;
+    }
+
+    protected override async Task<TimeSpan> OnRefresh()
+    {
+        await Forms.RefreshAsync(false);
+        return TimeSpan.Zero;
+    }
+
+    [RelayCommand]
+    private void FormClicked(EmployeeFormShell shell)
+    {
+        DigitalFormsHostViewModel<EmployeeFormModel, EmployeeFormShell, Employee, EmployeeLink, EmployeeForm>
+            .EditForm(Forms, shell, Repositories.Me.Entity);
+    }
 }

+ 1 - 1
PRS.Avalonia/PRS.Avalonia/Repositories/EmployeeForm/EmployeeFormModel.cs

@@ -8,7 +8,7 @@ namespace PRS.Avalonia;
 
 public class EmployeeFormModel : DigitalFormInstanceModel<EmployeeFormModel, EmployeeFormShell, EmployeeForm>
 {
-    public EmployeeFormModel(IModelHost host, Func<Filter<EmployeeForm>> filter) : base(host, filter)
+    public EmployeeFormModel(IModelHost host, Func<Filter<EmployeeForm>> filter, Func<string>? filename = null) : base(host, filter, filename)
     {
     }
 

+ 6 - 0
PRS.Avalonia/PRS.Avalonia/RepositoryLayer.cs

@@ -75,4 +75,10 @@ public partial class RepositoryLayer : ObservableObject
                     new Filter<JobEmployee>(x => x.EmployeeLink.ID).IsEqualTo(Me.ID),
                     x => x.JobLink.ID);
     }
+
+    public DigitalFormModel DigitalForms() => new DigitalFormModel(Data,
+            () => new Filter<DigitalForm>(x => x.ID).InQuery(new Filter<EmployeeDigitalForm>(x => x.Employee.ID).IsEqualTo(Me.ID), x => x.Form.ID)
+                .And(x => x.Active).IsEqualTo(true)
+                .And(x => x.ID).InQuery(new Filter<DigitalFormLayout>(x => x.Active).IsEqualTo(true), x => x.Form.ID),
+            () => DefaultCacheFileName<DigitalFormShell>());
 }