Compare commits
2 Commits
8c636a57b3
...
9526bf094f
Author | SHA1 | Date | |
---|---|---|---|
9526bf094f | |||
a7dce830c8 |
@ -13,6 +13,7 @@ module.exports =
|
||||
parserFail: "La lecture des données du fichier a échoué.",
|
||||
parserNeedUrl: "Merci de fournir une url valide pour le fichier à parser.",
|
||||
renderNeedDatas: "Il ne peut y avoir de pagination, si les données n'ont pas été récupérées.",
|
||||
renderUnknownField: "Un champ non attendu a été trouvé dans les données à afficher : ",
|
||||
selector2HTMLFail: "Le création d'un filtre dans le DOM nécessite l'initialisation de l'élément HTML et du numéro du champs à filter.",
|
||||
selectorCheckIsOkFail: "Le test est lancé sur un filtre incorrectement initialisé ou sur un attribut absent de la donnée à tester.",
|
||||
selectorFieldNotFound: "Au moins un des champs devant servir à filtrer les données n'existe pas dans le fichier.",
|
||||
|
@ -24,10 +24,12 @@ const initialise = async () =>
|
||||
converter.datasSourceUrl="http://localhost:8080/datas/elements-chimiques.csv";
|
||||
await converter.parse();
|
||||
converter.datasSortingFunctions=[{ datasFieldNb:4, sort:mySort }];
|
||||
// Adaptation du rendu
|
||||
// Adaptation du rendu suivant la taille de l'écran
|
||||
const myRender=new Render(converter);
|
||||
if(window.innerWidth < 800)
|
||||
{
|
||||
converter.datasRender.settings={
|
||||
myRender.settings=
|
||||
{
|
||||
allBegining:"<h4>Affichage petits écrans !</h4>",
|
||||
allEnding:"",
|
||||
linesBegining:"<ul>",
|
||||
@ -36,9 +38,13 @@ const initialise = async () =>
|
||||
lineEnding:"</ul></li>",
|
||||
dataDisplaying:"<li><b>#FIELDNAME :</b> #VALUE</li>",
|
||||
};
|
||||
converter.datasRender=myRender;
|
||||
}
|
||||
else
|
||||
converter.datasRender.settings.allBegining="<table class='table-hover'>";
|
||||
{
|
||||
myRender.settings.allBegining="<table class='table-hover'>";
|
||||
converter.datasRender=myRender;
|
||||
}
|
||||
|
||||
// Configuration de la pagination
|
||||
const pagination=new Pagination(converter, { id:"pages" }, "Page à afficher :");
|
||||
|
@ -3,12 +3,11 @@ export interface Counter
|
||||
displayElement?: DOMElement; // peut être undefined si on ne souhaite pas d'affichage automatique dans la page
|
||||
value?: number; // undefined jusqu'à recevoir sa première valeur
|
||||
}
|
||||
export interface DatasRenders
|
||||
export interface DatasRenders // interface à respecter par toute alternative à la classe Render par défaut
|
||||
{
|
||||
rend2HTML(datas: any[]): string;
|
||||
settings: DatasRendersSettings;
|
||||
}
|
||||
export interface DatasRendersSettings
|
||||
export interface DatasRendersSettings // interface spécifique à la classe Render par défaut.
|
||||
{
|
||||
allBegining: string;
|
||||
allEnding: string;
|
||||
|
@ -27,16 +27,17 @@ export class Render implements DatasRenders
|
||||
this.settings=settings;
|
||||
}
|
||||
|
||||
// Reçoit les données à afficher et créer le HTML correspondant
|
||||
// Reçoit les données à afficher et retourne le HTML correspondant.
|
||||
public rend2HTML(datas: any[]) : string
|
||||
{
|
||||
// Il peut n'y avoir aucune donnée (filtres...), mais les noms des champs doivent être connus.
|
||||
if(this._converter.parseMetas === undefined || this._converter.parseMetas.fields === undefined)
|
||||
throw new Error(errors.renderNeedDatas);
|
||||
else
|
||||
{
|
||||
let datasHTML=this.settings.allBegining;
|
||||
// On ne souhaite pas nécessairement afficher les noms de colonne
|
||||
if(this.settings.fieldsBegining !== undefined && this.settings.fieldDisplaying !== undefined)
|
||||
// On ne souhaite pas nécessairement afficher les noms des champs
|
||||
if(this.settings.fieldsBegining !== undefined && this.settings.fieldDisplaying !== undefined && this.settings.fieldsEnding !== undefined )
|
||||
{
|
||||
datasHTML+=this.settings.fieldsBegining;
|
||||
for (let i in this._converter.parseMetas!.fields)
|
||||
@ -49,8 +50,11 @@ export class Render implements DatasRenders
|
||||
datasHTML+=this.settings.lineBegining;
|
||||
for(let field in datas[row])
|
||||
{
|
||||
// On n'affiche que les champs attendus et signale les erreurs dans la console
|
||||
if(this._converter.parseMetas.fields.indexOf(field) !== -1)
|
||||
datasHTML+=this.settings.dataDisplaying.replace("#VALUE" , datas[row][field]).replace("#FIELDNAME" , field);
|
||||
else
|
||||
console.log(errors.renderUnknownField+field);
|
||||
}
|
||||
datasHTML+=this.settings.lineEnding;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user