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.

146 lines
4.7 KiB

  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img(src='/svg/icon-social-group.svg', alt='Edit Group', style='width: 80px;')
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2 Edit Group
  9. .subtitle-1.grey--text {{group.name}}
  10. v-spacer
  11. .caption.grey--text ID #[strong {{group.id}}]
  12. v-divider.mx-3(vertical)
  13. v-btn(color='grey', large, outlined, to='/groups')
  14. v-icon mdi-arrow-left
  15. v-dialog(v-model='deleteGroupDialog', max-width='500', v-if='!group.isSystem')
  16. template(v-slot:activator='{ on }')
  17. v-btn.ml-2(color='red', large, outlined, v-on='{ on }')
  18. v-icon(color='red') mdi-trash-can-outline
  19. v-card
  20. .dialog-header.is-red Delete Group?
  21. v-card-text Are you sure you want to delete group #[strong {{ group.name }}]? All users will be unassigned from this group.
  22. v-card-actions
  23. v-spacer
  24. v-btn(flat, @click='deleteGroupDialog = false') Cancel
  25. v-btn(color='red', dark, @click='deleteGroup') Delete
  26. v-btn.ml-2(color='success', large, depressed, @click='updateGroup')
  27. v-icon(left) mdi-check
  28. span Update Group
  29. v-card.mt-3
  30. v-tabs(v-model='tab', :background-color='$vuetify.theme.dark ? "primary" : "grey darken-2"', fixed-tabs, slider-color='white', show-arrows, dark)
  31. v-tab(key='permissions') Permissions
  32. v-tab(key='rules') Page Rules
  33. v-tab(key='users') Users
  34. v-tab-item(key='permissions', :transition='false', :reverse-transition='false')
  35. group-permissions(v-model='group', @refresh='refresh')
  36. v-tab-item(key='rules', :transition='false', :reverse-transition='false')
  37. group-rules(v-model='group', @refresh='refresh')
  38. v-tab-item(key='users', :transition='false', :reverse-transition='false')
  39. group-users(v-model='group', @refresh='refresh')
  40. </template>
  41. <script>
  42. import _ from 'lodash'
  43. import GroupPermissions from './admin-groups-edit-permissions.vue'
  44. import GroupRules from './admin-groups-edit-rules.vue'
  45. import GroupUsers from './admin-groups-edit-users.vue'
  46. import groupQuery from 'gql/admin/groups/groups-query-single.gql'
  47. import deleteGroupMutation from 'gql/admin/groups/groups-mutation-delete.gql'
  48. import updateGroupMutation from 'gql/admin/groups/groups-mutation-update.gql'
  49. export default {
  50. components: {
  51. GroupPermissions,
  52. GroupRules,
  53. GroupUsers
  54. },
  55. data() {
  56. return {
  57. group: {
  58. id: 0,
  59. name: '',
  60. isSystem: false,
  61. permissions: [],
  62. pageRules: [],
  63. users: []
  64. },
  65. deleteGroupDialog: false,
  66. tab: null
  67. }
  68. },
  69. methods: {
  70. async updateGroup() {
  71. try {
  72. await this.$apollo.mutate({
  73. mutation: updateGroupMutation,
  74. variables: {
  75. id: this.group.id,
  76. name: this.group.name,
  77. permissions: this.group.permissions,
  78. pageRules: this.group.pageRules
  79. },
  80. watchLoading (isLoading) {
  81. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-update')
  82. }
  83. })
  84. this.$store.commit('showNotification', {
  85. style: 'success',
  86. message: `Group changes have been saved.`,
  87. icon: 'check'
  88. })
  89. } catch (err) {
  90. this.$store.commit('pushGraphError', err)
  91. }
  92. },
  93. async deleteGroup() {
  94. this.deleteGroupDialog = false
  95. try {
  96. await this.$apollo.mutate({
  97. mutation: deleteGroupMutation,
  98. variables: {
  99. id: this.group.id
  100. },
  101. watchLoading (isLoading) {
  102. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-delete')
  103. }
  104. })
  105. this.$store.commit('showNotification', {
  106. style: 'success',
  107. message: `Group ${this.group.name} has been deleted.`,
  108. icon: 'delete'
  109. })
  110. this.$router.replace('/groups')
  111. } catch (err) {
  112. this.$store.commit('pushGraphError', err)
  113. }
  114. },
  115. async refresh() {
  116. return this.$apollo.queries.group.refetch()
  117. }
  118. },
  119. apollo: {
  120. group: {
  121. query: groupQuery,
  122. variables() {
  123. return {
  124. id: _.toSafeInteger(this.$route.params.id)
  125. }
  126. },
  127. fetchPolicy: 'network-only',
  128. update: (data) => _.cloneDeep(data.groups.single),
  129. watchLoading (isLoading) {
  130. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  131. }
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang='scss'>
  137. </style>