Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves issue #7 #15

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion public/manifest-chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"default_title": "NumÉcoDiag"
},
"permissions": [
"storage"
"storage",
"tabs"
]
}
3 changes: 2 additions & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"permissions": [
"storage"
"storage",
"tabs"
]
}
13 changes: 13 additions & 0 deletions public/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" type="image/png" href="./static/numecodiag-logo-48x48.png" />
<link rel="stylesheet" href="./assets/options.css" />
<title>NumÉcoDiag | Options</title>
<script defer src="./assets/options.js"></script>
</head>
<body>
</body>
</html>
30 changes: 22 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
# NumÉcoDiag

Cette WebExtension développée et mise à disposition gratuitement par la [MiNumEco](https://ecoresponsable.numerique.gouv.fr/) facilite l’auto-diagnostic de l’écoconception d’un service numérique, conformément au [Référentiel Général d'Écoconception de Services Numériques](https://ecoresponsable.numerique.gouv.fr/publications/referentiel-general-ecoconception/) (RGESN).
Cette webExtension développée et mise à disposition gratuitement par la [MiNumEco](https://ecoresponsable.numerique.gouv.fr/) facilite l’auto-diagnostic de l’écoconception d’un service numérique, conformément au [Référentiel Général d'Écoconception de Services Numériques](https://ecoresponsable.numerique.gouv.fr/publications/referentiel-general-ecoconception/) (RGESN).

Réalisation : [Pôle écoconception Temesis](https://www.temesis.com/).

## Installation
## Installation de l'extension

* [Firefox](https://addons.mozilla.org/fr/firefox/addon/num%C3%A9codiag/)
* [Chrome](https://chrome.google.com/webstore/detail/num%C3%A9codiag/fhdeahmddgflanbgilcglipaeofmcabc)
* Edge (à venir, utiliser en attendant l'extension [Chrome](https://chrome.google.com/webstore/detail/num%C3%A9codiag/fhdeahmddgflanbgilcglipaeofmcabc))

## Installation manuelle

### Installer en tant que webExtension

1. Installer [nodeJS](https://nodejs.org/fr/) (v16 minimum) et le gestionnaire de paquets NPM.
2. Dans un terminal, depuis le dossier téléchargé, lancer la commande `npm install` pour télécharger / installer les dépendances de développement du projet.
3. Dans le même terminal, lancer ensuite la commande `npm run build` pour construire l'application depuis les sources fournies.
4. Procédure d'installation spécifique
- Sur Firefox : charger l'extension depuis l'adresse `about:debbuging` en sélectionnant le fichier `public/manifest.json`.
- Sur Chrome :
1. Renommer le fichier `/public/manifest-chrome.json` en `manifest.json`.
2. Charger l'extension depuis l'adresse `chrome://extensions/` en sélectionnant le dossier `public`.
5. L'accès au popup se fait depuis la partie supérieure droite du navigateur.
4. Procédure d'installation spécifique aux navigateurs web :
* Sur Firefox : charger l'extension depuis l'adresse "about:debbuging" en sélectionnant le fichier "public/manifest.json".
* Sur Chrome :
1. Supprimer le fichier "/public/manifest.json".
2. Renommer le fichier "/public/manifest-chrome.json" en "manifest.json".
3. Charger l'extension depuis l'adresse "chrome://extensions/" en sélectionnant le dossier "public".

### Utiliser en tant que webApplication

1. Installer [nodeJS](https://nodejs.org/fr/) (v16 minimum) et le gestionnaire de paquets NPM.
2. Dans un terminal, depuis le dossier téléchargé, lancer la commande `npm install` pour télécharger / installer les dépendances de développement du projet.
3. Dans le même terminal, lancer ensuite la commande `npm run dev` pour travailler sur le projet.
4. Passer la valeur de la constante `webAppMode` du fichier "/src/modules/webAppMode.mjs" à `true.
5. Se rendre à l'adresse "http://localhost:37271/".

### Différences entre les deux versions

* La webExtension utilise l'[API storage](https://developer.mozilla.org/fr/docs/Mozilla/Add-ons/webExtensions/API/storage) alors que la webApplication l'application utilise l'[API Web Storage](https://developer.mozilla.org/fr/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API).

## Licences

Expand Down
98 changes: 54 additions & 44 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,59 @@ function serve() {
};
}

export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/assets/app.js'
export default [
{
input: 'src/app.js',
output: {
format: 'iife',
name: 'app',
file: 'public/assets/app.js'
},
plugins: [
svelte({
compilerOptions: {
dev: !production
}
}),
css({ output: 'app.css' }),
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
!production && serve(),
!production && livereload('public'),
production && terser()
],
watch: {
clearScreen: false
}
},
plugins: [
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production
}
}),
// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: 'app.css' }),

// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),

// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),

// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),

// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
{
input: 'src/options.js',
output: {
format: 'iife',
name: 'app',
file: 'public/assets/options.js'
},
plugins: [
svelte({
compilerOptions: {
dev: !production
}
}),
css({ output: 'options.css' }),
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
!production && serve(),
!production && livereload('public'),
production && terser()
],
watch: {
clearScreen: false
}
}
};
];
163 changes: 19 additions & 144 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<script>

/* ### VARIABLES ### */
/* ### IMPORTS ### */

// Shared code
import { getLocalData, setLocalData, getAudits, getRGESN } from './modules/helpers.mjs';

// Svelte components
import Navigation from './components/Navigation.svelte';
import Results from './components/Results.svelte';
import AuditForm from './components/AuditForm.svelte';
import Options from './components/Options.svelte';
import About from './components/About.svelte';
import Header from './components/Header.svelte';

// const versions = ['v1']; // Available versions (stored in /public/rgesn)

/* ### VARIABLES ### */

let defaultVersion = 'v1';
let referential; // RGESN content
let index = 0; // Current audit index identifier
Expand All @@ -25,65 +29,10 @@
}
];
let render = false; // Makes Results & AuditForm components reactives
const env = window.browser === undefined ? window.chrome : window.browser; // Makes extension cross platform

/* ### FUNCTIONS ### */

function getRGESN(versionToLoad) {
return new Promise((resolve, reject) => {
fetch(`./rgesn/${versionToLoad}.json`)
.then((resp) => {
if(resp.ok) {
resp.text()
.then((data) => {
try {
resolve(JSON.parse(data));
}
catch(e) {
reject('Lecture du référentiel impossible');
}
}
)
}
else {
reject('Ouverture du référentiel impossible');
}
}
)
})
.then((data) => referential = data)
.catch((error) => console.error(error));
}

function changeRGESN(versionToApply) {
if(versionToApply !== audits[index].selectedVersion) {
if(resetAudit(versionToApply)) {
getRGESN(versionToApply);
}
}
else {
alert("Vous utilisez déjà cette version du référentiel");
}
}

function resetAudit(currentVersion = defaultVersion) {
if(confirm("Attention : cette action entraîne la perte de toutes les données non exportées saisies jusqu'à présent. Souhaitez-vous poursuivre ?")) {
// Udpates runtime values
audits[index].byCriteria = {};
audits[index].byCounters.satisfied = 0;
audits[index].byCounters.rejected = 0;
audits[index].byCounters.notApplicable = 0;
audits[index].selectedVersion = currentVersion;
// Udpates storage
env.storage.local.set({'audits': JSON.stringify(audits)});
// Updates view
render = !render;
return true;
}
return false
}

function updateAudit(e) {
function setAudit(e) {
const criterion = {
prop: e.detail.prop,
id: e.detail.criterionId,
Expand Down Expand Up @@ -129,90 +78,21 @@
}
// Sets the new value and saves updated audit
audits[index].byCriteria[criterion.id][criterion.prop] = criterion.value;
env.storage.local.set({'audits': JSON.stringify(audits)});
}

function getAudits() {
return new Promise((resolve ,reject) => {
env.storage.local.get(['audits']).then((data) =>
data.audits !== undefined ? resolve(data) : reject('Absence d\'historique')
);
});
}

function exportAudit() {
let csv = 'ID;Thématique;Libellé du critère;Évaluation;Commentaire;\n';
for(const criterion of referential.criteres) {
csv += `${criterion.id};${criterion.thematique};${criterion.critere};`;
const assessed = audits[index].byCriteria[criterion.id];
if(assessed !== undefined) {
switch(assessed.status) {
case 'satisfied':
csv += 'conforme;';
break;
case 'rejected':
csv += 'non conforme;';
break;
case 'not-applicable':
csv += 'non applicable;';
break;
default:
csv += 'à évaluer;';
break;
}
}
else {
csv += 'à évaluer;';
}
if(assessed !== undefined) {
if(assessed.analysis !== undefined) {
csv += `"${assessed.analysis}"`;
}
else {
csv += ';';
}
}
else {
csv += ';';
}
csv += ';\n';
}
let blob = new Blob([csv], {});
let aElm = document.createElement('a');
aElm.setAttribute('href', window.URL.createObjectURL(blob));
aElm.setAttribute('download', 'NumÉcoDiag.csv');
aElm.click();
aElm.remove();
}

function buildBadge() {
alert(`Retrouvez votre badge en HTML dans votre dossier téléchargement. Vous pouvez afficher ce badge dans vos communications losque 100% des critères sont évalués.`);

const nbOfCriteria= referential.criteres.length;
const counters = audits[index].byCounters;
const assessed = counters.satisfied + counters.rejected + counters.notApplicable;
const assessedPercent = (assessed/nbOfCriteria * 100).toFixed(0);
const score = (counters.satisfied / (nbOfCriteria - counters.notApplicable) * 100).toFixed(0);
const html = `<div class="numecodiag-badge" style="display:flex; align-items: center; gap: 1em; max-width: 60ch; padding: 1em"><img src=" data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAH0AAAA/CAMAAAD6zjdwAAABCFBMVEX///8AAI/+/P3s7Pe2tuDh4fK/v+Pc3PCfn9by8vkDA5Krq9vo6PXIyOiBgcn4+Pynp9nU1O2Jic3Pz+rl5fS6uuHY2O/19fuxsd2Xl9N0dMT/8fL6+v3Ly+nw8Pivr9zDw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UhcFzMoX2cGMAni951k0sjkXfHV2f+aLVOcCH6nKZHRVcsXGoTPWTIcc7zmRe15Mqnh8aty6jXH7WhNRJf4FzymPD/arbA0mdorUMZUraoq+U0xYzZoQZSpLFXf1G6v76ataTKFy8N+yUNoLcsXroW2cYaV/Z0evSOcytCi0vpAfOeBUCVIqK1MQ6csRmA4Aw/gk3jT+TiKoriNv5fiwMTjDqQUDjGbi2G9ADYEvRIbUOE0ceg4B9gFsRdboJoEyfm2IBN2wEXX0SC6a9+079qDditpt734feYoYtjFkG4eXbLbAEsfKXRpdhFuq7svrkmuvkAovpP5IcBou2ET2QDQ20l72j6fn9fO5y2wfT6feP9Bm0s44+i2VMCRnbtOH6qZUww620tWsB89yBI4AXEV1716rTZP5uN46rW8qO7h3uQXXh7oYhrBHJMohNmTbefQQvG0hqOANoB4x+sCCjJ8js/r8SRqJ/Ag2D6vPcZjDw75L5Eawbu9NUs9HS+KzffcTPBkmDhaLDQ/m/orf+X/Iv8A+Ctv6vUqsuwAAAAASUVORK5CYII=" alt="Logo MiNum_Eco"><p>Après auto-évaluation, ce service numérique a un taux de conformité de ${score}% pour ${assessedPercent}% des critères évalués selon le <a href="https://ecoresponsable.numerique.gouv.fr/publications/referentiel-general-ecoconception/" target="_blank">Référentiel Général d'Écoconception de Services Numériques</a> (RGESN). </p></div>`;
let blob = new Blob([html], {});
let aElm = document.createElement('a');
aElm.setAttribute('href', window.URL.createObjectURL(blob));
aElm.setAttribute('download', 'badge.html');
aElm.click();
aElm.remove();
setLocalData('audits', JSON.stringify(audits));
}

/* ### PROCEDURAL ### */

getAudits()
.then(data => audits = JSON.parse(data.audits))
.then((data) => audits = JSON.parse(data))
.catch((warning) => console.warn(warning))
.finally(() => getRGESN(audits[index].selectedVersion).then(() => {
window.onscroll = () => env.storage.local.set({'scrollPosY': window.scrollY});
env.storage.local.get('scrollPosY').then(data => window.scroll(0, (data.scrollPosY || 0)));
}
)
);
.finally(() => getRGESN(audits[index].selectedVersion)
.then((rgesn) => {
referential = rgesn;
window.onscroll = () => setLocalData('scrollPosY', window.scrollY);
getLocalData('scrollPosY').then(scrollPosY => window.scroll(0, (scrollPosY || 0)));
}))
.catch((error) => console.error(error));

</script>

Expand All @@ -224,15 +104,10 @@
<Results
bind:counters="{audits[index].byCounters}"
bind:nbOfCriteria="{referential.criteres.length}" />
<Options
on:changeVersion="{(e) => changeRGESN(e.detail.versionToApply)}"
on:resetAudit="{() => resetAudit(undefined)}"
on:buildBadge="{() => buildBadge()}"
on:exportAudit="{exportAudit}" />
<AuditForm
audit="{audits[index]}"
referential="{referential}"
on:updated="{updateAudit}" />
on:updated="{setAudit}" />
{/key}
{/if}
<About />
Expand Down
Loading