DashboardContainer.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using FastReport.DataVisualization.Charting;
  2. using InABox.Core;
  3. using InABox.WPF;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using InABox.Configuration;
  18. using InABox.Wpf;
  19. namespace PRSDesktop;
  20. /// <summary>
  21. /// Interaction logic for DashboardContainer.xaml
  22. /// </summary>
  23. public partial class DashboardContainer : UserControl
  24. {
  25. private ICorePanel _panel;
  26. public ICorePanel Panel { get => _panel; }
  27. private DashboardContainer(ICorePanel panel, string name)
  28. {
  29. InitializeComponent();
  30. _panel = panel;
  31. DashboardName.Content = name;
  32. if(panel is IActionsDashboard)
  33. {
  34. Settings.Visibility = Visibility.Visible;
  35. }
  36. else
  37. {
  38. Settings.Visibility = Visibility.Collapsed;
  39. }
  40. if(panel is IHeaderDashboard headerDashboard)
  41. {
  42. RefreshHeader(headerDashboard.Header);
  43. headerDashboard.Header.HeaderChanged += Header_HeaderChanged;
  44. }
  45. }
  46. private void RefreshHeader(DashboardHeader header)
  47. {
  48. if (HeaderItems.Children.Count > 0)
  49. {
  50. HeaderItems.Children.Clear();
  51. }
  52. if (HeaderItemsRight.Children.Count > 0)
  53. {
  54. HeaderItemsRight.Children.Clear();
  55. }
  56. foreach (var item in header.GetLeftElements())
  57. {
  58. HeaderItems.Children.Add(item);
  59. }
  60. foreach (var item in header.GetRightElements())
  61. {
  62. HeaderItemsRight.Children.Add(item);
  63. }
  64. }
  65. private void Header_HeaderChanged(DashboardHeader header)
  66. {
  67. RefreshHeader(header);
  68. }
  69. public static DashboardContainer Create<TWidget, TProperties>(DFLayoutElement<TProperties> element, string name)
  70. where TWidget : FrameworkElement, IDashboardWidget<TProperties>, new()
  71. where TProperties : IConfigurationSettings, IDashboardProperties, new()
  72. {
  73. var result = new TWidget();
  74. element.Properties ??= new TProperties();
  75. result.Properties = element.Properties;
  76. result.Setup();
  77. var container = new DashboardContainer(result, name);
  78. container.ContentControl.Content = result;
  79. container._panel = result;
  80. return container;
  81. }
  82. private void Settings_Click(object sender, RoutedEventArgs e)
  83. {
  84. var menu = new ContextMenu();
  85. if (Panel is IActionsDashboard actions)
  86. {
  87. actions.BuildActionsMenu(menu);
  88. }
  89. if (menu.Items[^1] is Separator separator)
  90. {
  91. menu.Items.Remove(separator);
  92. }
  93. if (menu.Items.Count == 0)
  94. {
  95. menu.AddItem("No Actions", null, null, false);
  96. }
  97. menu.IsOpen = true;
  98. }
  99. }