2
0

admin-users.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. v-icon(size='80', color='grey lighten-2') perm_identity
  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(width='50')
  33. th.text-xs-left(
  34. v-for='header in props.headers'
  35. :key='header.text'
  36. :width='header.width'
  37. :class='[`column`, header.sortable ? `sortable` : ``, pagination.descending ? `desc` : `asc`, header.value === pagination.sortBy ? `active` : ``]'
  38. @click='changeSort(header.value)'
  39. )
  40. | {{ header.text }}
  41. v-icon(small, v-if='header.sortable') arrow_upward
  42. template(slot='items', slot-scope='props')
  43. tr(:active='props.selected')
  44. //- td
  45. v-checkbox(hide-details, :input-value='props.selected', color='blue darken-2', @click='props.selected = !props.selected')
  46. td.text-xs-right {{ props.item.id }}
  47. td: strong {{ props.item.name }}
  48. td {{ props.item.email }}
  49. td {{ props.item.providerKey }}
  50. td {{ props.item.createdAt | moment('from') }}
  51. td
  52. v-menu(bottom, right, min-width='200')
  53. v-btn(icon, slot='activator'): v-icon.grey--text.text--darken-1 more_horiz
  54. v-list
  55. v-list-tile(@click='')
  56. v-list-tile-action
  57. v-icon(color='primary') edit
  58. v-list-tile-content
  59. v-list-tile-title Edit
  60. v-list-tile(@click='')
  61. v-list-tile-action
  62. v-icon(color='red') block
  63. v-list-tile-content
  64. v-list-tile-title Block
  65. template(slot='no-data')
  66. .pa-3
  67. v-alert(icon='warning', :value='true', outline) No users to display!
  68. .text-xs-center.py-2
  69. v-pagination(v-model='pagination.page', :length='pages')
  70. user-authorize(v-model='isAuthorizeDialogShown')
  71. user-create(v-model='isCreateDialogShown')
  72. </template>
  73. <script>
  74. import usersQuery from 'gql/admin/users/users-query-list.gql'
  75. import UserAuthorize from './admin-users-authorize.vue'
  76. import UserCreate from './admin-users-create.vue'
  77. export default {
  78. components: {
  79. UserAuthorize,
  80. UserCreate
  81. },
  82. data() {
  83. return {
  84. selected: [],
  85. pagination: {},
  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. search: '',
  96. isAuthorizeDialogShown: false,
  97. isCreateDialogShown: false
  98. }
  99. },
  100. computed: {
  101. pages () {
  102. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  103. return 0
  104. }
  105. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  106. }
  107. },
  108. methods: {
  109. authorizeUser() {
  110. this.isAuthorizeDialogShown = true
  111. },
  112. createUser() {
  113. this.isCreateDialogShown = true
  114. },
  115. async refresh() {
  116. await this.$apollo.queries.users.refetch()
  117. this.$store.commit('showNotification', {
  118. message: 'Users list has been refreshed.',
  119. style: 'success',
  120. icon: 'cached'
  121. })
  122. },
  123. changeSort (column) {
  124. if (this.pagination.sortBy === column) {
  125. this.pagination.descending = !this.pagination.descending
  126. } else {
  127. this.pagination.sortBy = column
  128. this.pagination.descending = false
  129. }
  130. },
  131. toggleAll () {
  132. if (this.selected.length) {
  133. this.selected = []
  134. } else {
  135. this.selected = this.items.slice()
  136. }
  137. }
  138. },
  139. apollo: {
  140. users: {
  141. query: usersQuery,
  142. fetchPolicy: 'network-only',
  143. update: (data) => data.users.list,
  144. watchLoading (isLoading) {
  145. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-refresh')
  146. }
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang='scss'>
  152. </style>