2021-10-25 10:53:54 +02:00
|
|
|
import { FreeDatas2HTML, Pagination, Render, Selector, SortingField } from "./FreeDatas2HTML";
|
2021-08-10 15:56:53 +02:00
|
|
|
|
|
|
|
const initialise = async () =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-09-21 17:48:26 +02:00
|
|
|
// Fonction spécifique de classement utile pour les données du 4ième champs
|
2021-09-06 17:25:30 +02:00
|
|
|
const mySort = (a: any, b: any, order: "asc"|"desc" = "asc") =>
|
|
|
|
{
|
|
|
|
const values = [ "> 100000", "> 1 et < 100 000", "≤ 1", "Traces", "Inexistant"];
|
|
|
|
if(order === "desc")
|
|
|
|
values.reverse();
|
|
|
|
if(values.indexOf(a) > values.indexOf(b))
|
|
|
|
return -1;
|
|
|
|
else if(values.indexOf(a) < values.indexOf(b))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
};
|
2021-09-21 17:48:26 +02:00
|
|
|
|
|
|
|
// Création d'un convertisseur parsant les données d'un fichier CSV "distant"
|
2021-10-11 16:44:20 +02:00
|
|
|
let converter=new FreeDatas2HTML("CSV");
|
|
|
|
converter.parser.setRemoteSource({ url:"http://localhost:8080/datas/elements-chimiques.csv" });
|
2021-09-21 17:48:26 +02:00
|
|
|
converter.datasViewElt={ id:"datas" };
|
2021-09-29 17:56:10 +02:00
|
|
|
await converter.run();
|
2021-09-27 12:10:22 +02:00
|
|
|
// Adaptation du rendu suivant la taille de l'écran
|
2021-10-20 17:34:10 +02:00
|
|
|
const myRender=new Render();
|
2021-09-23 17:19:31 +02:00
|
|
|
if(window.innerWidth < 800)
|
|
|
|
{
|
2021-09-27 12:10:22 +02:00
|
|
|
myRender.settings=
|
|
|
|
{
|
2021-09-27 11:39:31 +02:00
|
|
|
allBegining:"<h4>Affichage petits écrans !</h4>",
|
2021-09-23 17:19:31 +02:00
|
|
|
allEnding:"",
|
|
|
|
linesBegining:"<ul>",
|
|
|
|
linesEnding:"</ul>",
|
|
|
|
lineBegining:"<li><ul>",
|
|
|
|
lineEnding:"</ul></li>",
|
|
|
|
dataDisplaying:"<li><b>#FIELDNAME :</b> #VALUE</li>",
|
|
|
|
};
|
2021-09-27 12:10:22 +02:00
|
|
|
converter.datasRender=myRender;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myRender.settings.allBegining="<table class='table-hover'>";
|
|
|
|
converter.datasRender=myRender;
|
2021-09-23 17:19:31 +02:00
|
|
|
}
|
2021-09-21 17:48:26 +02:00
|
|
|
|
2021-09-29 17:56:10 +02:00
|
|
|
// Ajout d'une fonction de classement spécifique
|
|
|
|
converter.datasSortingFunctions=[{ datasFieldNb:4, sort:mySort }];
|
|
|
|
|
2021-09-21 17:48:26 +02:00
|
|
|
// Configuration de la pagination
|
|
|
|
const pagination=new Pagination(converter, { id:"pages" }, "Page à afficher :");
|
|
|
|
pagination.options={ displayElement: { id:"paginationOptions" }, values: [10,20,50,500] , name: "Choix de pagination :" };
|
2021-09-22 17:36:11 +02:00
|
|
|
pagination.selectedValue=10;
|
2021-09-21 17:48:26 +02:00
|
|
|
converter.pagination=pagination;
|
2021-10-20 12:37:39 +02:00
|
|
|
pagination.options2HTML();
|
2021-09-23 17:19:31 +02:00
|
|
|
|
2021-09-21 17:48:26 +02:00
|
|
|
// Affichage initial
|
2021-10-26 18:02:43 +02:00
|
|
|
converter.datasCounterElt={ id:"compteur" };
|
2021-09-29 17:56:10 +02:00
|
|
|
await converter.run();
|
2021-09-21 17:48:26 +02:00
|
|
|
|
|
|
|
// Création d'outils permettant de filtrer les données des champs de données
|
2021-09-22 17:12:00 +02:00
|
|
|
let filtre1=new Selector(converter, 3, { id:"filtre1"} );
|
2021-10-20 17:57:34 +02:00
|
|
|
filtre1.filter2HTML();
|
2021-09-22 17:12:00 +02:00
|
|
|
let filtre2=new Selector(converter, 4, { id:"filtre2"} );
|
2021-10-20 17:57:34 +02:00
|
|
|
filtre2.filter2HTML();
|
2021-10-21 17:11:04 +02:00
|
|
|
let filtre3=new Selector(converter, 5, { id:"filtre3"}, ",");
|
2021-10-20 17:57:34 +02:00
|
|
|
filtre3.filter2HTML();
|
2021-09-22 17:12:00 +02:00
|
|
|
// + Injection des filtres dans le convertisseur
|
2021-10-20 17:57:34 +02:00
|
|
|
converter.datasFilters=[filtre1,filtre2,filtre3];
|
2021-09-29 17:56:10 +02:00
|
|
|
|
2021-09-21 17:48:26 +02:00
|
|
|
// Ajout de champs permettant de classer les données
|
2021-09-23 17:19:31 +02:00
|
|
|
// Uniquement avec un rendu tableau (grand écran), car entêtes de colonne nécessaires
|
|
|
|
if(window.innerWidth >= 800)
|
|
|
|
{
|
|
|
|
let sortingField1=new SortingField(converter, 0);
|
|
|
|
sortingField1.field2HTML();
|
|
|
|
let sortingField2=new SortingField(converter, 1);
|
|
|
|
sortingField2.field2HTML();
|
|
|
|
let sortingField3=new SortingField(converter, 2);
|
|
|
|
sortingField3.field2HTML();
|
|
|
|
let sortingField4=new SortingField(converter, 4);
|
|
|
|
sortingField4.field2HTML();
|
|
|
|
converter.datasSortingFields=[sortingField1,sortingField2,sortingField3,sortingField4];
|
|
|
|
}
|
2021-08-10 15:56:53 +02:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
|
|
|
console.error(e);
|
2021-08-13 20:00:03 +02:00
|
|
|
if(document.getElementById("datas")!==null)
|
|
|
|
document.getElementById("datas")!.innerHTML="<strong>Désolé, mais un problème technique empêche l'affichage des données.</strong>";
|
2021-08-10 15:56:53 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-11 15:24:00 +02:00
|
|
|
initialise();
|