Explorar el Código

Added the document set link to the stiles

Kenric Nugteren hace 1 año
padre
commit
e01cd85f69

+ 30 - 15
prs.classes/Entities/Job/DocumentSet/JobDocumentSet.cs

@@ -1,5 +1,7 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
 using InABox.Clients;
 using InABox.Core;
 
@@ -17,40 +19,40 @@ namespace Comal.Classes
         Custom,
         NotSet
     }
-    
+
     public class JobDocumentSet : Entity, IRemotable, IPersistent, IOneToMany<Job>, IJobDocumentSet, ILicense<ProjectManagementLicense>
     {
-        
+
         [EntityRelationship(DeleteAction.Cascade)]
         [NullEditor]
         public JobLink Job { get; set; }
-        
+
         [EntityRelationship(DeleteAction.Cascade)]
         [NullEditor]
         public JobDocumentSetFolderLink Folder { get; set; }
-        
+
         [NullEditor]
         [EntityRelationship(DeleteAction.Cascade)]
         public JobDocumentSetLink Parent { get; set; }
-        
+
         [CodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
         [EditorSequence(1)]
         public string Code { get; set; }
-        
+
         [TextBoxEditor]
         [EditorSequence(2)]
         public string Description { get; set; }
-        
+
         [EditorSequence(3)]
         public JobDocumentSetDisciplineLink Discipline { get; set; }
-        
+
         [EditorSequence(4)]
         public JobDocumentSetTypeLink Type { get; set; }
-        
+
         [DateTimeEditor]
         [EditorSequence(5)]
         public DateTime Date { get; set; }
-        
+
         [Caption("Assigned To")]
         [EditorSequence(6)]
         public EmployeeLink Employee { get; set; }
@@ -62,14 +64,27 @@ namespace Comal.Classes
         [CodeEditor(Editable = Editable.Enabled)]
         [EditorSequence("Advanced", 2)]
         public string Scale { get; set; } = "";
-        
-        [EditorSequence("Advanced",3)]
+
+        [EditorSequence("Advanced", 3)]
         public JobDocumentSetCategoryLink Category { get; set; }
-        
-        [EditorSequence("Advanced",4)]
+
+        [EditorSequence("Advanced", 4)]
         public JobITPLink Area { get; set; }
-        
+
         [EditorSequence("Advanced", 5)]
         public DateTime Retired { get; set; }
+
+        /*[Aggregate(typeof(JobDocumentSetCurrentAggregate))]
+        public DateTime Current { get; set; }*/
     }
+
+    /*
+    public class JobDocumentSetCurrentAggregate : CoreAggregate<JobDocumentSet, JobDocumentSetMileStone, DateTime>
+    {
+        public override Expression<Func<JobDocumentSetMileStone, DateTime>> Aggregate => x => x.Date;
+
+        public override Dictionary<Expression<Func<JobDocumentSetMileStone, object>>, Expression<Func<JobDocumentSet, object>>> Links => throw new NotImplementedException();
+
+        public override AggregateCalculation Calculation => throw new NotImplementedException();
+    }*/
 }

+ 12 - 9
prs.classes/Entities/Job/JobProductMapping.cs

@@ -1,24 +1,27 @@
 using InABox.Core;
 using System;
 using System.Collections.Generic;
+using System.Linq.Expressions;
 using System.Text;
 
 namespace Comal.Classes
 {
     public class JobProductMapping : Entity, IRemotable, IPersistent, ILicense<ProjectManagementLicense>
     {
-        [CodeEditor(Editable = Editable.Enabled)]
-        public string Code { get; set; }
+        [CodeEditor(Editable = Editable.Enabled, Visible = Visible.Default)]
+        public string Code { get; set; } = "";
 
-        [MemoEditor]
-        public string Description { get; set; }
+        [MemoEditor(Visible = Visible.Default)]
+        public string Description { get; set; } = "";
+
+        [EntityRelationship(DeleteAction.Cascade)]
         public JobLink Job { get; set; }
+
+        [EntityRelationship(DeleteAction.SetNull)]
         public ProductLink Product { get; set; }
 
-        public JobProductMapping()
-        {
-            Code = "";
-            Description = "";
-        }
+        [NullEditor]
+        [EntityRelationship(DeleteAction.SetNull)]
+        public JobDocumentSetLink JobDocumentSet { get; set; }
     }
 }

+ 3 - 0
prs.classes/Entities/Job/JobStyle.cs

@@ -15,5 +15,8 @@ namespace Comal.Classes
         [EditorSequence(3)]
         [MemoEditor]
         public string Note { get; set; } = "";
+
+        [NullEditor]
+        public JobDocumentSetLink JobDocumentSet { get; set; }
     }
 }

+ 109 - 7
prs.desktop/Panels/Jobs/JobProductMappingsGrid.cs

@@ -1,6 +1,9 @@
 using Comal.Classes;
+using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
+using InABox.Wpf;
+using Syncfusion.Data.Extensions;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -15,9 +18,99 @@ public class JobProductMappingsGrid : DynamicDataGrid<JobProductMapping>, IJobCo
 
     JobPanelSettings IJobControl.Settings { get; set; }
 
-    public string SectionName => "Job Product Mappings";
+    protected override void Init()
+    {
+        base.Init();
 
-    public event DataModelUpdateEvent? OnUpdateDataModel;
+        HiddenColumns.Add(x => x.JobDocumentSet.ID);
+        HiddenColumns.Add(x => x.Code);
+        HiddenColumns.Add(x => x.Description);
+
+        ActionColumns.Add(new DynamicMenuColumn(BuildMenu));
+    }
+
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+        options.Add(DynamicGridOption.SelectColumns);
+    }
+
+    private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
+    {
+        if (row is not null)
+        {
+            var docSet = row.Get<JobProductMapping, Guid>(x => x.JobDocumentSet.ID);
+            if(docSet != Guid.Empty)
+            {
+                var caption = Security.CanEdit<JobDocumentSet>() ? "Edit Document Set" : "View Document Set";
+                column.AddItem("Edit Document Set", PRSDesktop.Resources.design, (_) =>
+                {
+                    ViewDocumentSet(docSet);
+                });
+            }
+            else
+            {
+                if (Security.CanEdit<JobDocumentSet>())
+                {
+                    column.AddItem("Create Document Set", PRSDesktop.Resources.design, (_) =>
+                    {
+                        CreateDocumentSet(row);
+                    });
+                }
+            }
+        }
+    }
+
+    private static DynamicDataGrid<JobDocumentSet> GetDocumentSetGrid()
+    {
+        var gridType = DynamicGridUtils.FindDynamicGrid(typeof(DynamicDataGrid<>), typeof(JobDocumentSet))
+            ?? typeof(DynamicDataGrid<JobDocumentSet>);
+        return (Activator.CreateInstance(gridType) as DynamicDataGrid<JobDocumentSet>)!;
+    }
+
+    private void ViewDocumentSet(Guid docSetID)
+    {
+        var docSet = Client.Query(
+            new Filter<JobDocumentSet>(x => x.ID).IsEqualTo(docSetID),
+            DynamicGridUtils.LoadEditorColumns<JobDocumentSet>(new Columns<JobDocumentSet>(x => x.ID)))
+            .ToObjects<JobDocumentSet>()
+            .FirstOrDefault();
+        if(docSet is null)
+        {
+            MessageWindow.ShowMessage("Document set does not exist.", "Error");
+            Logger.Send(LogType.Information, "", "Document set does not exist.");
+            return;
+        }
+        GetDocumentSetGrid().EditItems(new JobDocumentSet[] { docSet });
+    }
+
+    private void CreateDocumentSet(CoreRow row)
+    {
+        var folder = new MultiSelectDialog<JobDocumentSetFolder>(
+            new Filter<JobDocumentSetFolder>(x => x.Job.ID).IsEqualTo(Job.ID),
+            new Columns<JobDocumentSetFolder>(x => x.ID));
+        if (!folder.ShowDialog())
+        {
+            MessageWindow.ShowMessage("You need to select a folder to add this document set to.", "Folder required");
+            return;
+        }
+
+        var code = row.Get<JobProductMapping, string>(x => x.Code);
+        var docSet = new JobDocumentSet
+        {
+            Code = code,
+            Description = row.Get<JobProductMapping, string>(x => x.Description) + $"\nAttached to JobProductMapping '{code}'"
+        };
+        docSet.Job.ID = Job.ID;
+        docSet.Folder.ID = folder.IDs().First();
+        if(GetDocumentSetGrid().EditItems(new JobDocumentSet[] { docSet }))
+        {
+            var productMapping = row.ToObject<JobProductMapping>();
+            productMapping.JobDocumentSet.ID = docSet.ID;
+            Client.Save(productMapping, "Attached to new JobDocumentSet");
+            Refresh(false, true);
+        }
+    }
 
     protected override bool CanCreateItems()
     {
@@ -32,15 +125,24 @@ public class JobProductMappingsGrid : DynamicDataGrid<JobProductMapping>, IJobCo
         return result;
     }
 
+    protected override void Reload(Filters<JobProductMapping> criteria, Columns<JobProductMapping> columns, ref SortOrder<JobProductMapping>? sort, Action<CoreTable?, Exception?> action)
+    {
+        criteria.Add(new Filter<JobProductMapping>(x => x.Job.ID).IsEqualTo(Job.ID));
+        base.Reload(criteria, columns, ref sort, action);
+    }
+
+    #region IPanel
+
+    public string SectionName => "Job Product Mappings";
+
+    public event DataModelUpdateEvent? OnUpdateDataModel;
+
     public DataModel DataModel(Selection selection)
     {
         var ids = ExtractValues(x => x.ID, selection).ToArray();
         return new BaseDataModel<JobProductMapping>(new Filter<JobProductMapping>(x => x.ID).InList(ids));
     }
 
-    protected override void Reload(Filters<JobProductMapping> criteria, Columns<JobProductMapping> columns, ref SortOrder<JobProductMapping>? sort, Action<CoreTable?, Exception?> action)
-    {
-        criteria.Add(new Filter<JobProductMapping>(x => x.Job.ID).IsEqualTo(Job.ID));
-        base.Reload(criteria, columns, ref sort, action);
-    }
+    #endregion
+
 }

+ 97 - 0
prs.desktop/Panels/Jobs/JobProductStylesGrid.cs

@@ -1,6 +1,8 @@
 using Comal.Classes;
+using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
+using InABox.Wpf;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -13,6 +15,101 @@ public class JobProductStylesGrid : DynamicDataGrid<JobStyle>, IJobControl, IDat
 {
     public Job Job { get; set; }
 
+    protected override void Init()
+    {
+        base.Init();
+
+        HiddenColumns.Add(x => x.JobDocumentSet.ID);
+        HiddenColumns.Add(x => x.Style.Code);
+        HiddenColumns.Add(x => x.Style.Description);
+
+        ActionColumns.Add(new DynamicMenuColumn(BuildMenu));
+    }
+
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+        options.Add(DynamicGridOption.SelectColumns);
+    }
+
+    private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
+    {
+        if (row is not null)
+        {
+            var docSet = row.Get<JobStyle, Guid>(x => x.JobDocumentSet.ID);
+            if (docSet != Guid.Empty)
+            {
+                var caption = Security.CanEdit<JobDocumentSet>() ? "Edit Document Set" : "View Document Set";
+                column.AddItem("Edit Document Set", PRSDesktop.Resources.design, (_) =>
+                {
+                    ViewDocumentSet(docSet);
+                });
+            }
+            else
+            {
+                if (Security.CanEdit<JobDocumentSet>())
+                {
+                    column.AddItem("Create Document Set", PRSDesktop.Resources.design, (_) =>
+                    {
+                        CreateDocumentSet(row);
+                    });
+                }
+            }
+        }
+    }
+
+    private static DynamicDataGrid<JobDocumentSet> GetDocumentSetGrid()
+    {
+        var gridType = DynamicGridUtils.FindDynamicGrid(typeof(DynamicDataGrid<>), typeof(JobDocumentSet))
+            ?? typeof(DynamicDataGrid<JobDocumentSet>);
+        return (Activator.CreateInstance(gridType) as DynamicDataGrid<JobDocumentSet>)!;
+    }
+
+    private void ViewDocumentSet(Guid docSetID)
+    {
+        var docSet = Client.Query(
+            new Filter<JobDocumentSet>(x => x.ID).IsEqualTo(docSetID),
+            DynamicGridUtils.LoadEditorColumns<JobDocumentSet>(new Columns<JobDocumentSet>(x => x.ID)))
+            .ToObjects<JobDocumentSet>()
+            .FirstOrDefault();
+        if (docSet is null)
+        {
+            MessageWindow.ShowMessage("Document set does not exist.", "Error");
+            Logger.Send(LogType.Information, "", "Document set does not exist.");
+            return;
+        }
+        GetDocumentSetGrid().EditItems(new JobDocumentSet[] { docSet });
+    }
+
+    private void CreateDocumentSet(CoreRow row)
+    {
+        var folder = new MultiSelectDialog<JobDocumentSetFolder>(
+            new Filter<JobDocumentSetFolder>(x => x.Job.ID).IsEqualTo(Job.ID),
+            new Columns<JobDocumentSetFolder>(x => x.ID));
+        if (!folder.ShowDialog())
+        {
+            MessageWindow.ShowMessage("You need to select a folder to add this document set to.", "Folder required");
+            return;
+        }
+
+        var code = row.Get<JobStyle, string>(x => x.Style.Code);
+        var docSet = new JobDocumentSet
+        {
+            Code = code,
+            Description = row.Get<JobStyle, string>(x => x.Style.Description) + $"\nAttached to Product Style '{code}'"
+        };
+        docSet.Job.ID = Job.ID;
+        docSet.Folder.ID = folder.IDs().First();
+        if (GetDocumentSetGrid().EditItems(new JobDocumentSet[] { docSet }))
+        {
+            var jobStyle = row.ToObject<JobStyle>();
+            jobStyle.JobDocumentSet.ID = docSet.ID;
+            Client.Save(jobStyle, "Attached to new JobDocumentSet");
+            Refresh(false, true);
+        }
+    }
+
+
     JobPanelSettings IJobControl.Settings { get; set; }
 
     public string SectionName => "Job Product Styles";