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.

162 lines
5.2 KiB

3 years ago
3 years ago
  1. <app-users>
  2. <div class="buckets">
  3. <table class="table">
  4. <thead>
  5. <tr class="table__tr">
  6. <th class="table__th">
  7. Email
  8. </th>
  9. <th class="table__th">
  10. Display Name
  11. </th>
  12. <th class="table__th" colspan="2">
  13. Roles
  14. </th>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <tr class="table__tr" each={ user in state.users }>
  19. <td class="table__td">
  20. { user.email }
  21. </td>
  22. <td class="table__td">
  23. { user.display_name }
  24. </td>
  25. <td class="table__td">
  26. <div if={ user.roles && user.roles.indexOf('admin') >= 0 }>
  27. Admin
  28. <svg class="icon" aria-hidden="true">
  29. <use xlink:href="/symbol-defs.svg#icon-check"></use>
  30. </svg>
  31. </div>
  32. </td>
  33. <!-- actions -->
  34. <td class="table__td right">
  35. <app-sidebar-button class="m-bottom-0 m-right-3" event="app-users-form-open" selector="app-users-form" data={ user }>
  36. <svg class="icon" aria-hidden="true">
  37. <use xlink:href="/symbol-defs.svg#icon-edit"></use>
  38. </svg>
  39. </app-sidebar-button>
  40. <button class="button button--small m-bottom-0" type="button" onclick={ (event) => { handleDelete(event, user) } }>
  41. <svg class="icon" aria-hidden="true">
  42. <use xlink:href="/symbol-defs.svg#icon-delete"></use>
  43. </svg>
  44. </button>
  45. </td>
  46. </tr>
  47. </tbody>
  48. </table>
  49. <app-modal id="user-delete-confirm">
  50. <span slot="title">
  51. <svg class="icon fill-text-contrast" aria-hidden="true">
  52. <use xlink:href="/symbol-defs.svg#icon-close"></use>
  53. </svg>
  54. Delete
  55. </span>
  56. </app-modal>
  57. <div class="grid" if={ state.maxLength > state.users.length }>
  58. <div class="col-12">
  59. <div class="buckets__more">
  60. <button type="button" class="button" onclick={ handleClick }>
  61. More
  62. <svg class="icon" aria-hidden="true">
  63. <use xlink:href="/symbol-defs.svg#icon-arrow-down"></use>
  64. </svg>
  65. </button>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <script>
  71. import axios from 'axios'
  72. import remove from 'lodash.remove'
  73. import * as riot from 'riot'
  74. import AppModal from './modal.riot'
  75. riot.register('app-modal', AppModal)
  76. riot.mount('app-modal')
  77. /**
  78. *
  79. *
  80. *
  81. * @author Björn Hase
  82. *
  83. */
  84. export default {
  85. state: {
  86. users: [],
  87. maxLength: 0
  88. },
  89. onBeforeMount() {
  90. this.fetch()
  91. },
  92. /**
  93. *
  94. * @param {[type]} event
  95. * @param {[type]} user
  96. * @return {[type]}
  97. *
  98. */
  99. handleUpdate(event, user) {
  100. const customEvent = new CustomEvent('app-users-form-open', {
  101. 'detail': user
  102. })
  103. document.querySelector('app-users-form').dispatchEvent(customEvent);
  104. },
  105. handleDelete(event, user) {
  106. event.preventDefault()
  107. const customEvent = new CustomEvent('open', {
  108. 'detail': {
  109. 'confirm': () => {
  110. axios.delete('/api/users/v1/' + user._id)
  111. .then((response) => {
  112. // removing from buckets
  113. remove(this.state.users, function(u) {
  114. return u._id === user._id
  115. })
  116. this.update()
  117. })
  118. },
  119. // @TODO find a better solution to create body text
  120. 'body': 'Do you want delete ' + user.email + '?'
  121. }
  122. })
  123. this.$('#user-delete-confirm').dispatchEvent(customEvent);
  124. },
  125. /**
  126. * getting all buckets
  127. *
  128. *
  129. */
  130. fetch() {
  131. axios.get('/api/users/v1').then((response) => {
  132. this.state.users = response.data.data
  133. this.update()
  134. })
  135. }
  136. }
  137. </script>
  138. </app-users>