Skip to content
Snippets Groups Projects
Commit a17d865c authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

refs meta#30 bokmål og nynorsk

parent c7c2c0f6
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,14 @@ ...@@ -4,9 +4,14 @@
<div class=""> <div class="">
<form class="" action="search" method="get"> <form class="" action="search" method="get">
<input placeholder="Søk..." name="q" /> <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!">
</form> </form>
</div> </div>
<SearchResults :hits="search_results" /> <SearchResults :hits="search_results" :lang="query_lang" />
<Article :article="article" /> <Article :article="article" />
</div> </div>
</template> </template>
...@@ -18,14 +23,18 @@ import SearchResults from './components/SearchResults.vue' ...@@ -18,14 +23,18 @@ import SearchResults from './components/SearchResults.vue'
//import Autocomplete from '@trevoreyre/autocomplete-vue' //import Autocomplete from '@trevoreyre/autocomplete-vue'
//import '@trevoreyre/autocomplete-vue/dist/style.css' //import '@trevoreyre/autocomplete-vue/dist/style.css'
var api_endpoint = 'https://ordbok-dev.aws.uib.no/api/dict/nob/article' var api_endpoint = 'https://ordbok-dev.aws.uib.no/api/dict/'
export default { export default {
name: 'app', name: 'app',
data: function() { data: function() {
let params = new URLSearchParams(window.location.search.substring(1))
let path = window.location.href.split("/")
return { return {
article_id: parseInt(window.location.href.split("/").pop()), article_id: parseInt(path.pop()),
search_query: window.location.href.split("?q=")[1], search_query: params.get('q'),
query_lang: params.get('lang'),
path_lang: path.pop(),
search_results: [], search_results: [],
article: {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}}, article: {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}},
/*search: function(q) { /*search: function(q) {
...@@ -73,14 +82,14 @@ export default { ...@@ -73,14 +82,14 @@ export default {
mounted: function(){ mounted: function(){
var self = this; var self = this;
if(this.search_query) { if(this.search_query) {
axios.get(api_endpoint + '?expand_lemmas=true&lemma_text=' + self.search_query) axios.get(api_endpoint + self.query_lang + '/article' + '?expand_lemmas=true&lemma_text=' + self.search_query)
.then(function(response){ .then(function(response){
self.search_results = response.data self.search_results = response.data
}) })
} }
else else
{ {
axios.get(api_endpoint + '/' + self.article_id + '?expand_lemmas=true&expand_refs=true') axios.get(api_endpoint + self.path_lang + '/article' + '/' + self.article_id + '?expand_lemmas=true&expand_refs=true')
.then(function(response){ .then(function(response){
self.article = response.data self.article = response.data
}) })
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<div class=""> <div class="">
<h2 v-if="hits.length">Søkeresultater</h2> <h2 v-if="hits.length">Søkeresultater</h2>
<ul> <ul>
<li v-for="result in extended_results"> <li v-for="(result, index) in extended_results" :key="index">
<a :href="result.id">{{result.label}}</a> ({{result.classification}}) <a :href="lang + '/' + result.id">{{result.label}}</a> ({{result.classification}})
</li> </li>
</ul> </ul>
</div> </div>
...@@ -14,7 +14,8 @@ import helpers from '../utils/helpers.js' ...@@ -14,7 +14,8 @@ import helpers from '../utils/helpers.js'
export default { export default {
name: 'SearchResults', name: 'SearchResults',
props: { props: {
hits: Array hits: Array,
lang: String
}, },
computed: { computed: {
extended_results: function(){ extended_results: function(){
......
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