Browse Source

Job Scope Documents tab

Kenric Nugteren 1 year ago
parent
commit
975d9c6085

+ 6 - 0
prs.desktop/Panels/Jobs/JobScopes/JobScopeAssignmentGrid.cs

@@ -9,6 +9,12 @@ public class JobScopeAssignmentGrid : DynamicDataGrid<Assignment>, IJobScopeGrid
 {
     public JobScope? Scope { get; set; }
 
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+        options.Remove(DynamicGridOption.AddRows);
+    }
+
     protected override void Reload(Filters<Assignment> criteria, Columns<Assignment> columns, ref SortOrder<Assignment>? sort, Action<CoreTable?, Exception?> action)
     {
         if ((Scope == null) || (Scope.ID == Guid.Empty))

+ 83 - 0
prs.desktop/Panels/Jobs/JobScopes/JobScopeDocumentGrid.cs

@@ -0,0 +1,83 @@
+using Comal.Classes;
+using InABox.Clients;
+using InABox.Core;
+using InABox.DynamicGrid;
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PRSDesktop;
+
+public class JobScopeDocumentGrid : DynamicDocumentGrid<JobScopeDocument, JobScope, JobScopeLink>, IJobScopeGrid
+{
+    public JobScope? Scope
+    {
+        get => Item;
+        set
+        {
+            Load(value ?? new JobScope(), null);
+        }
+    }
+
+    protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
+    {
+        if((Scope?.ID ?? Guid.Empty) == Guid.Empty)
+        {
+            MessageBox.Show("Please select a scope.");
+            return;
+        }
+        base.DoAdd(OpenEditorOnDirectEdit);
+    }
+
+    public override void SaveItem(JobScopeDocument item)
+    {
+        Client.Save(item, "Updated by user.");
+    }
+
+    public override void SaveItems(JobScopeDocument[] items)
+    {
+        Client.Save(items, "Updated by user.");
+    }
+
+    protected override void DeleteItems(params CoreRow[] rows)
+    {
+        Client.Delete(rows.Select(x => new JobScopeDocument { ID = x.Get<JobScopeDocument, Guid>(x => x.ID) }), "Deleted by user.");
+    }
+
+    protected override JobScopeDocument LoadItem(CoreRow row)
+    {
+        var id = row.Get<JobScopeDocument, Guid>(x => x.ID);
+        return Client.Query(
+            new Filter<JobScopeDocument>(x => x.ID).IsEqualTo(id),
+            DynamicGridUtils.LoadEditorColumns(DataColumns()))
+            .ToObjects<JobScopeDocument>()
+            .FirstOrDefault()
+            ?? throw new Exception($"No {nameof(JobScopeDocument)} with ID {id}");
+    }
+
+    protected override JobScopeDocument[] LoadItems(CoreRow[] rows)
+    {
+        var ids = rows.Select(x => x.Get<JobScopeDocument, Guid>(x => x.ID));
+        return Client.Query(
+            new Filter<JobScopeDocument>(x => x.ID).InList(ids),
+            DynamicGridUtils.LoadEditorColumns(DataColumns()))
+            .ToObjects<JobScopeDocument>().ToArray();
+    }
+
+    protected override void Reload(Filters<JobScopeDocument> criteria, Columns<JobScopeDocument> columns, ref SortOrder<JobScopeDocument>? sort, Action<CoreTable?, Exception?> action)
+    {
+        if(Scope is null || Scope.ID == Guid.Empty)
+        {
+            criteria.Add(new Filter<JobScopeDocument>().None());
+        }
+        else
+        {
+            criteria.Add(new Filter<JobScopeDocument>(x => x.EntityLink.ID).IsEqualTo(Scope?.ID ?? Guid.Empty));
+        }
+        new Client<JobScopeDocument>().Query(criteria.Combine(), columns, sort, action);
+    }
+}

+ 1 - 0
prs.desktop/Panels/Jobs/JobScopes/JobScopePanel.xaml

@@ -37,6 +37,7 @@
                     <dynamicGrid:DynamicTabItem Header="Manufacturing" x:Name="_manufacturing" />
                     <dynamicGrid:DynamicTabItem Header="Delivery Items" x:Name="_deliveryItems" />
                     <dynamicGrid:DynamicTabItem Header="Activities" x:Name="_assignments" />
+                    <dynamicGrid:DynamicTabItem Header="Documents" x:Name="_documents" />
                 </dynamicGrid:DynamicTabControl.Items>
             </dynamicGrid:DynamicTabControl>
         </dynamicGrid:DynamicSplitPanel.Detail>

+ 5 - 0
prs.desktop/Panels/Jobs/JobScopes/JobScopePanel.xaml.cs

@@ -19,12 +19,14 @@ public partial class JobScopePanel : UserControl, IPanel<JobScope>, IJobControl
         ManufacturingPackets,
         DeliveryItems,
         Assignments,
+        Documents
     }
             
     private int _currentPage = -1;
     
     private JobScopeRequisitionItemGrid? _requisitionItemsGrid;
     private JobScopeAssignmentGrid? _assignmentGrid;
+    private JobScopeDocumentGrid? _documentGrid;
 
     public JobScopePanel()
     {
@@ -84,6 +86,9 @@ public partial class JobScopePanel : UserControl, IPanel<JobScope>, IJobControl
             case PageIndex.Assignments : 
                 RefreshGrid(_assignments, ref _assignmentGrid, scope);
                 break;
+            case PageIndex.Documents:
+                RefreshGrid(_documents, ref _documentGrid, scope);
+                break;
         }
     }
 

+ 6 - 0
prs.desktop/Panels/Jobs/JobScopes/JobScopeRequisitionItemGrid.cs

@@ -9,6 +9,12 @@ public class JobScopeRequisitionItemGrid : DynamicDataGrid<RequisitionItem>, IJo
 {
     public JobScope? Scope { get; set; }
 
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+        options.Remove(DynamicGridOption.AddRows);
+    }
+
     protected override void Reload(Filters<RequisitionItem> criteria, Columns<RequisitionItem> columns, ref SortOrder<RequisitionItem>? sort, Action<CoreTable?, Exception?> action)
     {
         if ((Scope == null) || (Scope.ID == Guid.Empty))