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.

152 lines
4.9 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.pa-4 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(text, @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.grad-tabs(v-model='tab', :color='$vuetify.theme.dark ? `blue` : `primary`', fixed-tabs, show-arrows, icons-and-text)
  31. v-tab(key='permissions')
  32. span Permissions
  33. v-icon mdi-lock-pattern
  34. v-tab(key='rules')
  35. span Page Rules
  36. v-icon mdi-file-lock
  37. v-tab(key='users')
  38. span Users
  39. v-icon mdi-account-group
  40. v-tab-item(key='permissions', :transition='false', :reverse-transition='false')
  41. group-permissions(v-model='group', @refresh='refresh')
  42. v-tab-item(key='rules', :transition='false', :reverse-transition='false')
  43. group-rules(v-model='group', @refresh='refresh')
  44. v-tab-item(key='users', :transition='false', :reverse-transition='false')
  45. group-users(v-model='group', @refresh='refresh')
  46. </template>
  47. <script>
  48. import _ from 'lodash'
  49. import GroupPermissions from './admin-groups-edit-permissions.vue'
  50. import GroupRules from './admin-groups-edit-rules.vue'
  51. import GroupUsers from './admin-groups-edit-users.vue'
  52. import groupQuery from 'gql/admin/groups/groups-query-single.gql'
  53. import deleteGroupMutation from 'gql/admin/groups/groups-mutation-delete.gql'
  54. import updateGroupMutation from 'gql/admin/groups/groups-mutation-update.gql'
  55. export default {
  56. components: {
  57. GroupPermissions,
  58. GroupRules,
  59. GroupUsers
  60. },
  61. data() {
  62. return {
  63. group: {
  64. id: 0,
  65. name: '',
  66. isSystem: false,
  67. permissions: [],
  68. pageRules: [],
  69. users: []
  70. },
  71. deleteGroupDialog: false,
  72. tab: null
  73. }
  74. },
  75. methods: {
  76. async updateGroup() {
  77. try {
  78. await this.$apollo.mutate({
  79. mutation: updateGroupMutation,
  80. variables: {
  81. id: this.group.id,
  82. name: this.group.name,
  83. permissions: this.group.permissions,
  84. pageRules: this.group.pageRules
  85. },
  86. watchLoading (isLoading) {
  87. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-update')
  88. }
  89. })
  90. this.$store.commit('showNotification', {
  91. style: 'success',
  92. message: `Group changes have been saved.`,
  93. icon: 'check'
  94. })
  95. } catch (err) {
  96. this.$store.commit('pushGraphError', err)
  97. }
  98. },
  99. async deleteGroup() {
  100. this.deleteGroupDialog = false
  101. try {
  102. await this.$apollo.mutate({
  103. mutation: deleteGroupMutation,
  104. variables: {
  105. id: this.group.id
  106. },
  107. watchLoading (isLoading) {
  108. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-delete')
  109. }
  110. })
  111. this.$store.commit('showNotification', {
  112. style: 'success',
  113. message: `Group ${this.group.name} has been deleted.`,
  114. icon: 'delete'
  115. })
  116. this.$router.replace('/groups')
  117. } catch (err) {
  118. this.$store.commit('pushGraphError', err)
  119. }
  120. },
  121. async refresh() {
  122. return this.$apollo.queries.group.refetch()
  123. }
  124. },
  125. apollo: {
  126. group: {
  127. query: groupQuery,
  128. variables() {
  129. return {
  130. id: _.toSafeInteger(this.$route.params.id)
  131. }
  132. },
  133. fetchPolicy: 'network-only',
  134. update: (data) => _.cloneDeep(data.groups.single),
  135. watchLoading (isLoading) {
  136. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  137. }
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang='scss'>
  143. </style>