diff --git a/src/App.vue b/src/App.vue index 52cd5eb5d4423fe281bf492383675870baf031e0..be668a75d41dc7cf06647b9a87f545b02753039b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,9 +4,14 @@ <div class=""> <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!"> </form> </div> - <SearchResults :hits="search_results" /> + <SearchResults :hits="search_results" :lang="query_lang" /> <Article :article="article" /> </div> </template> @@ -18,14 +23,18 @@ import SearchResults from './components/SearchResults.vue' //import Autocomplete from '@trevoreyre/autocomplete-vue' //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 { name: 'app', data: function() { + let params = new URLSearchParams(window.location.search.substring(1)) + let path = window.location.href.split("/") return { - article_id: parseInt(window.location.href.split("/").pop()), - search_query: window.location.href.split("?q=")[1], + article_id: parseInt(path.pop()), + search_query: params.get('q'), + query_lang: params.get('lang'), + path_lang: path.pop(), search_results: [], article: {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}}, /*search: function(q) { @@ -73,14 +82,14 @@ export default { mounted: function(){ var self = this; 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){ self.search_results = response.data }) } 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){ self.article = response.data }) diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index 637115b063d6a5a68a56b1361988e37d5eab0894..7616478953cf71e81e04cee68f6658933440fa0e 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -2,8 +2,8 @@ <div class=""> <h2 v-if="hits.length">Søkeresultater</h2> <ul> - <li v-for="result in extended_results"> - <a :href="result.id">{{result.label}}</a> ({{result.classification}}) + <li v-for="(result, index) in extended_results" :key="index"> + <a :href="lang + '/' + result.id">{{result.label}}</a> ({{result.classification}}) </li> </ul> </div> @@ -14,7 +14,8 @@ import helpers from '../utils/helpers.js' export default { name: 'SearchResults', props: { - hits: Array + hits: Array, + lang: String }, computed: { extended_results: function(){