Bläddra i källkod

avalonia: Added In/Out Board

Kenric Nugteren 1 månad sedan
förälder
incheckning
51d9f51d6f

+ 3 - 0
PRS.Avalonia/PRS.Avalonia/Images/Images.cs

@@ -34,6 +34,8 @@ public static class Images
     public static SvgImage? barcode => LoadSVG("/Images/barcode.svg");
     public static SvgImage? books => LoadSVG("/Images/books.svg");
     public static SvgImage? camera => LoadSVG("/Images/camera.svg");
+    public static SvgImage? circle_green => LoadSVG("/Images/circle_green.svg");
+    public static SvgImage? circle_red => LoadSVG("/Images/circle_red.svg");
     public static SvgImage? clock => LoadSVG("/Images/clock.svg");
     public static SvgImage? construction => LoadSVG("/Images/construction.svg");
     public static SvgImage? delivery => LoadSVG("/Images/delivery.svg");
@@ -49,6 +51,7 @@ public static class Images
     public static SvgImage? menu => LoadSVG("/Images/menu.svg");
     public static SvgImage? notification => LoadSVG("/Images/notification.svg");
     public static SvgImage? person => LoadSVG("/Images/person.svg");
+    public static SvgImage? phone => LoadSVG("/Images/phone.svg");
     public static SvgImage? plus => LoadSVG("/Images/plus.svg");
     public static SvgImage? refresh => LoadSVG("/Images/refresh.svg");
     public static SvgImage? save => LoadSVG("/Images/save.svg");

+ 13 - 2
PRS.Avalonia/PRS.Avalonia/Modules/InOut/InOutView.axaml

@@ -2,7 +2,18 @@
              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:components="using:InABox.Avalonia.Components"
+			 xmlns:local="using:PRS.Avalonia.Modules"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
-             x:Class="PRS.Avalonia.Modules.InOutView">
-    Welcome to Avalonia!
+             x:Class="PRS.Avalonia.Modules.InOutView"
+			 x:DataType="local:InOutViewModel">
+	<components:AvaloniaDataGrid ItemsSource="{Binding ItemsSource}"
+								 Columns="{Binding Columns}"
+								 Margin="5"
+								 RefreshRequested="Grid_OnRefreshRequested"
+								 SelectionMode="AlwaysSelected"
+								 ShowRecordCount="True"
+								 CanSearch="True"
+								 RefreshVisible="True"
+								 LastUpdated="{Binding LastUpdated}"/>
 </UserControl>

+ 8 - 0
PRS.Avalonia/PRS.Avalonia/Modules/InOut/InOutView.axaml.cs

@@ -1,11 +1,19 @@
 using Avalonia.Controls;
+using InABox.Avalonia.Components;
 
 namespace PRS.Avalonia.Modules;
 
 public partial class InOutView : UserControl
 {
+    private InOutViewModel Model => (DataContext as InOutViewModel)!;
+
     public InOutView()
     {
         InitializeComponent();
     }
+
+    private void Grid_OnRefreshRequested(object sender, AvaloniaDataGridRefreshRequestedEventArgs e)
+    {
+        Model.RefreshCommand.Execute(null);
+    }
 }

+ 90 - 1
PRS.Avalonia/PRS.Avalonia/Modules/InOut/InOutViewModel.cs

@@ -1,6 +1,95 @@
+using Avalonia.Controls;
+using Avalonia.Media;
+using Comal.Classes;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using InABox.Avalonia.Components;
+using InABox.Core;
+using System;
+using System.Collections;
+using System.Threading.Tasks;
+
 namespace PRS.Avalonia.Modules;
 
-public class InOutViewModel : ModuleViewModel
+public partial class InOutViewModel : ModuleViewModel
 {
     public override string Title => "In/Out";
+
+    [ObservableProperty]
+    private AvaloniaDataGridColumns _columns;
+
+    [ObservableProperty]
+    private IEnumerable? _itemsSource;
+
+    [ObservableProperty]
+    private DateTime _lastUpdated;
+
+    [ObservableProperty]
+    private InOutModel _model;
+
+    public InOutViewModel()
+    {
+        ProgressVisible = true;
+
+        Columns = new AvaloniaDataGridColumns().BeginUpdate();
+        if (!Security.IsAllowed<CanViewMobileInOutBoardDetails>())
+        {
+            Columns.Add(new AvaloniaDataGridImageColumn<InOutShell>()
+            {
+                Column = x => x.In,
+                Caption = "In?",
+                // Header = circle_gray
+                // Margin = 6
+                Width = new GridLength(30),
+            });
+        }
+        Columns.Add(new AvaloniaDataGridTextColumn<InOutShell>
+        {
+            Column = x => x.Name,
+            Alignment = TextAlignment.Start,
+            Width = GridLength.Star
+        });
+        if (Security.IsAllowed<CanViewMobileInOutBoardDetails>())
+        {
+            Columns.Add(new AvaloniaDataGridTimeColumn<InOutShell> { Column = x => x.Start, Width = new(50) });
+            Columns.Add(new AvaloniaDataGridTimeColumn<InOutShell> { Column = x => x.Finish, Width = new(50) });
+        }
+
+        Columns.Add(new AvaloniaDataGridImageColumn<InOutShell>()
+        {
+            Column = x => x.Call,
+            Caption = "Call",
+            Width = new GridLength(30),
+            Tapped = CallEmployee
+            // Margin = 6
+            // Header = phone
+        });
+
+        Columns.EndUpdate();
+
+        Model = new InOutModel(DataAccess,
+            () => new Filters<Employee>()
+                .Add(LookupFactory.DefineFilter<Employee>())
+                .Add(new Filter<Employee>(x => x.ID).IsNotEqualTo(Repositories.Me.ID).And(x => x.ShowOnInOutBoard).IsEqualTo(true))
+                .Combine() ?? new Filter<Employee>().All());
+    }
+
+    protected override async Task<TimeSpan> OnRefresh()
+    {
+        await Refresh();
+        return TimeSpan.Zero;
+    }
+
+    private void CallEmployee(IAvaloniaDataGridColumn column, object? arg2)
+    {
+    }
+
+    [RelayCommand]
+    private async Task Refresh()
+    {
+        await Model.RefreshAsync(true);
+        ItemsSource = Model.Items;
+        LastUpdated = Model.LastUpdated;
+        ProgressVisible = false;
+    }
 }

+ 1 - 1
PRS.Avalonia/PRS.Avalonia/Repositories/InOut/InOutModel.cs

@@ -10,7 +10,7 @@ public class InOutModel : CoreRepository<InOutModel, InOutShell, Employee>
 {
     private Tuple<Guid, TimeSpan, TimeSpan>[] _statuses;
 
-    public InOutModel(IModelHost host, Func<Filter<Employee>> filter) : base(host, filter)
+    public InOutModel(IModelHost host, Func<Filter<Employee>> filter, Func<string>? filename = null) : base(host, filter, filename)
     {
     }
 

+ 7 - 7
PRS.Avalonia/PRS.Avalonia/Repositories/InOut/InOutShell.cs

@@ -1,4 +1,5 @@
 using System;
+using Avalonia.Media;
 using Comal.Classes;
 using InABox.Avalonia;
 
@@ -10,9 +11,9 @@ public class InOutShell : Shell<InOutModel, Employee>
     
     public string Mobile => Get<string>();
 
-    // public ImageSource Call => string.IsNullOrWhiteSpace(Mobile)
-    //     ? null
-    //     : ImageSource.FromFile("phone");
+    public IImage? Call => string.IsNullOrWhiteSpace(Mobile)
+        ? null
+        : Images.phone;
 
     public TimeSpan Start => Parent.StartTime(ID);
 
@@ -20,10 +21,9 @@ public class InOutShell : Shell<InOutModel, Employee>
     
     public bool IsClockedOn => Parent.IsClockedOn(ID);
 
-    // //public Bitmap bmp 
-    // public ImageSource In => Parent.IsClockedOn(ID)
-    //     ? ImageSource.FromFile("circle_green")
-    //     : ImageSource.FromFile("circle_red");
+    public IImage? In => Parent.IsClockedOn(ID)
+        ? Images.circle_green
+        : Images.circle_red;
 
     protected override void ConfigureColumns(ShellColumns<InOutModel, Employee> columns)
     {