Search namespaces locally only when duplicating a list

This commit is contained in:
kolaente 2021-07-27 15:36:02 +02:00
parent ce84067982
commit 53fe5738c9
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -1,53 +1,43 @@
<template> <template>
<multiselect <multiselect
:loading="namespaceService.loading"
:placeholder="$t('namespace.search')" :placeholder="$t('namespace.search')"
@search="findNamespaces" @search="findNamespaces"
:search-results="namespaces" :search-results="namespaces"
@select="select" @select="select"
label="title" label="title"
v-model="namespace" :search-delay="10"
/> />
</template> </template>
<script> <script>
import NamespaceService from '../../services/namespace'
import NamespaceModel from '../../models/namespace'
import Multiselect from '@/components/input/multiselect.vue' import Multiselect from '@/components/input/multiselect.vue'
export default { export default {
name: 'namespace-search', name: 'namespace-search',
data() { data() {
return { return {
namespaceService: NamespaceService, query: '',
namespace: NamespaceModel,
namespaces: [],
} }
}, },
components: { components: {
Multiselect, Multiselect,
}, },
created() { computed: {
this.namespaceService = new NamespaceService() namespaces() {
if (this.query === '') {
return []
}
return this.$store.state.namespaces.namespaces.filter(n => {
return !n.isArchived &&
n.id > 0 &&
n.title.toLowerCase().includes(this.query.toLowerCase())
})
},
}, },
methods: { methods: {
findNamespaces(query) { findNamespaces(query) {
if (query === '') { this.query = query
this.clearAll()
return
}
this.namespaceService.getAll({}, {s: query})
.then(response => {
this.$set(this, 'namespaces', response)
})
.catch(e => {
this.error(e)
})
},
clearAll() {
this.$set(this, 'namespaces', [])
}, },
select(namespace) { select(namespace) {
this.$emit('selected', namespace) this.$emit('selected', namespace)