admin-users-edit.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.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-menu(bottom, right, min-width='200')
  52. v-btn(icon, slot='activator'): v-icon.grey--text.text--darken-1 more_horiz
  53. v-list
  54. v-list-tile(@click='')
  55. v-list-tile-action
  56. v-icon(color='primary') edit
  57. v-list-tile-content
  58. v-list-tile-title Edit
  59. v-list-tile(@click='')
  60. v-list-tile-action
  61. v-icon(color='red') block
  62. v-list-tile-content
  63. v-list-tile-title Block
  64. template(slot='no-data')
  65. .pa-3
  66. v-alert(icon='warning', :value='true', outline) No users to display!
  67. .text-xs-center.py-2
  68. v-pagination(v-model='pagination.page', :length='pages')
  69. user-authorize(v-model='isAuthorizeDialogShown')
  70. user-create(v-model='isCreateDialogShown')
  71. </template>
  72. <script>
  73. import usersQuery from 'gql/admin/users/users-query-list.gql'
  74. import UserAuthorize from './admin-users-authorize.vue'
  75. import UserCreate from './admin-users-create.vue'
  76. export default {
  77. components: {
  78. UserAuthorize,
  79. UserCreate
  80. },
  81. data() {
  82. return {
  83. selected: [],
  84. pagination: {},
  85. users: [],
  86. headers: [
  87. { text: 'ID', value: 'id', width: 80, sortable: true },
  88. { text: 'Name', value: 'name', sortable: true },
  89. { text: 'Email', value: 'email', sortable: true },
  90. { text: 'Provider', value: 'provider', sortable: true },
  91. { text: 'Created', value: 'createdAt', sortable: true },
  92. { text: '', value: 'actions', sortable: false, width: 50 }
  93. ],
  94. search: '',
  95. isAuthorizeDialogShown: false,
  96. isCreateDialogShown: false
  97. }
  98. },
  99. computed: {
  100. pages () {
  101. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  102. return 0
  103. }
  104. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  105. }
  106. },
  107. methods: {
  108. authorizeUser() {
  109. this.isAuthorizeDialogShown = true
  110. },
  111. createUser() {
  112. this.isCreateDialogShown = true
  113. },
  114. async refresh() {
  115. await this.$apollo.queries.users.refetch()
  116. this.$store.commit('showNotification', {
  117. message: 'Users list has been refreshed.',
  118. style: 'success',
  119. icon: 'cached'
  120. })
  121. },
  122. changeSort (column) {
  123. if (this.pagination.sortBy === column) {
  124. this.pagination.descending = !this.pagination.descending
  125. } else {
  126. this.pagination.sortBy = column
  127. this.pagination.descending = false
  128. }
  129. },
  130. toggleAll () {
  131. if (this.selected.length) {
  132. this.selected = []
  133. } else {
  134. this.selected = this.items.slice()
  135. }
  136. }
  137. },
  138. apollo: {
  139. users: {
  140. query: usersQuery,
  141. fetchPolicy: 'network-only',
  142. update: (data) => data.users.list,
  143. watchLoading (isLoading) {
  144. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-refresh')
  145. }
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang='scss'>
  151. </style>