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"
|
2022-11-13 21:04:57 +00:00
|
|
|
:placeholder="$t('project.search')"
|
|
|
|
:search-results="foundProjects"
|
2020-09-05 20:35:52 +00:00
|
|
|
label="title"
|
2022-11-13 21:04:57 +00:00
|
|
|
:select-placeholder="$t('project.searchSelect')"
|
|
|
|
:model-value="project"
|
|
|
|
@update:model-value="Object.assign(project, $event)"
|
2022-11-12 16:14:32 +00:00
|
|
|
@select="select"
|
2022-11-13 21:04:57 +00:00
|
|
|
@search="findProjects"
|
2020-04-18 12:39:56 +00:00
|
|
|
>
|
2022-10-17 11:14:07 +00:00
|
|
|
<template #searchResult="{option}">
|
2022-11-13 21:04:57 +00:00
|
|
|
<span class="project-namespace-title search-result">{{ namespace((option as IProject).namespaceId) }} ></span>
|
|
|
|
{{ (option as IProject).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 16:14:32 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
import type {IProject} from '@/modelTypes/IProject'
|
2022-11-12 16:14:32 +00:00
|
|
|
import type {INamespace} from '@/modelTypes/INamespace'
|
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
import {useProjectStore} from '@/stores/projects'
|
2022-09-02 09:15:29 +00:00
|
|
|
import {useNamespaceStore} from '@/stores/namespaces'
|
2022-11-12 16:14:32 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
import ProjectModel from '@/models/project'
|
2022-11-12 16:14:32 +00:00
|
|
|
|
|
|
|
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-11-13 21:04:57 +00:00
|
|
|
type: Object as PropType<IProject>,
|
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-11-13 21:04:57 +00:00
|
|
|
const project: IProject = reactive(new ProjectModel())
|
2022-05-22 20:35:02 +00:00
|
|
|
|
|
|
|
watch(
|
|
|
|
() => props.modelValue,
|
2022-11-13 21:04:57 +00:00
|
|
|
(newProject) => Object.assign(project, newProject),
|
2022-05-22 20:35:02 +00:00
|
|
|
{
|
|
|
|
immediate: true,
|
|
|
|
deep: true,
|
|
|
|
},
|
|
|
|
)
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
const projectStore = useProjectStore()
|
2022-09-02 09:15:29 +00:00
|
|
|
const namespaceStore = useNamespaceStore()
|
2022-11-13 21:04:57 +00:00
|
|
|
const foundProjects = ref<IProject[]>([])
|
|
|
|
function findProjects(query: string) {
|
2021-12-13 22:20:45 +00:00
|
|
|
if (query === '') {
|
|
|
|
select(null)
|
|
|
|
}
|
2022-11-13 21:04:57 +00:00
|
|
|
foundProjects.value = projectStore.searchProject(query)
|
2021-12-13 22:20:45 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
function select(l: IProject | null) {
|
2022-09-05 13:47:18 +00:00
|
|
|
if (l === null) {
|
|
|
|
return
|
|
|
|
}
|
2022-11-13 21:04:57 +00:00
|
|
|
Object.assign(project, l)
|
|
|
|
emit('update:modelValue', project)
|
2021-12-13 22:20:45 +00:00
|
|
|
}
|
|
|
|
|
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
|
2022-11-13 21:04:57 +00:00
|
|
|
: t('project.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>
|
2022-11-13 21:04:57 +00:00
|
|
|
.project-namespace-title {
|
2021-12-13 22:20:45 +00:00
|
|
|
color: var(--grey-500);
|
2021-10-18 12:21:02 +00:00
|
|
|
}
|
|
|
|
</style>
|