From a17d865ce9e70551f3a7d1d2857b86c1d8a65c60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole=20Volds=C3=A6ter?= <ole.voldsater@uib.no>
Date: Tue, 11 Feb 2020 14:18:34 +0100
Subject: [PATCH] =?UTF-8?q?refs=20meta#30=20bokm=C3=A5l=20og=20nynorsk?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/App.vue                      | 21 +++++++++++++++------
 src/components/SearchResults.vue |  7 ++++---
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/App.vue b/src/App.vue
index 52cd5eb5..be668a75 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 637115b0..76164789 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(){
-- 
GitLab