admin-groups-edit-users.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template lang="pug">
  2. v-card.wiki-form
  3. v-card-title(:class='$vuetify.dark ? `grey darken-3-d3` : `grey lighten-5`')
  4. v-text-field(
  5. outline
  6. flat
  7. prepend-inner-icon='search'
  8. v-model='search'
  9. label='Search Group Users...'
  10. hide-details
  11. )
  12. v-spacer
  13. v-btn(color='primary', depressed, @click='searchUserDialog = true', :disabled='group.id === 2')
  14. v-icon(left) assignment_ind
  15. | Assign User
  16. v-data-table(
  17. :items='group.users',
  18. :headers='headers',
  19. :search='search'
  20. :pagination.sync='pagination',
  21. :rows-per-page-items='[15]'
  22. hide-actions
  23. )
  24. template(slot='items', slot-scope='props')
  25. tr(:active='props.selected')
  26. td.text-xs-right {{ props.item.id }}
  27. td {{ props.item.name }}
  28. td {{ props.item.email }}
  29. td
  30. v-menu(bottom, right, min-width='200')
  31. v-btn(icon, slot='activator'): v-icon.grey--text.text--darken-1 more_horiz
  32. v-list
  33. v-list-item(:to='`/users/` + props.item.id')
  34. v-list-item-action: v-icon(color='primary') person
  35. v-list-item-content
  36. v-list-item-title View User Profile
  37. template(v-if='props.item.id !== 2')
  38. v-divider
  39. v-list-item(@click='unassignUser(props.item.id)')
  40. v-list-item-action: v-icon(color='orange') highlight_off
  41. v-list-item-content
  42. v-list-item-title Unassign
  43. template(slot='no-data')
  44. v-alert.ma-3(icon='warning', :value='true', outline) No users to display.
  45. .text-xs-center.py-2(v-if='group.users.length > 15')
  46. v-pagination(v-model='pagination.page', :length='pages')
  47. user-search(v-model='searchUserDialog', @select='assignUser')
  48. </template>
  49. <script>
  50. import UserSearch from '../common/user-search.vue'
  51. import assignUserMutation from 'gql/admin/groups/groups-mutation-assign.gql'
  52. import unassignUserMutation from 'gql/admin/groups/groups-mutation-unassign.gql'
  53. export default {
  54. props: {
  55. value: {
  56. type: Object,
  57. default: () => ({})
  58. }
  59. },
  60. components: {
  61. UserSearch
  62. },
  63. data() {
  64. return {
  65. headers: [
  66. { text: 'ID', value: 'id', width: 50, align: 'right' },
  67. { text: 'Name', value: 'name' },
  68. { text: 'Email', value: 'email' },
  69. { text: '', value: 'actions', sortable: false, width: 50 }
  70. ],
  71. searchUserDialog: false,
  72. pagination: {},
  73. search: ''
  74. }
  75. },
  76. computed: {
  77. group: {
  78. get() { return this.value },
  79. set(val) { this.$set('input', val) }
  80. },
  81. pages () {
  82. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  83. return 0
  84. }
  85. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  86. }
  87. },
  88. methods: {
  89. async assignUser(id) {
  90. try {
  91. await this.$apollo.mutate({
  92. mutation: assignUserMutation,
  93. variables: {
  94. groupId: this.group.id,
  95. userId: id
  96. },
  97. watchLoading (isLoading) {
  98. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-assign')
  99. }
  100. })
  101. this.$store.commit('showNotification', {
  102. style: 'success',
  103. message: `User has been assigned to ${this.group.name}.`,
  104. icon: 'assignment_ind'
  105. })
  106. this.$emit('refresh')
  107. } catch (err) {
  108. this.$store.commit('showNotification', {
  109. style: 'red',
  110. message: err.message,
  111. icon: 'warning'
  112. })
  113. }
  114. },
  115. async unassignUser(id) {
  116. try {
  117. await this.$apollo.mutate({
  118. mutation: unassignUserMutation,
  119. variables: {
  120. groupId: this.group.id,
  121. userId: id
  122. },
  123. watchLoading (isLoading) {
  124. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-unassign')
  125. }
  126. })
  127. this.$store.commit('showNotification', {
  128. style: 'success',
  129. message: `User has been unassigned from ${this.group.name}.`,
  130. icon: 'assignment_ind'
  131. })
  132. this.$emit('refresh')
  133. } catch (err) {
  134. this.$store.commit('showNotification', {
  135. style: 'red',
  136. message: err.message,
  137. icon: 'warning'
  138. })
  139. }
  140. }
  141. }
  142. }
  143. </script>