2
0

admin-users.vue 4.8 KB

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