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.

192 lines
6.0 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='/_assets/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', icon, @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.mt-3.animated.fadeInUp
  17. .pa-2.d-flex.align-center(:class='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-3`')
  18. v-text-field(
  19. solo
  20. flat
  21. v-model='search'
  22. prepend-inner-icon='mdi-account-search-outline'
  23. label='Search Users...'
  24. hide-details
  25. style='max-width: 400px;'
  26. dense
  27. )
  28. v-spacer
  29. v-select(
  30. solo
  31. flat
  32. hide-details
  33. label='Identity Provider'
  34. :items='strategies'
  35. v-model='filterStrategy'
  36. item-text='displayName'
  37. item-value='key'
  38. style='max-width: 300px;'
  39. dense
  40. )
  41. v-divider
  42. v-data-table(
  43. v-model='selected'
  44. :items='usersFiltered',
  45. :headers='headers',
  46. :search='search',
  47. :page.sync='pagination'
  48. :items-per-page='15'
  49. :loading='loading'
  50. @page-count='pageCount = $event'
  51. hide-default-footer
  52. )
  53. template(slot='item', slot-scope='props')
  54. tr.is-clickable(:active='props.selected', @click='$router.push("/users/" + props.item.id)')
  55. //- td
  56. v-checkbox(hide-details, :input-value='props.selected', color='blue darken-2', @click='props.selected = !props.selected')
  57. td {{ props.item.id }}
  58. td: strong {{ props.item.name }}
  59. td {{ props.item.email }}
  60. td {{ getStrategyName(props.item.providerKey) }}
  61. td {{ props.item.createdAt | moment('from') }}
  62. td
  63. span(v-if='props.item.lastLoginAt') {{ props.item.lastLoginAt | moment('from') }}
  64. em.grey--text(v-else) Never
  65. td.text-right
  66. v-icon.mr-3(v-if='props.item.isSystem') mdi-lock-outline
  67. status-indicator(positive, pulse, v-if='props.item.isActive')
  68. status-indicator(negative, pulse, v-else)
  69. template(slot='no-data')
  70. .pa-3
  71. v-alert.text-left(icon='mdi-alert', outlined, color='grey')
  72. em.body-2 No users to display!
  73. v-card-chin(v-if='pageCount > 1')
  74. v-spacer
  75. v-pagination(v-model='pagination', :length='pageCount')
  76. v-spacer
  77. user-create(v-model='isCreateDialogShown', @refresh='refresh(false)')
  78. </template>
  79. <script>
  80. import _ from 'lodash'
  81. import gql from 'graphql-tag'
  82. import { StatusIndicator } from 'vue-status-indicator'
  83. import UserCreate from './admin-users-create.vue'
  84. export default {
  85. components: {
  86. StatusIndicator,
  87. UserCreate
  88. },
  89. data() {
  90. return {
  91. selected: [],
  92. pagination: 1,
  93. pageCount: 0,
  94. users: [],
  95. headers: [
  96. { text: 'ID', value: 'id', width: 80, sortable: true },
  97. { text: 'Name', value: 'name', sortable: true },
  98. { text: 'Email', value: 'email', sortable: true },
  99. { text: 'Provider', value: 'provider', sortable: true },
  100. { text: 'Created', value: 'createdAt', sortable: true },
  101. { text: 'Last Login', value: 'lastLoginAt', sortable: true },
  102. { text: '', value: 'actions', sortable: false, width: 80 }
  103. ],
  104. strategies: [],
  105. filterStrategy: 'all',
  106. search: '',
  107. loading: false,
  108. isCreateDialogShown: false
  109. }
  110. },
  111. computed: {
  112. usersFiltered () {
  113. const all = this.filterStrategy === 'all' || this.filterStrategy === ''
  114. return _.filter(this.users, u => all || u.providerKey === this.filterStrategy)
  115. }
  116. },
  117. methods: {
  118. createUser() {
  119. this.isCreateDialogShown = true
  120. },
  121. async refresh(notify = true) {
  122. await this.$apollo.queries.users.refetch()
  123. if (notify) {
  124. this.$store.commit('showNotification', {
  125. message: 'Users list has been refreshed.',
  126. style: 'success',
  127. icon: 'cached'
  128. })
  129. }
  130. },
  131. getStrategyName(key) {
  132. return (_.find(this.strategies, ['key', key]) || {}).displayName || key
  133. }
  134. },
  135. apollo: {
  136. users: {
  137. query: gql`
  138. query {
  139. users {
  140. list {
  141. id
  142. name
  143. email
  144. providerKey
  145. isSystem
  146. isActive
  147. createdAt
  148. lastLoginAt
  149. }
  150. }
  151. }
  152. `,
  153. fetchPolicy: 'network-only',
  154. update: (data) => data.users.list,
  155. watchLoading (isLoading) {
  156. this.loading = isLoading
  157. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-refresh')
  158. }
  159. },
  160. strategies: {
  161. query: gql`
  162. query {
  163. authentication {
  164. activeStrategies {
  165. key
  166. displayName
  167. }
  168. }
  169. }
  170. `,
  171. fetchPolicy: 'network-only',
  172. update: (data) => {
  173. return _.concat({
  174. key: 'all',
  175. displayName: 'All Providers'
  176. }, data.authentication.activeStrategies)
  177. },
  178. watchLoading (isLoading) {
  179. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-strategies-refresh')
  180. }
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang='scss'>
  186. </style>