2021-09-23 17:19:31 +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"
|
|
|
|
let converter=new FreeDatas2HTML();
|
|
|
|
converter.datasViewElt={ id:"datas" };
|
2021-08-10 15:56:53 +02:00
|
|
|
converter.datasSourceUrl="http://localhost:8080/datas/elements-chimiques.csv";
|
2021-09-21 17:48:26 +02:00
|
|
|
await converter.parse();
|
2021-09-22 17:12:00 +02:00
|
|
|
converter.datasSortingFunctions=[{ datasFieldNb:4, sort:mySort }];
|
2021-09-23 17:19:31 +02:00
|
|
|
// Adaptation du rendu
|
|
|
|
if(window.innerWidth < 800)
|
|
|
|
{
|
|
|
|
converter.datasRender.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>",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
converter.datasRender.settings.allBegining="<table class='table-hover'>";
|
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;
|
|
|
|
pagination.rend2HTML();
|
2021-09-23 17:19:31 +02:00
|
|
|
|
2021-09-21 17:48:26 +02:00
|
|
|
// Affichage initial
|
2021-09-23 11:28:27 +02:00
|
|
|
converter.datasCounter={ id:"compteur" };
|
2021-08-10 15:56:53 +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-09-21 17:48:26 +02:00
|
|
|
filtre1.selector2HTML();
|
2021-09-22 17:12:00 +02:00
|
|
|
let filtre2=new Selector(converter, 4, { id:"filtre2"} );
|
2021-09-21 17:48:26 +02:00
|
|
|
filtre2.selector2HTML();
|
2021-09-22 17:12:00 +02:00
|
|
|
let filtre3=new Selector(converter, 5, { id:"filtre3"} );
|
2021-09-21 17:48:26 +02:00
|
|
|
filtre3.separator=",";
|
|
|
|
filtre3.selector2HTML();
|
2021-09-22 17:12:00 +02:00
|
|
|
// + Injection des filtres dans le convertisseur
|
2021-09-21 17:48:26 +02:00
|
|
|
converter.datasSelectors=[filtre1,filtre2,filtre3];
|
2021-09-23 17:19:31 +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();
|