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.

155 lines
5.0 KiB

  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. handleUpdate(event, user) {
  93. const customEvent = new CustomEvent('app-users-form-open', {
  94. 'detail': user
  95. })
  96. document.querySelector('app-users-form').dispatchEvent(customEvent);
  97. },
  98. handleDelete(event, user) {
  99. event.preventDefault()
  100. const customEvent = new CustomEvent('open', {
  101. 'detail': {
  102. 'confirm': () => {
  103. axios.delete('/api/users/' + user._id)
  104. .then((response) => {
  105. // removing from buckets
  106. remove(this.state.users, function(u) {
  107. return u._id === user._id
  108. })
  109. this.update()
  110. })
  111. },
  112. // @TODO find a better solution to create body text
  113. 'body': 'Do you want delete ' + user.email + '?'
  114. }
  115. })
  116. this.$('#user-delete-confirm').dispatchEvent(customEvent);
  117. },
  118. /**
  119. * getting all buckets
  120. *
  121. *
  122. */
  123. fetch() {
  124. axios.get('/api/users').then((response) => {
  125. this.state.users = response.data.data
  126. this.update()
  127. })
  128. }
  129. }
  130. </script>
  131. </app-users>