UserPanel.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. namespace PRSDesktop;
  10. /// <summary>
  11. /// Interaction logic for UserPanel.xaml
  12. /// </summary>
  13. public partial class UserPanel : UserControl, IPanel<User>
  14. {
  15. private readonly UserGrid Users;
  16. public UserPanel()
  17. {
  18. InitializeComponent();
  19. Users = new UserGrid
  20. {
  21. HorizontalAlignment = HorizontalAlignment.Stretch,
  22. VerticalAlignment = VerticalAlignment.Stretch,
  23. Margin = new Thickness(0)
  24. };
  25. Users.OnCustomiseEditor += Users_OnCustomiseEditor;
  26. AddChild(Users);
  27. }
  28. public event DataModelUpdateEvent? OnUpdateDataModel;
  29. public bool IsReady { get; set; }
  30. public Dictionary<string, object[]> Selected()
  31. {
  32. return new Dictionary<string, object[]> { { typeof(User).EntityName(), Users.SelectedRows } };
  33. }
  34. public void Setup()
  35. {
  36. Users.Refresh(true, false);
  37. }
  38. public void Shutdown()
  39. {
  40. }
  41. public void CreateToolbarButtons(IPanelHost host)
  42. {
  43. }
  44. public void Refresh()
  45. {
  46. Users.Refresh(false, true);
  47. }
  48. public string SectionName => "Users";
  49. public DataModel DataModel(Selection selection)
  50. {
  51. var ids = Users.ExtractValues(x => x.ID, selection).ToArray();
  52. return new BaseDataModel<User>(new Filter<User>(x => x.ID).InList(ids));
  53. }
  54. public void Heartbeat(TimeSpan time)
  55. {
  56. }
  57. private void Users_OnCustomiseEditor(IDynamicEditorForm sender, User[]? items, DynamicGridColumn column, BaseEditor editor)
  58. {
  59. if (editor is PasswordEditor pe)
  60. pe.ViewButtonVisible = Security.IsAllowed<CanViewPasswords>();
  61. }
  62. }