admin-groups-edit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template lang='pug'>
  2. v-card
  3. v-card(flat, color='grey lighten-5').pa-3.pt-4
  4. .headline.blue--text.text--darken-2 Edit Group
  5. .subheading.grey--text {{group.name}}
  6. v-btn(color='primary', fab, absolute, bottom, right, small, to='/groups'): v-icon arrow_upward
  7. v-tabs(color='grey lighten-4', fixed-tabs, slider-color='primary', show-arrows)
  8. v-tab(key='properties') Properties
  9. v-tab(key='rights') Permissions
  10. v-tab(key='users') Users
  11. v-tab-item(key='properties', :transition='false', :reverse-transition='false')
  12. v-card
  13. v-card-text
  14. v-text-field(v-model='group.name', label='Group Name', counter='255', prepend-icon='people')
  15. v-card-actions.pa-3
  16. v-btn(color='primary', @click='')
  17. v-icon(left) check
  18. | Save Changes
  19. .caption.ml-4.grey--text ID: {{group.id}}
  20. v-spacer
  21. v-dialog(v-model='deleteGroupDialog', max-width='500')
  22. v-btn(color='red', flat, @click='', slot='activator')
  23. v-icon(left) delete
  24. | Delete Group
  25. v-card
  26. .dialog-header.is-red Delete Group?
  27. v-card-text Are you sure you want to delete group #[strong {{ group.name }}]? All users will be unassigned from this group.
  28. v-card-actions
  29. v-spacer
  30. v-btn(flat, @click='deleteGroupDialog = false') Cancel
  31. v-btn(color='red', dark, @click='deleteGroup') Delete
  32. v-tab-item(key='rights', :transition='false', :reverse-transition='false')
  33. v-card Test
  34. v-tab-item(key='users', :transition='false', :reverse-transition='false')
  35. v-card
  36. v-card-title.pb-0
  37. v-btn(color='primary')
  38. v-icon(left) assignment_ind
  39. | Assign User
  40. v-data-table(
  41. :items='users',
  42. :headers='headers',
  43. :search='search',
  44. :pagination.sync='pagination',
  45. :rows-per-page-items='[15]'
  46. hide-actions
  47. )
  48. template(slot='items', slot-scope='props')
  49. tr(:active='props.selected')
  50. td.text-xs-right {{ props.item.id }}
  51. td {{ props.item.name }}
  52. td {{ props.item.userCount }}
  53. td {{ props.item.createdAt | moment('calendar') }}
  54. td {{ props.item.updatedAt | moment('calendar') }}
  55. td
  56. v-menu(bottom, right, min-width='200')
  57. v-btn(icon, slot='activator'): v-icon.grey--text.text--darken-1 more_horiz
  58. v-list
  59. v-list-tile(@click='deleteGroupConfirm(props.item)')
  60. v-list-tile-action: v-icon(color='orange') highlight_off
  61. v-list-tile-content
  62. v-list-tile-title Unassign
  63. template(slot='no-data')
  64. v-alert.ma-3(icon='warning', :value='true', outline) No users to display.
  65. .text-xs-center.py-2(v-if='users.length > 15')
  66. v-pagination(v-model='pagination.page', :length='pages')
  67. </template>
  68. <script>
  69. import groupsQuery from 'gql/admin-groups-query-list.gql'
  70. import deleteGroupMutation from 'gql/admin-groups-mutation-delete.gql'
  71. export default {
  72. data() {
  73. return {
  74. group: {
  75. id: 7,
  76. name: 'Editors'
  77. },
  78. deleteGroupDialog: false,
  79. pagination: {},
  80. users: [],
  81. headers: [
  82. { text: 'ID', value: 'id', width: 50, align: 'right' },
  83. { text: 'Name', value: 'name' },
  84. { text: 'Email', value: 'email' },
  85. { text: 'Created', value: 'createdAt', width: 250 },
  86. { text: 'Last Updated', value: 'updatedAt', width: 250 },
  87. { text: '', value: 'actions', sortable: false, width: 50 }
  88. ],
  89. search: ''
  90. }
  91. },
  92. computed: {
  93. pages () {
  94. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  95. return 0
  96. }
  97. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  98. }
  99. },
  100. methods: {
  101. async deleteGroupConfirm(group) {
  102. this.deleteGroupDialog = true
  103. this.selectedGroup = group
  104. },
  105. async deleteGroup() {
  106. this.deleteGroupDialog = false
  107. try {
  108. await this.$apollo.mutate({
  109. mutation: deleteGroupMutation,
  110. variables: {
  111. id: this.group.id
  112. },
  113. watchLoading (isLoading) {
  114. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-delete')
  115. }
  116. })
  117. this.$store.commit('showNotification', {
  118. style: 'success',
  119. message: `Group ${this.group.name} has been deleted.`,
  120. icon: 'delete'
  121. })
  122. this.$router.replace('/groups')
  123. } catch (err) {
  124. this.$store.commit('showNotification', {
  125. style: 'red',
  126. message: err.message,
  127. icon: 'warning'
  128. })
  129. }
  130. }
  131. },
  132. apollo: {
  133. users: {
  134. query: groupsQuery,
  135. update: (data) => data.groups.list,
  136. watchLoading (isLoading) {
  137. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  138. }
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang='scss'>
  144. </style>