2
0

admin-users.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. .subheading.grey--text.animated.fadeInLeft.wait-p2s Manage users #[v-chip(label, color='primary', small).white--text coming soon]
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s(outline, color='grey', large, @click='refresh')
  12. v-icon refresh
  13. v-btn.animated.fadeInDown(color='primary', large, depressed, @click='createUser')
  14. v-icon(left) add
  15. span New User
  16. v-card.wiki-form.mt-3.animated.fadeInUp
  17. v-toolbar(flat, :color='$vuetify.dark ? `grey darken-3-d5` : `grey lighten-5`', height='80')
  18. v-spacer
  19. v-text-field(
  20. outline
  21. v-model='search'
  22. prepend-inner-icon='search'
  23. label='Search Users...'
  24. hide-details
  25. )
  26. v-select.ml-2(
  27. outline
  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. :pagination.sync='pagination',
  43. :rows-per-page-items='[15]'
  44. :loading='loading'
  45. hide-actions,
  46. disable-initial-sort
  47. )
  48. template(slot='headers', slot-scope='props')
  49. tr
  50. th.text-xs-left(
  51. v-for='header in props.headers'
  52. :key='header.text'
  53. :width='header.width'
  54. :class='[`column`, header.sortable ? `sortable` : ``, pagination.descending ? `desc` : `asc`, header.value === pagination.sortBy ? `active` : ``]'
  55. @click='changeSort(header.value)'
  56. )
  57. | {{ header.text }}
  58. v-icon(small, v-if='header.sortable') arrow_upward
  59. template(slot='items', slot-scope='props')
  60. tr.is-clickable(:active='props.selected', @click='$router.push("/users/" + props.item.id)')
  61. //- td
  62. v-checkbox(hide-details, :input-value='props.selected', color='blue darken-2', @click='props.selected = !props.selected')
  63. td.text-xs-right {{ props.item.id }}
  64. td: strong {{ props.item.name }}
  65. td {{ props.item.email }}
  66. td {{ props.item.providerKey }}
  67. td {{ props.item.createdAt | moment('from') }}
  68. td
  69. v-tooltip(left, v-if='props.item.isSystem')
  70. v-icon(slot='activator') lock_outline
  71. span System User
  72. template(slot='no-data')
  73. .pa-3
  74. v-alert(icon='warning', :value='true', outline) No users to display!
  75. v-card-chin(v-if='this.pages > 1')
  76. v-spacer
  77. v-pagination(v-model='pagination.page', :length='pages')
  78. v-spacer
  79. user-create(v-model='isCreateDialogShown')
  80. </template>
  81. <script>
  82. import _ from 'lodash'
  83. import usersQuery from 'gql/admin/users/users-query-list.gql'
  84. import providersQuery from 'gql/admin/users/users-query-strategies.gql'
  85. import UserCreate from './admin-users-create.vue'
  86. export default {
  87. components: {
  88. UserCreate
  89. },
  90. data() {
  91. return {
  92. selected: [],
  93. pagination: {},
  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: '', value: 'actions', sortable: false, width: 50 }
  102. ],
  103. strategies: [],
  104. filterStrategy: 'all',
  105. search: '',
  106. loading: false,
  107. isCreateDialogShown: false
  108. }
  109. },
  110. computed: {
  111. usersFiltered () {
  112. const all = this.filterStrategy === 'all' || this.filterStrategy === ''
  113. return _.filter(this.users, u => all || u.providerKey === this.filterStrategy)
  114. },
  115. pages () {
  116. if (this.pagination.rowsPerPage == null || this.usersFiltered.length < 1) {
  117. return 0
  118. }
  119. return Math.ceil(this.usersFiltered.length / this.pagination.rowsPerPage)
  120. }
  121. },
  122. methods: {
  123. createUser() {
  124. this.isCreateDialogShown = true
  125. },
  126. async refresh() {
  127. await this.$apollo.queries.users.refetch()
  128. this.$store.commit('showNotification', {
  129. message: 'Users list has been refreshed.',
  130. style: 'success',
  131. icon: 'cached'
  132. })
  133. },
  134. changeSort (column) {
  135. if (this.pagination.sortBy === column) {
  136. this.pagination.descending = !this.pagination.descending
  137. } else {
  138. this.pagination.sortBy = column
  139. this.pagination.descending = false
  140. }
  141. },
  142. toggleAll () {
  143. if (this.selected.length) {
  144. this.selected = []
  145. } else {
  146. this.selected = this.items.slice()
  147. }
  148. }
  149. },
  150. apollo: {
  151. users: {
  152. query: usersQuery,
  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: providersQuery,
  162. fetchPolicy: 'network-only',
  163. update: (data) => {
  164. return _.concat({
  165. key: 'all',
  166. title: 'All'
  167. }, data.authentication.strategies)
  168. },
  169. watchLoading (isLoading) {
  170. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-strategies-refresh')
  171. }
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang='scss'>
  177. </style>