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.

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