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.4 KiB

  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-tile(:to='`/users/` + props.item.id')
  34. v-list-tile-action: v-icon(color='primary') person
  35. v-list-tile-content
  36. v-list-tile-title View User Profile
  37. template(v-if='props.item.id !== 2')
  38. v-divider
  39. v-list-tile(@click='unassignUser(props.item.id)')
  40. v-list-tile-action: v-icon(color='orange') highlight_off
  41. v-list-tile-content
  42. v-list-tile-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. }
  58. },
  59. components: {
  60. UserSearch
  61. },
  62. data() {
  63. return {
  64. headers: [
  65. { text: 'ID', value: 'id', width: 50, align: 'right' },
  66. { text: 'Name', value: 'name' },
  67. { text: 'Email', value: 'email' },
  68. { text: '', value: 'actions', sortable: false, width: 50 }
  69. ],
  70. searchUserDialog: false,
  71. pagination: {},
  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>