adding 'la suite territoriale' specific gaufre button/endpoint

This commit is contained in:
Emmanuel Pelletier
2024-05-02 12:58:24 +02:00
parent 001ca61773
commit c041c77360
9 changed files with 300 additions and 232 deletions

View File

@@ -66,11 +66,10 @@
iframe.width = "304"
iframe.height = "360"
iframe.style.cssText = "display: none !important"
const { host, protocol } = new URL(scriptTag.src)
const searchParams = new URLSearchParams(scriptTag.src)
const anct = searchParams.get("type") === "anct"
const { host, protocol, searchParams } = new URL(scriptTag.src)
const local = searchParams.get("type") === "local"
const lang = ["en"].includes(searchParams.get("lang")) ? searchParams.get("lang") : null
iframe.src = `${protocol}//${host}/api/v1/${(!!lang && `${lang}/`) || ""}gaufre${(!!anct && "?type=anct") || ""}`
iframe.src = `${protocol}//${host}/api/v1/${(!!lang && `${lang}/`) || ""}gaufre${(!!local && "/local") || ""}`
document.body.appendChild(iframe)
}

View File

@@ -0,0 +1,224 @@
---
import { Image } from "astro:assets"
const logos = import.meta.glob<{ default: ImageMetadata }>("/src/assets/logos/*.{svg,png,jpg}")
const { services } = Astro.props
---
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>Services de La Suite numérique</title>
<style is:inline>
@font-face {
font-family: Marianne;
src: url("/fonts/Marianne-Regular-subset.woff2") format("woff2");
font-weight: 400;
font-display: swap;
}
@font-face {
font-family: "Marianne fallback";
src: local("Arial");
ascent-override: 103.16%;
descent-override: 23.35%;
line-gap-override: 0%;
size-adjust: 109.64%;
}
* {
box-sizing: border-box;
}
html,
body,
.lasuite-Services {
height: 100vh;
max-height: 22rem;
}
html {
font-size: 100%;
font-family: Marianne, "Marianne fallback", BlinkMacSystemFont, "Segoe UI", "Noto Sans",
Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}
body {
margin: 0 0 0.5rem;
background: transparent;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
.fr-sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; /* added line */
border: 0;
display: block;
}
.fr-enlarge-link {
position: relative;
}
.fr-enlarge-link a {
background-image: none;
outline-width: 0;
}
.fr-enlarge-link a::before {
content: "";
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
outline-offset: 2px;
outline-style: inherit;
outline-color: inherit;
outline-width: 2px;
z-index: 1;
}
.lasuite-Services {
background-color: #01018fcc;
padding: 3px;
width: 19rem;
border-radius: 8px;
filter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.07)) drop-shadow(0 2px 2px rgb(0 0 0 / 0.06));
overflow: hidden;
}
.lasuite-Services-outer {
height: 100%;
border-radius: 6px;
overflow: hidden;
}
.lasuite-Services-inner {
border-radius: 2px;
background-color: white;
height: 100%;
overflow: auto;
}
.lasuite-Service {
display: flex;
align-items: center;
padding: 1rem 2rem;
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
}
.lasuite-Service:hover,
.lasuite-Service:focus-within {
background-color: #f0f0fa;
border-top: 1px solid #8989cd;
border-bottom: 1px solid #8989cd;
}
.lasuite-Service-icon {
display: flex;
align-items: center;
width: 40px;
height: 40px;
}
.lasuite-Service-name {
margin-left: 1.5rem;
text-decoration: none;
color: #161616;
}
.lasuite-Service-name:focus {
outline: 0;
}
.scrollbars {
scrollbar-width: thin;
scrollbar-color: #aaa transparent;
}
.scrollbars::-webkit-scrollbar {
width: 5px;
height: 5px;
}
.scrollbars::-webkit-scrollbar-track {
background: 0 0;
}
.scrollbars::-webkit-scrollbar-thumb {
background-color: #ddd;
border-radius: 6px;
}
.scrollbars:not(:hover, :focus) {
scrollbar-color: transparent transparent;
}
.scrollbars:not(:hover, :focus):-webkit-scrollbar-thumb {
background-color: transparent;
}
#lasuite-service-suite-numerique {
font-size: 0.85rem;
opacity: 0.75;
}
</style>
</head>
<body>
<div class="lasuite-Services">
<div class="lasuite-Services-outer">
<h1 class="fr-sr-only">Liste des services de La Suite numérique</h1>
<ul class="lasuite-Services-inner scrollbars">
{
services
.filter(({ enabled }) => !!enabled)
.map(({ id, name, url }, i) => {
const logo =
logos[`/src/assets/logos/${id}.svg`] ||
logos[`/src/assets/logos/${id}.jpg`] ||
logos[`/src/assets/logos/${id}.png`]
return (
<li>
<div class="lasuite-Services-item lasuite-Service fr-enlarge-link">
<div class="lasuite-Service-icon">
{!!logo ? (
<Image src={logo()} width="40" height="40" alt="" loading="eager" />
) : null}
</div>
<a
target="_parent"
class="lasuite-Service-name"
href={url}
id={`lasuite-service-${id}`}
{...((i === 0 && { autofocus: true }) || {})}
>
{name}
</a>
</div>
</li>
)
})
}
</ul>
</div>
</div>
<script>
document.addEventListener("keyup", (event) => {
if (event.key === "Escape") {
window.parent.postMessage("lasuite-close-services-iframe", "*")
}
})
</script>
</body>
</html>

View File

@@ -91,6 +91,10 @@ votre `<head>` :
lang="html"
/>
Si vous voulez afficher la liste des services de La Suite territoriale, remplacez `src` par :
<Code code={`${import.meta.env.PUBLIC_LASUITE_API_URL}/api/v1/gaufre.js?type=local`} lang="text" />
:::note
Pour que le script fonctionne il est nécessaire qu'il ait un id `lasuite-gaufre-script`. Ne

View File

@@ -74,13 +74,17 @@ https://integration.lasuite.numerique.gouv.fr/api/v1/gaufre.js
- Méthode : GET
- Retourne : le JavaScript s'occupant d'afficher la popup listant les services de La Suite au clic
sur le bouton [Gaufre](/guides/gaufre)
- Ajouter `?type=local` en paramètre pour afficher la liste des services de La Suite territoriale
## Liste des services de La Suite
`https://integration.lasuite.numerique.gouv.fr/api/v1/services.json`
```
https://integration.lasuite.numerique.gouv.fr/api/v1/services.json
https://integration.lasuite.numerique.gouv.fr/api/v1/services-local.json
```
Retourne un tableau JSON listant les services de La Suite numérique. Chaque service a cette
structure :
Retourne un tableau JSON listant les services de La Suite numérique ou de La Suite territoriale.
Chaque service a cette structure :
- `id` l'identifiant du service, utilisé par d'autres APIs,
- `name` le nom du service,

View File

@@ -0,0 +1,29 @@
[
{
"id": "grist",
"name": "Tableur collaboratif",
"url": "https://grist.incubateur.net/",
"tagline": "**Grist**, une feuille de calcul simple, <br>flexible, moderne et open source <br>qui va au-delà de la grille.",
"homepageType": "proconnect",
"entity": "Gouvernement",
"enabled": true
},
{
"id": "messagerie",
"name": "Messagerie",
"url": "https://webmail.numerique.gouv.fr/appsuite/",
"tagline": "**Messagerie** de l'État <br>le mail simple, centralisé et sécurisé",
"homepageType": "email",
"entity": "Gouvernement",
"enabled": true
},
{
"id": "resana",
"name": "Stockage",
"url": "https://resana.numerique.gouv.fr/public/",
"tagline": "**Resana** <br>groupes de travail <br>et suite collaborative en ligne",
"homepageType": "email-or-proconnect",
"entity": "Gouvernement",
"enabled": true
}
]

View File

@@ -1,224 +1,6 @@
---
import services from "@/data/services.json"
import { Image } from "astro:assets"
const logos = import.meta.glob<{ default: ImageMetadata }>("/src/assets/logos/*.{svg,png,jpg}")
import GaufrePage from "@/components/GaufrePage.astro"
---
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>Services de La Suite numérique</title>
<style is:inline>
@font-face {
font-family: Marianne;
src: url("/fonts/Marianne-Regular-subset.woff2") format("woff2");
font-weight: 400;
font-display: swap;
}
@font-face {
font-family: "Marianne fallback";
src: local("Arial");
ascent-override: 103.16%;
descent-override: 23.35%;
line-gap-override: 0%;
size-adjust: 109.64%;
}
* {
box-sizing: border-box;
}
html,
body,
.lasuite-Services {
height: 100vh;
max-height: 22rem;
}
html {
font-size: 100%;
font-family: Marianne, "Marianne fallback", BlinkMacSystemFont, "Segoe UI", "Noto Sans",
Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}
body {
margin: 0 0 0.5rem;
background: transparent;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
.fr-sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; /* added line */
border: 0;
display: block;
}
.fr-enlarge-link {
position: relative;
}
.fr-enlarge-link a {
background-image: none;
outline-width: 0;
}
.fr-enlarge-link a::before {
content: "";
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
outline-offset: 2px;
outline-style: inherit;
outline-color: inherit;
outline-width: 2px;
z-index: 1;
}
.lasuite-Services {
background-color: #01018fcc;
padding: 3px;
width: 19rem;
border-radius: 8px;
filter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.07)) drop-shadow(0 2px 2px rgb(0 0 0 / 0.06));
overflow: hidden;
}
.lasuite-Services-outer {
height: 100%;
border-radius: 6px;
overflow: hidden;
}
.lasuite-Services-inner {
border-radius: 2px;
background-color: white;
height: 100%;
overflow: auto;
}
.lasuite-Service {
display: flex;
align-items: center;
padding: 1rem 2rem;
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
}
.lasuite-Service:hover,
.lasuite-Service:focus-within {
background-color: #f0f0fa;
border-top: 1px solid #8989cd;
border-bottom: 1px solid #8989cd;
}
.lasuite-Service-icon {
display: flex;
align-items: center;
width: 40px;
height: 40px;
}
.lasuite-Service-name {
margin-left: 1.5rem;
text-decoration: none;
color: #161616;
}
.lasuite-Service-name:focus {
outline: 0;
}
.scrollbars {
scrollbar-width: thin;
scrollbar-color: #aaa transparent;
}
.scrollbars::-webkit-scrollbar {
width: 5px;
height: 5px;
}
.scrollbars::-webkit-scrollbar-track {
background: 0 0;
}
.scrollbars::-webkit-scrollbar-thumb {
background-color: #ddd;
border-radius: 6px;
}
.scrollbars:not(:hover, :focus) {
scrollbar-color: transparent transparent;
}
.scrollbars:not(:hover, :focus):-webkit-scrollbar-thumb {
background-color: transparent;
}
#lasuite-service-suite-numerique {
font-size: 0.85rem;
opacity: 0.75;
}
</style>
</head>
<body>
<div class="lasuite-Services">
<div class="lasuite-Services-outer">
<h1 class="fr-sr-only">Liste des services de La Suite numérique</h1>
<ul class="lasuite-Services-inner scrollbars">
{
services
.filter(({ enabled }) => !!enabled)
.map(({ id, name, url }, i) => {
const logo =
logos[`/src/assets/logos/${id}.svg`] ||
logos[`/src/assets/logos/${id}.jpg`] ||
logos[`/src/assets/logos/${id}.png`]
return (
<li>
<div class="lasuite-Services-item lasuite-Service fr-enlarge-link">
<div class="lasuite-Service-icon">
{!!logo ? (
<Image src={logo()} width="40" height="40" alt="" loading="eager" />
) : null}
</div>
<a
target="_parent"
class="lasuite-Service-name"
href={url}
id={`lasuite-service-${id}`}
{...((i === 0 && { autofocus: true }) || {})}
>
{name}
</a>
</div>
</li>
)
})
}
</ul>
</div>
</div>
<script>
document.addEventListener("keyup", (event) => {
if (event.key === "Escape") {
window.parent.postMessage("lasuite-close-services-iframe", "*")
}
})
</script>
</body>
</html>
<GaufrePage services={services} />

View File

@@ -0,0 +1,6 @@
---
import services from "@/data/services-local.json"
import GaufrePage from "@/components/GaufrePage.astro"
---
<GaufrePage services={services} />

View File

@@ -0,0 +1,18 @@
import type { APIContext } from "astro"
import services from "@/data/services-local.json"
export async function GET({ url }: APIContext) {
const response = new Response(
JSON.stringify(
services
.filter(({ enabled }) => !!enabled)
.map((service) => ({
id: service.id,
name: service.name,
url: new URL(`/services/${service.id}`, url).toString(),
})),
),
)
response.headers.set("Content-Type", "application/json")
return response
}

View File

@@ -4,11 +4,13 @@ import services from "@/data/services.json"
export async function GET({ url }: APIContext) {
const response = new Response(
JSON.stringify(
services.map((service) => ({
id: service.id,
name: service.name,
url: new URL(`/services/${service.id}`, url).toString(),
})),
services
.filter(({ enabled }) => !!enabled)
.map((service) => ({
id: service.id,
name: service.name,
url: new URL(`/services/${service.id}`, url).toString(),
})),
),
)
response.headers.set("Content-Type", "application/json")