Browse Source

Working on DeliveryList Functionality

frankvandenbos 6 tháng trước cách đây
mục cha
commit
1c5d10a01f

+ 3 - 0
PRS.Avalonia/Directory.Packages.props

@@ -15,6 +15,9 @@
     <PackageVersion Include="Avalonia.Desktop" Version="11.2.3" />
     <PackageVersion Include="Avalonia.Browser" Version="11.2.1" />
     <PackageVersion Include="Avalonia.Android" Version="11.2.1" />
+    <PackageVersion Include="Avalonia.Xaml.Interactions" Version="11.2.0.7" />
+    <PackageVersion Include="Avalonia.Xaml.Interactions.Custom" Version="11.2.0.7" />
+    <PackageVersion Include="Avalonia.Xaml.Interactions.Events" Version="11.2.0.7" />
     <PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
     <PackageVersion Include="Material.Avalonia" Version="3.9.1" />
     <PackageVersion Include="Material.Avalonia.DataGrid" Version="3.9.1" />

+ 1 - 0
PRS.Avalonia/PRS.Avalonia/App.axaml

@@ -18,6 +18,7 @@
         <StyleInclude Source="Assets/Classes/Label.axaml" />
         <StyleInclude Source="Assets/Classes/TextBox.axaml" />
         <StyleInclude Source="Assets/Classes/Separator.axaml" />
+        <StyleInclude Source="Assets/Classes/ListBox.axaml" />
 
     </Application.Styles>
 

+ 14 - 0
PRS.Avalonia/PRS.Avalonia/Assets/Classes/ListBox.axaml

@@ -0,0 +1,14 @@
+<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:avalonia="clr-namespace:PRS.Avalonia">
+        
+    <Style Selector="ListBoxItem">
+        <Setter Property="Padding">
+            <avalonia:ThicknessProvider Left="0" Right="0" Top="0" Bottom="0" />
+        </Setter>
+    </Style>
+    
+    <!--  PointerOver State  -->
+    <Style Selector="ListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter">
+        <Setter Property="Background" Value="Transparent" />
+    </Style>
+</Styles>

+ 98 - 2
PRS.Avalonia/PRS.Avalonia/Modules/DeliveryModule/DeliveryList/DeliveryListView.axaml

@@ -3,8 +3,104 @@
              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:avalonia="clr-namespace:PRS.Avalonia"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="PRS.Avalonia.Modules.DeliveryListView"
-             x:DataType="modules:DeliveryScannerViewModel">
-    Welcome to Avalonia!
+             x:DataType="modules:DeliveryListViewModel">
+
+    <UserControl.Resources>
+        
+        <modules:DeliveryColorConverter x:Key="DeliveryBackgroundConverter" Delivered="DimGray" Booked="LightGreen" Due="LightGray" />
+        <modules:DeliveryColorConverter x:Key="DeliveryForegroundConverter" Delivered="WhiteSmoke" Booked="Black" Due="DimGray" />
+        <modules:DeliveryDescriptionConverter x:Key="DeliveryDescriptionConverter"/>
+        <modules:DeliveryAddressConverter x:Key="DeliveryAddressConverter"/>
+        <modules:DeliveryDateConverter x:Key="DeliveryDateConverter"/>
+        <modules:DeliveryStatusConverter x:Key="DeliveryStatusConverter"/>
+        
+        <!-- Command="{Binding $parent[ItemsControl].((modules:DeliveryListViewModel)DataContext).SelectDeliveryCommand}" -->
+        <!-- CommandParameter="{Binding .}" -->
+        <!-- HorizontalContentAlignment="Stretch" -->
+        
+        <DataTemplate 
+            x:Key="DeliveryShellTemplate" 
+            x:DataType="avalonia:DeliveryShell">
+            
+            <Border
+                Margin="0,0,0,2"
+                Background="{Binding ., Converter={StaticResource DeliveryBackgroundConverter}}"
+                
+                >
+                <Grid>
+            
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="Auto" />
+                        <ColumnDefinition Width="*" />
+                        <ColumnDefinition Width="Auto" />                            
+                    </Grid.ColumnDefinitions>
+
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="Auto"/>
+                        <RowDefinition Height="Auto"/>
+                    </Grid.RowDefinitions>
+
+                    <Label
+                        Content="{Binding Number}"
+                        Grid.Row="0"
+                        Grid.Column="0"
+                        FontSize="{StaticResource PrsFontSizeSmall}"
+                        Foreground="{Binding ., Converter={StaticResource DeliveryForegroundConverter}}"
+                        HorizontalContentAlignment="Center"/>
+                    
+                    <TextBlock 
+                        Text="{Binding ., Converter={StaticResource DeliveryDescriptionConverter}}"
+                        Grid.Row="0"
+                        Grid.Column="1"
+                        FontSize="{StaticResource PrsFontSizeSmall}"
+                        Foreground="{Binding ., Converter={StaticResource DeliveryForegroundConverter}}"
+                        TextTrimming="CharacterEllipsis"/>
+                    
+                    <Label  
+                        Content="{Binding ., Converter={StaticResource DeliveryStatusConverter}}"
+                        Grid.Row="0"
+                        Grid.Column="2"
+                        FontSize="{StaticResource PrsFontSizeSmall}"
+                        Foreground="{Binding ., Converter={StaticResource DeliveryForegroundConverter}}"
+                        HorizontalContentAlignment="Center"/>
+                    
+                    <Label  
+                        Content="{Binding ., Converter={StaticResource DeliveryDateConverter}, StringFormat='{}{0:dd MMM yy}'}"
+                        Grid.Row="1"
+                        Grid.Column="2"
+                        FontSize="{StaticResource PrsFontSizeSmall}"
+                        Foreground="{Binding ., Converter={StaticResource DeliveryForegroundConverter}}"
+                        HorizontalContentAlignment="Center"/>
+
+                    <TextBlock  
+                        Text="{Binding ., Converter={StaticResource DeliveryAddressConverter}}"
+                        Grid.Row="1"
+                        Grid.Column="0"
+                        Grid.ColumnSpan="2"
+                        FontSize="{StaticResource PrsFontSizeExtraSmall}"
+                        FontStyle="{StaticResource PrsFontStylItalic}"
+                        Foreground="{Binding ., Converter={StaticResource DeliveryForegroundConverter}}"
+                        LineHeight="1"
+                        TextWrapping="Wrap"/>
+                    
+                </Grid>   
+
+            </Border>
+            
+        </DataTemplate>
+    </UserControl.Resources>
+    
+    
+        <ListBox x:Name="_listBox"
+            ItemsSource="{Binding Deliveries.Items}"
+            ItemTemplate="{StaticResource DeliveryShellTemplate}">
+            <ListBox.GestureRecognizers>
+                <PullGestureRecognizer PullDirection="TopToBottom" ></PullGestureRecognizer>
+            </ListBox.GestureRecognizers>
+        </ListBox>
+
+    
 </UserControl>

+ 94 - 1
PRS.Avalonia/PRS.Avalonia/Modules/DeliveryModule/DeliveryList/DeliveryListView.axaml.cs

@@ -1,11 +1,104 @@
-using Avalonia.Controls;
+using System;
+using System.Threading;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Media;
+using Avalonia.Media.Immutable;
+using InABox.Avalonia.Converters;
+using InABox.Core;
 
 namespace PRS.Avalonia.Modules;
 
+public class DeliveryDescriptionConverter : AbstractConverter<DeliveryShell, String>
+{
+    protected override string Convert(DeliveryShell? value, object? parameter = null)
+    {
+        return value != null
+            ? value.JobID != Guid.Empty
+                ? $"{value.JobNumber}: {value.JobName}"
+                : value.ContactName
+            : "";
+    }
+}
+
+public class DeliveryDateConverter : AbstractConverter<DeliveryShell?, DateTime>
+{
+    protected override DateTime Convert(DeliveryShell? value, object? parameter = null)
+    {
+        return value == null
+            ? DateTime.MinValue
+            : !value.Delivered.IsEmpty()
+                ? value.Delivered
+                : !value.Booked.IsEmpty()
+                    ? value.Booked
+                    : value.Due;
+    }
+}
+public class DeliveryStatusConverter : AbstractConverter<DeliveryShell?, String>
+{
+    
+    protected override String Convert(DeliveryShell? value, object? parameter = null)
+    {
+        return value == null
+            ? ""
+            : !value.Delivered.IsEmpty()
+                ? "DELIVERED"
+                : !value.Booked.IsEmpty()
+                    ? "BOOKED"
+                    : "DUE";
+    }
+}
+
+
+public class DeliveryColorConverter : AbstractConverter<DeliveryShell?, Color>
+{
+    
+    public Color Delivered { get; set; }
+    public Color Booked { get; set; }
+    public Color Due { get; set; }
+    public Color Unknown { get; set; }
+    
+    protected override Color Convert(DeliveryShell? value, object? parameter = null)
+    {
+        return value == null
+            ? Unknown
+            : !value.Delivered.IsEmpty()
+                ? Delivered
+                : !value.Booked.IsEmpty()
+                    ? Booked
+                    : Due;
+    }
+}
+
+public class DeliveryAddressConverter : AbstractConverter<DeliveryShell, String>
+{
+    protected override string Convert(DeliveryShell? value, object? parameter = null)
+    {
+        return $"{value?.Street} {value?.City} {value?.PostCode}".Trim().Replace("  ", " ");
+    }
+}
+
 public partial class DeliveryListView : UserControl
 {
     public DeliveryListView()
     {
         InitializeComponent();
+        _listBox.AddHandler(Gestures.PullGestureEvent, (sender, args) =>
+        {
+            
+        });
+        _listBox.AddHandler(Gestures.PullGestureEndedEvent, (sender, args) =>
+        {
+            
+        });
+    }
+
+    private void RefreshContainer_OnRefreshRequested(object? sender, RefreshRequestedEventArgs e)
+    {
+        var deferral = e.GetDeferral();
+
+        Thread.Sleep(1000);
+        
+        deferral.Complete();       
     }
 }

+ 37 - 2
PRS.Avalonia/PRS.Avalonia/Modules/DeliveryModule/DeliveryList/DeliveryListViewModel.cs

@@ -1,6 +1,41 @@
-namespace PRS.Avalonia.Modules;
+using System;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+using Comal.Classes;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using InABox.Core;
 
-public class DeliveryListViewViewModel : ModuleViewModel
+namespace PRS.Avalonia.Modules;
+
+
+
+
+public partial class DeliveryListViewModel : ModuleViewModel
 {
     public override string Title => "Delivery List";
+
+    [ObservableProperty]
+    private DeliveryModel _deliveries;
+
+    public DeliveryListViewModel()
+    {
+        Deliveries = new DeliveryModel(
+            DataAccess, 
+            () => new Filter<Delivery>().All(),
+            () => Deliveries.DefaultFileName()
+        );
+    }
+
+    protected override async Task<TimeSpan> OnRefresh()
+    {
+        await Deliveries.RefreshAsync(false);
+        return TimeSpan.Zero;
+    }
+
+    [RelayCommand]
+    private void SelectDelivery(DeliveryShell shell)
+    {
+        
+    }
 }

+ 1 - 1
PRS.Avalonia/PRS.Avalonia/Modules/DeliveryModule/DeliveryModuleViewModel.cs

@@ -11,7 +11,7 @@ public partial class DeliveryModuleViewModel : ModuleViewModel
     {
         Modules = new PrsModuleCollection();
         Modules.Add<DeliveryScannerViewModel>("Delivery Scanner", "Identify Delivery Items by barcode", "barcode");
-        Modules.Add<SiteDocumentsViewModel>("Delivery List", "View open or completed Deliveries", "delivery");
+        Modules.Add<DeliveryListViewModel>("Delivery List", "View open or completed Deliveries", "delivery");
     }
 
     public override string Title => "Deliveries";

+ 3 - 0
PRS.Avalonia/PRS.Avalonia/PRS.Avalonia.csproj

@@ -304,6 +304,9 @@
             <IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
             <PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
         </PackageReference>
+        <PackageReference Include="Avalonia.Xaml.Interactions" />
+        <PackageReference Include="Avalonia.Xaml.Interactions.Custom" />
+        <PackageReference Include="Avalonia.Xaml.Interactions.Events" />
         <PackageReference Include="CommunityToolkit.Mvvm"/>
         <PackageReference Include="Material.Avalonia"/>
         <PackageReference Include="Material.Avalonia.DataGrid"/>

+ 1 - 1
PRS.Avalonia/PRS.Avalonia/Repositories/Delivery/DeliveryModel.cs

@@ -7,7 +7,7 @@ namespace PRS.Avalonia;
 
 public class DeliveryModel : CoreRepository<DeliveryModel, DeliveryShell, Delivery>
 {
-    public DeliveryModel(IModelHost host, Func<Filter<Delivery>> filter) : base(host, filter)
+    public DeliveryModel(IModelHost host, Func<Filter<Delivery>> filter, Func<string> filename) : base(host, filter, filename)
     {
     }
 }