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.

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