Browse Source

Did some custom stuff for dataentrypanel with milestones

Kenric Nugteren 1 year ago
parent
commit
6f5a741143

+ 54 - 14
prs.desktop/Panels/DataEntry/DataEntryPanel.xaml.cs

@@ -10,7 +10,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
 using InABox.Configuration;
-using NPOI.SS.Formula.Functions;
+using PRSDesktop.Panels.DataEntry.Grids;
 
 namespace PRSDesktop;
 
@@ -29,9 +29,6 @@ public class DataEntryPanelSettings : BaseObject, IUserConfigurationSettings
 /// <summary>
 /// Interaction logic for DataEntryPanel.xaml
 /// </summary>
-/// <remarks>
-/// This is a host because it has a singular code popup editor
-/// </remarks>
 public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHost
 {
     private DataEntryPanelSettings _settings;
@@ -231,10 +228,9 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
 
     public void LoadLookups(ILookupEditorControl sender)
     {
-        var editor = sender.EditorDefinition as ILookupEditor;
         var colname = sender.ColumnName;
 
-        var values = editor.Values(colname, Editor.Items);
+        var values = sender.LookupEditorDefinition.Values(colname, Editor.Items);
         sender.LoadLookups(values);
     }
 
@@ -294,23 +290,45 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
         
         DetailBorder.Child = Editor;
         _grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), _selectedType) as IDynamicDataGrid;
-        
+
+        if (_grid is DynamicDataGrid<JobDocumentSetMileStone> milestoneGrid)
+        {
+            milestoneGrid.OnValidate += (o, items, err) =>
+            {
+                if (items.Any(x => x.ID == Guid.Empty))
+                {
+                    err.Add("Cannot create a new milestone from Data Entry screen. Please select a milestone to edit.");
+                }
+            };
+        }
     }
-    
+
     private void DoLookup(object editor, object? item)
     {
+        if (_selectedType == null)
+            return;
+
         if (editor is CodeEditorControl ce)
         {
-            
             Dictionary<string, string>? filter = null;
             if (ce.Value != null)
             {
-                filter = new Dictionary<string, string>();
-                filter[ce.ColumnName] = ce.Value;
+                filter = new Dictionary<string, string>
+                {
+                    [ce.ColumnName] = ce.Value
+                };
             }
 
-            var popup = new PopupList(_selectedType, _entityID, new String[] { }, filter);
-            popup.OnDefineFilter += type => LookupFactory.DefineFilter(type);
+            Type? gridType = null;
+            if (_selectedType == typeof(JobDocumentSetMileStone))
+            {
+                gridType = typeof(JobDocumentSetMileStoneDataEntryPopupGrid);
+            }
+
+            var popup = new PopupList(_selectedType, _entityID, Array.Empty<string>(), filter, gridType: gridType);
+
+            popup.OnDefineFilter += LookupFactory.DefineFilter;
+
             if (popup.ShowDialog() == true)
             {
                 _entityID = popup.ID;
@@ -362,7 +380,7 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
             var row = _documents._dataEntryGrid.SelectedRows.FirstOrDefault();
             if (row != null)
             {
-                var scan = row?.ToObject<DataEntryDocument>();
+                var scan = row.ToObject<DataEntryDocument>();
                 scan.EntityID = _entity.ID;
                 if (markasprocessed)
                 {
@@ -414,6 +432,28 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
         _process.Click += (sender, args) => DoSave(true);
         Editor.AddButton(_process);
         IsChanged = false;
+
+        if (_selectedType == typeof(JobDocumentSetMileStone))
+        {
+            var disabled = _entityID == Guid.Empty;
+            foreach (var page in Editor.Pages)
+            {
+                if (page is DynamicEditorGrid.DynamicEditPage editPage)
+                {
+                    foreach (var editor in editPage.Editors)
+                    {
+                        if (editor.EditorDefinition is not BaseCodeEditor)
+                        {
+                            editor.IsEnabled = !disabled && editor.EditorDefinition.Editable.IsEditable();
+                        }
+                    }
+                }
+                else
+                {
+                    page.ReadOnly = disabled;
+                }
+            }
+        }
     }
 
     private void _panel_OnOnChanged(object sender, DynamicSplitPanelSettings e)

+ 38 - 0
prs.desktop/Panels/DataEntry/Grids/JobDocumentSetMileStoneDataEntryPopupGrid.cs

@@ -0,0 +1,38 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.DynamicGrid;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRSDesktop.Panels.DataEntry.Grids;
+
+public class JobDocumentSetMileStoneDataEntryPopupGrid : DynamicDataGrid<JobDocumentSetMileStone>, ISpecificGrid
+{
+    public JobDocumentSetMileStoneDataEntryPopupGrid()
+    {
+        ColumnsTag = "DataEntryPopup";
+    }
+
+
+    public override DynamicGridColumns GenerateColumns()
+    {
+        var columns = new DynamicGridColumns();
+        columns.Add<JobDocumentSetMileStone, string>(x => x.DocumentSet.Job.JobNumber, 70, "Job No.", "", Alignment.MiddleCenter);
+        columns.Add<JobDocumentSetMileStone, string>(x => x.DocumentSet.Code, 120, "Document Set", "", Alignment.MiddleCenter);
+        columns.Add<JobDocumentSetMileStone, string>(x => x.DocumentSet.Description, 0, "Description", "", Alignment.MiddleLeft);
+        columns.Add<JobDocumentSetMileStone, string>(x => x.Revision, 70, "Revision", "", Alignment.MiddleCenter);
+        columns.Add<JobDocumentSetMileStone, JobDocumentSetMileStoneStatus>(x => x.Status, 80, "Status", "", Alignment.MiddleCenter);
+        return columns;
+    }
+
+    protected override void Reload(Filters<JobDocumentSetMileStone> criteria, Columns<JobDocumentSetMileStone> columns, ref SortOrder<JobDocumentSetMileStone>? sort, Action<CoreTable?, Exception?> action)
+    {
+        // Only get the most current milestones.
+        criteria.Add(new Filter<JobDocumentSetMileStone>(x => x.ID).InQuery<JobDocumentSet>(null, x => x.CurrentMileStone.ID));
+
+        base.Reload(criteria, columns, ref sort, action);
+    }
+}