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.

153 lines
4.8 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('showNotification', {
  90. style: 'red',
  91. message: err.message,
  92. icon: 'warning'
  93. })
  94. }
  95. },
  96. async deleteGroup() {
  97. this.deleteGroupDialog = false
  98. try {
  99. await this.$apollo.mutate({
  100. mutation: deleteGroupMutation,
  101. variables: {
  102. id: this.group.id
  103. },
  104. watchLoading (isLoading) {
  105. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-delete')
  106. }
  107. })
  108. this.$store.commit('showNotification', {
  109. style: 'success',
  110. message: `Group ${this.group.name} has been deleted.`,
  111. icon: 'delete'
  112. })
  113. this.$router.replace('/groups')
  114. } catch (err) {
  115. this.$store.commit('showNotification', {
  116. style: 'red',
  117. message: err.message,
  118. icon: 'warning'
  119. })
  120. }
  121. },
  122. async refresh() {
  123. return this.$apollo.queries.group.refetch()
  124. }
  125. },
  126. apollo: {
  127. group: {
  128. query: groupQuery,
  129. variables() {
  130. return {
  131. id: _.toSafeInteger(this.$route.params.id)
  132. }
  133. },
  134. fetchPolicy: 'network-only',
  135. update: (data) => _.cloneDeep(data.groups.single),
  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>