UserPanel.xaml.cs 1.8 KB

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