2020-04-18 12:39:56 +00:00
|
|
|
<template>
|
2022-07-20 19:15:35 +00:00
|
|
|
<Multiselect
|
2021-01-06 22:36:31 +00:00
|
|
|
class="control is-expanded"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('list.search')"
|
2021-01-06 22:36:31 +00:00
|
|
|
:search-results="foundLists"
|
2020-09-05 20:35:52 +00:00
|
|
|
label="title"
|
2021-06-23 23:24:57 +00:00
|
|
|
:select-placeholder="$t('list.searchSelect')"
|
2022-11-12 15:18:49 +00:00
|
|
|
:model-value="list"
|
|
|
|
@update:model-value="Object.assign(list, $event)"
|
|
|
|
@select="select"
|
|
|
|
@search="findLists"
|
2020-04-18 12:39:56 +00:00
|
|
|
>
|
2022-10-17 11:14:07 +00:00
|
|
|
<template #searchResult="{option}">
|
|
|
|
<span class="list-namespace-title search-result">{{ namespace((option as IList).namespaceId) }} ></span>
|
|
|
|
{{ (option as IList).title }}
|
2020-06-27 21:12:33 +00:00
|
|
|
</template>
|
2022-07-20 19:15:35 +00:00
|
|
|
</Multiselect>
|
2020-04-18 12:39:56 +00:00
|
|
|
</template>
|
|
|
|
|
2021-12-13 22:20:45 +00:00
|
|
|
<script lang="ts" setup>
|
2022-05-22 20:35:02 +00:00
|
|
|
import {reactive, ref, watch} from 'vue'
|
|
|
|
import type {PropType} from 'vue'
|
2021-12-13 22:20:45 +00:00
|
|
|
import {useI18n} from 'vue-i18n'
|
2022-11-12 15:18:49 +00:00
|
|
|
|
2022-09-06 09:36:01 +00:00
|
|
|
import type {IList} from '@/modelTypes/IList'
|
2022-11-12 15:18:49 +00:00
|
|
|
import type {INamespace} from '@/modelTypes/INamespace'
|
|
|
|
|
2022-09-21 16:21:25 +00:00
|
|
|
import {useListStore} from '@/stores/lists'
|
2022-09-02 09:15:29 +00:00
|
|
|
import {useNamespaceStore} from '@/stores/namespaces'
|
2022-11-12 15:18:49 +00:00
|
|
|
|
|
|
|
import ListModel from '@/models/list'
|
|
|
|
|
|
|
|
import Multiselect from '@/components/input/multiselect.vue'
|
2020-04-18 12:39:56 +00:00
|
|
|
|
2021-12-13 22:20:45 +00:00
|
|
|
const props = defineProps({
|
|
|
|
modelValue: {
|
2022-07-20 22:42:36 +00:00
|
|
|
type: Object as PropType<IList>,
|
2021-12-13 22:20:45 +00:00
|
|
|
required: false,
|
2021-07-17 21:21:46 +00:00
|
|
|
},
|
2021-12-13 22:20:45 +00:00
|
|
|
})
|
|
|
|
const emit = defineEmits(['update:modelValue'])
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-05-23 05:23:59 +00:00
|
|
|
const {t} = useI18n({useScope: 'global'})
|
2022-05-22 20:35:02 +00:00
|
|
|
|
2022-07-20 22:42:36 +00:00
|
|
|
const list: IList = reactive(new ListModel())
|
2022-05-22 20:35:02 +00:00
|
|
|
|
|
|
|
watch(
|
|
|
|
() => props.modelValue,
|
|
|
|
(newList) => Object.assign(list, newList),
|
|
|
|
{
|
|
|
|
immediate: true,
|
|
|
|
deep: true,
|
|
|
|
},
|
|
|
|
)
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-09-02 09:15:29 +00:00
|
|
|
const listStore = useListStore()
|
|
|
|
const namespaceStore = useNamespaceStore()
|
2022-09-21 16:21:25 +00:00
|
|
|
const foundLists = ref<IList[]>([])
|
2021-12-13 22:20:45 +00:00
|
|
|
function findLists(query: string) {
|
|
|
|
if (query === '') {
|
|
|
|
select(null)
|
|
|
|
}
|
2022-09-21 16:21:25 +00:00
|
|
|
foundLists.value = listStore.searchList(query)
|
2021-12-13 22:20:45 +00:00
|
|
|
}
|
|
|
|
|
2022-07-20 22:42:36 +00:00
|
|
|
function select(l: IList | null) {
|
2022-09-05 13:47:18 +00:00
|
|
|
if (l === null) {
|
|
|
|
return
|
|
|
|
}
|
2021-12-13 22:20:45 +00:00
|
|
|
Object.assign(list, l)
|
|
|
|
emit('update:modelValue', list)
|
|
|
|
}
|
|
|
|
|
2022-10-17 11:14:07 +00:00
|
|
|
function namespace(namespaceId: INamespace['id']) {
|
2022-09-02 09:15:29 +00:00
|
|
|
const namespace = namespaceStore.getNamespaceById(namespaceId)
|
2021-12-13 22:20:45 +00:00
|
|
|
return namespace !== null
|
|
|
|
? namespace.title
|
|
|
|
: t('list.shared')
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
2020-04-18 12:39:56 +00:00
|
|
|
</script>
|
2021-10-18 12:21:02 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.list-namespace-title {
|
2021-12-13 22:20:45 +00:00
|
|
|
color: var(--grey-500);
|
2021-10-18 12:21:02 +00:00
|
|
|
}
|
|
|
|
</style>
|