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.

147 lines
4.3 KiB

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