feat: simplify namespace search (#1835)
Co-authored-by: Dominik Pschenitschni <mail@celement.de> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1835 Reviewed-by: konrad <k@knt.li> Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de> Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
parent
ddc1cff7ea
commit
8578225982
3 changed files with 75 additions and 72 deletions
|
@ -1,32 +0,0 @@
|
||||||
<template>
|
|
||||||
<multiselect
|
|
||||||
:placeholder="$t('namespace.search')"
|
|
||||||
@search="findNamespaces"
|
|
||||||
:search-results="namespaces"
|
|
||||||
@select="select"
|
|
||||||
label="title"
|
|
||||||
:search-delay="10"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import {ref, computed} from 'vue'
|
|
||||||
import {useStore} from 'vuex'
|
|
||||||
import Multiselect from '@/components/input/multiselect.vue'
|
|
||||||
import NamespaceModel from '@/models/namespace'
|
|
||||||
|
|
||||||
const emit = defineEmits(['selected'])
|
|
||||||
|
|
||||||
const query = ref('')
|
|
||||||
|
|
||||||
const store = useStore()
|
|
||||||
const namespaces = computed(() => store.getters['namespaces/searchNamespace'](query.value))
|
|
||||||
|
|
||||||
function findNamespaces(newQuery: string) {
|
|
||||||
query.value = newQuery
|
|
||||||
}
|
|
||||||
|
|
||||||
function select(namespace: NamespaceModel) {
|
|
||||||
emit('selected', namespace)
|
|
||||||
}
|
|
||||||
</script>
|
|
19
src/composables/useNamespaceSearch.ts
Normal file
19
src/composables/useNamespaceSearch.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import {ref, computed, Ref} from 'vue'
|
||||||
|
import {useStore} from 'vuex'
|
||||||
|
|
||||||
|
export function useNameSpaceSearch() {
|
||||||
|
const query = ref('')
|
||||||
|
|
||||||
|
const store = useStore()
|
||||||
|
const namespaces = computed(() => store.getters['namespaces/searchNamespace'](query.value))
|
||||||
|
|
||||||
|
function findNamespaces(newQuery: string) {
|
||||||
|
query.value = newQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
namespaces,
|
||||||
|
findNamespaces,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,52 +6,68 @@
|
||||||
@primary="duplicateList"
|
@primary="duplicateList"
|
||||||
:loading="listDuplicateService.loading"
|
:loading="listDuplicateService.loading"
|
||||||
>
|
>
|
||||||
<p>
|
<p>{{ $t('list.duplicate.text') }}</p>
|
||||||
{{ $t('list.duplicate.text') }}
|
|
||||||
</p>
|
<Multiselect
|
||||||
<namespace-search @selected="selectNamespace"/>
|
:placeholder="$t('namespace.search')"
|
||||||
|
@search="findNamespaces"
|
||||||
|
:search-results="namespaces"
|
||||||
|
@select="selectNamespace"
|
||||||
|
label="title"
|
||||||
|
:search-delay="10"
|
||||||
|
/>
|
||||||
</create-edit>
|
</create-edit>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import {defineComponent} from 'vue'
|
import {ref, shallowReactive} from 'vue'
|
||||||
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
import { useStore } from 'vuex'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import ListDuplicateService from '@/services/listDuplicateService'
|
import ListDuplicateService from '@/services/listDuplicateService'
|
||||||
import NamespaceSearch from '@/components/namespace/namespace-search.vue'
|
|
||||||
import ListDuplicateModel from '@/models/listDuplicateModel'
|
|
||||||
import CreateEdit from '@/components/misc/create-edit.vue'
|
import CreateEdit from '@/components/misc/create-edit.vue'
|
||||||
|
import Multiselect from '@/components/input/multiselect.vue'
|
||||||
|
|
||||||
export default defineComponent({
|
import ListDuplicateModel from '@/models/listDuplicateModel'
|
||||||
name: 'list-setting-duplicate',
|
import NamespaceModel from '@/models/namespace'
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
listDuplicateService: new ListDuplicateService(),
|
|
||||||
selectedNamespace: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: {
|
|
||||||
CreateEdit,
|
|
||||||
NamespaceSearch,
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.setTitle(this.$t('list.duplicate.title'))
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
selectNamespace(namespace) {
|
|
||||||
this.selectedNamespace = namespace
|
|
||||||
},
|
|
||||||
|
|
||||||
async duplicateList() {
|
import { success } from '@/message'
|
||||||
const listDuplicate = new ListDuplicateModel({
|
import { useTitle } from '@/composables/useTitle'
|
||||||
listId: this.$route.params.listId,
|
import { useNameSpaceSearch } from '@/composables/useNamespaceSearch'
|
||||||
namespaceId: this.selectedNamespace.id,
|
|
||||||
})
|
|
||||||
const duplicate = await this.listDuplicateService.create(listDuplicate)
|
const { t } = useI18n()
|
||||||
this.$store.commit('namespaces/addListToNamespace', duplicate.list)
|
useTitle(() => t('list.duplicate.title'))
|
||||||
this.$store.commit('lists/setList', duplicate.list)
|
|
||||||
this.$message.success({message: this.$t('list.duplicate.success')})
|
|
||||||
this.$router.push({name: 'list.index', params: {listId: duplicate.list.id}})
|
const {
|
||||||
},
|
namespaces,
|
||||||
},
|
findNamespaces,
|
||||||
})
|
} = useNameSpaceSearch()
|
||||||
|
|
||||||
|
const selectedNamespace = ref<NamespaceModel>()
|
||||||
|
function selectNamespace(namespace: NamespaceModel) {
|
||||||
|
selectedNamespace.value = namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const router= useRouter()
|
||||||
|
|
||||||
|
const listDuplicateService = shallowReactive(new ListDuplicateService())
|
||||||
|
async function duplicateList() {
|
||||||
|
const listDuplicate = new ListDuplicateModel({
|
||||||
|
// FIXME: should be parameter
|
||||||
|
listId: route.params.listId,
|
||||||
|
namespaceId: selectedNamespace.value?.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
const duplicate = await listDuplicateService.create(listDuplicate)
|
||||||
|
|
||||||
|
const store = useStore()
|
||||||
|
store.commit('namespaces/addListToNamespace', duplicate.list)
|
||||||
|
store.commit('lists/setList', duplicate.list)
|
||||||
|
success({message: t('list.duplicate.success')})
|
||||||
|
router.push({name: 'list.index', params: {listId: duplicate.list.id}})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue