diff --git a/package.json b/package.json index 2cecfd8..3a7b706 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "freedatas2html", - "version": "0.4.5", + "version": "0.4.6", "description": "Visualization of data from various sources (CSV, API, HTML...) with filters, classification, pagination, etc.", "main": "index.js", "scripts": { diff --git a/public/index.html b/public/index.html index aa0dec1..2abf71a 100644 --- a/public/index.html +++ b/public/index.html @@ -19,15 +19,16 @@
- +

Nombre total de résultats :

Si tout se passe bien, ce texte sera remplacé par un tableau de données extraites du fichier csv.

\ No newline at end of file diff --git a/src/firstExample.ts b/src/firstExample.ts index 6a46ac6..4adfd87 100644 --- a/src/firstExample.ts +++ b/src/firstExample.ts @@ -33,6 +33,7 @@ const initialise = async () => pagination.rend2HTML(); // Affichage initial + converter.datasCounter={ id:"compteur" }; await converter.run(); // Création d'outils permettant de filtrer les données des champs de données diff --git a/src/freeDatas2HTML.ts b/src/freeDatas2HTML.ts index a5827aa..1fcd144 100644 --- a/src/freeDatas2HTML.ts +++ b/src/freeDatas2HTML.ts @@ -2,7 +2,7 @@ const Papa = require("papaparse"); const errors = require("./errors.js"); const { compare }= require('natural-orderby'); -import { DOMElement, Paginations, Selectors, SortingFields, SortingFunctions } from "./freeDatas2HTMLInterfaces"; +import { Counter, DOMElement, Paginations, Selectors, SortingFields, SortingFunctions } from "./freeDatas2HTMLInterfaces"; import { Pagination} from "./freeDatas2HTMLPagination"; import { Selector } from "./freeDatas2HTMLSelector"; import { SortingField } from "./freeDatas2HTMLSortingField"; @@ -37,6 +37,8 @@ export class FreeDatas2HTML datasSortedField: SortingFields|undefined; // La Pagination : pagination: Paginations|undefined; + // Affichage du nombre total de lignes de données (optionnel) : + private _datasCounter: Counter = {}; // Vérifie s'il y a bien un élément dans le DOM pour l'id fourni public static checkInDOMById(checkedElt: DOMElement) : DOMElement @@ -89,6 +91,21 @@ export class FreeDatas2HTML } } + // On teste l'id de l'élément du DOM où afficher le compteur s'il est fourni + set datasCounter(counterDisplayElement: DOMElement) + { + this._datasCounter={ displayElement: FreeDatas2HTML.checkInDOMById(counterDisplayElement), value: undefined }; + } + + // Retourne la valeur du compteur de lignes (sans l'élément DOM) + public getDatasCounterValue(): number|undefined + { + if(this._datasCounter !== undefined && this._datasCounter.value != undefined) + return this._datasCounter.value; + else + return undefined; + } + // Retourne l'éventuelle fonction spécifique de classement associée à un champ public getSortingFunctionForField(datasFieldNb: number): SortingFunctions|undefined { @@ -234,6 +251,11 @@ export class FreeDatas2HTML nbTotal++; } datasHTML+=""; + if(this._datasCounter !== undefined && this._datasCounter.displayElement !== undefined) + { + this._datasCounter.value=nbTotal; + this._datasCounter.displayElement.eltDOM!.innerHTML=""+nbTotal; // eltDOM ne peut être undefined (cf setter) + } // Tout réaffichage peut entraîner une modification du nombre de pages (évolution filtres, etc.) if(this.pagination !== undefined) this.pagination.creaPageSelector(nbTotal); diff --git a/src/freeDatas2HTMLInterfaces.ts b/src/freeDatas2HTMLInterfaces.ts index 140996c..002f0ca 100644 --- a/src/freeDatas2HTMLInterfaces.ts +++ b/src/freeDatas2HTMLInterfaces.ts @@ -1,3 +1,8 @@ +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 DOMElement { id: string; diff --git a/tests/fixtures.js b/tests/fixtures.js index 6de4e84..c6b4e42 100644 --- a/tests/fixtures.js +++ b/tests/fixtures.js @@ -1,6 +1,6 @@ module.exports = { - datasViewEltHTML: '
', + datasViewEltHTML: '
', datasHTML : '
Z (numéro atomique)ÉlémentSymboleFamilleAbondance des éléments dans la croûte terrestre (μg/k)
1HydrogèneHNon-métal> 100000
2HéliumHeGaz noble> 1 et < 100 000
3LithiumLiMétal alcalin> 1 et < 100 000
4BérylliumBeMétal alcalino-terreux> 1 et < 100 000
5BoreBMétalloïde> 1 et < 100 000
6CarboneCNon-métal> 100000
7AzoteNNon-métal> 1 et < 100 000
8OxygèneONon-métal> 100000
9FluorFHalogène> 100000
10NéonNeGaz noble> 1 et < 100 000
11SodiumNaMétal alcalin> 100000
12MagnésiumMgMétal alcalino-terreux> 100000
13AluminiumAlMétal pauvre> 100000
14SiliciumSiMétalloïde> 100000
15PhosphorePNon-métal> 100000
16SoufreSNon-métal> 100000
17ChloreClHalogène> 100000
18ArgonArGaz noble> 1 et < 100 000
19PotassiumKMétal alcalin> 100000
20CalciumCaMétal alcalino-terreux> 100000
21ScandiumScMétal de transition> 1 et < 100 000
22TitaneTiMétal de transition> 100000
23VanadiumVMétal de transition> 100000
24ChromeCrMétal de transition> 100000
25ManganèseMnMétal de transition> 100000
26FerFeMétal de transition> 100000
27CobaltCoMétal de transition> 1 et < 100 000
28NickelNiMétal de transition> 1 et < 100 000
29CuivreCuMétal de transition> 1 et < 100 000
30ZincZnMétal pauvre> 1 et < 100 000
31GalliumGaMétal pauvre> 1 et < 100 000
32GermaniumGeMétalloïde> 1 et < 100 000
33ArsenicAsMétalloïde> 1 et < 100 000
34SéléniumSeNon-métal> 1 et < 100 000
35BromeBrHalogène> 1 et < 100 000
36KryptonKrgaz rare≤ 1
37RubidiumRbMétal alcalin> 1 et < 100 000
38StrontiumSrMétal alcalino-terreux> 100000
39YttriumYMétal de transition> 1 et < 100 000
40ZirconiumZrMétal de transition> 100000
41NiobiumNbMétal de transition> 1 et < 100 000
42MolybdèneMoMétal de transition> 1 et < 100 000
43TechnétiumTcMétal de transitionTraces
44RuthéniumRuMétal de transition≤ 1
45RhodiumRhMétal de transition≤ 1
46PalladiumPdMétal de transition> 1 et < 100 000
47ArgentAgMétal de transition> 1 et < 100 000
48CadmiumCdMétal pauvre> 1 et < 100 000
49IndiumInMétal pauvre> 1 et < 100 000
50ÉtainSnMétal pauvre> 1 et < 100 000
51AntimoineSbMétalloïde> 1 et < 100 000
52TellureTeMétalloïde≤ 1
53IodeIHalogène> 1 et < 100 000
54XénonXegaz rare≤ 1
55CésiumCsMétal alcalin> 1 et < 100 000
56BaryumBaMétal alcalino-terreux> 100000
57LanthaneLaLanthanide> 1 et < 100 000
58CériumCeLanthanide> 1 et < 100 000
59PraséodymePrLanthanide> 1 et < 100 000
60NéodymeNdLanthanide> 1 et < 100 000
61ProméthiumPmLanthanideTraces
62SamariumSmLanthanide> 1 et < 100 000
63EuropiumEuLanthanide> 1 et < 100 000
64GadoliniumGdLanthanide> 1 et < 100 000
65TerbiumTbLanthanide> 1 et < 100 000
66DysprosiumDyLanthanide> 1 et < 100 000
67HolmiumHoLanthanide> 1 et < 100 000
68ErbiumErLanthanide> 1 et < 100 000
69ThuliumTmLanthanide> 1 et < 100 000
70YtterbiumYbLanthanide> 1 et < 100 000
71LutéciumLuLanthanide> 1 et < 100 000
72HafniumHfMétal de transition> 1 et < 100 000
73TantaleTaMétal de transition> 1 et < 100 000
74TungstèneWMétal de transition> 1 et < 100 000
75RhéniumReMétal de transition≤ 1
76OsmiumOsMétal de transition> 1 et < 100 000
77IridiumIrMétal de transition≤ 1
78PlatinePtMétal de transition> 1 et < 100 000
79OrAuMétal de transition> 1 et < 100 000
80MercureHgMétal pauvre> 1 et < 100 000
81ThalliumTlMétal pauvre> 1 et < 100 000
82PlombPbMétal pauvre> 1 et < 100 000
83BismuthBiMétal pauvre> 1 et < 100 000
84PoloniumPoMétal pauvre≤ 1
85AstateAtMétalloïdeTraces
86RadonRnGaz noble≤ 1
87FranciumFrMétal alcalinTraces
88RadiumRaMétal alcalino-terreux≤ 1
89ActiniumAcActinide≤ 1
90ThoriumThActinide> 1 et < 100 000
91ProtactiniumPaActinide≤ 1
92UraniumUActinide> 1 et < 100 000
93NeptuniumNpActinideTraces
94PlutoniumPuActinideTraces
95AmériciumAmActinideInexistant
96CuriumCmActinideInexistant
97BerkéliumBkActinideInexistant
98CaliforniumCfActinideInexistant
99EinsteiniumEsActinideInexistant
100FermiumFmActinideInexistant
101MendéléviumMdActinideInexistant
102NobéliumNoActinideInexistant
103LawrenciumLrActinideInexistant
104RutherfordiumRfMétal de transitionInexistant
105DubniumDbMétal de transitionInexistant
106SeaborgiumSgMétal de transitionInexistant
107BohriumBhMétal de transitionInexistant
108HassiumHsMétal de transitionInexistant
109MeitnériumMtIndéfinieInexistant
110DarmstadtiumDsIndéfinieInexistant
111RoentgeniumRgIndéfinieInexistant
112CoperniciumCnMétal de transitionInexistant
113NihoniumNhIndéfinieInexistant
114FléroviumFlIndéfinieInexistant
115MoscoviumMcIndéfinieInexistant
116LivermoriumLvIndéfinieInexistant
117TennesseTsIndéfinieInexistant
118OganessonOgIndéfinieInexistant
', selector1HTML: '', selector2HTML: '', diff --git a/tests/freeDatas2HTMLSpec.ts b/tests/freeDatas2HTMLSpec.ts index cbc3c37..da411da 100644 --- a/tests/freeDatas2HTMLSpec.ts +++ b/tests/freeDatas2HTMLSpec.ts @@ -184,6 +184,17 @@ describe("Test du script central de FreeDatas2HTML", () => let txtDatasViewsElt=document.getElementById("datas").innerHTML; expect(txtDatasViewsElt).toEqual(fixtures.datasHTML); }); + + it("Si demandé, doit afficher le nombre de lignes de données du fichier.", async () => + { + converter.datasViewElt={ id:"datas" }; + converter.datasSourceUrl="http://localhost:9876/datas/datas1.csv"; + converter.datasCounter={ id:"counter" }; + await converter.run(); + let txtDatasViewsElt=document.getElementById("counter").innerHTML; + expect(txtDatasViewsElt).toEqual("118"); + }); + }); }); \ No newline at end of file