Skip to content

Commit 6fd253a

Browse files
🪄 Ajout de rendering conditionnel selon qu'on soit dans une iframe ou non (#1738)
* Fix fixtures installation * ename and comment * Rename * Fix selector * Fixtures * Missing proposition services * Disable test for now * Click on svg explicitely * Ignore file * Test * Add basic config * redirect http to https locally * wip * Remove sidebar * Add share / embed buttons * Improve spacing * Improve alignment on homepage * Add icon to footer * Missing produit * Add comment * Retours Delphine * Update wordings * WIP * Add header * WIP * Improve patchwork spacing * add contactez nous menu item * Use main menu instead * Use main menu * Add loupe in header * add conditionnal rendering * missing querystring * WIP * Improve querystring navigation * wip * WIP * Add iframe field to search form to customize links * Rely on session storage instead * Remove setting * WIP * Better persist querystring accross navigation * Better persist querystring accross navigation * cleanup
1 parent 5c95442 commit 6fd253a

File tree

10 files changed

+102
-17
lines changed

10 files changed

+102
-17
lines changed

‎.secrets.baseline‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@
9090
{
9191
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
9292
},
93-
{
94-
"path": "detect_secrets.filters.common.is_baseline_file",
95-
"filename": ".secrets.baseline"
96-
},
9793
{
9894
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
9995
"min_level": 2
@@ -142,7 +138,7 @@
142138
"filename": "core/settings.py",
143139
"hashed_secret": "1ee34e26aeaf89c64ecc2c85efe6a961b75a50e9",
144140
"is_verified": false,
145-
"line_number": 292
141+
"line_number": 295
146142
}
147143
],
148144
"dbt/package-lock.yml": [
@@ -191,5 +187,5 @@
191187
}
192188
]
193189
},
194-
"generated_at": "2025-06-25T12:33:12Z"
190+
"generated_at": "2025-07-01T21:48:21Z"
195191
}

‎core/settings.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ def context_processors():
256256
"sites_faciles.content_manager.context_processors.skiplinks",
257257
"sites_faciles.content_manager.context_processors.mega_menus",
258258
],
259+
"builtins": [
260+
"core.templatetags.iframe_tags",
261+
],
259262
},
260263
},
261264
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django import template
2+
from django.http.request import QueryDict
3+
4+
register = template.Library()
5+
6+
7+
@register.filter
8+
def iframe(querydict: QueryDict, template_path: str):
9+
"""
10+
Conditionally returns an iframe-specific template path based on query parameters.
11+
12+
This Django template filter checks whether the `"iframe"` parameter is present
13+
in the provided query dictionary (typically `request.GET`). If it is, the function
14+
returns a modified version of the `template_path` by replacing `.html` with
15+
`.iframe.html`. Otherwise, it returns the original path.
16+
17+
:param querydict: The GET parameters from the request (e.g., ``request.GET``).
18+
:type querydict: django.http.QueryDict
19+
:param template_path: The path to the default
20+
template (e.g., ``"components/header/base.html"``).
21+
:type template_path: str
22+
:return: The modified or original template path depending on the
23+
presence of ``"iframe"`` in the query.
24+
:rtype: str
25+
26+
**Example usage in a Django template**::
27+
28+
{% extends request.GET|iframe:"components/header/base.html" %}
29+
30+
This would extend either ``base.html`` or ``base.iframe.html`` depending on whether
31+
``?iframe`` is in the URL query string.
32+
"""
33+
alternative_path = template_path.replace("html", "iframe.html")
34+
35+
if "iframe" in querydict:
36+
return alternative_path
37+
38+
return template_path

‎qfdmd/forms.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class SearchForm(DsfrBaseForm):
2222
input = forms.CharField(
2323
help_text="Entrez un objet ou un déchet", required=False, widget=SearchInput
2424
)
25+
iframe = forms.BooleanField(
26+
required=False,
27+
help_text="Ce champ sert uniquement à faire persister le mode iframe d'une page"
28+
"à une recherche",
29+
widget=forms.HiddenInput,
30+
)
2531

2632
def search(self) -> dict[str, str]:
2733
search_query: str = self.cleaned_data.get("input")

‎static/to_compile/controllers/assistant/state.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SearchFormController from "../carte/search_solution_form_controller"
66
export default class extends Controller<HTMLElement> {
77
static values = {
88
location: Object,
9+
iframe: Boolean,
910
}
1011
static outlets = ["address-autocomplete", "search-solution-form"]
1112
declare addressAutocompleteOutlets: Array<AdresseAutocompleteController>
@@ -15,12 +16,34 @@ export default class extends Controller<HTMLElement> {
1516
latitude: string | null
1617
longitude: string | null
1718
}
19+
declare iframeValue: boolean
1820

1921
connect() {
20-
document.addEventListener(
21-
"turbo:frame-load",
22-
this.fetchLocationFromSessionStorageOnFirstLoad.bind(this),
23-
)
22+
document.addEventListener("turbo:frame-load", this.#initRecurringEvents.bind(this))
23+
}
24+
25+
#initRecurringEvents(event) {
26+
/**
27+
These methods must be called every time we add elements to the dom through a turbo-frame
28+
so that all new DOM nodes get updated.
29+
*/
30+
this.fetchLocationFromSessionStorageOnFirstLoad(event)
31+
this.configureIframeSpecificUI()
32+
}
33+
34+
configureIframeSpecificUI() {
35+
if (sessionStorage.getItem("iframe") === "true") {
36+
this.iframeValue = true
37+
}
38+
39+
if (this.iframeValue) {
40+
document.querySelectorAll<HTMLLinkElement>('a[href^="/"]').forEach((link) => {
41+
const url = new URL(link.href, window.location.origin)
42+
url.searchParams.set("iframe", "1")
43+
link.href = url.toString()
44+
})
45+
sessionStorage.setItem("iframe", "true")
46+
}
2447
}
2548

2649
fetchLocationFromSessionStorageOnFirstLoad(event) {

‎templates/components/button.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
data-testid="{{ testid }}"
55
{% endif %}
66
class="fr-btn fr-btn--secondary {{ class }}"
7-
href="{{ href }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}"
7+
href="{{ href }}"
88
>
99
{{ text }}
1010
</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "dsfr/header.html" %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% if not assistant.is_home %}
2+
<header role="banner" class="fr-container qf-filter-none fr-header max-md:qf-hidden">
3+
<div class="fr-header__body">
4+
<div class="fr-container">
5+
<div class="fr-header__body-row">
6+
{% block brand %}
7+
{% endblock brand %}
8+
9+
{% block header_search %}
10+
{% endblock header_search %}
11+
</div>
12+
</div>
13+
</div>
14+
</header>
15+
{% endif %}

‎templates/components/header/header.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{% extends "dsfr/header.html" %}
1+
{% extends request.GET|iframe:"components/header/base.html" %}
2+
23
{% load menu_tags static %}
34

45
{% block header_search %}

‎templates/qfdmd/base.html‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
data-state-adresse-value=""
4949
data-state-longitude-value=""
5050
data-state-latitude-value=""
51+
{% if "iframe" in request.GET %}
52+
data-state-iframe-value="true"
53+
{% endif %}
5154
data-state-map-outlet="[data-controller='map']"
5255
data-state-address-autocomplete-outlet="[data-controller='address-autocomplete']"
5356
data-state-search-solution-form-outlet="[data-controller='search-solution-form']"
@@ -70,11 +73,10 @@
7073
Vous êtes bien authentifié, vos statistiques PostHog seront ignorées pour cette session | <a href="{% url 'admin:index' %}">accéder à l'administration</a>
7174
</div>
7275
{% endif %}
73-
{% if not assistant.is_iframe %}
74-
{% block header %}
75-
{% include "components/header/header.html" %}
76-
{% endblock header %}
77-
{% endif %}
76+
77+
{% block header %}
78+
{% include "components/header/header.html" %}
79+
{% endblock header %}
7880

7981
{% block pre_main %}
8082
{% endblock pre_main %}

0 commit comments

Comments
 (0)