Newer
Older
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">

Ole Voldsæter
committed
<form class="" action="search" method="get">
<input placeholder="Søk..." name="q" />
<select class="" name="lang">
<option value="nob">Bokmål</option>
<option value="nno">Nynorsk</option>
</select>
<input type="submit" name="" value="Yay!">

Ole Voldsæter
committed
</form>
<img id="spinner" :class="waiting ? 'show' : 'hide'" src="./assets/spinner.gif" alt="" />
<SearchResults :hits="search_results" :lang="query_lang" />
import SearchResults from './components/SearchResults.vue'

Ole Voldsæter
committed
//import Autocomplete from '@trevoreyre/autocomplete-vue'
//import '@trevoreyre/autocomplete-vue/dist/style.css'
var api_endpoint = 'https://ordbok-dev.aws.uib.no/api/dict/'
let params = new URLSearchParams(window.location.search.substring(1))
let path = window.location.href.split("/")
article_id: parseInt(path.pop()),
search_query: params.get('q'),
query_lang: params.get('lang'),
path_lang: path.pop(),

Ole Voldsæter
committed
article: {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}},

Ole Voldsæter
committed
return axios.post(api_endpoint + '_search/',
{
"suggest": {
"suggest" : {
"prefix" : q,
"completion" : {
"field" : "suggest"
}
}
}
}).then(function(response) {
let hits = response.data.suggest.suggest[0].options
if(q.length) hits = hits.concat({q: q})
resolve(hits)
})
if (result._source)
return result._source.lemmas.map(x => x.word).join(', ')
else
return 'Alle søkeresultater...'

Ole Voldsæter
committed
//Autocomplete,
},
methods: {
select_result: function(event) {
if(event._source){
this.search_results = []
this.article = event._source
}else{
window.location.href="search?q=" + event.q
}
}
},
mounted: function(){
var self = this;
axios.get(api_endpoint + self.query_lang + '/article' + '?expand_lemmas=true&lemma_text=' + self.search_query)

Ole Voldsæter
committed
self.search_results = response.data
axios.get(api_endpoint + self.path_lang + '/article' + '/' + self.article_id + '?expand_lemmas=true&expand_refs=true')

Ole Voldsæter
committed
self.article = response.data
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
margin-top: 60px;
.show {
display: block;
}
.hide {
display: none;
}
.autocomplete {
width: 25em;
}