Browse Source

avalonia: added job forms and switched to datagrid for job selection screen.

Kenric Nugteren 1 month ago
parent
commit
fb6424f4a3

+ 0 - 44
PRS.Avalonia/PRS.Avalonia/Dialogs/SelectJobDialogView.axaml

@@ -1,44 +0,0 @@
-<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:listView="clr-namespace:PRS.Avalonia.Components.ListView"
-             xmlns:dialogs="clr-namespace:PRS.Avalonia.Dialogs"
-             xmlns:avalonia="clr-namespace:PRS.Avalonia"
-             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
-             x:Class="PRS.Avalonia.Dialogs.SelectJobDialogView"
-             x:DataType="dialogs:SelectJobDialogViewModel">
-    
-    <UserControl.Resources>
-        <DataTemplate x:Key="SelectJobDialogTemplate" x:DataType="avalonia:JobShell">
-            <Button Classes="Standard"
-                Margin="0,0,0,2"
-                Background="{StaticResource PrsTileBackground}"
-                Command="{Binding $parent[listView:PrsListView].((dialogs:SelectJobDialogViewModel)DataContext).SelectJobCommand}"
-                CommandParameter="{Binding .}"
-                HorizontalContentAlignment="Stretch">
-                <Grid>
-                    <Grid.ColumnDefinitions>
-                        <ColumnDefinition Width="100" />
-                        <ColumnDefinition Width="*"/>
-                    </Grid.ColumnDefinitions>
-                    <Label
-                        Grid.Row="0"
-                        Grid.Column="0"
-                        Content="{Binding JobNumber}"
-                        HorizontalContentAlignment="Center"
-                        FontSize="{StaticResource PrsFontSizeNormal}"/>
-                    <Label
-                        Grid.Row="0"
-                        Grid.Column="1"
-                        Content="{Binding Name}"
-                        FontSize="{StaticResource PrsFontSizeNormal}"/>
-                </Grid>
-            </Button>
-        </DataTemplate>
-    </UserControl.Resources>
-    
-    <listView:PrsListView
-        Repository="{Binding Repositories.Jobs}"
-        ItemTemplate="{StaticResource SelectJobDialogTemplate}" />
-</UserControl>

+ 0 - 13
PRS.Avalonia/PRS.Avalonia/Dialogs/SelectJobDialogView.axaml.cs

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

+ 0 - 28
PRS.Avalonia/PRS.Avalonia/Dialogs/SelectJobDialogViewModel.cs

@@ -1,28 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using System.Windows.Input;
-using CommunityToolkit.Mvvm.Input;
-
-namespace PRS.Avalonia.Dialogs;
-
-
-public partial class SelectJobDialogViewModel : ViewModelBase
-{
-    
-    protected override async Task<TimeSpan> OnRefresh()
-    {
-        await Repositories.Jobs.RefreshAsync(false);
-        return TimeSpan.Zero;
-    }
-
-    public ICommand? JobSelectedCommand { get; set; }
-    
-    [RelayCommand]
-    private void SelectJob(JobShell job)
-    {
-        if (JobSelectedCommand != null && JobSelectedCommand.CanExecute(job))
-            JobSelectedCommand.Execute(job);
-    }
-    
-    
-}

+ 3 - 1
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteForms/SiteFormsView.axaml

@@ -3,8 +3,10 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:modules="clr-namespace:PRS.Avalonia.Modules"
+             xmlns:avComponents="using:PRS.Avalonia.Components"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="PRS.Avalonia.Modules.SiteFormsView"
              x:DataType="modules:SiteFormsViewModel">
-    Welcome to Avalonia!
+	<avComponents:FormsList Model="{Binding Forms}"
+							FormClicked="{Binding FormClickedCommand}"/>
 </UserControl>

+ 58 - 2
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteForms/SiteFormsViewModel.cs

@@ -1,6 +1,62 @@
-namespace PRS.Avalonia.Modules;
+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.Threading.Tasks;
 
-public class SiteFormsViewModel : SiteModuleViewModel
+namespace PRS.Avalonia.Modules;
+
+public partial class SiteFormsViewModel : SiteModuleViewModel
 {
     public override string Title => "Site Forms";
+
+    [ObservableProperty]
+    private JobFormModel _forms;
+
+    [ObservableProperty]
+    private DigitalFormModel _digitalForms;
+
+    public SiteFormsViewModel()
+    {
+        Forms = new JobFormModel(DataAccess,
+            () => new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(JobShell?.ID),
+            () => DefaultCacheFileName<JobFormShell>(JobShell?.ID));
+
+        DigitalForms = Repositories.DigitalForms();
+
+        PrimaryMenu.Add(new AvaloniaMenuItem(Images.plus, AddForm));
+    }
+
+    private async Task<bool> AddForm()
+    {
+        var form = await FormsList.SelectForm<JobForm, Job, JobLink>(DigitalForms);
+        if (form is null) return true;
+        
+        var jobForm = Forms.CreateItem();
+        jobForm.ParentID = JobShell!.ID;
+        jobForm.FormID = form.ID;
+        jobForm.FormCode = form.Code;
+        jobForm.FormDescription = form.Description;
+        jobForm.FormDescriptionExpression = form.DescriptionExpression;
+
+        DigitalFormsHostViewModel<JobFormModel, JobFormShell, Job, JobLink, JobForm>.EditForm(Forms, jobForm, JobShell.Entity);
+
+        return true;
+    }
+
+    protected override async Task<TimeSpan> OnRefresh()
+    {
+        await Forms.RefreshAsync(false);
+        return TimeSpan.Zero;
+    }
+
+    [RelayCommand]
+    private void FormClicked(JobFormShell shell)
+    {
+        DigitalFormsHostViewModel<JobFormModel, JobFormShell, Job, JobLink, JobForm>.EditForm(Forms, shell, JobShell!.Entity);
+    }
 }

+ 55 - 9
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteViewModel.cs

@@ -1,11 +1,14 @@
 using System;
 using System.Linq;
 using System.Threading.Tasks;
+using Avalonia.Controls;
+using Comal.Classes;
 using CommunityToolkit.Mvvm.ComponentModel;
 using CommunityToolkit.Mvvm.Input;
 using InABox.Avalonia;
 using InABox.Avalonia.Components;
 using InABox.Configuration;
+using InABox.Core;
 using PRS.Avalonia.Components;
 using PRS.Avalonia.Dialogs;
 
@@ -35,6 +38,24 @@ public partial class SiteViewModel : ModuleViewModel
         Modules.Add<SiteTasksViewModel>("Job Tasks", "Manage Tasks for this Job", Images.task, LaunchSiteModule);
         Modules.Add<SiteRequisitionsViewModel>("Site Requisitions", "Create/Edit Site Requis for this Job", Images.trolley, LaunchSiteModule);
         Modules.Add<SiteDeliveriesViewModel>("Deliveries", "View Deliveries for this Job", Images.delivery, LaunchSiteModule);
+
+        foreach(var module in Modules.Items)
+        {
+            module.IsEnabled = false;
+        }
+    }
+
+    private async Task<bool> HasJob()
+    {
+        if(SelectedJob is null)
+        {
+            await MessageDialog.ShowMessage("Please select a job first.");
+            return false;
+        }
+        else
+        {
+            return true;
+        }
     }
 
     private void LaunchSiteModule(SiteModuleViewModel model)
@@ -52,17 +73,42 @@ public partial class SiteViewModel : ModuleViewModel
         await Task.CompletedTask;
     }
 
+    partial void OnSelectedJobChanged(JobShell? value)
+    {
+        foreach(var module in Modules.Items)
+        {
+            module.IsEnabled = value != null;
+        }
+    }
+
     [RelayCommand]
-    private void SelectJob()
+    private async Task SelectJob()
     {
-        Navigation.Navigate<SelectJobDialogViewModel>((vm) =>
+        var job = (await SelectionViewModel.ExecutePopup<JobShell>(model =>
+        {
+            model.Columns.BeginUpdate()
+                .Add(new AvaloniaDataGridTextColumn<JobShell>
+                {
+                    Column = x => x.JobNumber,
+                    Caption = "Number",
+                    Width = GridLength.Auto
+                })
+                .Add(new AvaloniaDataGridTextColumn<JobShell>
+                {
+                    Column = x => x.Name,
+                    Caption = "Name",
+                    Width = GridLength.Star
+                })
+                .EndUpdate();
+            model.AddFilters(Repositories.Jobs.AvailableFilters.Select(x => x.Name).NotNull());
+        }, args =>
         {
-            vm.JobSelectedCommand = new RelayCommand<JobShell>((job) =>
-            {
-                Settings.JobID = job?.ID ?? Guid.Empty;
-                new LocalConfiguration<SiteModuleSettings>().Save(Settings);
-                Navigation.Back();
-            });
-        });
+            Repositories.Jobs.SelectFilter(args.Filter);
+            return Repositories.Jobs.Refresh(args.Force);
+        }))?.FirstOrDefault();
+        if (job is null) return;
+
+        Settings.JobID = job.ID;
+        SelectedJob = job;
     }
 }

+ 1 - 1
PRS.Avalonia/PRS.Avalonia/Repositories/JobForm/JobFormModel.cs

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