Browse Source

Fix DF Dashboard Progress causing weird refresh issues. Employee qualifications dashboard now loads new employees by default;

Kenric Nugteren 2 năm trước cách đây
mục cha
commit
1eb0ef0767

+ 11 - 21
prs.desktop/Dashboards/Common/DigitalFormsDashboard.xaml.cs

@@ -1116,30 +1116,20 @@ namespace PRSDesktop
         {
             if (!IsSetup) return;
 
-            Progress.Show("Refreshing");
-            try
-            {
-                Questions.Clear();
-                QAGrid.Clear();
-                QAGrid.LoadChecks("", Array.Empty<QAQuestion>(), new Dictionary<Guid, object>());
-                DataGrid.ItemsSource = null;
-
-                if (ParentType is null || FormType is null || Form is null || Form.ID == Guid.Empty)
-                {
-                    QAGrid.Visibility = Visibility.Collapsed;
-                    DataGrid.Visibility = Visibility.Collapsed;
-                    return;
-                }
-
-                Progress.SetMessage("Loading Data");
+            Questions.Clear();
+            QAGrid.Clear();
+            QAGrid.LoadChecks("", Array.Empty<QAQuestion>(), new Dictionary<Guid, object>());
+            DataGrid.ItemsSource = null;
 
-                var refreshMethod = typeof(DigitalFormsDashboard).GetMethod(nameof(RefreshData), BindingFlags.Instance | BindingFlags.NonPublic)!.MakeGenericMethod(FormType);
-                refreshMethod.Invoke(this, Array.Empty<object?>());
-            }
-            finally
+            if (ParentType is null || FormType is null || Form is null || Form.ID == Guid.Empty)
             {
-                Progress.Close();
+                QAGrid.Visibility = Visibility.Collapsed;
+                DataGrid.Visibility = Visibility.Collapsed;
+                return;
             }
+
+            var refreshMethod = typeof(DigitalFormsDashboard).GetMethod(nameof(RefreshData), BindingFlags.Instance | BindingFlags.NonPublic)!.MakeGenericMethod(FormType);
+            refreshMethod.Invoke(this, Array.Empty<object?>());
         }
 
         public void Shutdown()

+ 52 - 31
prs.desktop/Dashboards/HumanResources/EmployeeQualificationDashboard.xaml.cs

@@ -69,8 +69,8 @@ namespace PRSDesktop
 
     public class EmployeeQualificationDashboardProperties : IDashboardProperties
     {
-        public List<Guid>? Employees { get; set; } = null;
-        public List<Guid>? Qualifications { get; set; } = null;
+        public Dictionary<Guid, bool>? Employees { get; set; } = null;
+        public Dictionary<Guid, bool>? Qualifications { get; set; } = null;
     }
 
     public class EmployeeQualificationDashboardElement : DashboardElement<EmployeeQualificationDashboard, HumanResources, EmployeeQualificationDashboardProperties> { }
@@ -83,8 +83,9 @@ namespace PRSDesktop
         private DataTable DataTable;
         private CoreTable CoreTable;
 
-        private HashSet<Guid> Employees;
-        private HashSet<Guid> Qualifications;
+        private List<Guid> AllEmployees;
+        private Dictionary<Guid, bool> Employees;
+        private Dictionary<Guid, bool> Qualifications;
 
         private Dictionary<Guid, string> ColumnHeaders;
 
@@ -107,8 +108,8 @@ namespace PRSDesktop
 
         public void Refresh()
         {
-            Properties.Qualifications = Qualifications.ToList();
-            Properties.Employees = Employees.ToList();
+            Properties.Qualifications = Qualifications;
+            Properties.Employees = Employees;
 
             CoreTable = new();
             CoreTable.TableName = "Qualifications";
@@ -117,7 +118,7 @@ namespace PRSDesktop
             var employeeFilter = EmployeeFilter;
             var results = Client.QueryMultiple(
                 new KeyedQueryDef<Employee>(nameof(Employee),
-                    employeeFilter,
+                    new Filter<Employee>(x => x.ID).InList(Employees.Where(x => x.Value).Select(x => x.Key).ToArray()),
                     new Columns<Employee>(x => x.ID, x => x.Name)),
                 new KeyedQueryDef<EmployeeQualification>(nameof(EmployeeQualification),
                     new Filter<EmployeeQualification>(x => x.Employee.ID).InQuery(employeeFilter, x => x.ID),
@@ -126,7 +127,7 @@ namespace PRSDesktop
                         x => x.Qualification.ID,
                         x => x.Expiry)),
                 new KeyedQueryDef<Qualification>(nameof(Qualification),
-                    new Filter<Qualification>(x => x.ID).InList(Qualifications.ToArray()),
+                    new Filter<Qualification>(x => x.ID).InList(Qualifications.Where(x => x.Value).Select(x => x.Key).ToArray()),
                     new Columns<Qualification>(x => x.ID, x => x.Description)));
 
             CoreTable.Columns.Add(new CoreColumn() { ColumnName = "Employee", DataType = typeof(string) });
@@ -152,10 +153,6 @@ namespace PRSDesktop
             foreach (var employee in results[nameof(Employee)].Rows)
             {
                 var employeeID = employee.Get<Employee, Guid>(x => x.ID);
-                if (!Employees.Contains(employeeID))
-                {
-                    continue;
-                }
                 EmployeeIDs.Add(employeeID);
 
                 List<object?> values = new()
@@ -205,23 +202,41 @@ namespace PRSDesktop
             }
         }
 
+        public static bool IsEmployeeActive(Employee employee)
+            => (employee.StartDate == DateTime.MinValue || employee.StartDate < DateTime.Now)
+            && (employee.FinishDate == DateTime.MinValue || employee.FinishDate > DateTime.Now);
+
         public void Setup()
         {
-            var employees = Properties.Employees?.ToHashSet();
-            var qualifications = Properties.Qualifications?.ToHashSet();
-            if (employees == null || qualifications == null)
+            var employeeFilter = EmployeeFilter;
+            var results = Client.QueryMultiple(
+                new KeyedQueryDef<Employee>(nameof(Employee),
+                    new Filter<Employee>().All(),
+                    new Columns<Employee>(x => x.ID, x => x.StartDate, x => x.FinishDate)),
+                new KeyedQueryDef<Qualification>(nameof(Qualification),
+                    new Filter<Qualification>().All(),
+                    new Columns<Qualification>(x => x.ID)));
+
+            var employees = results[nameof(Employee)].ToObjects<Employee>().ToDictionary(
+                x => x.ID,
+                x => IsEmployeeActive(x));
+            if (Properties.Employees is not null)
+            {
+                employees = employees
+                    .ToDictionary(
+                        x => x.Key,
+                        x => !Properties.Employees.ContainsKey(x.Key) || Properties.Employees[x.Key]);
+            }
+
+            var qualifications = results[nameof(Qualification)].Rows.Select(x => x.Get<Qualification, Guid>(x => x.ID)).ToDictionary(x => x, x => true);
+            if(Properties.Qualifications is not null)
             {
-                var employeeFilter = EmployeeFilter;
-                var results = Client.QueryMultiple(
-                    new KeyedQueryDef<Employee>(nameof(Employee), employeeFilter, new Columns<Employee>(x => x.ID, x => x.StartDate, x => x.FinishDate)),
-                    new KeyedQueryDef<Qualification>(nameof(Qualification),
-                        new Filter<Qualification>().All(),
-                        new Columns<Qualification>(x => x.ID)));
-
-                
-                employees ??= results[nameof(Employee)].Rows.Select(x => x.Get<Employee, Guid>(x => x.ID)).ToHashSet();
-                qualifications ??= results[nameof(Qualification)].Rows.Select(x => x.Get<Qualification, Guid>(x => x.ID)).ToHashSet();
+                qualifications = qualifications
+                    .ToDictionary(
+                        x => x.Key,
+                        x => !Properties.Qualifications.ContainsKey(x.Key) || Properties.Qualifications[x.Key]);
             }
+
             Employees = employees;
             Qualifications = qualifications;
 
@@ -386,7 +401,7 @@ namespace PRSDesktop
                     var hideQualification = new MenuItem() { Header = $"Hide '{column.ColumnName}'" };
                     hideQualification.Click += (sender, e) =>
                     {
-                        Qualifications.Remove(QualificationIDs[rci.ColumnIndex - 1]);
+                        Qualifications[QualificationIDs[rci.ColumnIndex - 1]] = false;
                         Refresh();
                     };
                     menu.Items.Add(hideQualification);
@@ -404,7 +419,7 @@ namespace PRSDesktop
                     var hideEmployee = new MenuItem() { Header = $"Hide '{row["Employee"]}'" };
                     hideEmployee.Click += (sender, e) =>
                     {
-                        Employees.Remove(EmployeeIDs[rci.RowIndex - 1]);
+                        Employees[EmployeeIDs[rci.RowIndex - 1]] = false;
                         Refresh();
                     };
                     menu.Items.Add(hideEmployee);
@@ -419,17 +434,23 @@ namespace PRSDesktop
 
         private void SelectEmployee_Click(object sender, RoutedEventArgs e)
         {
-            var window = new EntitySelectionWindow(typeof(Employee), Employees, typeof(EmployeeSelectionGrid));
+            var window = new EntitySelectionWindow(typeof(Employee), Employees.Where(x => x.Value).Select(x => x.Key).ToHashSet(), typeof(EmployeeSelectionGrid));
             window.ShowDialog();
-            Employees = window.Entities;
+
+            Employees = Employees.ToDictionary(
+                x => x.Key,
+                x => window.Entities.Contains(x.Key));
+
             Refresh();
         }
 
         private void SelectQualification_Click(object sender, RoutedEventArgs e)
         {
-            var window = new EntitySelectionWindow(typeof(Qualification), Qualifications);
+            var window = new EntitySelectionWindow(typeof(Qualification), Qualifications.Where(x => x.Value).Select(x => x.Key).ToHashSet());
             window.ShowDialog();
-            Qualifications = window.Entities;
+            Qualifications = Qualifications.ToDictionary(
+                x => x.Key,
+                x => window.Entities.Contains(x.Key));
             Refresh();
         }
 

+ 2 - 2
prs.desktop/Forms/EntitySelectionGrid.cs

@@ -40,7 +40,7 @@ namespace PRSDesktop
             ActionColumns.Add(new DynamicImageColumn(TickImage, TickAction));
         }
 
-        private BitmapImage TickImage(CoreRow row)
+        private BitmapImage TickImage(CoreRow? row)
         {
             if (row == null)
             {
@@ -49,7 +49,7 @@ namespace PRSDesktop
             return _entities.Contains((Guid)row["ID"]) ? ticked : unticked;
         }
 
-        private bool TickAction(CoreRow row)
+        private bool TickAction(CoreRow? row)
         {
             if (row == null)
             {

+ 2 - 2
prs.desktop/Panels/Security/Global/GlobalTokenGrid.cs

@@ -235,8 +235,8 @@ namespace PRSDesktop
         private CoreTable _table = null;
         
         protected override void Reload(Filters<SecurityDescriptor> criteria, Columns<SecurityDescriptor> columns,
-            ref SortOrder<SecurityDescriptor> sort,
-            Action<CoreTable, Exception> action)
+            ref SortOrder<SecurityDescriptor>? sort,
+            Action<CoreTable?, Exception?> action)
         {
 
             if (_table == null)