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.

154 lines
4.7 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. <button class="button button--small m-bottom-0 m-right-3">
  36. <svg class="icon" aria-hidden="true">
  37. <use xlink:href="/symbol-defs.svg#icon-edit"></use>
  38. </svg>
  39. </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. handleClick() {
  93. },
  94. handleDelete(event, user) {
  95. event.preventDefault()
  96. const customEvent = new CustomEvent('open', {
  97. 'detail': {
  98. 'confirm': () => {
  99. axios.delete('/api/users/' + user._id)
  100. .then((response) => {
  101. // removing from buckets
  102. remove(this.state.users, function(u) {
  103. return u._id === user._id
  104. })
  105. this.update()
  106. })
  107. },
  108. // @TODO find a better solution to create body text
  109. 'body': 'Do you want delete ' + user.email + '?'
  110. }
  111. });
  112. this.$('#user-delete-confirm').dispatchEvent(customEvent);
  113. /**
  114. */
  115. },
  116. /**
  117. * getting all buckets
  118. *
  119. *
  120. */
  121. fetch() {
  122. axios.get('/api/users').then((response) => {
  123. this.state.users = response.data.data
  124. this.update()
  125. })
  126. }
  127. }
  128. </script>
  129. </app-users>