admin-groups-edit-users.vue 4.5 KB

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