ModalNotifications.razor 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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>@n.Value.Body</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 void Open(Dictionary<int, Notification> notifications, AccountModel acc)
  63. {
  64. _notifications = notifications;
  65. _currentAcc = acc;
  66. JsRuntime.InvokeVoidAsync("OpenModal", elementid);
  67. }
  68. public void Close()
  69. {
  70. JsRuntime.InvokeVoidAsync("CloseModal", elementid);
  71. }
  72. async Task ReadOnClick(int id)
  73. {
  74. if (!_notifications[id].IsRead)
  75. {
  76. _notifications[id].IsRead = true;
  77. _notifications[id].DateRead = DateTime.Now;
  78. }
  79. else
  80. {
  81. _notifications[id].IsRead = false;
  82. _notifications[id].DateRead = null;
  83. }
  84. await _notifications[id].Update();
  85. }
  86. async Task ApproveOnClick(int id)
  87. {
  88. if (!_notifications[id].IsApproved)
  89. {
  90. _notifications[id].IsApproved = true;
  91. _notifications[id].DateApprove = DateTime.Now;
  92. }
  93. else
  94. {
  95. _notifications[id].IsApproved = false;
  96. _notifications[id].DateApprove = null;
  97. }
  98. await _notifications[id].Update();
  99. }
  100. async Task RejectOnClick(int id)
  101. {
  102. if (!_notifications[id].IsRejected)
  103. {
  104. _notifications[id].IsRejected = true;
  105. _notifications[id].DateReject = DateTime.Now;
  106. }
  107. else
  108. {
  109. _notifications[id].IsRejected = false;
  110. _notifications[id].DateReject = null;
  111. }
  112. await _notifications[id].Update();
  113. }
  114. async Task SendTestNotification()
  115. {
  116. Notification notification = new(NotificationType.System, "Test from button", "message", _currentAcc.UUID, _currentAcc.UUID);
  117. int newid = await notification.Send();
  118. /// adding only in local collection yet
  119. _notifications.Add(newid, notification);
  120. }
  121. }