Pārlūkot izejas kodu

Added filter button and checkbox to ignore non-scheduled equipment to Maintenance Planner

Kenric Nugteren 7 mēneši atpakaļ
vecāks
revīzija
d4a18ae649

+ 56 - 167
prs.desktop/Dashboards/Equipment/EquipmentSchedulesDashboard.xaml.cs

@@ -20,12 +20,16 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using InABox.Configuration;
 using Client = InABox.Clients.Client;
+using System.Windows;
+using InABox.Wpf;
 
 namespace PRSDesktop.Dashboards;
 
 public class EquipmentSchedulesDashboardProperties : IUserConfigurationSettings, IDashboardProperties
 {
+    public bool OnlyShowSchedules { get; set; } = true;
 
+    public DynamicGridSelectedFilterSettings Filters { get; set; } = new();
 }
 
 public class ScheduleViewModel : INotifyPropertyChanged
@@ -202,175 +206,53 @@ public partial class EquipmentSchedulesDashboard : UserControl, IDashboardWidget
 
     #region Header
 
-    CheckBox ShowAllBox = null!;
+    private CheckBox ShowSchedulesBox = null!;
+    private FilterButton<Equipment> FilterBtn = null!;
 
     public void SetupHeader()
     {
-        ShowAllBox = new CheckBox();
-
-        // CategoryBox = new ComboBox
-        // {
-        //     Width = 150,
-        //     VerticalContentAlignment = VerticalAlignment.Center,
-        //     Margin = new Thickness(0, 0, 5, 0)
-        // };
-        // CategoryBox.ItemsSource = Categories;
-        // CategoryBox.SelectedValuePath = "Item1";
-        // CategoryBox.DisplayMemberPath = "Item3";
-        // CategoryBox.SelectedValue = Properties.Category;
-        // CategoryBox.SelectionChanged += Category_SelectionChanged;
-
-        // CategoryButtonPanel = new StackPanel
-        // {
-        //     Orientation = Orientation.Horizontal,
-        //     Margin = new Thickness(0, 0, 5, 0)
-        // };
-        // 
-        // CategoryButtons.Clear();
-        // foreach(var (appliesTo, category, display) in Categories)
-        // {
-        //     if(category is null)
-        //     {
-        //         continue;
-        //     }
-        //     var button = new Button();
-        //     button.Tag = appliesTo;
-        //     button.Margin = new Thickness(0, 0, 2, 0);
-        //     button.BorderBrush = new SolidColorBrush(Colors.Gray);
-        //     button.BorderThickness = new Thickness(0.75);
-        //     button.Width = 25D;
-        //     button.Padding = new Thickness(2);
-        //     button.ToolTip = category.EntityName().Split('.').Last().SplitCamelCase();
-        //     if (CategoryImages.TryGetValue(category, out var image))
-        //     {
-        //         button.Content = new Image { Source = image.AsBitmapImage() };
-        //     }
-        //     else
-        //     {
-        //         button.Content = display;
-        //     }
-
-        //     button.Click += CatagoryButton_Click;
-        //     CategoryButtons.Add(category, button);
-        //     CategoryButtonPanel.Children.Add(button);
-        // }
-
-        // if (Properties.UseIconsForFormTypes)
-        // {
-        //     CategoryButtonPanel.Visibility = Visibility.Visible;
-        //     CategoryBox.Visibility = Visibility.Collapsed;
-        // }
-        // else
-        // {
-        //     CategoryButtonPanel.Visibility = Visibility.Collapsed;
-        //     CategoryBox.Visibility = Visibility.Visible;
-        // }
-
-        // FormBox = new ComboBox
-        // {
-        //     Width = 250,
-        //     VerticalContentAlignment = VerticalAlignment.Center,
-        //     Margin = new Thickness(0, 0, 5, 0),
-        //     IsEnabled = false
-        // };
-        // FormBox.SelectionChanged += FormBox_SelectionChanged;
-        // FormBox.ItemsSource = new Dictionary<DigitalForm, string> { };
-
-        // JobBox = new ComboBox
-        // {
-        //     Width = 250,
-        //     Margin = new Thickness(0, 0, 5, 0),
-        //     VerticalContentAlignment = VerticalAlignment.Center
-        // };
-        // JobBox.ItemsSource = Jobs.ToDictionary(x => x.ID, x => $"{x.JobNumber} : {x.Name}");
-        // JobBox.SelectedIndex = 0;
-        // JobBox.SelectedValuePath = "Key";
-        // JobBox.DisplayMemberPath = "Value";
-        // JobBox.SelectionChanged += JobBox_SelectionChanged;
-
-        // DateTypeBox = new ComboBox
-        // {
-        //     Width = 120,
-        //     VerticalContentAlignment = VerticalAlignment.Center
-        // };
-        // DateTypeBox.ItemsSource = FilterTypes;
-        // DateTypeBox.SelectedValuePath = "Key";
-        // DateTypeBox.DisplayMemberPath = "Value";
-        // DateTypeBox.SelectedValue = Properties.DateFilterType;
-        // DateTypeBox.SelectionChanged += DateTypeBox_SelectionChanged;
-
-        // FromLabel = new Label { Content = "From", VerticalContentAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 5, 0) };
-        // FromPicker = new DatePicker
-        // {
-        //     Width = 100,
-        //     Background = new SolidColorBrush(Colors.LightYellow),
-        //     VerticalContentAlignment = VerticalAlignment.Center,
-        //     FirstDayOfWeek = DayOfWeek.Monday,
-        //     Margin = new Thickness(0, 0, 5, 0)
-        // };
-        // FromPicker.SelectedDateChanged += FromPicker_SelectedDateChanged;
-
-        // ToLabel = new Label { Content = "To", VerticalContentAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 5, 0) };
-        // ToPicker = new DatePicker
-        // {
-        //     Width = 100,
-        //     Background = new SolidColorBrush(Colors.LightYellow),
-        //     VerticalContentAlignment = VerticalAlignment.Center,
-        //     FirstDayOfWeek = DayOfWeek.Monday,
-        //     Margin = new Thickness(0, 0, 5, 0)
-        // };
-        // ToPicker.SelectedDateChanged += ToPicker_SelectedDateChanged;
-
-        // IncompleteFormsBox = new ComboBox
-        // {
-        //     Width = 130,
-        //     Margin = new Thickness(0, 0, 5, 0),
-        //     VerticalContentAlignment = VerticalAlignment.Center
-        // };
-        // IncompleteFormsBox.ItemsSource = new List<Tuple<string, bool>>
-        // {
-        //     new Tuple<string, bool>("Completed Forms", false),
-        //     new Tuple<string, bool>("All Forms", true)
-        // };
-        // IncompleteFormsBox.DisplayMemberPath = "Item1";
-        // IncompleteFormsBox.SelectedValuePath = "Item2";
-        // IncompleteFormsBox.SelectedValue = Properties.ShowIncompleteForms;
-        // IncompleteFormsBox.SelectionChanged += IncompleteFormsBox_SelectionChanged;
-
-        // Print = new Button
-        // {
-        //     Width = 25,
-        //     Height = 25,
-        //     Content = new Image { Source = PRSDesktop.Resources.printer.AsBitmapImage() }
-        // };
-        // Print.Click += Print_Click;
-
-        // FilterBtn = new Button
-        // {
-        //     Width = 25,
-        //     Height = 25,
-        //     Content = new Image { Source = InABox.Wpf.Resources.filter.AsBitmapImage() },
-        //     Margin = new Thickness(0, 0, 5, 0)
-        // };
-        // FilterBtn.Click += Filter_Click;
-
-        // Header.BeginUpdate()
-        //     .Clear()
-        //     .Add(CategoryBox)
-        //     .Add(CategoryButtonPanel)
-        //     .Add(FormBox)
-        //     .Add(JobBox)
-        //     .Add(DateTypeBox)
-        //     .Add(FromLabel)
-        //     .Add(FromPicker)
-        //     .Add(ToLabel)
-        //     .Add(ToPicker)
-        //     .Add(IncompleteFormsBox)
-        //     .AddRight(FilterBtn)
-        //     .AddRight(Print)
-        //     .EndUpdate();
-
-        // UpdateCategory(Properties.Category);
+        ShowSchedulesBox = new CheckBox
+        {
+            Content = "Only show schedules?",
+            IsChecked = Properties.OnlyShowSchedules,
+            VerticalAlignment = VerticalAlignment.Center
+        };
+        ShowSchedulesBox.Checked += ShowSchedulesBox_Checked;
+        ShowSchedulesBox.Unchecked += ShowSchedulesBox_Checked;
+
+        FilterBtn = new FilterButton<Equipment>(
+            new GlobalConfiguration<CoreFilterDefinitions>(nameof(EquipmentSchedulesDashboard)),
+            new UserConfiguration<CoreFilterDefinitions>(nameof(EquipmentSchedulesDashboard)))
+        {
+            Width = 25,
+            Height = 25,
+            Padding = new()
+        };
+        FilterBtn.SetSettings(Properties.Filters, false);
+        FilterBtn.OnFiltersSelected += FilterBtn_OnFiltersSelected;
+        FilterBtn.OnFilterRefresh += FilterBtn_OnFilterRefresh;
+
+        Header.BeginUpdate()
+            .Clear()
+            .Add(ShowSchedulesBox)
+            .AddRight(FilterBtn)
+            .EndUpdate();
+    }
+
+    private void ShowSchedulesBox_Checked(object sender, RoutedEventArgs e)
+    {
+        Properties.OnlyShowSchedules = ShowSchedulesBox.IsChecked == true;
+        Refresh();
+    }
+
+    private void FilterBtn_OnFilterRefresh()
+    {
+        Refresh();
+    }
+
+    private void FilterBtn_OnFiltersSelected(DynamicGridSelectedFilterSettings filters)
+    {
+        Properties.Filters = filters;
     }
 
     #endregion
@@ -428,9 +310,11 @@ public partial class EquipmentSchedulesDashboard : UserControl, IDashboardWidget
 
     public void Refresh()
     {
+        var eqFilter = FilterBtn.GetFilter();
+
         var results = Client.QueryMultiple(
             new KeyedQueryDef<Equipment>(
-                new Filter<Equipment>().All(),
+                eqFilter,
                 Columns.None<Equipment>().Add(x => x.ID)
                     .Add(x => x.Code)
                     .Add(x => x.Description)
@@ -462,6 +346,11 @@ public partial class EquipmentSchedulesDashboard : UserControl, IDashboardWidget
             foreach (var equipmentItem in equipmentItems)
             {
                 var equipmentSchedules = schedules.GetValueOrDefault(equipmentItem.ID);
+                if(equipmentSchedules is null && Properties.OnlyShowSchedules)
+                {
+                    continue;
+                }
+
                 var model = new EquipmentScheduleViewModel
                 {
                     Code = equipmentItem.Code,