|
@@ -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
|
|
|
+
|
|
|
}
|