|
@@ -15,6 +15,9 @@ using InABox.Wpf;
|
|
|
using InABox.WPF.Themes;
|
|
|
using Microsoft.Xaml.Behaviors.Core;
|
|
|
using Syncfusion.Windows.Tools.Controls;
|
|
|
+using PRSDesktop.Dashboards;
|
|
|
+using InABox.Wpf.Dashboard.Editor;
|
|
|
+using InABox.Wpf.Dashboard;
|
|
|
|
|
|
namespace PRSDesktop
|
|
|
{
|
|
@@ -32,13 +35,24 @@ namespace PRSDesktop
|
|
|
public string Layout { get; set; }
|
|
|
}
|
|
|
|
|
|
+ public class CustomDashboard : BaseObject
|
|
|
+ {
|
|
|
+ public string Name { get; set; }
|
|
|
+
|
|
|
+ [NullEditor]
|
|
|
+ public string Layout { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
public class GlobalUtilityDashboardSettings : IGlobalConfigurationSettings
|
|
|
{
|
|
|
public List<DashboardFavourite> Favourites { get; set; }
|
|
|
|
|
|
+ public List<CustomDashboard> CustomDashboards { get; set; }
|
|
|
+
|
|
|
public GlobalUtilityDashboardSettings()
|
|
|
{
|
|
|
Favourites = new();
|
|
|
+ CustomDashboards = new();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -486,19 +500,26 @@ namespace PRSDesktop
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private FrameworkElement CreateElement<TWidget, TGroup, TProperties>(DynamicFormDesignGrid grid, DFLayoutElement<TProperties> element)
|
|
|
- where TWidget : FrameworkElement, IDashboardWidget<TGroup, TProperties>, new()
|
|
|
- where TGroup : DashboardWidgetGroup
|
|
|
+ private FrameworkElement CreateElement<TWidget, TProperties>(DynamicFormDesignGrid grid, DFLayoutElement<TProperties> element)
|
|
|
+ where TWidget : FrameworkElement, IDashboardWidget<TProperties>, new()
|
|
|
where TProperties : IConfigurationSettings, IDashboardProperties, new()
|
|
|
{
|
|
|
if (!_panels.ContainsKey(grid))
|
|
|
_panels[grid] = new List<ICorePanel>();
|
|
|
|
|
|
- var dashboardName = GetDashboardElements()
|
|
|
- .Where(x => x.DashboardElement == element.GetType())
|
|
|
- .FirstOrDefault()?.WidgetCaption ?? "Unknown Dashboard";
|
|
|
+ string dashboardName;
|
|
|
+ if(element is CustomDashboardElement custom)
|
|
|
+ {
|
|
|
+ dashboardName = custom.Properties.DashboardName;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dashboardName = GetDashboardElements()
|
|
|
+ .Where(x => x.DashboardElement == element.GetType())
|
|
|
+ .FirstOrDefault()?.WidgetCaption ?? "Unknown Dashboard";
|
|
|
+ }
|
|
|
|
|
|
- var container = DashboardContainer.Create<TWidget, TGroup, TProperties>(element, dashboardName);
|
|
|
+ var container = DashboardContainer.Create<TWidget, TProperties>(element, dashboardName);
|
|
|
|
|
|
_panels[grid].Add(container.Panel);
|
|
|
|
|
@@ -507,21 +528,27 @@ namespace PRSDesktop
|
|
|
|
|
|
private FrameworkElement OnCreateElement(object sender, DynamicFormCreateElementArgs e)
|
|
|
{
|
|
|
- var widgetType = GetVisibleDashboardElements().Where(x => x.DashboardElement == e.Element.GetType()).FirstOrDefault();
|
|
|
- if(widgetType == null)
|
|
|
+ var method = typeof(UtilityDashboard).GetMethod(nameof(CreateElement), BindingFlags.Instance | BindingFlags.NonPublic)!;
|
|
|
+ if(e.Element is CustomDashboardElement custom)
|
|
|
{
|
|
|
- var border = new Border
|
|
|
+ method = method.MakeGenericMethod(typeof(CustomDashboardWidget), typeof(CustomDashboardProperties));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var widgetType = GetVisibleDashboardElements().Where(x => x.DashboardElement == e.Element.GetType()).FirstOrDefault();
|
|
|
+ if(widgetType == null)
|
|
|
{
|
|
|
- BorderBrush = new SolidColorBrush(Colors.Gray),
|
|
|
- BorderThickness = new Thickness(0.0),
|
|
|
- Margin = new Thickness(0.0),
|
|
|
- Background = ThemeManager.WorkspaceBackgroundBrush //new SolidColorBrush(Colors.Silver);
|
|
|
- };
|
|
|
- return border;
|
|
|
+ var border = new Border
|
|
|
+ {
|
|
|
+ BorderBrush = new SolidColorBrush(Colors.Gray),
|
|
|
+ BorderThickness = new Thickness(0.0),
|
|
|
+ Margin = new Thickness(0.0),
|
|
|
+ Background = ThemeManager.WorkspaceBackgroundBrush //new SolidColorBrush(Colors.Silver);
|
|
|
+ };
|
|
|
+ return border;
|
|
|
+ }
|
|
|
+ method = method.MakeGenericMethod(widgetType.Widget, widgetType.Properties);
|
|
|
}
|
|
|
- var method = typeof(UtilityDashboard)
|
|
|
- .GetMethod(nameof(CreateElement), BindingFlags.Instance | BindingFlags.NonPublic)!
|
|
|
- .MakeGenericMethod(widgetType.Widget, widgetType.Group, widgetType.Properties);
|
|
|
return (method.Invoke(this, new object[] { sender, e.Element }) as FrameworkElement)!;
|
|
|
}
|
|
|
|
|
@@ -557,6 +584,7 @@ namespace PRSDesktop
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return _dashboardElements;
|
|
|
}
|
|
|
|
|
@@ -584,6 +612,14 @@ namespace PRSDesktop
|
|
|
grid.AddElement(widget.DashboardElement, widget.WidgetCaption, widget.GroupCaption, true);
|
|
|
}
|
|
|
|
|
|
+ var customDashboards = new GlobalConfiguration<GlobalUtilityDashboardSettings>().Load().CustomDashboards;
|
|
|
+ grid.AddElement(typeof(CustomDashboardElement), "Custom", "Custom", visible: false);
|
|
|
+ foreach(var customDashboard in customDashboards)
|
|
|
+ {
|
|
|
+ grid.AddElementAction(customDashboard.Name, null, "Custom", customDashboard, AddCustom_Click);
|
|
|
+ }
|
|
|
+ grid.AddElementAction<object?>("Create New", InABox.Wpf.Resources.add, "Custom", null, CreateNewCustom_Click);
|
|
|
+
|
|
|
grid.ShowBorders = false;
|
|
|
grid.OnCreateElement += OnCreateElement;
|
|
|
grid.OnAfterDesign += OnAfterDesign;
|
|
@@ -608,6 +644,84 @@ namespace PRSDesktop
|
|
|
return border;
|
|
|
}
|
|
|
|
|
|
+ private DFLayoutElement? AddCustom_Click(CustomDashboard dashboard)
|
|
|
+ {
|
|
|
+ var element = new CustomDashboardElement();
|
|
|
+ element.Properties = new CustomDashboardProperties
|
|
|
+ {
|
|
|
+ DashboardName = dashboard.Name
|
|
|
+ };
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+
|
|
|
+ private DFLayoutElement? CreateNewCustom_Click(object? tag)
|
|
|
+ {
|
|
|
+ var grid = new Grid();
|
|
|
+ grid.AddRow(GridUnitType.Auto);
|
|
|
+ grid.AddRow(GridUnitType.Auto);
|
|
|
+ grid.AddRow(GridUnitType.Star);
|
|
|
+
|
|
|
+ grid.AddColumn(GridUnitType.Auto);
|
|
|
+ grid.AddColumn(GridUnitType.Star);
|
|
|
+
|
|
|
+ grid.AddChild(new Label
|
|
|
+ {
|
|
|
+ Content = "Dashboard Name:",
|
|
|
+ VerticalAlignment = VerticalAlignment.Center
|
|
|
+ }, 0, 0);
|
|
|
+ var textBox = new TextBox
|
|
|
+ {
|
|
|
+ Background = Colors.LightYellow.ToBrush(),
|
|
|
+ Padding = new Thickness(5),
|
|
|
+ VerticalContentAlignment = VerticalAlignment.Center
|
|
|
+ };
|
|
|
+ grid.AddChild(textBox, 0, 1);
|
|
|
+
|
|
|
+ grid.AddChild(new Separator
|
|
|
+ {
|
|
|
+ Margin = new(5)
|
|
|
+ }, 1, 0, colSpan: 2);
|
|
|
+
|
|
|
+ var dashboard = new DynamicDashboard();
|
|
|
+
|
|
|
+ var editor = new DynamicDashboardEditor(dashboard);
|
|
|
+ grid.AddChild(editor, 2, 0, colSpan: 2);
|
|
|
+
|
|
|
+ var dlg = new DynamicContentDialog(grid)
|
|
|
+ {
|
|
|
+ Title = "Create new dashboard",
|
|
|
+ SizeToContent = SizeToContent.Height
|
|
|
+ };
|
|
|
+
|
|
|
+ textBox.TextChanged += (o, e) =>
|
|
|
+ {
|
|
|
+ dlg.CanSave = !textBox.Text.IsNullOrWhiteSpace();
|
|
|
+ };
|
|
|
+
|
|
|
+ if(dlg.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ var config = new GlobalConfiguration<GlobalUtilityDashboardSettings>();
|
|
|
+ var settings = config.Load();
|
|
|
+ settings.CustomDashboards.Add(new CustomDashboard
|
|
|
+ {
|
|
|
+ Layout = DynamicDashboardUtils.Serialize(editor.GetDashboard()),
|
|
|
+ Name = textBox.Text
|
|
|
+ });
|
|
|
+ config.Save(settings);
|
|
|
+
|
|
|
+ var element = new CustomDashboardElement();
|
|
|
+ element.Properties = new CustomDashboardProperties
|
|
|
+ {
|
|
|
+ DashboardName = textBox.Text
|
|
|
+ };
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void OnAfterRender(DynamicFormDesignGrid sender)
|
|
|
{
|
|
|
if (!sender.IsDesigning)
|