diff --git a/src/components/DictionaryView.vue b/src/components/DictionaryView.vue index fa3e948065c44373b0ac2cea392dbccb948eb184..b5e18086c1e3926e4aecec8109f9b854fa8a4830 100644 --- a/src/components/DictionaryView.vue +++ b/src/components/DictionaryView.vue @@ -212,62 +212,83 @@ export default { SearchResults }, methods: { - select_result: function(event) { - this.event = event - if(event.article_ids){ - let source = '/' + this.lang + '/w/' + event.match - this.$router.push(source) - let unwrapped = [] - for (const d in event.article_ids) { - event.article_ids[d].forEach(i => unwrapped.push({dictionary: d, id: i})) - } - - let self = this - Promise.all(unwrapped.map((article) => { - return axios.get(`${api_endpoint}/${article.dictionary}/article/${article.id}`) - - })) - .then((response) => { - self.search_results = response.map((element, index) => { - return Object.assign(element.data, {source: source, match: event.match, dictionary: unwrapped[index].dictionary}) - }) - self.article = null - self.error = null - - }) - .catch(error => { - self.search_results = [] - if (error.response) { - self.error = "Noe gikk galt på serversiden" - } else { - self.error = "Nettverksproblemer, prøv igjen" + select_result: function (event) { + this.event = event + if (event.article_ids) { + let source = '/' + this.lang + '/w/' + event.match + this.$router.push(source) + let unwrapped = [] + for (const d in event.article_ids) { + event.article_ids[d].forEach(i => unwrapped.push({ + dictionary: d, + id: i + })) } + + let self = this + Promise.all(unwrapped.map((article) => { + return axios.get(`${api_endpoint}/${article.dictionary}/article/${article.id}`) + + })) + .then((response) => { + self.search_results = response.map((element, index) => { + return Object.assign(element.data, { + source: source, + match: event.match, + dictionary: unwrapped[index].dictionary + }) + }) + self.article = null + self.error = null + + }) + .catch(error => { + self.search_results = [] + if (error.response) { + self.error = "Noe gikk galt på serversiden" + } else { + self.error = "Nettverksproblemer, prøv igjen" + } + }) + .then(() => { + self.$plausible.trackEvent('dropdown selection', { + props: { + query: event.q, + match: event.match + } + }) + self.waiting_for_articles = false + history.replaceState({ + article: self.article, + search_results: self.search_results, + lang: self.lang, + error: self.error + }, '') + }) + + + + } else { + this.waiting_for_articles = true + this.article = null + this.$router.push(`/${this.lang}/search/${event.q}`) + navigate_to_search(this, event.q) + this.$plausible.trackEvent('dropdown selection', { + props: { + query: event.q, + match: '<fritekstsøk>' + } }) - .then(() => { - self.$plausible.trackEvent('dropdown selection', {props: {query: event.q, match: event.match}}) - self.waiting_for_articles = false - history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang, error: self.error}, '') - }) - - - - }else{ - this.waiting_for_articles = true - this.article = null - this.$router.push(`/${this.lang}/search/${event.q}`) - navigate_to_search(this, event.q) - this.$plausible.trackEvent('dropdown selection', {props: {query: event.q, match: '<fritekstsøk>'}}) - } - }, - update_lang_form: function(event) { - if (this.event){ - this.event.articles = null - this.select_result(this.event) - } - else{ - navigate_to_search(this, this.$router.history.current.params.word || this.$router.history.current.params.query) - } - }, + } + }, + update_lang_form: function (event) { + if (this.event) { + this.event.articles = null + this.select_result(this.event) + } else { + navigate_to_search(this, this.$router.history.current.params.word || this.$router.history.current.params.query) + } + }, article_link_click: function(item) { if (this.article && this.article.article_id == item.article_id){ this.article_key++