Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui-styleguide
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
TO
Weby
ui-styleguide
Commits
e0b56962
Commit
e0b56962
authored
4 years ago
by
xaralis
Browse files
Options
Downloads
Patches
Plain Diff
Persist selected view in URL on elections page
parent
aaf354f4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/_patterns/03-templates/elections.mustache
+1
-1
1 addition, 1 deletion
source/_patterns/03-templates/elections.mustache
source/js/components/ViewProvider.vue
+45
-9
45 additions, 9 deletions
source/js/components/ViewProvider.vue
with
46 additions
and
10 deletions
source/_patterns/03-templates/elections.mustache
+
1
−
1
View file @
e0b56962
...
...
@@ -2,7 +2,7 @@
{{>
organisms-elections-hero
}}
<div
class=
"__js-root"
>
<ui-view-provider
:initial=
"{candidates: true, program: false}"
v-slot=
"{ isCurrentView, toggleView }"
>
<ui-view-provider
:initial=
"{candidates: true, program: false}"
:sync-location=
"true"
v-slot=
"{ isCurrentView, toggleView }"
>
<main>
<div
class=
"container container--default pt-8 lg:py-24"
>
<div
class=
"text-center"
>
...
...
This diff is collapsed.
Click to expand it.
source/js/components/ViewProvider.vue
+
45
−
9
View file @
e0b56962
...
...
@@ -4,6 +4,7 @@
v-bind:views=
"views"
v-bind:isCurrentView=
"isCurrentView"
v-bind:toggleView=
"toggleView"
v-bind:showView=
"showView"
v-bind:setView=
"setView"
></slot>
</div>
...
...
@@ -14,11 +15,20 @@ export default {
props
:
{
initial
:
{
default
:
()
=>
{}
},
syncLocation
:
{
type
:
Boolean
,
default
:
false
,
},
locationParam
:
{
type
:
String
,
default
:
"
view
"
,
}
},
data
()
{
return
{
views
:
this
.
$props
.
initial
,
queryParams
:
null
,
keyListener
:
e
=>
{
// Esc
if
(
e
.
keyCode
===
27
)
{
...
...
@@ -27,21 +37,38 @@ export default {
}
};
},
watch
:
{
routeView
()
{
const
queryParams
=
new
URLSearchParams
(
window
.
location
.
search
);
}
},
methods
:
{
setView
(
viewId
,
show
)
{
setView
(
viewId
,
show
,
hideOthers
=
false
)
{
if
(
hideOthers
)
{
Object
.
keys
(
this
.
$data
.
views
).
forEach
(
key
=>
{
if
(
key
!==
viewId
)
{
this
.
setView
(
key
,
false
);
}
});
}
this
.
$data
.
views
[
viewId
]
=
show
;
if
(
show
&&
this
.
$props
.
syncLocation
)
{
const
queryParams
=
new
URLSearchParams
(
window
.
location
.
search
);
queryParams
.
set
(
this
.
$props
.
locationParam
,
viewId
);
history
.
pushState
(
null
,
null
,
"
?
"
+
queryParams
.
toString
());
}
},
setViews
(
updates
)
{
this
.
$data
.
views
=
Object
.
assign
({},
this
.
data
.
views
,
updates
);
},
toggleView
(
viewId
)
{
Object
.
keys
(
this
.
$data
.
views
).
forEach
(
key
=>
{
if
(
key
!==
viewId
)
{
this
.
setView
(
key
,
false
);
}
});
this
.
setView
(
viewId
,
!
this
.
isCurrentView
(
viewId
));
this
.
setView
(
viewId
,
!
this
.
isCurrentView
(
viewId
),
true
);
},
showView
(
viewId
)
{
this
.
setView
(
viewId
,
true
,
true
);
},
isCurrentView
(
viewId
)
{
return
this
.
$data
.
views
[
viewId
];
...
...
@@ -53,7 +80,16 @@ export default {
}
},
mounted
()
{
window
.
addEventListener
(
'
keydown
'
,
this
.
$data
.
keyListener
);;
window
.
addEventListener
(
'
keydown
'
,
this
.
$data
.
keyListener
);
if
(
this
.
$props
.
syncLocation
)
{
const
queryParams
=
new
URLSearchParams
(
window
.
location
.
search
);
const
locationView
=
queryParams
.
get
(
this
.
$props
.
locationParam
);
if
(
Object
.
keys
(
this
.
$data
.
views
).
indexOf
(
locationView
)
!==
-
1
)
{
this
.
showView
(
locationView
);
}
}
},
destroyed
()
{
window
.
removeEventListener
(
'
keydown
'
,
this
.
$data
.
keyListener
);
...
...
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