wikijs-fork/client/components/common/user-search.vue

137 lines
3.1 KiB
Vue
Raw Permalink Normal View History

2018-04-23 04:27:30 +00:00
<template lang="pug">
v-dialog(
v-model='dialogOpen'
max-width='650'
)
v-card
.dialog-header
2019-06-15 21:05:56 +00:00
span {{$t('common:user.search')}}
v-spacer
v-progress-circular(
indeterminate
color='white'
:size='20'
:width='2'
v-show='searchLoading'
)
v-card-text.pt-5
2018-06-11 03:23:09 +00:00
v-text-field(
outlined
2019-06-15 21:05:56 +00:00
:label='$t(`common:user.searchPlaceholder`)'
v-model='search'
prepend-inner-icon='mdi-account-search-outline'
color='primary'
ref='searchIpt'
hide-details
)
v-list.grey.mt-3.py-0.radius-7(
:class='$vuetify.theme.dark ? `darken-3-d5` : `lighten-3`'
two-line
dense
)
template(v-for='(usr, idx) in items')
2020-05-30 20:34:09 +00:00
v-list-item(:key='usr.id', @click='setUser(usr)')
2019-07-29 04:50:03 +00:00
v-list-item-avatar(size='40', color='primary')
span.body-1.white--text {{usr.name | initials}}
2019-07-29 04:50:03 +00:00
v-list-item-content
v-list-item-title.body-2 {{usr.name}}
v-list-item-subtitle {{usr.email}}
2019-07-29 04:50:03 +00:00
v-list-item-action
v-icon(color='primary') mdi-arrow-right
v-divider.my-0(v-if='idx < items.length - 1')
2018-06-11 03:23:09 +00:00
v-card-chin
2018-04-23 04:27:30 +00:00
v-spacer
v-btn(
text
@click='close'
:disabled='loading'
2019-06-15 21:05:56 +00:00
) {{$t('common:actions.cancel')}}
2018-04-23 04:27:30 +00:00
</template>
<script>
import _ from 'lodash'
2020-05-30 20:34:09 +00:00
import gql from 'graphql-tag'
2018-04-23 04:27:30 +00:00
export default {
filters: {
initials(val) {
return val.split(' ').map(v => v.substring(0, 1)).join('')
}
},
2018-04-23 04:27:30 +00:00
props: {
multiple: {
type: Boolean,
default: false
},
2018-04-23 04:27:30 +00:00
value: {
type: Boolean,
default: false
}
},
data() {
return {
loading: false,
searchLoading: false,
search: '',
items: []
2018-04-23 04:27:30 +00:00
}
},
computed: {
dialogOpen: {
get() { return this.value },
set(value) { this.$emit('input', value) }
}
},
watch: {
value(newValue, oldValue) {
if (newValue && !oldValue) {
this.search = ''
this.selectedItems = null
_.delay(() => { this.$refs.searchIpt.focus() }, 100)
}
}
},
2018-04-23 04:27:30 +00:00
methods: {
close() {
this.$emit('input', false)
},
2020-05-30 20:34:09 +00:00
setUser(usr) {
this.$emit('select', usr)
this.close()
},
searchFilter(item, queryText, itemText) {
return _.includes(_.toLower(item.email), _.toLower(queryText)) || _.includes(_.toLower(item.name), _.toLower(queryText))
2018-04-23 04:27:30 +00:00
}
},
apollo: {
items: {
2020-05-30 20:34:09 +00:00
query: gql`
query ($query: String!) {
users {
search(query:$query) {
id
name
email
providerKey
}
}
}
`,
2018-04-23 04:27:30 +00:00
variables() {
return {
query: this.search
2018-04-23 04:27:30 +00:00
}
},
fetchPolicy: 'cache-and-network',
2018-04-23 04:27:30 +00:00
skip() {
return !this.search || this.search.length < 2
},
update: (data) => data.users.search,
2018-04-23 04:27:30 +00:00
watchLoading (isLoading) {
this.searchLoading = isLoading
}
}
}
}
</script>