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-10-06 17:00:32 +02:00
|
|
|
{
|
|
|
|
// Création d'un convertisseur parsant des données transmises en JSON
|
2021-10-11 16:44:20 +02:00
|
|
|
let converter=new FreeDatas2HTML("JSON");
|
|
|
|
converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/posts.json", withCredentials:true, headers: [{ key:"Authorization", value:"Token YWxhZGRpbjpvcGVuc2VzYW1l" }] });
|
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
|
|
|
|
const myRender=new Render(converter);
|
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
|
|
|
|
|
|
|
// Configuration de la pagination
|
|
|
|
const pagination=new Pagination(converter, { id:"pages" }, "Page à afficher :");
|
2021-10-06 17:00:32 +02:00
|
|
|
pagination.options={ displayElement: { id:"paginationOptions" }, values: [15,30,50,100] , name: "Nombre de lignes par page :" };
|
|
|
|
pagination.selectedValue=15;
|
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-09-23 11:28:27 +02:00
|
|
|
converter.datasCounter={ id:"compteur" };
|
2021-09-29 17:56:10 +02:00
|
|
|
await converter.run();
|
2021-09-21 17:48:26 +02:00
|
|
|
|
2021-10-06 17:00:32 +02:00
|
|
|
// Création d'un filtre par auteur :
|
|
|
|
let filtre1=new Selector(converter, 0, { id:"filtre1"} );
|
2021-09-21 17:48:26 +02:00
|
|
|
filtre1.selector2HTML();
|
2021-10-06 17:00:32 +02:00
|
|
|
converter.datasSelectors=[filtre1];
|
|
|
|
|
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();
|
2021-10-06 17:00:32 +02:00
|
|
|
converter.datasSortingFields=[sortingField1,sortingField2,sortingField3];
|
2021-09-23 17:19:31 +02:00
|
|
|
}
|
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();
|