ProjectsPanel.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using Comal.Classes;
  6. using InABox.Configuration;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using InABox.Wpf;
  10. using PRSDesktop.Panels.Jobs;
  11. namespace PRSDesktop;
  12. public class ProjectsPanelSettings : BaseObject, IUserConfigurationSettings, IMasterDetailSettings
  13. {
  14. [NullEditor] public DynamicSplitPanelView ViewType { get; set; } = DynamicSplitPanelView.Combined;
  15. [NullEditor]
  16. public double AnchorWidth { get; set; } = 300;
  17. [NullEditor]
  18. public Guid MasterID { get; set; }
  19. private class VisiblePanelsGenerator : LookupGenerator<object>
  20. {
  21. public VisiblePanelsGenerator(object[] items) : base(items)
  22. {
  23. AddValue(typeof(JobDetails).EntityName().Split('.').Last(),"Details");
  24. AddValue(typeof(JobScopePanel).EntityName().Split('.').Last(), "Scopes");
  25. AddValue(typeof(JobDocumentSetPanel).EntityName().Split('.').Last(), "Documents");
  26. AddValue(typeof(JobStagesPanel).EntityName().Split('.').Last(), "Stages");
  27. AddValue(typeof(JobITPGrid).EntityName().Split('.').Last(), "ITPs");
  28. AddValue(typeof(JobProductMappingsGrid).EntityName().Split('.').Last(), "Product Mappings");
  29. AddValue(typeof(JobProductStylesGrid).EntityName().Split('.').Last(), "Product Styles");
  30. AddValue(typeof(JobBillOfMaterialsPanel).EntityName().Split('.').Last(), "BOM");
  31. AddValue(typeof(JobRequisitionPanel).EntityName().Split('.').Last(), "Requisitions");
  32. AddValue(typeof(JobStockGrid).EntityName().Split('.').Last(), "Stock Holdings");
  33. AddValue(typeof(JobPickingListPanel).EntityName().Split('.').Last(), "Picking Lists");
  34. AddValue(typeof(JobOrderGrid).EntityName().Split('.').Last(), "Orders");
  35. AddValue(typeof(JobDesignPanel).EntityName().Split('.').Last(), "Designs");
  36. AddValue(typeof(ManufacturingGrid).EntityName().Split('.').Last(), "Manufacturing");
  37. AddValue(typeof(ReadyToGoGrid).EntityName().Split('.').Last(), "Dispatch");
  38. AddValue(typeof(DeliveryPanel).EntityName().Split('.').Last(), "Deliveries");
  39. AddValue(typeof(DeliveredOnSiteGrid).EntityName().Split('.').Last(), "OnSite");
  40. AddValue(typeof(TaskPanel).EntityName().Split('.').Last(), "Tasks");
  41. AddValue(typeof(JobEquipmentGrid).EntityName().Split('.').Last(), "EquipmentTab");
  42. AddValue(typeof(JobEmployeePanel).EntityName().Split('.').Last(), "Employees");
  43. AddValue(typeof(JobTrackerGrid).EntityName().Split('.').Last(), "Trackers");
  44. AddValue(typeof(JobAssignmentPanel).EntityName().Split('.').Last(), "Assignments");
  45. AddValue(typeof(JobTimesheetGrid).EntityName().Split('.').Last(), "Timesheets");
  46. AddValue(typeof(JobFormGrid).EntityName().Split('.').Last(), "Forms");
  47. AddValue(typeof(InvoicePanel).EntityName().Split('.').Last(), "Invoices");
  48. AddValue(typeof(JobSpreadsheetGrid).EntityName().Split('.').Last(), "Spreadsheets");
  49. AddValue(typeof(JobSummaryPanel).EntityName().Split('.').Last(), "Summary");
  50. }
  51. }
  52. [CheckListEditor(typeof(VisiblePanelsGenerator))]
  53. public Dictionary<string, bool> VisiblePanels { get; set; }
  54. public ProjectsPanelSettings()
  55. {
  56. VisiblePanels = new Dictionary<string, bool>();
  57. }
  58. }
  59. public class ProjectsPanel : MasterDetailPanel<Job,ProjectsGrid,ProjectsPanelSettings>
  60. {
  61. protected override string MasterCaption => "Project List";
  62. protected override string DetailCaption => "Project Details";
  63. protected override string MasterColumnsTag => "Projects";
  64. private void SetPageVisible(Type type, IMasterDetailPage? page)
  65. {
  66. if (page is null)
  67. return;
  68. var isvisible = Settings.VisiblePanels.TryGetValue(type.EntityName().Split('.').Last(), out bool visible)
  69. ? visible
  70. : true;
  71. page.Tab.Visibility = isvisible
  72. ? Visibility.Visible
  73. : Visibility.Collapsed;
  74. }
  75. private void SetPagesVisible()
  76. {
  77. foreach (var page in _pages.Where(x=>x.Value is not null))
  78. SetPageVisible(page.Key,page.Value);
  79. }
  80. private void DoCreatePanel<TPanel>(Func<bool> cancreate, string caption)
  81. where TPanel : class, IBasePanel, IMasterDetailControl<Job>, new()
  82. {
  83. _pages[typeof(TPanel)] = CreatePage<JobDetailPanel<TPanel>>(cancreate, caption);
  84. }
  85. private void DoCreateGrid<TGrid,TEntity>(Func<bool> cancreate, string caption)
  86. where TGrid : DynamicGrid<TEntity>, IDataModelSource, IMasterDetailControl<Job,TEntity>, new()
  87. where TEntity : BaseObject, new()
  88. {
  89. _pages[typeof(TGrid)] = CreatePage<JobDetailGrid<TGrid,TEntity>>(cancreate, caption);
  90. }
  91. private Dictionary<Type, IMasterDetailPage?> _pages = new();
  92. protected override void CreatePages()
  93. {
  94. DoCreatePanel<JobDetails>(() => true,"Details");
  95. DoCreatePanel<JobScopePanel>(Security.CanView<JobScope>, "Scopes");
  96. DoCreatePanel<JobDocumentSetPanel>(Security.CanView<JobDocumentSet>, "Documents");
  97. DoCreatePanel<JobStagesPanel>(Security.CanView<JobStage>, "Stages");
  98. DoCreateGrid<JobITPGrid, JobITP>(Security.CanView<JobITP>, "ITPs");
  99. DoCreateGrid<JobProductMappingsGrid, JobProductMapping>(Security.CanView<JobProductMapping>, "Product Mappings");
  100. DoCreateGrid<JobProductStylesGrid, JobStyle>(Security.CanView<JobStyle>, "Product Styles");
  101. DoCreatePanel<JobBillOfMaterialsPanel>(Security.CanView<JobBillOfMaterials>, "BOM");
  102. DoCreatePanel<JobRequisitionPanel>(Security.CanView<JobRequisition>, "Requisitions");
  103. DoCreatePanel<JobStockGrid>(Security.CanView<StockHolding>, "Stock Holdings");
  104. DoCreatePanel<JobPickingListPanel>(Security.CanView<Requisition>, "Picking Lists");
  105. DoCreateGrid<JobOrderGrid, PurchaseOrderItem>(Security.CanView<PurchaseOrderItem>, "Orders");
  106. DoCreatePanel<JobDesignPanel>(Security.CanView<Setout>, "Designs");
  107. DoCreateGrid<ManufacturingGrid, ManufacturingPacket>(Security.CanView<ManufacturingPacket>, "Manufacturing");
  108. DoCreateGrid<ReadyToGoGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "Dispatch");
  109. DoCreatePanel<DeliveryPanel>(Security.CanView<Delivery>, "Deliveries");
  110. DoCreateGrid<DeliveredOnSiteGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "OnSite");
  111. DoCreatePanel<TaskPanel>(Security.CanView<Kanban>, "Tasks");
  112. DoCreateGrid<JobEquipmentGrid, JobEquipment>(Security.CanView<Equipment>, "Equipment");
  113. DoCreatePanel<JobEmployeePanel>(Security.CanView<Employee>, "Employees");
  114. DoCreateGrid<JobTrackerGrid, JobTracker>(Security.CanView<GPSTracker>, "Trackers");
  115. DoCreatePanel<JobAssignmentPanel>(Security.CanView<Assignment>, "Assignments");
  116. DoCreateGrid<JobTimesheetGrid, TimeSheet>(Security.CanView<TimeSheet>, "Timesheets");
  117. DoCreateGrid<JobFormGrid, JobForm>(Security.CanView<JobForm>, "Forms");
  118. DoCreatePanel<InvoicePanel>(Security.CanView<Invoice>, "Invoices");
  119. DoCreateGrid<JobSpreadsheetGrid, JobSpreadsheet>(Security.CanView<JobSpreadsheet>, "Spreadsheets");
  120. DoCreatePanel<JobSummaryPanel>(Security.CanView<JobMaterial>, "Summary");
  121. SetPagesVisible();
  122. }
  123. protected override void AfterLoadSettings(ProjectsPanelSettings settings)
  124. {
  125. }
  126. protected override void BeforeSaveSettings(ProjectsPanelSettings settings)
  127. {
  128. }
  129. public override void CreateToolbarButtons(IPanelHost host)
  130. {
  131. host.CreateSetupAction(new PanelAction()
  132. {
  133. Caption = "Projects Settings",
  134. Image = PRSDesktop.Resources.specifications,
  135. OnExecute = action =>
  136. {
  137. var settings = new UserConfiguration<ProjectsPanelSettings>().Load();
  138. var grid = new DynamicItemsListGrid<ProjectsPanelSettings>();
  139. if (grid.EditItems(new ProjectsPanelSettings[] { Settings }))
  140. {
  141. SaveSettings();
  142. SetPagesVisible();
  143. }
  144. }
  145. });
  146. ProjectSetupActions.JobStatuses(host);
  147. ProjectSetupActions.DocumentMilestones(host);
  148. ProjectSetupActions.JobScopeStatuses(host);
  149. ProjectSetupActions.DrawingTemplates(host);
  150. host.CreateSetupSeparator();
  151. ProjectSetupActions.JobSpreadsheetTemplates(host);
  152. host.CreateSetupSeparator();
  153. ProjectSetupActions.SetoutGroups(host);
  154. if (SelectedPage is IMasterDetailPanelPage { Panel: not null } subpanel)
  155. subpanel.Panel.CreateToolbarButtons(host);
  156. }
  157. }