Просмотр исходного кода

avalonia: more tweaks to In/Out Board

Kenric Nugteren 2 месяцев назад
Родитель
Сommit
eeaf36d2e9

+ 3 - 3
PRS.Avalonia/PRS.Avalonia/Modules/InOut/InOutView.axaml

@@ -7,16 +7,16 @@
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="PRS.Avalonia.Modules.InOutView"
 			 x:DataType="local:InOutViewModel">
-	<Grid>
+	<Grid Margin="2">
 		<Grid.RowDefinitions>
 			<RowDefinition Height="Auto"/>
 			<RowDefinition Height="*"/>
 		</Grid.RowDefinitions>
-		<components:ButtonStrip Name="Filters" Grid.Row="0" ItemsSource="{Binding FilterButtons}" SelectedCommand="{Binding FilterSelectedCommand}"/>
+		<components:ButtonStrip Name="Filters" Grid.Row="0" ItemsSource="{Binding FilterButtons}" SelectedCommand="{Binding FilterSelectedCommand}"
+								Margin="0,0,0,2" ItemSpacing="2"/>
 		<components:AvaloniaDataGrid Grid.Row="1"
 									 ItemsSource="{Binding ItemsSource}"
 									 Columns="{Binding Columns}"
-									 Margin="5"
 									 RefreshRequested="Grid_OnRefreshRequested"
 									 Focusable="False"
 									 SelectionMode="None"

+ 14 - 7
PRS.Avalonia/PRS.Avalonia/Modules/InOut/InOutViewModel.cs

@@ -18,7 +18,7 @@ namespace PRS.Avalonia.Modules;
 public partial class InOutViewModel : ModuleViewModel
 {
     const string AllFilter = "All";
-    const string NotInFilter = "Not In";
+    const string NotInFilter = "Absent";
 
     public override string Title => "In/Out";
 
@@ -78,13 +78,14 @@ public partial class InOutViewModel : ModuleViewModel
                 .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());
-
-        FilterButtons = [AllFilter, NotInFilter, .. Model.AvailableFilters];
     }
 
     protected override async Task<TimeSpan> OnRefresh()
     {
         await Refresh();
+
+        FilterButtons = [AllFilter, NotInFilter, .. Model.AvailableFilters.Where(x => x.Name != "All")];
+
         return TimeSpan.Zero;
     }
 
@@ -110,11 +111,16 @@ public partial class InOutViewModel : ModuleViewModel
     }
 
     [RelayCommand]
-    private void FilterSelected(object? filter)
+    private async Task FilterSelected(object? filter)
     {
-        if(filter is string stringFilter)
+        if (filter is string stringFilter)
         {
-            Model.SelectFilter(null);
+            if (Model.SelectedFilterName is not null)
+            {
+                Model.SelectFilter(null);
+                await Model.RefreshAsync(true);
+            }
+
             if(stringFilter == AllFilter)
             {
                 Model.Search(null);
@@ -127,7 +133,8 @@ public partial class InOutViewModel : ModuleViewModel
         else if(filter is CoreRepositoryFilter coreFilter)
         {
             Model.SelectFilter(coreFilter.Name);
-            Model.Search(null);
+            Model.SearchPredicate = null;
+            await Model.RefreshAsync(true);
         }
     }
 }

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

@@ -186,7 +186,6 @@ public class InOutModel : CoreRepository<InOutModel, InOutShell, Employee>
 
     protected override void AfterLoad(MultiQuery query)
     {
-        base.AfterLoad(query);
         _timeSheets = query.Get<TimeSheet>()
             .ToObjects<TimeSheet>()
             .GroupBy(x => x.EmployeeLink.ID)
@@ -203,5 +202,8 @@ public class InOutModel : CoreRepository<InOutModel, InOutShell, Employee>
             .ToDictionary(x => x.Key, x => x.ToArray());
         _activities = query.Get<Activity>()
             .ToObjects<Activity>().ToDictionary(x => x.ID);
+
+        // Needs to happen after the above things.
+        base.AfterLoad(query);
     }
 }