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.

157 lines
5.1 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-customer.svg', alt='Users', style='width: 80px;')
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2.animated.fadeInLeft Users
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p2s Manage users
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s.mr-3(outlined, color='grey', large, @click='refresh')
  12. v-icon mdi-refresh
  13. v-btn.animated.fadeInDown(color='primary', large, depressed, @click='createUser')
  14. v-icon(left) mdi-plus
  15. span New User
  16. v-card.wiki-form.mt-3.animated.fadeInUp
  17. v-toolbar(flat, :color='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-5`', height='80')
  18. v-spacer
  19. v-text-field(
  20. outlined
  21. v-model='search'
  22. prepend-inner-icon='mdi-account-search-outline'
  23. label='Search Users...'
  24. hide-details
  25. )
  26. v-select.ml-2(
  27. outlined
  28. hide-details
  29. label='Identity Provider'
  30. :items='strategies'
  31. v-model='filterStrategy'
  32. item-text='title'
  33. item-value='key'
  34. )
  35. v-spacer
  36. v-divider
  37. v-data-table(
  38. v-model='selected'
  39. :items='usersFiltered',
  40. :headers='headers',
  41. :search='search',
  42. :page.sync='pagination'
  43. :items-per-page='15'
  44. :loading='loading'
  45. @page-count='pageCount = $event'
  46. hide-default-footer
  47. )
  48. template(slot='item', slot-scope='props')
  49. tr.is-clickable(:active='props.selected', @click='$router.push("/users/" + props.item.id)')
  50. //- td
  51. v-checkbox(hide-details, :input-value='props.selected', color='blue darken-2', @click='props.selected = !props.selected')
  52. td {{ props.item.id }}
  53. td: strong {{ props.item.name }}
  54. td {{ props.item.email }}
  55. td {{ props.item.providerKey }}
  56. td {{ props.item.createdAt | moment('from') }}
  57. td
  58. v-tooltip(left, v-if='props.item.isSystem')
  59. template(v-slot:activator='{ on }')
  60. v-icon(v-on='{ on }') mdi-lock-outline
  61. span System User
  62. template(slot='no-data')
  63. .pa-3
  64. v-alert.text-left(icon='mdi-alert', outlined, color='grey')
  65. em.body-2 No users to display!
  66. v-card-chin(v-if='pageCount > 1')
  67. v-spacer
  68. v-pagination(v-model='pagination', :length='pageCount')
  69. v-spacer
  70. user-create(v-model='isCreateDialogShown', @refresh='refresh(false)')
  71. </template>
  72. <script>
  73. import _ from 'lodash'
  74. import usersQuery from 'gql/admin/users/users-query-list.gql'
  75. import providersQuery from 'gql/admin/users/users-query-strategies.gql'
  76. import UserCreate from './admin-users-create.vue'
  77. export default {
  78. components: {
  79. UserCreate
  80. },
  81. data() {
  82. return {
  83. selected: [],
  84. pagination: 1,
  85. pageCount: 0,
  86. users: [],
  87. headers: [
  88. { text: 'ID', value: 'id', width: 80, sortable: true },
  89. { text: 'Name', value: 'name', sortable: true },
  90. { text: 'Email', value: 'email', sortable: true },
  91. { text: 'Provider', value: 'provider', sortable: true },
  92. { text: 'Created', value: 'createdAt', sortable: true },
  93. { text: '', value: 'actions', sortable: false, width: 50 }
  94. ],
  95. strategies: [],
  96. filterStrategy: 'all',
  97. search: '',
  98. loading: false,
  99. isCreateDialogShown: false
  100. }
  101. },
  102. computed: {
  103. usersFiltered () {
  104. const all = this.filterStrategy === 'all' || this.filterStrategy === ''
  105. return _.filter(this.users, u => all || u.providerKey === this.filterStrategy)
  106. }
  107. },
  108. methods: {
  109. createUser() {
  110. this.isCreateDialogShown = true
  111. },
  112. async refresh(notify = true) {
  113. await this.$apollo.queries.users.refetch()
  114. if (notify) {
  115. this.$store.commit('showNotification', {
  116. message: 'Users list has been refreshed.',
  117. style: 'success',
  118. icon: 'cached'
  119. })
  120. }
  121. }
  122. },
  123. apollo: {
  124. users: {
  125. query: usersQuery,
  126. fetchPolicy: 'network-only',
  127. update: (data) => data.users.list,
  128. watchLoading (isLoading) {
  129. this.loading = isLoading
  130. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-refresh')
  131. }
  132. },
  133. strategies: {
  134. query: providersQuery,
  135. fetchPolicy: 'network-only',
  136. update: (data) => {
  137. return _.concat({
  138. key: 'all',
  139. title: 'All'
  140. }, data.authentication.strategies)
  141. },
  142. watchLoading (isLoading) {
  143. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-strategies-refresh')
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang='scss'>
  150. </style>