Browse Source

Added ClosedForms indicator to SiteITPs; fixed error with Open/Closed forms aggregate on JobITP

Kenric Nugteren 1 tháng trước cách đây
mục cha
commit
009793fb30

+ 1 - 0
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteItps/SiteITPFormsView.axaml.cs

@@ -24,6 +24,7 @@ public partial class SiteITPFormsView : UserControl
     private bool FormsList_Search(object sender, FormsListSearchEventArgs args)
     {
         if (args.Shell is not JobITPFormShell shell) return false;
+        if (Model is null) return false;
         return Model.Search(shell);
     }
 }

+ 21 - 1
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteItps/SiteITPFormsViewModel.cs

@@ -47,6 +47,9 @@ public partial class SiteITPFormsViewModel : ModuleViewModel
         newForm.FormDescription = itp.FormName;
         newForm.Save("Created on Mobile Device");
 
+        itp.Entity.OpenForms += 1;
+        itp.SyncRow();
+
         Forms.Search();
     }
 
@@ -64,7 +67,24 @@ public partial class SiteITPFormsViewModel : ModuleViewModel
     {
         if (ITP is not JobITPShell itp) return;
 
-        DigitalFormsHostViewModel<JobITPFormModel, JobITPFormShell, JobITP, JobITPLink, JobITPForm>.EditForm(Forms, shell, itp);
+        var complete = shell.Completed != DateTime.MinValue;
+        DigitalFormsHostViewModel<JobITPFormModel, JobITPFormShell, JobITP, JobITPLink, JobITPForm>.EditForm(Forms, shell, itp, () =>
+        {
+            var nowComplete = shell.Completed != DateTime.MinValue;
+            if(complete != nowComplete)
+            {
+                if (nowComplete)
+                {
+                    itp.Entity.OpenForms -= 1;
+                    itp.Entity.ClosedForms += 1;
+                }
+                else
+                {
+                    itp.Entity.OpenForms += 1;
+                    itp.Entity.ClosedForms -= 1;
+                }
+            }
+        });
     }
 
     public bool Search(JobITPFormShell shell)

+ 92 - 8
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteItps/SiteItpsView.axaml

@@ -3,6 +3,7 @@
              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:converters="using:InABox.Avalonia.Converters"
 			 xmlns:avalonia="using:PRS.Avalonia"
 			 xmlns:components="using:InABox.Avalonia.Components"
 			 xmlns:aComponents="using:PRS.Avalonia.Components"
@@ -14,16 +15,99 @@
 		<modules:ITPColorConverter x:Key="FormColorConverter"
 								   OpenColor="LightSalmon" ClosedColor="LightGreen" NoneColor="Silver"/>
 		<modules:ITPTextConverter x:Key="OpenFormsTextConverter" Closed="False"/>
+		<modules:ITPVisibilityConverter x:Key="OpenFormsVisibilityConverter" Closed="False"/>
+		<modules:ITPTextConverter x:Key="ClosedFormsTextConverter" Closed="True"/>
+		<modules:ITPVisibilityConverter x:Key="ClosedFormsVisibilityConverter" Closed="True"/>
+
+        <converters:DoubleToCornerRadiusConverter
+            x:Key="SphericalBorder"
+            Ratio="0.5" />
+
+        <converters:DoubleToThicknessConverter
+            x:Key="MarginDoubler"
+            Ratio="2.0" />
 		
 		<DataTemplate x:Key="ITPShellTemplate" DataType="avalonia:JobITPShell">
-			<components:ListViewButton Background="{Binding .,Converter={StaticResource FormColorConverter}}"
-									   Foreground="Black"
-									   Command="{Binding $parent[listView:PrsListView].((modules:SiteItpsViewModel)DataContext).SelectITPCommand}"
-									   CommandParameter="{Binding .}"
-									   Image="{SvgImage /Images/badge.svg}"
-									   Title="{Binding Code}"
-									   Description="{Binding Description}"
-									   Alert="{Binding .,Converter={StaticResource OpenFormsTextConverter}}"/>
+			<!--components:ListViewButton 
+									   Alert="{}"/-->
+            <Button Classes="Standard"
+                    Background="{Binding .,Converter={StaticResource FormColorConverter}}"
+                    Foreground="Black"
+                    Command="{Binding $parent[listView:PrsListView].((modules:SiteItpsViewModel)DataContext).SelectITPCommand}"
+                    CommandParameter="{Binding .}"
+                    Height="80"
+                    Padding="0"
+                    HorizontalContentAlignment="Stretch"
+                    VerticalContentAlignment="Stretch">
+                <Grid>
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="*" />
+                        <RowDefinition Height="1.2*" />
+                    </Grid.RowDefinitions>
+
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="70" />
+                        <ColumnDefinition Width="*" />
+                    </Grid.ColumnDefinitions>
+
+                    <Image Classes="Large"
+                           Grid.Row="0" Grid.Column="0" Grid.RowSpan="2"
+                           Source="{SvgImage /Images/badge.svg}"
+                           HorizontalAlignment="Center"
+                           VerticalAlignment="Center" />
+
+                    <Label Grid.Row="0" Grid.Column="1"
+                           VerticalAlignment="Stretch" VerticalContentAlignment="Center"
+                           FontSize="{StaticResource PrsFontSizeLarge}"
+                           FontWeight="{StaticResource PrsFontWeightBold}"
+                           Content="{Binding Code}" />
+
+                    <TextBlock Grid.Row="1" Grid.Column="1"
+                               FontSize="{StaticResource PrsFontSizeNormal}"
+                               FontStyle="{StaticResource PrsFontStylItalic}"
+                               TextWrapping="WrapWithOverflow"
+                               VerticalAlignment="Stretch"
+                               Text="{Binding Description}" />
+
+                    <Border
+                        Background="Yellow"
+                        BorderBrush="Black"
+                        Grid.Row="0"
+                        Grid.RowSpan="2"
+                        Grid.Column="1"
+                        VerticalAlignment="Top"
+                        HorizontalAlignment="Right"
+                        IsVisible="{Binding ., Converter={StaticResource OpenFormsVisibilityConverter}}"
+                        MinWidth="{Binding $self.Bounds.Height}"
+                        Margin="{Binding $self, Converter={StaticResource MarginDoubler}, ConverterParameter={StaticResource PrsControlSpacing}}"
+                        CornerRadius="{Binding $self.Bounds.Height, Converter={StaticResource SphericalBorder}}">
+
+                        <Label Background="Transparent" Foreground="{StaticResource PrsTileForeground}"
+                               HorizontalContentAlignment="Center"
+                               Content="{Binding .,Converter={StaticResource OpenFormsTextConverter}}" />
+                    </Border>
+
+                    <Border
+                        Background="WhiteSmoke"
+                        BorderBrush="Black"
+                        BorderThickness="1"
+                        Grid.Row="0"
+                        Grid.RowSpan="2"
+                        Grid.Column="1"
+                        VerticalAlignment="Bottom"
+                        HorizontalAlignment="Right"
+                        IsVisible="{Binding ., Converter={StaticResource ClosedFormsVisibilityConverter}}"
+                        MinWidth="{Binding $self.Bounds.Height}"
+                        Margin="{Binding $self, Converter={StaticResource MarginDoubler}, ConverterParameter={StaticResource PrsControlSpacing}}"
+                        CornerRadius="{Binding $self.Bounds.Height, Converter={StaticResource SphericalBorder}}">
+
+                        <Label Background="Transparent" Foreground="{StaticResource PrsTileForeground}"
+                               HorizontalContentAlignment="Center"
+                               Content="{Binding .,Converter={StaticResource ClosedFormsTextConverter}}" />
+                    </Border>
+
+                </Grid>
+            </Button>
 		</DataTemplate>
 	</UserControl.Resources>
     <listView:PrsListView ItemTemplate="{StaticResource ITPShellTemplate}"

+ 15 - 1
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteItps/SiteItpsView.axaml.cs

@@ -36,9 +36,23 @@ public class ITPTextConverter : AbstractConverter<JobITPShell, string>
     {
         if (value is null) return "";
 
-        return value.OpenForms > 0 ? value.OpenForms.ToString() : "";
+        return !Closed
+            ? (value.OpenForms > 0 ? value.OpenForms.ToString() : "")
+            : (value.ClosedForms > 0 ? value.ClosedForms.ToString() : "");
     }
 }
+public class ITPVisibilityConverter : AbstractConverter<JobITPShell, bool>
+{
+    public bool Closed { get; set; }
+    
+    protected override bool Convert(JobITPShell? value, object? parameter = null)
+    {
+        if (value is null) return false;
+
+        return !Closed ? value.OpenForms > 0 : value.ClosedForms > 0;
+    }
+}
+
 
 public partial class SiteItpsView : UserControl
 {

+ 4 - 2
prs.classes/Entities/Job/ITP/JobITP.cs

@@ -40,7 +40,8 @@ namespace Comal.Classes
         {
             public override IComplexFormulaNode<JobITP, int> GetFormula() =>
                 Count<JobITPForm, Guid>(x => x.Property(x => x.ID),
-                    new Filter<JobITPForm>(x => x.FormCompleted).IsEqualTo(DateTime.MinValue))
+                    new Filter<JobITPForm>(x => x.FormCompleted).IsEqualTo(DateTime.MinValue)
+                        .And(x => x.FormCancelled).IsEqualTo(DateTime.MinValue))
                 .WithLink(x => x.Parent.ID, x => x.ID);
         }
         [ComplexFormula(typeof(OpenFormsFormula))]
@@ -51,7 +52,8 @@ namespace Comal.Classes
         {
             public override IComplexFormulaNode<JobITP, int> GetFormula() =>
                 Count<JobITPForm, Guid>(x => x.Property(x => x.ID),
-                    new Filter<JobITPForm>(x => x.FormCompleted).IsNotEqualTo(DateTime.MinValue))
+                    new Filter<JobITPForm>(x => x.FormCompleted).IsNotEqualTo(DateTime.MinValue)
+                        .And(x => x.FormCancelled).IsEqualTo(DateTime.MinValue))
                 .WithLink(x => x.Parent.ID, x => x.ID);
         }
         [ComplexFormula(typeof(ClosedFormsFormula))]