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.

149 lines
4.4 KiB

  1. <template lang="pug">
  2. v-card(flat)
  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. dense
  12. style='max-width: 450px;'
  13. )
  14. v-spacer
  15. v-btn(color='primary', depressed, @click='searchUserDialog = true', :disabled='group.id === 2')
  16. v-icon(left) mdi-clipboard-account
  17. | Assign User
  18. v-data-table(
  19. :items='group.users',
  20. :headers='headers',
  21. :search='search'
  22. :page.sync='pagination'
  23. :items-per-page='15'
  24. @page-count='pageCount = $event'
  25. must-sort,
  26. hide-default-footer
  27. )
  28. template(v-slot:item.actions='{ item }')
  29. v-menu(bottom, right, min-width='200')
  30. template(v-slot:activator='{ on }')
  31. v-btn(icon, v-on='on', small)
  32. v-icon.grey--text.text--darken-1 mdi-dots-horizontal
  33. v-list(dense, nav)
  34. v-list-item(:to='`/users/` + item.id')
  35. v-list-item-action: v-icon(color='primary') mdi-account-outline
  36. v-list-item-content
  37. v-list-item-title View User Profile
  38. template(v-if='item.id !== 2')
  39. v-list-item(@click='unassignUser(item.id)')
  40. v-list-item-action: v-icon(color='orange') mdi-account-remove-outline
  41. v-list-item-content
  42. v-list-item-title Unassign
  43. template(slot='no-data')
  44. v-alert.ma-3(icon='mdi-alert', outlined) No users to display.
  45. .text-center.py-2(v-if='group.users.length > 15')
  46. v-pagination(v-model='pagination', :length='pageCount')
  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: 70 },
  67. { text: 'Name', value: 'name' },
  68. { text: 'Email', value: 'email' },
  69. { text: 'Actions', value: 'actions', sortable: false, width: 50 }
  70. ],
  71. searchUserDialog: false,
  72. pagination: 1,
  73. pageCount: 0,
  74. search: ''
  75. }
  76. },
  77. computed: {
  78. group: {
  79. get() { return this.value },
  80. set(val) { this.$set('input', val) }
  81. },
  82. pages () {
  83. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  84. return 0
  85. }
  86. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  87. }
  88. },
  89. methods: {
  90. async assignUser({ id, email, name }) {
  91. try {
  92. await this.$apollo.mutate({
  93. mutation: assignUserMutation,
  94. variables: {
  95. groupId: this.group.id,
  96. userId: id
  97. },
  98. watchLoading (isLoading) {
  99. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-assign')
  100. }
  101. })
  102. this.$store.commit('showNotification', {
  103. style: 'success',
  104. message: `User has been assigned to ${this.group.name}.`,
  105. icon: 'assignment_ind'
  106. })
  107. this.$emit('refresh')
  108. } catch (err) {
  109. this.$store.commit('showNotification', {
  110. style: 'red',
  111. message: err.message,
  112. icon: 'warning'
  113. })
  114. }
  115. },
  116. async unassignUser(id) {
  117. try {
  118. await this.$apollo.mutate({
  119. mutation: unassignUserMutation,
  120. variables: {
  121. groupId: this.group.id,
  122. userId: id
  123. },
  124. watchLoading (isLoading) {
  125. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-unassign')
  126. }
  127. })
  128. this.$store.commit('showNotification', {
  129. style: 'success',
  130. message: `User has been unassigned from ${this.group.name}.`,
  131. icon: 'assignment_ind'
  132. })
  133. this.$emit('refresh')
  134. } catch (err) {
  135. this.$store.commit('showNotification', {
  136. style: 'red',
  137. message: err.message,
  138. icon: 'warning'
  139. })
  140. }
  141. }
  142. }
  143. }
  144. </script>