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.

140 lines
4.5 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-customer.svg', alt='Users', style='width: 80px;')
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2 Users
  9. .subheading.grey--text Manage users
  10. v-spacer
  11. v-btn(outline, color='grey', large, @click='refresh')
  12. v-icon refresh
  13. v-btn(color='primary', large, depressed, @click='createUser')
  14. v-icon(left) add
  15. span New User
  16. v-card.mt-3
  17. v-data-table(
  18. v-model='selected'
  19. :items='users',
  20. :headers='headers',
  21. :search='search',
  22. :pagination.sync='pagination',
  23. :rows-per-page-items='[15]'
  24. hide-actions,
  25. disable-initial-sort
  26. )
  27. template(slot='headers', slot-scope='props')
  28. tr
  29. th.text-xs-left(
  30. v-for='header in props.headers'
  31. :key='header.text'
  32. :width='header.width'
  33. :class='[`column`, header.sortable ? `sortable` : ``, pagination.descending ? `desc` : `asc`, header.value === pagination.sortBy ? `active` : ``]'
  34. @click='changeSort(header.value)'
  35. )
  36. | {{ header.text }}
  37. v-icon(small, v-if='header.sortable') arrow_upward
  38. template(slot='items', slot-scope='props')
  39. tr.is-clickable(:active='props.selected', @click='$router.push("/users/" + props.item.id)')
  40. //- td
  41. v-checkbox(hide-details, :input-value='props.selected', color='blue darken-2', @click='props.selected = !props.selected')
  42. td.text-xs-right {{ props.item.id }}
  43. td: strong {{ props.item.name }}
  44. td {{ props.item.email }}
  45. td {{ props.item.providerKey }}
  46. td {{ props.item.createdAt | moment('from') }}
  47. td
  48. v-tooltip(left, v-if='props.item.isSystem')
  49. v-icon(slot='activator') lock_outline
  50. span System User
  51. template(slot='no-data')
  52. .pa-3
  53. v-alert(icon='warning', :value='true', outline) No users to display!
  54. v-card-chin(v-if='this.pages > 0')
  55. v-spacer
  56. v-pagination(v-model='pagination.page', :length='pages')
  57. v-spacer
  58. user-create(v-model='isCreateDialogShown')
  59. </template>
  60. <script>
  61. import usersQuery from 'gql/admin/users/users-query-list.gql'
  62. import UserCreate from './admin-users-create.vue'
  63. export default {
  64. components: {
  65. UserCreate
  66. },
  67. data() {
  68. return {
  69. selected: [],
  70. pagination: {},
  71. users: [],
  72. headers: [
  73. { text: 'ID', value: 'id', width: 80, sortable: true },
  74. { text: 'Name', value: 'name', sortable: true },
  75. { text: 'Email', value: 'email', sortable: true },
  76. { text: 'Provider', value: 'provider', sortable: true },
  77. { text: 'Created', value: 'createdAt', sortable: true },
  78. { text: '', value: 'actions', sortable: false, width: 50 }
  79. ],
  80. search: '',
  81. isCreateDialogShown: false
  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. methods: {
  93. createUser() {
  94. this.isCreateDialogShown = true
  95. },
  96. async refresh() {
  97. await this.$apollo.queries.users.refetch()
  98. this.$store.commit('showNotification', {
  99. message: 'Users list has been refreshed.',
  100. style: 'success',
  101. icon: 'cached'
  102. })
  103. },
  104. changeSort (column) {
  105. if (this.pagination.sortBy === column) {
  106. this.pagination.descending = !this.pagination.descending
  107. } else {
  108. this.pagination.sortBy = column
  109. this.pagination.descending = false
  110. }
  111. },
  112. toggleAll () {
  113. if (this.selected.length) {
  114. this.selected = []
  115. } else {
  116. this.selected = this.items.slice()
  117. }
  118. }
  119. },
  120. apollo: {
  121. users: {
  122. query: usersQuery,
  123. fetchPolicy: 'network-only',
  124. update: (data) => data.users.list,
  125. watchLoading (isLoading) {
  126. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-refresh')
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang='scss'>
  133. </style>