Преглед на файлове

Added option to use icons instead of a drop down for Dashboard category

Kenric Nugteren преди 1 година
родител
ревизия
a826a2331d

+ 136 - 14
prs.desktop/Dashboards/Common/DigitalFormsDashboard.xaml.cs

@@ -37,6 +37,9 @@ using InABox.Wpf.Reports;
 using System.ComponentModel;
 using Syncfusion.Windows.Shared;
 using System.Globalization;
+using System.Windows.Media.Imaging;
+using System.Drawing;
+using Image = System.Windows.Controls.Image;
 
 namespace PRSDesktop
 {
@@ -82,6 +85,8 @@ namespace PRSDesktop
         public bool ShowJobFilter { get; set; } = false;
         public bool ShowDateFilter { get; set; } = true;
 
+        public bool UseIconsForFormTypes { get; set; } = false;
+
         public string? Category { get; set; }
 
         public Guid SelectedForm { get; set; }
@@ -113,7 +118,8 @@ namespace PRSDesktop
 
         private List<DigitalForm> DigitalForms;
         private List<Job> Jobs;
-        private Dictionary<string, string> Categories;
+
+        private List<Tuple<string, Type?, string>> Categories;
 
         public DashboardHeader Header { get; set; } = new();
 
@@ -143,9 +149,18 @@ namespace PRSDesktop
             categories.OnAfterGenerateLookups += (sender, entries) => { entries.Insert(0, new LookupEntry("", "Select Category")); };
 
             Categories = categories.AsTable("AppliesTo")
-                .ToDictionary("AppliesTo", "Display")
-                .Cast<KeyValuePair<object, string>>()
-                .ToDictionary(x => (x.Key as string)!, x => x.Value);
+                .Rows.Select(x =>
+                {
+                    var appliesTo = x.Get<string>("AppliesTo");
+                    if (CategoryToType(appliesTo, out var formType, out var parentType))
+                    {
+                        return new Tuple<string, Type?, string>(appliesTo, formType, x.Get<string>("Display"));
+                    }
+                    else
+                    {
+                        return new Tuple<string, Type?, string>(appliesTo, null, x.Get<string>("Display"));
+                    }
+                }).ToList();
 
             Jobs = results.Get<Job>().ToObjects<Job>().ToList();
             Jobs.Insert(0, new Job { ID = Guid.Empty, JobNumber = "ALL", Name = "All Jobs" });
@@ -158,6 +173,8 @@ namespace PRSDesktop
 
         #region Header
 
+        private StackPanel CategoryButtonPanel;
+        private Dictionary<Type, Button> CategoryButtons = new();
         private ComboBox CategoryBox;
         private ComboBox FormBox;
         private ComboBox JobBox;
@@ -186,6 +203,23 @@ namespace PRSDesktop
             { DateFilterType.Custom,        "Custom" }
         };
 
+        private static readonly SolidColorBrush EnabledBrush = new SolidColorBrush(Colors.LightYellow);
+        private static readonly SolidColorBrush DisabledBrush = new SolidColorBrush(Colors.LightGray);
+
+        private static readonly Dictionary<Type, Bitmap> CategoryImages = new()
+        {
+            { typeof(AssignmentForm), PRSDesktop.Resources.assignments },
+            { typeof(KanbanForm), PRSDesktop.Resources.kanban },
+            { typeof(JobForm), PRSDesktop.Resources.project },
+            { typeof(JobITPForm), PRSDesktop.Resources.checklist },
+            { typeof(EmployeeForm), PRSDesktop.Resources.employees },
+            { typeof(LeaveRequestForm), PRSDesktop.Resources.leave },
+            { typeof(ManufacturingPacketStage), PRSDesktop.Resources.factory },
+            { typeof(TimeSheetForm), PRSDesktop.Resources.time },
+            { typeof(PurchaseOrderItemForm), PRSDesktop.Resources.purchase },
+            { typeof(DeliveryForm), PRSDesktop.Resources.truck },
+        };
+
         public void SetupHeader()
         {
             CategoryBox = new ComboBox
@@ -195,11 +229,57 @@ namespace PRSDesktop
                 Margin = new Thickness(0, 0, 5, 0)
             };
             CategoryBox.ItemsSource = Categories;
+            CategoryBox.SelectedValuePath = "Item1";
+            CategoryBox.DisplayMemberPath = "Item3";
             CategoryBox.SelectedValue = Properties.Category;
-            CategoryBox.SelectedValuePath = "Key";
-            CategoryBox.DisplayMemberPath = "Value";
             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,
@@ -275,6 +355,7 @@ namespace PRSDesktop
             Header.BeginUpdate()
                 .Clear()
                 .Add(CategoryBox)
+                .Add(CategoryButtonPanel)
                 .Add(FormBox)
                 .Add(JobBox)
                 .Add(DateTypeBox)
@@ -283,9 +364,8 @@ namespace PRSDesktop
                 .Add(ToLabel)
                 .Add(ToPicker)
                 .AddRight(FilterBtn)
-                .AddRight(Print);
-
-            Header.EndUpdate();
+                .AddRight(Print)
+                .EndUpdate();
 
             UpdateCategory(Properties.Category);
         }
@@ -294,8 +374,9 @@ namespace PRSDesktop
         {
             var menu = new ContextMenu();
 
-            menu.AddCheckItem<object?>("Show Date Filter", null, ToggleDateFilter, Properties.ShowDateFilter);
-            menu.AddCheckItem<object?>("Show Job Filter", null, ToggleJobFilter, Properties.ShowJobFilter);
+            menu.AddCheckItem("Use Form Type Icons", ToggleFormTypeIcons, isChecked: Properties.UseIconsForFormTypes);
+            menu.AddCheckItem("Show Date Filter", ToggleDateFilter, Properties.ShowDateFilter);
+            menu.AddCheckItem("Show Job Filter", ToggleJobFilter, Properties.ShowJobFilter);
             menu.AddSeparator();
 
             if (ParentType is not null)
@@ -321,6 +402,21 @@ namespace PRSDesktop
             menu.IsOpen = true;
         }
 
+        private void ToggleFormTypeIcons(bool isChecked)
+        {
+            Properties.UseIconsForFormTypes = !Properties.UseIconsForFormTypes;
+            if (Properties.UseIconsForFormTypes)
+            {
+                CategoryButtonPanel.Visibility = Visibility.Visible;
+                CategoryBox.Visibility = Visibility.Collapsed;
+            }
+            else
+            {
+                CategoryButtonPanel.Visibility = Visibility.Collapsed;
+                CategoryBox.Visibility = Visibility.Visible;
+            }
+        }
+
         private void Print_Click(object sender, RoutedEventArgs e)
         {
             var menu = new ContextMenu();
@@ -424,11 +520,27 @@ namespace PRSDesktop
             Properties.ToDate = ToPicker.SelectedDate ?? DateTime.Today;
         }
 
+        private bool _changing = false;
+
         private void UpdateCategory(string? category)
         {
+            _changing = true;
+            
             Properties.Category = category;
             SetCategory(Properties.Category);
 
+            foreach(var (type, button) in CategoryButtons)
+            {
+                if(type == FormType)
+                {
+                    button.Background = EnabledBrush;
+                }
+                else
+                {
+                    button.Background = DisabledBrush;
+                }
+            }
+
             var jobLink = FormType is not null ? GetJobLink("", FormType) : "";
             if (string.IsNullOrWhiteSpace(jobLink))
             {
@@ -467,10 +579,17 @@ namespace PRSDesktop
 
                 FormBox.IsEnabled = true;
             }
+            _changing = false;
 
             OnUpdateDataModel?.Invoke(SectionName, DataModel(Selection.None));
         }
 
+        private void CatagoryButton_Click(object sender, RoutedEventArgs e)
+        {
+            UpdateCategory(((sender as Button)!.Tag as string)!);
+            Refresh();
+        }
+
         private void Category_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             UpdateCategory((CategoryBox.SelectedValue as string)!);
@@ -482,7 +601,10 @@ namespace PRSDesktop
             Form = FormBox.SelectedValue as DigitalForm;
             Properties.SelectedForm = Form?.ID ?? Guid.Empty;
 
-            OnUpdateDataModel?.Invoke(SectionName, DataModel(Selection.None));
+            if (!_changing)
+            {
+                OnUpdateDataModel?.Invoke(SectionName, DataModel(Selection.None));
+            }
 
             Refresh();
         }
@@ -710,13 +832,13 @@ namespace PRSDesktop
             manager.ShowDialog();
         }
 
-        private void ToggleDateFilter(object? tag, bool isChecked)
+        private void ToggleDateFilter(bool isChecked)
         {
             Properties.ShowDateFilter = isChecked;
             SetDateFilterVisibility(Properties.ShowDateFilter);
         }
 
-        private void ToggleJobFilter(object? tag, bool isChecked)
+        private void ToggleJobFilter(bool isChecked)
         {
             Properties.ShowJobFilter = isChecked;
             SetJobFilterVisibility(Properties.ShowJobFilter);

+ 11 - 0
prs.desktop/Dashboards/DashboardContainerPanel.cs

@@ -14,6 +14,17 @@ using System.Windows.Media;
 
 namespace PRSDesktop;
 
+/// <summary>
+/// An <see cref="IPanel{T}"/> which wraps a <typeparamref name="TDashboard"/>, with a header. <typeparamref name="TDashboard"/>
+/// must be an <see cref="IBasePanel"/>, so that it can act as a normal PRS panel.
+/// </summary>
+/// <remarks>
+/// <see cref="IActionsDashboard"/> has no effect here, and instead, since <typeparamref name="TDashboard"/> must implement <see cref="IBasePanel"/>,
+/// one should use <see cref="IBasePanel.CreateToolbarButtons(PRSDesktop.IPanelHost)"/> to create actions.
+/// </remarks>
+/// <typeparam name="TDashboard"></typeparam>
+/// <typeparam name="TGroup"></typeparam>
+/// <typeparam name="TProperties"></typeparam>
 public class DashboardContainerPanel<TDashboard, TGroup, TProperties> : UserControl, IBasePanel
     where TDashboard : IDashboardWidget<TGroup, TProperties>, IBasePanel, new()
     where TGroup : DashboardWidgetGroup

+ 0 - 5
prs.desktop/Panels/DigitalForms/CompletedFormsPanel.cs

@@ -1,10 +1,5 @@
 using InABox.Core;
 using PRSDesktop.WidgetGroups;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace PRSDesktop;