Browse Source

Merge remote-tracking branch 'origin/kenric' into frank

frankvandenbos 6 months ago
parent
commit
f3e4e4b046

+ 1 - 6
prs.desktop/Panels/Jobs/ProjectsPanel.cs

@@ -206,7 +206,6 @@ public class ProjectsPanel : MasterDetailPanel<Job,ProjectsGrid,ProjectsPanelSet
             } 
         });
 
-
         ProjectSetupActions.JobStatuses(host);
         ProjectSetupActions.DocumentMilestones(host);
         ProjectSetupActions.JobScopeStatuses(host);
@@ -218,11 +217,7 @@ public class ProjectsPanel : MasterDetailPanel<Job,ProjectsGrid,ProjectsPanelSet
         host.CreateSetupSeparator();
         ProjectSetupActions.SetoutGroups(host);
 
-        if (SelectedPage is IMasterDetailPanelPage { Panel: not null } subpanel)
-            subpanel.Panel.CreateToolbarButtons(host);
-
-
+        base.CreateToolbarButtons(host);
     }
-
 }
 

+ 8 - 99
prs.desktop/Panels/PanelHost.cs

@@ -92,76 +92,11 @@ public class PanelHost : IPanelHost
 
     #region Panel Properties
 
-    private void InitializePanelProperties(IBasePanel panel)
-    {
-        var propertiesInterface = panel.GetType().GetInterfaceDefinition(typeof(IPropertiesPanel<>));
-        if (propertiesInterface is not null)
-        {
-            var propertiesType = propertiesInterface.GenericTypeArguments[0];
-            var method = typeof(PanelHost)
-                .GetMethod(nameof(InitializePanelPropertiesGeneric), BindingFlags.NonPublic | BindingFlags.Instance)
-                ?.MakeGenericMethod(panel.GetType(), propertiesType)
-                .Invoke(this, new object?[] { panel });
-        }
-    }
-    private void InitializePanelPropertiesGeneric<TPanel, TProperties>(TPanel panel)
-        where TPanel : IPropertiesPanel<TProperties>
-        where TProperties : BaseObject, IGlobalConfigurationSettings, new()
-    {
-        panel.Properties = LoadPanelProperties<TPanel, TProperties>();
-    }
-    private TProperties LoadPanelProperties<TPanel, TProperties>()
-        where TPanel : IPropertiesPanel<TProperties>
-        where TProperties : BaseObject, IGlobalConfigurationSettings, new()
-    {
-        var config = new GlobalConfiguration<TProperties>();
-        return config.Load();
-    }
-
-    private void SavePanelProperties<TPanel, TProperties>(TProperties properties)
-        where TPanel : IPropertiesPanel<TProperties>
-        where TProperties : BaseObject, IGlobalConfigurationSettings, new()
-    {
-        var config = new GlobalConfiguration<TProperties>();
-        config.Save(properties);
-    }
-    private void EditPanelProperties<TPanel, TProperties>()
-        where TPanel : IPropertiesPanel<TProperties>
-        where TProperties : BaseObject, IGlobalConfigurationSettings, new()
-    {
-        var properties = LoadPanelProperties<TPanel, TProperties>();
-
-        bool result;
-        if (DynamicGridUtils.TryFindDynamicGrid(typeof(DynamicGrid<>), typeof(TProperties), out var gridType))
-        {
-            var grid = (Activator.CreateInstance(gridType) as DynamicGrid<TProperties>)!;
-            result = grid.EditItems(new TProperties[] { properties });
-        }
-        else
-        {
-            var grid = new DynamicItemsListGrid<TProperties>();
-            result = grid.EditItems(new TProperties[] { properties });
-        }
-
-        if (result)
-        {
-            SavePanelProperties<TPanel, TProperties>(properties);
-        }
-    }
-
     private void ConfigurePanel()
     {
         if (CurrentPanel is null) return;
 
-        var propertiesInterface = CurrentPanel.GetType().GetInterfaceDefinition(typeof(IPropertiesPanel<>))!;
-        var propertiesType = propertiesInterface.GenericTypeArguments[0];
-        var basemethod = typeof(PanelHost)
-            .GetMethod(nameof(EditPanelProperties), BindingFlags.NonPublic | BindingFlags.Instance);
-        if (basemethod == null)
-            return;
-        var method = basemethod?.MakeGenericMethod(CurrentPanel.GetType(), propertiesType);
-        if (method != null)
-            method.Invoke(this, Array.Empty<object?>());
+        PanelUtils.ConfigurePanel(CurrentPanel);
     }
 
     #endregion
@@ -170,6 +105,9 @@ public class PanelHost : IPanelHost
 
     private void ReloadActions(string sectionName, DataModel model)
     {
+        ReportUtils.ExportDefinitions.Clear();
+        ReportUtils.ExportDefinitions.AddRange(PRSEmailUtils.CreateTemplateDefinitions(model));
+
         SetupActions.Clear();
         HostControl.ClearActions();
         HostControl.ClearReports();
@@ -260,15 +198,6 @@ public class PanelHost : IPanelHost
 
     #region Reports
 
-    private IEnumerable<ReportExportDefinition> AddTemplateDefinitions()
-    {
-        if (CurrentPanel is null)
-            return new List<ReportExportDefinition>() { new ReportExportDefinition("Email Report", PRSDesktop.Resources.email, ReportExportType.PDF,
-                            PRSEmailUtils.DoEmailReport)};
-        else
-            return PRSEmailUtils.CreateTemplateDefinitions(CurrentPanel.DataModel(Selection.None));
-    }
-
     public static PanelAction CreateReportAction(ReportTemplate template, Func<Selection, DataModel> getDataModel)
     {
         var action = new PanelAction
@@ -454,21 +383,12 @@ public class PanelHost : IPanelHost
 
     public T LoadPanel<T>(string moduleName) where T : class, IBasePanel, new()
     {
-        var panel = new T();
+        var panel = PanelUtils.LoadPanel<T>();
         CurrentPanel = panel;
 
-        ReportUtils.ExportDefinitions.Clear();
-        ReportUtils.ExportDefinitions.AddRange(AddTemplateDefinitions());
-
-        InitializePanelProperties(panel);
-
         CurrentModuleName = moduleName;
         TrackedTicks = DateTime.Now;
 
-        CurrentPanel.IsReady = false;
-        CurrentPanel.Setup();
-        CurrentPanel.IsReady = true;
-
         CurrentPanel.OnUpdateDataModel += ReloadActions;
 
         var model = CurrentPanel.DataModel(Selection.None);
@@ -530,21 +450,10 @@ public class PanelHost : IPanelHost
         if (CurrentPanel != null)
         {
             Heartbeat(DateTime.Now - TrackedTicks, true);
-            try
-            {
-                if(CurrentPanel is ISubPanelHost host)
-                {
-                    host.ShutdownSubPanels(cancel);
-                }
-                CurrentPanel.Shutdown(cancel);
-                if (cancel?.Cancel == true)
-                {
-                    return;
-                }
-            }
-            catch (Exception e)
+            PanelUtils.UnloadPanel(CurrentPanel, cancel);
+            if (cancel?.Cancel == true)
             {
-                Logger.Send(LogType.Error, ClientFactory.UserID, string.Format("Error in UnloadPanel(): {0}\n{1}", e.Message, e.StackTrace));
+                return;
             }
 
             TrackedTicks = DateTime.MinValue;

+ 69 - 68
prs.desktop/Panels/Tasks/ITaskControl.cs

@@ -7,93 +7,94 @@ using Comal.Classes;
 using InABox.Core;
 using InABox.Wpf;
 
-namespace PRSDesktop
+namespace PRSDesktop;
+
+public interface ITaskHost : IMasterDetailControl<Job>
 {
-    public interface ITaskHost : IMasterDetailControl<Job>
-    {
-        IList<KanbanType> KanbanTypes { get; }
+    IList<KanbanType> KanbanTypes { get; }
 
-        KanbanSettings KanbanSettings { get; }
+    KanbanSettings KanbanSettings { get; }
 
-        void SaveSettings();
+    TaskPanelProperties Properties { get; }
 
-        void PopulateMenu(ITaskControl control, TaskModel task, ContextMenu menu);
+    void SaveSettings();
 
-        Kanban? CreateKanban(Action<Kanban> customise);
-        IEnumerable<Kanban> LoadKanbans(IEnumerable<TaskModel> models, Columns<Kanban> columns);
+    void PopulateMenu(ITaskControl control, TaskModel task, ContextMenu menu);
 
-        bool EditKanbans(IEnumerable<TaskModel> models, Action<Kanban>? customise = null);
-        void DeleteKanbans(IEnumerable<TaskModel> models, string auditnote);
+    Kanban? CreateKanban(Action<Kanban> customise);
+    IEnumerable<Kanban> LoadKanbans(IEnumerable<TaskModel> models, Columns<Kanban> columns);
 
-        //Requisition CreateRequisition(TaskModel model, Action<Requisition> customise);
-        //bool EditRequisition(TaskModel model, Action<Requisition> customise = null);
+    bool EditKanbans(IEnumerable<TaskModel> models, Action<Kanban>? customise = null);
+    void DeleteKanbans(IEnumerable<TaskModel> models, string auditnote);
 
-        KanbanReferences[] GetReferences(IEnumerable<TaskModel> models);
-        bool EditReferences(IEnumerable<TaskModel> models);
+    //Requisition CreateRequisition(TaskModel model, Action<Requisition> customise);
+    //bool EditRequisition(TaskModel model, Action<Requisition> customise = null);
 
-        bool CanChangeTasks(IEnumerable<TaskModel> models);
-    }
+    KanbanReferences[] GetReferences(IEnumerable<TaskModel> models);
+    bool EditReferences(IEnumerable<TaskModel> models);
 
-    public interface ITaskControl
-    {
-        ITaskHost Host { get; set; }
+    bool CanChangeTasks(IEnumerable<TaskModel> models);
+}
+
+public interface ITaskControl
+{
+    ITaskHost Host { get; set; }
+
+    KanbanViewType KanbanViewType { get; }
 
-        KanbanViewType KanbanViewType { get; }
+    bool IsReady { get; set; }
 
-        bool IsReady { get; set; }
+    IEnumerable<TaskModel> SelectedModels(TaskModel? sender = null);
 
-        IEnumerable<TaskModel> SelectedModels(TaskModel? sender = null);
+    string SectionName { get; }
 
-        string SectionName { get; }
+    DataModel DataModel(Selection selection);
 
-        DataModel DataModel(Selection selection);
+    void Setup();
 
-        void Setup();
+    void Refresh();
+}
 
-        void Refresh();
+public class KanbanReferences
+{
+    public KanbanReferences()
+    {
+        Requisitions = new Guid[] { };
+        Setouts = new Guid[] { };
+        Deliveries = new Guid[] { };
+        Orders = new Guid[] { };
+    }
+
+    public Guid Kanban { get; set; }
+
+    public Guid[] Requisitions { get; set; }
+    public Guid[] Setouts { get; set; }
+    public Guid[] Deliveries { get; set; }
+    public Guid[] Orders { get; set; }
+
+    public Type ReferenceType()
+    {
+        if (Requisitions.Any())
+            return typeof(Requisition);
+        if (Setouts.Any())
+            return typeof(Setout);
+        if (Deliveries.Any())
+            return typeof(Delivery);
+        if (Orders.Any())
+            return typeof(PurchaseOrder);
+        return null;
     }
 
-    public class KanbanReferences
+    public Guid GetID()
     {
-        public KanbanReferences()
-        {
-            Requisitions = new Guid[] { };
-            Setouts = new Guid[] { };
-            Deliveries = new Guid[] { };
-            Orders = new Guid[] { };
-        }
-
-        public Guid Kanban { get; set; }
-
-        public Guid[] Requisitions { get; set; }
-        public Guid[] Setouts { get; set; }
-        public Guid[] Deliveries { get; set; }
-        public Guid[] Orders { get; set; }
-
-        public Type ReferenceType()
-        {
-            if (Requisitions.Any())
-                return typeof(Requisition);
-            if (Setouts.Any())
-                return typeof(Setout);
-            if (Deliveries.Any())
-                return typeof(Delivery);
-            if (Orders.Any())
-                return typeof(PurchaseOrder);
-            return null;
-        }
-
-        public Guid GetID()
-        {
-            if (Requisitions.Any())
-                return Requisitions.First();
-            if (Setouts.Any())
-                return Setouts.First();
-            if (Deliveries.Any())
-                return Deliveries.First();
-            if (Orders.Any())
-                return Orders.First();
-            return Guid.Empty;
-        }
+        if (Requisitions.Any())
+            return Requisitions.First();
+        if (Setouts.Any())
+            return Setouts.First();
+        if (Deliveries.Any())
+            return Deliveries.First();
+        if (Orders.Any())
+            return Orders.First();
+        return Guid.Empty;
     }
 }

+ 10 - 0
prs.desktop/Panels/Tasks/TaskGrid.cs

@@ -36,6 +36,16 @@ public class TaskGrid : DynamicDataGrid<Kanban>, ITaskControl, IDefaultGrid
         options.PageSize = 1000;
     }
 
+    protected override void DoValidate(Kanban[] items, List<string> errors)
+    {
+        base.DoValidate(items, errors);
+
+        if (Host.Properties.RequireTaskTypes && items.Any(x => x.Type.ID == Guid.Empty))
+        {
+            errors.Add("[Task Type] may not be blank!");
+        }
+    }
+
     private bool FormMenuClick(CoreRow? row)
     {
         if (row is null)

+ 3 - 15
prs.desktop/Panels/Tasks/TaskPanel.xaml.cs

@@ -734,6 +734,7 @@ public partial class TaskPanel : UserControl, IPanel<Kanban>, ITaskHost, IMaster
                 KanbanSettings.ViewType = panel.KanbanViewType;
                 new UserConfiguration<KanbanSettings>().Save(KanbanSettings);
                 panel.Refresh();
+                OnUpdateDataModel?.Invoke(SectionName, DataModel(Selection.None));
             }
         }
         finally
@@ -903,9 +904,9 @@ public partial class TaskPanel : UserControl, IPanel<Kanban>, ITaskHost, IMaster
             grid = (DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), typeof(TEntity)) as DynamicDataGrid<TEntity>)!;
             _grids[typeof(TEntity)] = grid;
 
-            if (typeof(TEntity) == typeof(Kanban))
+            if(grid is ITaskControl ctl)
             {
-                CustomiseKanbanGrid((grid as DynamicDataGrid<Kanban>)!);
+                ctl.Host = this;
             }
         }
 
@@ -1043,19 +1044,6 @@ public partial class TaskPanel : UserControl, IPanel<Kanban>, ITaskHost, IMaster
         return DoLoad(models, columns);
     }
 
-    public void OnValidateKanban(object sender, Kanban[] items, List<string> errors)
-    {
-        if (Properties.RequireTaskTypes && items.Any(x => x.Type.ID == Guid.Empty))
-        {
-            errors.Add("[Task Type] may not be blank!");
-        }
-    }
-
-    public void CustomiseKanbanGrid(DynamicDataGrid<Kanban> grid)
-    {
-        grid.OnValidate += OnValidateKanban;
-    }
-
     public bool EditKanbans(IEnumerable<TaskModel> models, Action<Kanban>? customise = null)
     {
         var entities = LoadKanbans(models, GetGrid<Kanban>().LoadEditorColumns());