CustomDashboardGrid.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using InABox.Core;
  2. using InABox.DynamicGrid;
  3. using InABox.Wpf;
  4. using InABox.Wpf.Dashboard;
  5. using InABox.Wpf.Dashboard.Editor;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. namespace PRSDesktop.Dashboards;
  13. public class CustomDashboardGrid : DynamicItemsListGrid<CustomDashboard>
  14. {
  15. protected override void DoReconfigure(DynamicGridOptions options)
  16. {
  17. base.DoReconfigure(options);
  18. options.Clear();
  19. options.AddRows = true;
  20. options.EditRows = true;
  21. options.DeleteRows = true;
  22. }
  23. public override CustomDashboard CreateItem()
  24. {
  25. var item = base.CreateItem();
  26. item.Name = "New Dashboard";
  27. item.Group = "Custom";
  28. item.ID = Guid.NewGuid();
  29. return item;
  30. }
  31. public override bool EditItems(CustomDashboard[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false)
  32. {
  33. if(items.Length > 1)
  34. {
  35. MessageWindow.ShowMessage("Please select only one dashboard to edit.", "Error");
  36. return false;
  37. }
  38. var customDashboard = items[0];
  39. var dashboard = DynamicDashboardUtils.Deserialize(customDashboard.Layout)
  40. ?? new();
  41. var editor = new DynamicDashboardEditor(dashboard);
  42. editor.DashboardName = customDashboard.Name;
  43. editor.DashboardGroup = customDashboard.Group;
  44. var dlg = new DynamicContentDialog(editor)
  45. {
  46. Title = "Edit dashboard",
  47. SizeToContent = SizeToContent.Height,
  48. CanSave = true
  49. };
  50. if(dlg.ShowDialog() == true)
  51. {
  52. customDashboard.Layout = DynamicDashboardUtils.Serialize(editor.GetDashboard());
  53. customDashboard.Name = editor.DashboardName;
  54. customDashboard.Group = editor.DashboardGroup;
  55. SaveItem(customDashboard);
  56. return true;
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62. }
  63. }