Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beta.ordbok.uib.no
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Margunn.Rauset
beta.ordbok.uib.no
Commits
833329da
Commit
833329da
authored
4 years ago
by
Ole Voldsæter
Browse files
Options
Downloads
Patches
Plain Diff
refaktorering av API-spørringer
parent
71a2f5b0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/App.vue
+12
-6
12 additions, 6 deletions
src/App.vue
with
12 additions
and
6 deletions
src/App.vue
+
12
−
6
View file @
833329da
...
...
@@ -68,8 +68,11 @@ axios.interceptors.request.use(function (config) {
window
.
onpopstate
=
function
(
event
)
{
if
(
event
.
state
)
{
// eslint-disable-next-line
app
.
__vue__
.
_data
.
article
=
event
.
state
.
article
// eslint-disable-next-line
app
.
__vue__
.
_data
.
search_results
=
event
.
state
.
search_results
// eslint-disable-next-line
app
.
__vue__
.
_data
.
lang
=
event
.
state
.
lang
}
}
...
...
@@ -86,11 +89,14 @@ export default {
}
},
computed
:
{
api_pref
:
function
()
{
return
api_endpoint
+
'
/
'
+
this
.
lang
+
'
/article/
'
},
search
:
function
()
{
let
self
=
this
return
function
(
q
)
{
return
new
Promise
(
resolve
=>
{
return
axios
.
get
(
api_endpoint
+
'
/
'
+
self
.
lang
+
'
/article/
suggest?q=
'
+
q
).
then
(
return
axios
.
get
(
self
.
api_pref
+
'
suggest?q=
'
+
q
).
then
(
function
(
response
)
{
let
hits
=
q
.
length
?
[{
q
:
q
}]
:
[]
hits
=
hits
.
concat
(
response
.
data
.
suggest
.
suggest
[
0
].
options
.
sort
((
o1
,
o2
)
=>
o1
.
text
.
length
-
o2
.
text
.
length
))
...
...
@@ -119,7 +125,7 @@ export default {
var
self
=
this
self
.
waiting
=
true
self
.
article
=
{
lemmas
:
[],
body
:{
pronunciation
:
[],
definitions
:
[],
etymology
:
[]}}
axios
.
get
(
api_endpoint
+
'
/
'
+
self
.
lang
+
'
/article/
search?q=
'
+
event
.
q
+
'
'
+
event
.
q
+
'
*&size=20
'
)
axios
.
get
(
self
.
api_pref
+
'
search?q=
'
+
event
.
q
+
'
'
+
event
.
q
+
'
*&size=20
'
)
.
then
(
function
(
response
){
self
.
$router
.
push
(
'
/
'
+
`/search?q=
${
event
.
q
}
&lang=
${
self
.
lang
}
`
)
self
.
search_results
=
response
.
data
.
hits
.
hits
...
...
@@ -136,7 +142,7 @@ export default {
}
else
{
self
.
article
=
{
lemmas
:
[],
body
:{
pronunciation
:
[],
definitions
:
[],
etymology
:
[]}}
self
.
waiting
=
true
axios
.
get
(
api_endpoint
+
'
/
'
+
self
.
lang
+
'
/article/
'
+
item
.
article_id
)
axios
.
get
(
self
.
api_pref
+
'
'
+
item
.
article_id
)
.
then
(
function
(
response
){
self
.
article
=
response
.
data
.
_source
self
.
waiting
=
false
...
...
@@ -154,7 +160,7 @@ export default {
this
.
lang
=
this
.
$route
.
params
.
lang
||
this
.
$route
.
query
.
lang
||
'
bob,nob
'
var
self
=
this
;
if
(
this
.
$route
.
query
.
q
)
{
axios
.
get
(
api_endpoint
+
'
/
'
+
self
.
lang
+
'
/article/
search?q=
'
+
self
.
$route
.
query
.
q
+
'
'
+
self
.
$route
.
query
.
q
+
'
*&size=20
'
)
axios
.
get
(
self
.
api_pref
+
'
search?q=
'
+
self
.
$route
.
query
.
q
+
'
'
+
self
.
$route
.
query
.
q
+
'
*&size=20
'
)
.
then
(
function
(
response
){
self
.
search_results
=
response
.
data
.
hits
.
hits
self
.
waiting
=
false
...
...
@@ -162,7 +168,7 @@ export default {
})
}
else
if
(
this
.
$route
.
params
.
id
){
axios
.
get
(
api_endpoint
+
'
/
'
+
self
.
lang
+
'
/article/
'
+
self
.
$route
.
params
.
id
)
axios
.
get
(
self
.
api_pref
+
'
'
+
self
.
$route
.
params
.
id
)
.
then
(
function
(
response
){
self
.
article
=
response
.
data
.
_source
self
.
waiting
=
false
...
...
@@ -175,7 +181,7 @@ export default {
}
},
watch
:
{
$route
(
to
,
from
)
{
$route
()
{
this
.
lang
=
this
.
$route
.
params
.
lang
||
this
.
$route
.
query
.
lang
||
'
bob,nob
'
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment