This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/components/tasks/partials/listSearch.vue

74 lines
1.6 KiB
Vue
Raw Normal View History

2020-04-18 12:39:56 +00:00
<template>
2022-07-20 19:15:35 +00:00
<Multiselect
class="control is-expanded"
:placeholder="$t('list.search')"
@search="findLists"
:search-results="foundLists"
@select="select"
label="title"
v-model="list"
:select-placeholder="$t('list.searchSelect')"
2020-04-18 12:39:56 +00:00
>
<template #searchResult="props">
2021-08-06 17:34:22 +00:00
<span class="list-namespace-title search-result">{{ namespace(props.option.namespaceId) }} ></span>
{{ props.option.title }}
</template>
2022-07-20 19:15:35 +00:00
</Multiselect>
2020-04-18 12:39:56 +00:00
</template>
<script lang="ts" setup>
import {reactive, ref, watch} from 'vue'
import type {PropType} from 'vue'
2022-07-21 16:45:58 +00:00
import {useStore} from '@/store'
import {useI18n} from 'vue-i18n'
2022-07-20 22:42:36 +00:00
import ListModel, { type IList } from '@/models/list'
import Multiselect from '@/components/input/multiselect.vue'
2020-04-18 12:39:56 +00:00
const props = defineProps({
modelValue: {
2022-07-20 22:42:36 +00:00
type: Object as PropType<IList>,
required: false,
},
})
const emit = defineEmits(['update:modelValue'])
const store = useStore()
const {t} = useI18n({useScope: 'global'})
2022-07-20 22:42:36 +00:00
const list: IList = reactive(new ListModel())
watch(
() => props.modelValue,
(newList) => Object.assign(list, newList),
{
immediate: true,
deep: true,
},
)
const foundLists = ref([])
function findLists(query: string) {
if (query === '') {
select(null)
}
foundLists.value = store.getters['lists/searchList'](query)
}
2022-07-20 22:42:36 +00:00
function select(l: IList | null) {
Object.assign(list, l)
emit('update:modelValue', list)
}
function namespace(namespaceId: number) {
const namespace = store.getters['namespaces/getNamespaceById'](namespaceId)
return namespace !== null
? namespace.title
: t('list.shared')
}
2020-04-18 12:39:56 +00:00
</script>
<style lang="scss" scoped>
.list-namespace-title {
color: var(--grey-500);
}
</style>