Преглед изворни кода

Persisting job selection on job panel

Kenric Nugteren пре 1 година
родитељ
комит
361dd34dad

+ 1 - 0
prs.classes/Settings/JobScreenSettings.cs

@@ -5,6 +5,7 @@ namespace Comal.Classes
 {
     public class JobScreenSettings : IUserConfigurationSettings
     {
+        public Guid CurrentJob { get; set; }
         public Guid JobStatus { get; set; }
         public ScreenViewType ViewType { get; set; }
         public double AnchorWidth { get; set; }

+ 1 - 0
prs.desktop/DockPanels/JobDock.xaml.cs

@@ -59,6 +59,7 @@ namespace PRSDesktop
             if (_jobs == null)
                 return;
             _jobs.StatusID = (Guid)JobStatus.SelectedValue;
+            _jobs.Refresh(false, true);
         }
     }
 }

+ 0 - 1
prs.desktop/Panels/Jobs/JobGrid.cs

@@ -80,7 +80,6 @@ namespace PRSDesktop
             set
             {
                 _statusid = value;
-                Refresh(false, true);
             }
         }
 

+ 33 - 1
prs.desktop/Panels/Jobs/JobPanel.xaml.cs

@@ -26,6 +26,8 @@ namespace PRSDesktop
         public KanbanTypeLink DocumentMilestoneKanbanType { get; set; }
 
     }
+
+
     /// <summary>
     ///     Interaction logic for JobPanel.xaml
     /// </summary>
@@ -200,6 +202,8 @@ namespace PRSDesktop
                 JobStatus.SelectedValue = sc.Keys.First();
 
             JobGrid.OnSelectItem += JobGrid_OnSelectItem;
+            JobGrid.BeforeRefresh += JobGrid_BeforeRefresh;
+            JobGrid.AfterRefresh += JobGrid_AfterRefresh;
 
             Scopes.Visibility = Security.CanView<JobScope>() ? Visibility.Visible : Visibility.Collapsed;
             Documents.Visibility = Security.CanView<JobDocumentSet>() ? Visibility.Visible : Visibility.Collapsed;
@@ -233,6 +237,26 @@ namespace PRSDesktop
             timer.IsEnabled = true;
         }
 
+        private bool _jobGridRefreshing;
+
+        private void JobGrid_BeforeRefresh(object sender, BeforeRefreshEventArgs args)
+        {
+            _jobGridRefreshing = true;
+        }
+
+        private void JobGrid_AfterRefresh(object sender, AfterRefreshEventArgs args)
+        {
+            if (settings.CurrentJob == Guid.Empty)
+            {
+                JobGrid.SelectedRows = Array.Empty<CoreRow>();
+            }
+            else
+            {
+                JobGrid.SelectedRows = JobGrid.Data.Rows.Where(x => x.Get<Job, Guid>(x => x.ID) == settings.CurrentJob).ToArray();
+            }
+            _jobGridRefreshing = false;
+        }
+
         public void Shutdown(CancelEventArgs? cancel)
         {
             timer.IsEnabled = false;
@@ -316,7 +340,9 @@ namespace PRSDesktop
 
         public void Refresh()
         {
-            JobGrid.StatusID = (Guid)JobStatus.SelectedValue; // Refresh(false, true);
+            JobGrid.StatusID = (Guid)JobStatus.SelectedValue;
+            JobGrid.Refresh(false, true);
+
             lastselection = DateTime.MinValue;
         }
 
@@ -520,6 +546,11 @@ namespace PRSDesktop
         private void JobGrid_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
         {
             lastselection = DateTime.Now;
+            if (IsReady && !_jobGridRefreshing)
+            {
+                settings.CurrentJob = e.Rows?.FirstOrDefault()?.Get<Job, Guid>(x => x.ID) ?? Guid.Empty;
+                new UserConfiguration<JobScreenSettings>().Save(settings);
+            }
         }
 
         private void ShowEmailInterface(PanelAction obj)
@@ -712,6 +743,7 @@ namespace PRSDesktop
                 settings.JobStatus = (Guid)JobStatus.SelectedValue;
                 new UserConfiguration<JobScreenSettings>().Save(settings);
                 JobGrid.StatusID = (Guid)JobStatus.SelectedValue;
+                JobGrid.Refresh(false, true);
             }
         }