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.

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