ModalNotifications.razor 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <div class="modal" tabindex="-1" role="dialog" style="display:none" id="@elementid">
  2. <div class="modal-container">
  3. <div class="modal__body">
  4. <div class="modal__body__header">
  5. <div class="modal__body__header__info">
  6. <img src="img/user.svg" alt="">
  7. <p>@Title</p>
  8. </div>
  9. </div>
  10. <div class="modal__body__container modal__body__container_noflex" style="vertical-align:top">
  11. <div class="modal__404__text__box">
  12. @Body
  13. <button class="btn_orange" style="margin-bottom: 20px" @onclick="SendTestNotification">Отправить тестовое сообщение этому юзеру</button>
  14. <table border="1">
  15. <tr>
  16. <th>Тип</th>
  17. <th>Заголовок</th>
  18. <th>Сообщение</th>
  19. <th>Прочитано</th>
  20. <th>Утверждено</th>
  21. <th>Отклонено</th>
  22. </tr>
  23. @foreach (var n in _notifications)
  24. {
  25. <tr>
  26. <td>@n.Value.NotifiType</td>
  27. <td>@n.Value.Header</td>
  28. <td><div style="width:100%; padding:5px">@n.Value.Body</div></td>
  29. <td>
  30. <input type="checkbox" @bind="n.Value.IsRead" disabled>
  31. <button @onclick="(() => ReadOnClick(n.Value.ID))">read</button>
  32. </td>
  33. <td>
  34. <input type="checkbox" @bind="n.Value.IsApproved" disabled>
  35. <button @onclick="(() => ApproveOnClick(n.Value.ID))">approve</button>
  36. </td>
  37. <td>
  38. <input type="checkbox" @bind="n.Value.IsRejected" disabled>
  39. <button @onclick="(() => RejectOnClick(n.Value.ID))">reject</button>
  40. </td>
  41. </tr>
  42. }
  43. </table>
  44. </div>
  45. </div>
  46. </div>
  47. <a class="modal_close" style="cursor:pointer" @onclick="@Close">&#10006;</a>
  48. </div>
  49. </div>
  50. @code {
  51. @using HyperCube.Models;
  52. [Inject]
  53. public IJSRuntime JsRuntime { get; set; }
  54. [Parameter]
  55. public RenderFragment Title { get; set; }
  56. [Parameter]
  57. public RenderFragment Body { get; set; }
  58. string message = "";
  59. string elementid = "modal_notifications";
  60. Dictionary<int, Models.Notification> _notifications = new();
  61. AccountModel _currentAcc = new();
  62. public async Task SendTestNotification()
  63. {
  64. await _currentAcc.SendTestNotification(_currentAcc, "Test text");
  65. }
  66. public void Open(Dictionary<int, Notification> notifications, AccountModel acc)
  67. {
  68. _notifications = acc.notifications;
  69. _currentAcc = acc;
  70. JsRuntime.InvokeVoidAsync("OpenModal", elementid);
  71. }
  72. public void Close()
  73. {
  74. JsRuntime.InvokeVoidAsync("CloseModal", elementid);
  75. }
  76. async Task ReadOnClick(int id)
  77. {
  78. if (!_notifications[id].IsRead)
  79. {
  80. _notifications[id].IsRead = true;
  81. _notifications[id].DateRead = DateTime.Now;
  82. }
  83. else
  84. {
  85. _notifications[id].IsRead = false;
  86. _notifications[id].DateRead = null;
  87. }
  88. await _notifications[id].Update();
  89. }
  90. async Task ApproveOnClick(int id)
  91. {
  92. if (!_notifications[id].IsApproved)
  93. {
  94. _notifications[id].IsApproved = true;
  95. _notifications[id].DateApprove = DateTime.Now;
  96. }
  97. else
  98. {
  99. _notifications[id].IsApproved = false;
  100. _notifications[id].DateApprove = null;
  101. }
  102. await _notifications[id].Update();
  103. }
  104. async Task RejectOnClick(int id)
  105. {
  106. if (!_notifications[id].IsRejected)
  107. {
  108. _notifications[id].IsRejected = true;
  109. _notifications[id].DateReject = DateTime.Now;
  110. }
  111. else
  112. {
  113. _notifications[id].IsRejected = false;
  114. _notifications[id].DateReject = null;
  115. }
  116. await _notifications[id].Update();
  117. }
  118. }