mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 22:39:34 +00:00
89 lines
2.3 KiB
Vue
89 lines
2.3 KiB
Vue
<template>
|
|
<div>
|
|
<p v-if="!this.searchResults" class="px-3 py-3">{{ this.search?.length ? $t('Searching...') : $t('Type something') }}</p>
|
|
<p v-else-if="this.searchResults.error" class="px-3">{{ this.searchResults.error }}</p>
|
|
|
|
<div v-else class="results-wrapper">
|
|
<A-search-result-mastertasks :mastertasks="searchResults.mastertasks"/>
|
|
<A-search-result-subtasks :subtasks="searchResults.subtasks" />
|
|
<A-search-result-team :teams="searchResults.teams" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { debounce } from 'lodash-es'
|
|
import ASearchResultTeam from '@/plugins/lib@search/search/_components/a-search-result-team.vue'
|
|
import ASearchResultSubtasks from '@/plugins/lib@search/search/_components/a-search-result-subtasks.vue'
|
|
import ASearchResultMastertasks from '@/plugins/lib@search/search/_components/a-search-result-mastertasks.vue'
|
|
|
|
export default {
|
|
components: {
|
|
ASearchResultTeam,
|
|
ASearchResultSubtasks,
|
|
ASearchResultMastertasks
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
searchResults: null,
|
|
search: ''
|
|
}
|
|
},
|
|
|
|
created() {
|
|
this.$events.on('onSearch', (search) => {
|
|
if (!search?.length)
|
|
return
|
|
|
|
this.search = search
|
|
this.onSearch(search)
|
|
})
|
|
},
|
|
|
|
mounted() {
|
|
this.$events.on('on-subtask-edited', () => {
|
|
this.onSearch(this.search, false)
|
|
})
|
|
|
|
this.$events.on('on-subtask-deleted', () => {
|
|
this.onSearch(this.search, false)
|
|
})
|
|
|
|
this.$events.on('on-mastertask-edited', () => {
|
|
this.onSearch(this.search, false)
|
|
})
|
|
|
|
this.$events.on('on-mastertask-deleted', () => {
|
|
this.onSearch(this.search, false)
|
|
})
|
|
},
|
|
|
|
unmounted() {
|
|
this.$events.off('on-subtask-edited')
|
|
this.$events.off('on-subtask-deleted')
|
|
this.$events.off('on-mastertask-edited')
|
|
this.$events.off('on-mastertask-deleted')
|
|
},
|
|
|
|
methods: {
|
|
onSearch: debounce(async function (search, reset = true) {
|
|
try {
|
|
if (reset)
|
|
this.searchResults = null
|
|
|
|
const { mastertasks, subtasks, teams} = await this.$axios.get_auth(`v1/search?q=${search}`)
|
|
this.searchResults = {mastertasks: mastertasks.data, subtasks: subtasks.data, teams: teams.data}
|
|
} catch (error) {
|
|
this.$toast.error(this.$parseError(error))
|
|
this.searchResults = {error}
|
|
}
|
|
}, 300)
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="sass" scoped>
|
|
.results-wrapper
|
|
margin-bottom: 60px
|
|
</style> |