You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
8.2 KiB

Use AJAX for notifications table (#10961) * Use AJAX for notifications table Signed-off-by: Andrew Thornton <art27@cantab.net> * move to separate js Signed-off-by: Andrew Thornton <art27@cantab.net> * placate golangci-lint Signed-off-by: Andrew Thornton <art27@cantab.net> * Add autoupdating notification count Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix wipeall Signed-off-by: Andrew Thornton <art27@cantab.net> * placate tests Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hide and hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * More auto-update improvements Only run checker on pages that have a count Change starting checker to 10s with a back-off to 60s if there is no change Signed-off-by: Andrew Thornton <art27@cantab.net> * string comparison! Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * add configurability as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add documentation as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Use CSRF header not query Signed-off-by: Andrew Thornton <art27@cantab.net> * Further JS improvements Fix @etzelia update notification table request Fix @silverwind comments Co-Authored-By: silverwind <me@silverwind.io> Signed-off-by: Andrew Thornton <art27@cantab.net> * Simplify the notification count fns Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io>
4 years ago
  1. <div class="user notification" id="notification_div" data-params="{{.Page.GetParams}}">
  2. <div class="ui container">
  3. <h1 class="ui dividing header">{{.i18n.Tr "notification.notifications"}}</h1>
  4. <div class="ui top attached tabular menu">
  5. {{ $notificationUnreadCount := call .NotificationUnreadCount}}
  6. <a href="{{AppSubUrl}}/notifications?q=unread" class="{{if eq .Status 1}}active{{end}} item">
  7. {{.i18n.Tr "notification.unread"}}
  8. <div class="ui label {{if not $notificationUnreadCount}}hidden{{end}}">{{$notificationUnreadCount}}</div>
  9. </a>
  10. <a href="{{AppSubUrl}}/notifications?q=read" class="{{if eq .Status 2}}active{{end}} item">
  11. {{.i18n.Tr "notification.read"}}
  12. </a>
  13. {{if and (eq .Status 1)}}
  14. <form action="{{AppSubUrl}}/notifications/purge" method="POST" style="margin-left: auto;">
  15. {{$.CsrfTokenHtml}}
  16. <div class="{{if not $notificationUnreadCount}}hide{{end}}">
  17. <button class="ui mini button primary" title='{{$.i18n.Tr "notification.mark_all_as_read"}}'>
  18. {{svg "octicon-checklist" 16}}
  19. </button>
  20. </div>
  21. </form>
  22. {{end}}
  23. </div>
  24. <div class="ui bottom attached active tab segment">
  25. {{if eq (len .Notifications) 0}}
  26. {{if eq .Status 1}}
  27. {{.i18n.Tr "notification.no_unread"}}
  28. {{else}}
  29. {{.i18n.Tr "notification.no_read"}}
  30. {{end}}
  31. {{else}}
  32. <table class="ui unstackable striped very compact small selectable table" id="notification_table">
  33. <tbody>
  34. {{range $notification := .Notifications}}
  35. {{$issue := .Issue}}
  36. {{$repo := .Repository}}
  37. {{$repoOwner := $repo.MustOwner}}
  38. <tr id="notification_{{.ID}}">
  39. <td class="collapsing" data-href="{{.HTMLURL}}">
  40. {{if eq .Status 3}}
  41. <span class="blue">{{svg "octicon-pin" 16}}</span>
  42. {{else if $issue.IsPull}}
  43. {{if $issue.IsClosed}}
  44. {{if $issue.GetPullRequest.HasMerged}}
  45. <span class="purple">{{svg "octicon-git-merge" 16}}</span>
  46. {{else}}
  47. <span class="red">{{svg "octicon-git-pull-request" 16}}</span>
  48. {{end}}
  49. {{else}}
  50. <span class="green">{{svg "octicon-git-pull-request" 16}}</span>
  51. {{end}}
  52. {{else}}
  53. {{if $issue.IsClosed}}
  54. <span class="red">{{svg "octicon-issue-closed" 16}}</span>
  55. {{else}}
  56. <span class="green">{{svg "octicon-issue-opened" 16}}</span>
  57. {{end}}
  58. {{end}}
  59. </td>
  60. <td class="eleven wide" data-href="{{.HTMLURL}}">
  61. <a class="item" href="{{.HTMLURL}}">
  62. #{{$issue.Index}} - {{$issue.Title}}
  63. </a>
  64. </td>
  65. <td data-href="{{AppSubUrl}}/{{$repoOwner.Name}}/{{$repo.Name}}">
  66. <a class="item" href="{{AppSubUrl}}/{{$repoOwner.Name}}/{{$repo.Name}}">
  67. {{$repoOwner.Name}}/{{$repo.Name}}
  68. </a>
  69. </td>
  70. <td class="collapsing">
  71. {{if ne .Status 3}}
  72. <form action="{{AppSubUrl}}/notifications/status" method="POST">
  73. {{$.CsrfTokenHtml}}
  74. <input type="hidden" name="notification_id" value="{{.ID}}" />
  75. <input type="hidden" name="status" value="pinned" />
  76. <button class="ui mini button" title='{{$.i18n.Tr "notification.pin"}}'
  77. data-url="{{AppSubUrl}}/notifications/status"
  78. data-status="pinned"
  79. data-page="{{$.Page.Paginater.Current}}"
  80. data-notification-id="{{.ID}}"
  81. data-q="{{$.Keyword}}">
  82. {{svg "octicon-pin" 16}}
  83. </button>
  84. </form>
  85. {{end}}
  86. </td>
  87. <td class="collapsing">
  88. {{if or (eq .Status 1) (eq .Status 3)}}
  89. <form action="{{AppSubUrl}}/notifications/status" method="POST">
  90. {{$.CsrfTokenHtml}}
  91. <input type="hidden" name="notification_id" value="{{.ID}}" />
  92. <input type="hidden" name="status" value="read" />
  93. <input type="hidden" name="page" value="{{$.Page.Paginater.Current}}" />
  94. <button class="ui mini button" title='{{$.i18n.Tr "notification.mark_as_read"}}'
  95. data-url="{{AppSubUrl}}/notifications/status"
  96. data-status="read"
  97. data-page="{{$.Page.Paginater.Current}}"
  98. data-notification-id="{{.ID}}"
  99. data-q="{{$.Keyword}}">
  100. {{svg "octicon-check" 16}}
  101. </button>
  102. </form>
  103. {{else if eq .Status 2}}
  104. <form action="{{AppSubUrl}}/notifications/status" method="POST">
  105. {{$.CsrfTokenHtml}}
  106. <input type="hidden" name="notification_id" value="{{.ID}}" />
  107. <input type="hidden" name="status" value="unread" />
  108. <input type="hidden" name="page" value="{{$.Page.Paginater.Current}}" />
  109. <button class="ui mini button" title='{{$.i18n.Tr "notification.mark_as_unread"}}'
  110. data-url="{{AppSubUrl}}/notifications/status"
  111. data-status="unread"
  112. data-page="{{$.Page.Paginater.Current}}"
  113. data-notification-id="{{.ID}}"
  114. data-q="{{$.Keyword}}">
  115. {{svg "octicon-bell" 16}}
  116. </button>
  117. </form>
  118. {{end}}
  119. </td>
  120. </tr>
  121. {{end}}
  122. </tbody>
  123. </table>
  124. {{end}}
  125. </div>
  126. {{template "base/paginate" .}}
  127. </div>
  128. </div>