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.

123 lines
2.8 KiB

  1. <template lang="pug">
  2. v-dialog(
  3. v-model='dialogOpen'
  4. max-width='650'
  5. )
  6. v-card
  7. .dialog-header
  8. span Search User
  9. v-spacer
  10. v-progress-circular(
  11. indeterminate
  12. color='white'
  13. :size='20'
  14. :width='2'
  15. v-show='searchLoading'
  16. )
  17. v-card-text
  18. v-text-field(
  19. solo
  20. flat
  21. label='Search Users...'
  22. v-model='search'
  23. prepend-icon='search'
  24. :background-color='$vuetify.dark ? "grey darken-4" : "blue lighten-5"'
  25. color='primary'
  26. ref='searchIpt'
  27. hide-details
  28. )
  29. v-list(two-line)
  30. template(v-for='(usr, idx) in items')
  31. v-list-tile(:key='usr.id', @click='setUser(usr.id)')
  32. v-list-tile-avatar(size='40', color='primary')
  33. span.body-1.white--text {{usr.name | initials}}
  34. v-list-tile-content
  35. v-list-tile-title {{usr.name}}
  36. v-list-tile-sub-title {{usr.email}}
  37. v-list-tile-action
  38. v-icon(color='primary') arrow_forward
  39. v-divider.my-0(v-if='idx < items.length - 1')
  40. v-card-chin
  41. v-spacer
  42. v-btn(
  43. flat
  44. @click='close'
  45. :disabled='loading'
  46. ) Cancel
  47. </template>
  48. <script>
  49. import _ from 'lodash'
  50. import searchUsersQuery from 'gql/common/common-users-query-search.gql'
  51. export default {
  52. filters: {
  53. initials(val) {
  54. return val.split(' ').map(v => v.substring(0, 1)).join()
  55. }
  56. },
  57. props: {
  58. multiple: {
  59. type: Boolean,
  60. default: false
  61. },
  62. value: {
  63. type: Boolean,
  64. default: false
  65. }
  66. },
  67. data() {
  68. return {
  69. loading: false,
  70. searchLoading: false,
  71. search: '',
  72. items: []
  73. }
  74. },
  75. computed: {
  76. dialogOpen: {
  77. get() { return this.value },
  78. set(value) { this.$emit('input', value) }
  79. }
  80. },
  81. watch: {
  82. value(newValue, oldValue) {
  83. if (newValue && !oldValue) {
  84. this.search = ''
  85. this.selectedItems = null
  86. _.delay(() => { this.$refs.searchIpt.focus() }, 100)
  87. }
  88. }
  89. },
  90. methods: {
  91. close() {
  92. this.$emit('input', false)
  93. },
  94. setUser(id) {
  95. this.$emit('select', id)
  96. this.close()
  97. },
  98. searchFilter(item, queryText, itemText) {
  99. return _.includes(_.toLower(item.email), _.toLower(queryText)) || _.includes(_.toLower(item.name), _.toLower(queryText))
  100. }
  101. },
  102. apollo: {
  103. items: {
  104. query: searchUsersQuery,
  105. variables() {
  106. return {
  107. query: this.search
  108. }
  109. },
  110. skip() {
  111. return !this.search || this.search.length < 2
  112. },
  113. update: (data) => data.users.search,
  114. watchLoading (isLoading) {
  115. this.searchLoading = isLoading
  116. }
  117. }
  118. }
  119. }
  120. </script>