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.

171 lines
5.4 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. <app-loading loading={ state.loading }></app-loading>
  70. </div>
  71. <script>
  72. import axios from 'axios'
  73. import remove from 'lodash.remove'
  74. import * as riot from 'riot'
  75. import AppModal from './modal.riot'
  76. riot.register('app-modal', AppModal)
  77. riot.mount('app-modal')
  78. /**
  79. *
  80. *
  81. *
  82. * @author Björn Hase
  83. *
  84. */
  85. export default {
  86. state: {
  87. users: [],
  88. maxLength: 0
  89. },
  90. onBeforeMount() {
  91. this.fetch()
  92. },
  93. /**
  94. *
  95. * @param {[type]} event
  96. * @param {[type]} user
  97. * @return {[type]}
  98. *
  99. */
  100. handleUpdate(event, user) {
  101. const customEvent = new CustomEvent('app-users-form-open', {
  102. 'detail': user
  103. })
  104. document.querySelector('app-users-form').dispatchEvent(customEvent);
  105. },
  106. handleDelete(event, user) {
  107. event.preventDefault()
  108. const customEvent = new CustomEvent('open', {
  109. 'detail': {
  110. 'confirm': () => {
  111. this.state.loading = true
  112. axios.delete('/api/users/v1/' + user._id)
  113. .then((response) => {
  114. // removing from buckets
  115. remove(this.state.users, function(u) {
  116. return u._id === user._id
  117. })
  118. }).catch((error) => {
  119. }).then(() => {
  120. this.state.loading = false
  121. this.update()
  122. })
  123. },
  124. // @TODO find a better solution to create body text
  125. 'body': 'Do you want delete ' + user.email + '?'
  126. }
  127. })
  128. this.$('#user-delete-confirm').dispatchEvent(customEvent);
  129. },
  130. /**
  131. * getting all buckets
  132. *
  133. *
  134. */
  135. fetch() {
  136. axios.get('/api/users/v1').then((response) => {
  137. this.state.users = response.data.data
  138. this.update()
  139. })
  140. }
  141. }
  142. </script>
  143. </app-users>