UserPanel.xaml.cs 1.9 KB

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