Skip to content
Snippets Groups Projects
Commit 1c91e2a7 authored by Henrik Askjer's avatar Henrik Askjer
Browse files

Beautify

parent 27f2f450
No related branches found
No related tags found
No related merge requests found
...@@ -212,62 +212,83 @@ export default { ...@@ -212,62 +212,83 @@ export default {
SearchResults SearchResults
}, },
methods: { methods: {
select_result: function(event) { select_result: function (event) {
this.event = event this.event = event
if(event.article_ids){ if (event.article_ids) {
let source = '/' + this.lang + '/w/' + event.match let source = '/' + this.lang + '/w/' + event.match
this.$router.push(source) this.$router.push(source)
let unwrapped = [] let unwrapped = []
for (const d in event.article_ids) { for (const d in event.article_ids) {
event.article_ids[d].forEach(i => unwrapped.push({dictionary: d, id: i})) 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"
} }
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 update_lang_form: function (event) {
history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang, error: self.error}, '') 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)
}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)
}
},
article_link_click: function(item) { article_link_click: function(item) {
if (this.article && this.article.article_id == item.article_id){ if (this.article && this.article.article_id == item.article_id){
this.article_key++ this.article_key++
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment