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.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. .subheading.grey--text.animated.fadeInLeft.wait-p4s Manage groups and their permissions
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s(color='grey', outline, @click='refresh', large)
  12. v-icon refresh
  13. v-dialog(v-model='newGroupDialog', max-width='500')
  14. v-btn.animated.fadeInDown(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.animated.fadeInUp
  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. export default {
  65. data() {
  66. return {
  67. newGroupDialog: false,
  68. newGroupName: '',
  69. selectedGroup: {},
  70. pagination: {},
  71. groups: [],
  72. headers: [
  73. { text: 'ID', value: 'id', width: 50, align: 'right' },
  74. { text: 'Name', value: 'name' },
  75. { text: 'Users', value: 'userCount', width: 200 },
  76. { text: 'Created', value: 'createdAt', width: 250 },
  77. { text: 'Last Updated', value: 'updatedAt', width: 250 },
  78. { text: '', value: 'isSystem', width: 20, sortable: false }
  79. ],
  80. search: ''
  81. }
  82. },
  83. computed: {
  84. pages () {
  85. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  86. return 0
  87. }
  88. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  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.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  158. }
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang='scss'>
  164. </style>