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.

193 lines
5.9 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='title'
  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 {{ 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. },
  132. apollo: {
  133. users: {
  134. query: gql`
  135. query {
  136. users {
  137. list {
  138. id
  139. name
  140. email
  141. providerKey
  142. isSystem
  143. isActive
  144. createdAt
  145. lastLoginAt
  146. }
  147. }
  148. }
  149. `,
  150. fetchPolicy: 'network-only',
  151. update: (data) => data.users.list,
  152. watchLoading (isLoading) {
  153. this.loading = isLoading
  154. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-refresh')
  155. }
  156. },
  157. strategies: {
  158. query: gql`
  159. query {
  160. authentication {
  161. strategies(
  162. isEnabled: true
  163. ) {
  164. key
  165. title
  166. icon
  167. color
  168. }
  169. }
  170. }
  171. `,
  172. fetchPolicy: 'network-only',
  173. update: (data) => {
  174. return _.concat({
  175. key: 'all',
  176. title: 'All Providers'
  177. }, data.authentication.strategies)
  178. },
  179. watchLoading (isLoading) {
  180. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-strategies-refresh')
  181. }
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang='scss'>
  187. </style>