Преглед на файлове

Dashboards now use an ID, and the manage dashboards button now works

Kenric Nugteren преди 7 месеца
родител
ревизия
4f71039912

+ 5 - 0
prs.classes/SecurityDescriptors/Dashboard_Descriptors.cs

@@ -12,6 +12,11 @@ namespace Comal.Classes
     {
     }
 
+    [Caption("Manage Custom Dashboards")]
+    public class CanManageCustomDashboards : EnabledSecurityDescriptor<DashboardLicense>
+    {
+    }
+
     [Caption("View the Factory KPI Dashboard")]
     public class CanViewFactoryKPIs : EnabledSecurityDescriptor<DashboardLicense, ManufacturingHistory>
     {

+ 5 - 3
prs.desktop/Dashboards/CustomDashboard.xaml.cs

@@ -21,14 +21,16 @@ namespace PRSDesktop;
 
 public class CustomDashboardProperties : IDashboardProperties, IUserConfigurationSettings
 {
-    public string DashboardName { get; set; } = "";
+    public Guid DashboardID { get; set; }
 }
 
 public class CustomDashboardElement : DFLayoutElement<CustomDashboardProperties>
 {
     protected override string GetDescription()
     {
-        return Properties.DashboardName;
+        var customDashboard = new GlobalConfiguration<GlobalUtilityDashboardSettings>().Load()
+            .CustomDashboards.FirstOrDefault(x => x.ID == Properties.DashboardID);
+        return customDashboard?.Name ?? "Unknown Dashboard";
     }
 }
 
@@ -53,7 +55,7 @@ public partial class CustomDashboardWidget : UserControl, IDashboardWidget<Custo
     public void Setup()
     {
         var customDashboard = new GlobalConfiguration<GlobalUtilityDashboardSettings>().Load()
-            .CustomDashboards.FirstOrDefault(x => x.Name == Properties.DashboardName);
+            .CustomDashboards.FirstOrDefault(x => x.ID == Properties.DashboardID);
         if(customDashboard is null)
         {
             return;

+ 62 - 1
prs.desktop/Dashboards/CustomDashboardGrid.cs

@@ -1,12 +1,73 @@
-using InABox.DynamicGrid;
+using InABox.Core;
+using InABox.DynamicGrid;
+using InABox.Wpf;
+using InABox.Wpf.Dashboard;
+using InABox.Wpf.Dashboard.Editor;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PRSDesktop.Dashboards;
 
 public class CustomDashboardGrid : DynamicItemsListGrid<CustomDashboard>
 {
+    protected override void DoReconfigure(DynamicGridOptions options)
+    {
+        base.DoReconfigure(options);
+
+        options.Clear();
+        options.AddRows = true;
+        options.EditRows = true;
+        options.DeleteRows = true;
+    }
+
+    public override CustomDashboard CreateItem()
+    {
+        var item = base.CreateItem();
+        item.Name = "New Dashboard";
+        item.Group = "Custom";
+        item.ID = Guid.NewGuid();
+        return item;
+    }
+
+    public override bool EditItems(CustomDashboard[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false)
+    {
+        if(items.Length > 1)
+        {
+            MessageWindow.ShowMessage("Please select only one dashboard to edit.", "Error");
+            return false;
+        }
+
+        var customDashboard = items[0];
+
+        var dashboard = DynamicDashboardUtils.Deserialize(customDashboard.Layout)
+            ?? new();
+
+        var editor = new DynamicDashboardEditor(dashboard);
+        editor.DashboardName = customDashboard.Name;
+        editor.DashboardGroup = customDashboard.Group;
+
+        var dlg = new DynamicContentDialog(editor)
+        {
+            Title = "Edit dashboard",
+            SizeToContent = SizeToContent.Height,
+            CanSave = true
+        };
+
+        if(dlg.ShowDialog() == true)
+        {
+            customDashboard.Layout = DynamicDashboardUtils.Serialize(editor.GetDashboard());
+            customDashboard.Name = editor.DashboardName;
+            customDashboard.Group = editor.DashboardGroup;
+
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
 }

+ 26 - 13
prs.desktop/Dashboards/UtilityDashboard.xaml.cs

@@ -37,6 +37,8 @@ namespace PRSDesktop
 
     public class CustomDashboard : BaseObject
     {
+        public Guid ID { get; set; }
+
         public string Name { get; set; }
 
         public string Group { get; set; }
@@ -128,7 +130,7 @@ namespace PRSDesktop
 
         public void CreateToolbarButtons(IPanelHost host)
         {
-            host.CreateSetupAction("Manage Custom Dashboards", null, ManageCustomDashboards_Click);
+            host.CreateSetupActionIf<CanManageCustomDashboards>("Manage Custom Dashboards", null, ManageCustomDashboards_Click);
         }
 
         private void ManageCustomDashboards_Click(PanelAction action)
@@ -138,6 +140,18 @@ namespace PRSDesktop
 
             var grid = new CustomDashboardGrid();
             grid.Items = settings.CustomDashboards;
+            grid.Refresh(true, true);
+
+            var dlg = new DynamicContentDialog(grid)
+            {
+                Title = "Manage Custom Dashboards"
+            };
+            dlg.CanSave = true;
+            if(dlg.ShowDialog() == true)
+            {
+                config.Save(settings);
+                UpdateCustomDashboardList();
+            }
         }
 
         private void SaveSettings()
@@ -522,7 +536,9 @@ namespace PRSDesktop
             string dashboardName;
             if(element is CustomDashboardElement custom)
             {
-                dashboardName = custom.Properties.DashboardName;
+                var customDashboard = new GlobalConfiguration<GlobalUtilityDashboardSettings>().Load()
+                    .CustomDashboards.FirstOrDefault(x => x.ID == custom.Properties.DashboardID);
+                dashboardName = customDashboard?.Name ?? "Unknown Dashboard";
             }
             else
             {
@@ -682,7 +698,7 @@ namespace PRSDesktop
             var config = new GlobalConfiguration<GlobalUtilityDashboardSettings>();
             var settings = config.Load();
 
-            var customDashboard = settings.CustomDashboards.FirstOrDefault(x => x.Name == element.Properties.DashboardName);
+            var customDashboard = settings.CustomDashboards.FirstOrDefault(x => x.ID == element.Properties.DashboardID);
             if(customDashboard is null)
             {
                 return;
@@ -711,11 +727,6 @@ namespace PRSDesktop
                 customDashboard.Group = editor.DashboardGroup;
                 config.Save(settings);
 
-                element.Properties = new CustomDashboardProperties
-                {
-                    DashboardName = editor.DashboardName
-                };
-
                 UpdateCustomDashboardList();
             }
         }
@@ -725,7 +736,7 @@ namespace PRSDesktop
             var element = new CustomDashboardElement();
             element.Properties = new CustomDashboardProperties
             {
-                DashboardName = dashboard.Name
+                DashboardID = dashboard.ID
             };
             return element;
         }
@@ -749,18 +760,20 @@ namespace PRSDesktop
             {
                 var config = new GlobalConfiguration<GlobalUtilityDashboardSettings>();
                 var settings = config.Load();
-                settings.CustomDashboards.Add(new CustomDashboard
+                var newDashboard = new CustomDashboard
                 {
                     Layout = DynamicDashboardUtils.Serialize(editor.GetDashboard()),
                     Name = editor.DashboardName,
-                    Group = editor.DashboardGroup
-                });
+                    Group = editor.DashboardGroup,
+                    ID = Guid.NewGuid()
+                };
+                settings.CustomDashboards.Add(newDashboard);
                 config.Save(settings);
 
                 var element = new CustomDashboardElement();
                 element.Properties = new CustomDashboardProperties
                 {
-                    DashboardName = editor.DashboardName
+                    DashboardID = newDashboard.ID
                 };
 
                 UpdateCustomDashboardList();