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.

170 lines
5.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.animated.fadeInUp(src='/_assets/svg/icon-people.svg', alt='Groups', style='width: 80px;')
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2.animated.fadeInLeft Groups
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s Manage groups and their permissions
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p3s(icon, outlined, color='grey', href='https://docs.requarks.io/groups', target='_blank')
  12. v-icon mdi-help-circle
  13. v-btn.animated.fadeInDown.wait-p2s.mx-3(color='grey', outlined, @click='refresh', icon)
  14. v-icon mdi-refresh
  15. v-dialog(v-model='newGroupDialog', max-width='500')
  16. template(v-slot:activator='{ on }')
  17. v-btn.animated.fadeInDown(color='primary', depressed, v-on='on', large)
  18. v-icon(left) mdi-plus
  19. span New Group
  20. v-card
  21. .dialog-header.is-short New Group
  22. v-card-text.pt-5
  23. v-text-field.md2(
  24. outlined
  25. prepend-icon='mdi-account-group'
  26. v-model='newGroupName'
  27. label='Group Name'
  28. counter='255'
  29. @keyup.enter='createGroup'
  30. @keyup.esc='newGroupDialog = false'
  31. ref='groupNameIpt'
  32. )
  33. v-card-chin
  34. v-spacer
  35. v-btn(text, @click='newGroupDialog = false') Cancel
  36. v-btn(color='primary', @click='createGroup') Create
  37. v-card.mt-3.animated.fadeInUp
  38. v-data-table(
  39. :items='groups'
  40. :headers='headers'
  41. :search='search'
  42. :page.sync='pagination'
  43. :items-per-page='15'
  44. :loading='loading'
  45. @page-count='pageCount = $event'
  46. must-sort,
  47. hide-default-footer
  48. )
  49. template(slot='item', slot-scope='props')
  50. tr.is-clickable(:active='props.selected', @click='$router.push("/groups/" + props.item.id)')
  51. td {{ props.item.id }}
  52. td: strong {{ props.item.name }}
  53. td {{ props.item.userCount }}
  54. td {{ props.item.createdAt | moment('calendar') }}
  55. td {{ props.item.updatedAt | moment('calendar') }}
  56. td
  57. v-tooltip(left, v-if='props.item.isSystem')
  58. template(v-slot:activator='{ on }')
  59. v-icon(v-on='on') mdi-lock-outline
  60. span System Group
  61. template(slot='no-data')
  62. v-alert.ma-3(icon='mdi-alert', :value='true', outline) No groups to display.
  63. .text-xs-center.py-2(v-if='pageCount > 1')
  64. v-pagination(v-model='pagination', :length='pageCount')
  65. </template>
  66. <script>
  67. import _ from 'lodash'
  68. import groupsQuery from 'gql/admin/groups/groups-query-list.gql'
  69. import createGroupMutation from 'gql/admin/groups/groups-mutation-create.gql'
  70. export default {
  71. data() {
  72. return {
  73. newGroupDialog: false,
  74. newGroupName: '',
  75. selectedGroup: {},
  76. pagination: 1,
  77. pageCount: 0,
  78. groups: [],
  79. headers: [
  80. { text: 'ID', value: 'id', width: 80, sortable: true },
  81. { text: 'Name', value: 'name' },
  82. { text: 'Users', value: 'userCount', width: 200 },
  83. { text: 'Created', value: 'createdAt', width: 250 },
  84. { text: 'Last Updated', value: 'updatedAt', width: 250 },
  85. { text: '', value: 'isSystem', width: 20, sortable: false }
  86. ],
  87. search: '',
  88. loading: false
  89. }
  90. },
  91. watch: {
  92. newGroupDialog(newValue, oldValue) {
  93. if (newValue) {
  94. this.$nextTick(() => {
  95. this.$refs.groupNameIpt.focus()
  96. })
  97. }
  98. }
  99. },
  100. methods: {
  101. async refresh() {
  102. await this.$apollo.queries.groups.refetch()
  103. this.$store.commit('showNotification', {
  104. message: 'Groups have been refreshed.',
  105. style: 'success',
  106. icon: 'cached'
  107. })
  108. },
  109. async createGroup() {
  110. if (_.trim(this.newGroupName).length < 1) {
  111. this.$store.commit('showNotification', {
  112. style: 'red',
  113. message: 'Enter a group name.',
  114. icon: 'warning'
  115. })
  116. return
  117. }
  118. this.newGroupDialog = false
  119. try {
  120. await this.$apollo.mutate({
  121. mutation: createGroupMutation,
  122. variables: {
  123. name: this.newGroupName
  124. },
  125. update (store, resp) {
  126. const data = _.get(resp, 'data.groups.create', { responseResult: {} })
  127. if (data.responseResult.succeeded === true) {
  128. const apolloData = store.readQuery({ query: groupsQuery })
  129. data.group.userCount = 0
  130. apolloData.groups.list.push(data.group)
  131. store.writeQuery({ query: groupsQuery, data: apolloData })
  132. } else {
  133. throw new Error(data.responseResult.message)
  134. }
  135. },
  136. watchLoading (isLoading) {
  137. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-create')
  138. }
  139. })
  140. this.newGroupName = ''
  141. this.$store.commit('showNotification', {
  142. style: 'success',
  143. message: `Group has been created successfully.`,
  144. icon: 'check'
  145. })
  146. } catch (err) {
  147. this.$store.commit('pushGraphError', err)
  148. }
  149. }
  150. },
  151. apollo: {
  152. groups: {
  153. query: groupsQuery,
  154. fetchPolicy: 'network-only',
  155. update: (data) => data.groups.list,
  156. watchLoading (isLoading) {
  157. this.loading = isLoading
  158. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang='scss'>
  165. </style>