Sfoglia il codice sorgente

Added Reset to Default on Employee Qualifications dashboard

Kenric Nugteren 2 anni fa
parent
commit
e00e30b7c3

+ 59 - 14
prs.desktop/Dashboards/HumanResources/EmployeeQualificationDashboard.xaml.cs

@@ -3,9 +3,6 @@ using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
-using jdk.nashorn.@internal.ir;
-using Microsoft.Win32;
-using Org.BouncyCastle.Crypto;
 using PRSDesktop.WidgetGroups;
 using Syncfusion.UI.Xaml.Grid.Helpers;
 using Syncfusion.UI.Xaml.ScrollAxis;
@@ -140,8 +137,8 @@ namespace PRSDesktop
 
         public void Refresh()
         {
-            Properties.Qualifications = Qualifications;
-            Properties.Employees = Employees;
+            //Properties.Qualifications = Qualifications;
+            //Properties.Employees = Employees;
 
             CoreTable = new("Qualifications");
             ColumnHeaders = new();
@@ -252,6 +249,36 @@ namespace PRSDesktop
             => (employee.StartDate == DateTime.MinValue || employee.StartDate < DateTime.Now)
             && (employee.FinishDate == DateTime.MinValue || employee.FinishDate > DateTime.Now);
 
+        private void LoadEmployees()
+        {
+            var employees = Client.Query(null, new Columns<Employee>(x => x.ID, x => x.StartDate, x => x.FinishDate))
+                .ToObjects<Employee>()
+                .ToDictionary(
+                    x => x.ID,
+                    IsEmployeeActive);
+            if (Properties.Employees is not null)
+            {
+                employees = employees
+                    .ToDictionary(
+                        x => x.Key,
+                        x => !Properties.Employees.ContainsKey(x.Key) || Properties.Employees[x.Key]);
+            }
+            Employees = employees;
+        }
+        private void LoadQualifications()
+        {
+            var qualifications = Client.Query(null, new Columns<Qualification>(x => x.ID))
+                .Rows.Select(x => x.Get<Qualification, Guid>(x => x.ID)).ToDictionary(x => x, x => true);
+            if (Properties.Qualifications is not null)
+            {
+                qualifications = qualifications
+                    .ToDictionary(
+                        x => x.Key,
+                        x => !Properties.Qualifications.ContainsKey(x.Key) || Properties.Qualifications[x.Key]);
+            }
+            Qualifications = qualifications;
+        }
+
         public void Setup()
         {
             var employeeFilter = EmployeeFilter;
@@ -497,17 +524,25 @@ namespace PRSDesktop
             menu.Items.Clear();
             if(rci.RowIndex == 0)
             {
-                var selectQualification = new MenuItem() { Header = "Select Qualifications" };
-                selectQualification.Click += SelectQualification_Click;
-                menu.Items.Add(selectQualification);
+                menu.AddItem("Select Qualifications", null, SelectQualification_Click);
+                if (Properties.Qualifications is not null)
+                {
+                    menu.AddItem("Reset to Default", null, () =>
+                    {
+                        Properties.Qualifications = null;
+                        LoadQualifications();
+                        Refresh();
+                    });
+                }
 
-                if(rci.ColumnIndex > 0)
+                if (rci.ColumnIndex > 0)
                 {
                     var column = CoreTable.Columns[rci.ColumnIndex];
                     var hideQualification = new MenuItem() { Header = $"Hide '{column.ColumnName}'" };
                     hideQualification.Click += (sender, e) =>
                     {
                         Qualifications[QualificationIDs[rci.ColumnIndex - 1]] = false;
+                        Properties.Qualifications = Qualifications;
                         Refresh();
                     };
                     menu.Items.Add(hideQualification);
@@ -515,9 +550,16 @@ namespace PRSDesktop
             }
             if(rci.ColumnIndex == 0)
             {
-                var selectEmployee = new MenuItem() { Header = "Select Employees" };
-                selectEmployee.Click += SelectEmployee_Click;
-                menu.Items.Add(selectEmployee);
+                menu.AddItem("Select Employees", null, SelectEmployee_Click);
+                if(Properties.Employees is not null)
+                {
+                    menu.AddItem("Reset to Default", null, () =>
+                    {
+                        Properties.Employees = null;
+                        LoadEmployees();
+                        Refresh();
+                    });
+                }
 
                 if (rci.RowIndex > 0)
                 {
@@ -526,6 +568,7 @@ namespace PRSDesktop
                     hideEmployee.Click += (sender, e) =>
                     {
                         Employees[EmployeeIDs[rci.RowIndex - 1]] = false;
+                        Properties.Employees = Employees;
                         Refresh();
                     };
                     menu.Items.Add(hideEmployee);
@@ -538,7 +581,7 @@ namespace PRSDesktop
             }
         }
 
-        private void SelectEmployee_Click(object sender, RoutedEventArgs e)
+        private void SelectEmployee_Click()
         {
             var window = new EntitySelectionWindow(typeof(Employee), Employees.Where(x => x.Value).Select(x => x.Key).ToHashSet(), typeof(EmployeeSelectionGrid));
             window.ShowDialog();
@@ -546,17 +589,19 @@ namespace PRSDesktop
             Employees = Employees.ToDictionary(
                 x => x.Key,
                 x => window.Entities.Contains(x.Key));
+            Properties.Employees = Employees;
 
             Refresh();
         }
 
-        private void SelectQualification_Click(object sender, RoutedEventArgs e)
+        private void SelectQualification_Click()
         {
             var window = new EntitySelectionWindow(typeof(Qualification), Qualifications.Where(x => x.Value).Select(x => x.Key).ToHashSet());
             window.ShowDialog();
             Qualifications = Qualifications.ToDictionary(
                 x => x.Key,
                 x => window.Entities.Contains(x.Key));
+            Properties.Qualifications = Qualifications;
             Refresh();
         }