Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
monnaie-libre-fr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websites
monnaie-libre-fr
Commits
2ebad4ec
Commit
2ebad4ec
authored
3 years ago
by
Emmanuel Salomon
Browse files
Options
Downloads
Patches
Plain Diff
Bind url query to ressources filters
parent
a71b5f05
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
components/layout/LayoutFooter.vue
+5
-2
5 additions, 2 deletions
components/layout/LayoutFooter.vue
components/search/SearchContainer.vue
+11
-3
11 additions, 3 deletions
components/search/SearchContainer.vue
pages/ressources.vue
+32
-2
32 additions, 2 deletions
pages/ressources.vue
with
48 additions
and
7 deletions
components/layout/LayoutFooter.vue
+
5
−
2
View file @
2ebad4ec
...
...
@@ -21,7 +21,7 @@
class=
"flex"
>
<template
#button
="
{ onClick }">
<t-button
@
click=
"onClick"
class=
"w-full lg:w-max"
>
<t-button
class=
"w-full lg:w-max"
@
click=
"onClick"
>
<fa
icon=
"heart"
></fa><span
class=
"ml-2"
>
Je participe !
</span>
</t-button>
</
template
>
...
...
@@ -59,7 +59,10 @@
<li
v-for=
"category in categories"
:key=
"category.title"
>
<nuxt-link
class=
"hover:underline"
:to=
"`/ressources?cat=${category.title}`"
:to=
"{
path: 'ressources',
query: { filters: category.title },
}"
>
{{ category.title }}
</nuxt-link>
...
...
This diff is collapsed.
Click to expand it.
components/search/SearchContainer.vue
+
11
−
3
View file @
2ebad4ec
...
...
@@ -108,6 +108,14 @@ export default {
type
:
Function
,
required
:
true
,
}
,
getQueryUrl
:
{
type
:
Function
,
default
(
q
)
{
return
new
URLSearchParams
({
q
,
}
)
}
,
}
,
}
,
data
()
{
return
{
...
...
@@ -136,10 +144,8 @@ export default {
methods
:
{
async
search
(
force
)
{
const
query
=
this
.
query
.
trim
()
let
queryUrl
=
null
if
(
query
.
length
||
force
)
{
queryUrl
=
encodeURIComponent
(
query
)
const
results
=
await
this
.
searchFunction
(
this
.
query
)
if
(
results
.
length
)
{
...
...
@@ -154,10 +160,12 @@ export default {
this
.
hasNoResult
=
false
}
// Replace url with query string
const
queryUrl
=
this
.
getQueryUrl
(
query
).
toString
()
history
.
replaceState
(
{
}
,
null
,
this
.
$route
.
path
+
(
queryUrl
?
`?
q=
${queryUrl
}
`
:
''
)
this
.
$route
.
path
+
(
queryUrl
.
length
?
`?${queryUrl
}
`
:
''
)
)
}
,
}
,
...
...
This diff is collapsed.
Click to expand it.
pages/ressources.vue
+
32
−
2
View file @
2ebad4ec
...
...
@@ -5,6 +5,7 @@
:results=
"results"
:search-placeholder=
"$t('ressources.searchPlaceholder')"
:search-function=
"searchFunction"
:get-query-url=
"getQueryUrl"
>
<RessourcesSubmitModal
slot=
"search"
/>
...
...
@@ -32,11 +33,13 @@
<
script
>
import
categories
from
'
~/static/settings/categories.json
'
const
defaultSelected
=
'
Mises en avant
'
export
default
{
name
:
'
RessourcesPage
'
,
async
asyncData
({
$content
})
{
const
results
=
await
$content
(
'
ressources
'
)
.
where
({
categories
:
{
$containsAny
:
'
Mises en avant
'
}
})
.
where
({
categories
:
{
$containsAny
:
defaultSelected
}
})
.
sortBy
(
'
featured
'
,
'
asc
'
)
.
fetch
()
...
...
@@ -48,7 +51,7 @@ export default {
const
allCategories
=
categories
.
ressources
.
map
((
cat
)
=>
cat
.
title
)
return
{
categories
:
allCategories
,
selectedCategories
:
[
'
Mises en avant
'
],
// allCategories,
selectedCategories
:
[
defaultSelected
],
// allCategories,
}
},
watch
:
{
...
...
@@ -56,6 +59,14 @@ export default {
this
.
$refs
.
searchContainer
.
search
(
true
)
},
},
mounted
()
{
// Get url params
const
query
=
this
.
$route
.
query
if
(
query
.
filters
)
this
.
selectedCategories
=
Array
.
isArray
(
query
.
filters
)
?
query
.
filters
:
[
query
.
filters
]
},
methods
:
{
async
searchFunction
(
query
)
{
return
await
this
.
$content
(
'
ressources
'
)
...
...
@@ -64,6 +75,25 @@ export default {
.
sortBy
(
'
title
'
,
'
asc
'
)
.
fetch
()
},
getQueryUrl
(
query
)
{
const
params
=
new
URLSearchParams
()
if
(
query
.
length
)
params
.
set
(
'
q
'
,
query
)
if
(
this
.
selectedCategories
.
length
===
1
)
{
if
(
this
.
selectedCategories
[
0
]
!==
defaultSelected
)
{
params
.
set
(
'
filters
'
,
this
.
selectedCategories
[
0
])
}
}
else
if
(
this
.
selectedCategories
.
length
>
1
)
{
if
(
this
.
selectedCategories
.
length
===
this
.
categories
.
length
)
{
params
.
set
(
'
filters
'
,
'
all
'
)
}
else
{
this
.
selectedCategories
.
forEach
((
cat
)
=>
params
.
append
(
'
filters
'
,
cat
)
)
}
}
return
params
},
},
}
</
script
>
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