From 26f3967729b5f07a1532414edb72760df7d3ec97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20PENHO=C3=8BT?= Date: Sun, 10 Dec 2023 11:07:16 +0100 Subject: [PATCH] =?UTF-8?q?Refonte=20de=20l'ensemble=20du=20script=20pour?= =?UTF-8?q?=20une=20meilleure=20prise=20en=20compte=20des=20possibilit?= =?UTF-8?q?=C3=A9s=20du=20module=20XPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +- public/CSS/flickity.min.css | 4 - public/CSS/vcarousel.css | 31 ------ public/cd_catalog.xml | 211 ------------------------------------ public/index.html | 9 +- src/messages.js | 9 +- src/xpathTrainer.ts | 46 +++++--- webpack.config.js | 9 +- 8 files changed, 57 insertions(+), 269 deletions(-) delete mode 100644 public/CSS/flickity.min.css delete mode 100644 public/CSS/vcarousel.css delete mode 100644 public/cd_catalog.xml diff --git a/README.md b/README.md index 102f56b..24dff29 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,9 @@ Le gros du travail est réalisé par le module [xpath](https://www.npmjs.com/pac Le script d’Xpath Trainer se contentant de récupérer le contenu du fichier sélectionné pour l’afficher dans une iframe d’une part et d’autre part le fournir à [xpath](https://www.npmjs.com/package/xpath) pour y tester les chemins saisis par l’utilisateur. Le résultat est ensuite affiché dans la même page web. -La simplicité du script fait qu’il n’y a pas de tests unitaires. \ No newline at end of file +La simplicité du script fait qu’il n’y a pas de tests unitaires. + +## Limites + +L'affichage de manière lisible d'un fichier XML sans feuille de style dans l'iframe ne fonctionne que dans Firefox. +La gestion des attributs et des espaces de nom reste à améliorer. \ No newline at end of file diff --git a/public/CSS/flickity.min.css b/public/CSS/flickity.min.css deleted file mode 100644 index 18829b0..0000000 --- a/public/CSS/flickity.min.css +++ /dev/null @@ -1,4 +0,0 @@ -/*! Flickity v2.2.2 -https://flickity.metafizzy.co ----------------------------------------------- */ -.flickity-enabled{position:relative}.flickity-enabled:focus{outline:0}.flickity-viewport{overflow:hidden;position:relative;height:100%}.flickity-slider{position:absolute;width:100%;height:100%}.flickity-enabled.is-draggable{-webkit-tap-highlight-color:transparent;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.flickity-enabled.is-draggable .flickity-viewport{cursor:move;cursor:-webkit-grab;cursor:grab}.flickity-enabled.is-draggable .flickity-viewport.is-pointer-down{cursor:-webkit-grabbing;cursor:grabbing}.flickity-button{position:absolute;background:hsla(0,0%,100%,.75);border:none;color:#333}.flickity-button:hover{background:#fff;cursor:pointer}.flickity-button:focus{outline:0;box-shadow:0 0 0 5px #19f}.flickity-button:active{opacity:.6}.flickity-button:disabled{opacity:.3;cursor:auto;pointer-events:none}.flickity-button-icon{fill:currentColor}.flickity-prev-next-button{top:50%;width:44px;height:44px;border-radius:50%;transform:translateY(-50%)}.flickity-prev-next-button.previous{left:10px}.flickity-prev-next-button.next{right:10px}.flickity-rtl .flickity-prev-next-button.previous{left:auto;right:10px}.flickity-rtl .flickity-prev-next-button.next{right:auto;left:10px}.flickity-prev-next-button .flickity-button-icon{position:absolute;left:20%;top:20%;width:60%;height:60%}.flickity-page-dots{position:absolute;width:100%;bottom:-25px;padding:0;margin:0;list-style:none;text-align:center;line-height:1}.flickity-rtl .flickity-page-dots{direction:rtl}.flickity-page-dots .dot{display:inline-block;width:10px;height:10px;margin:0 8px;background:#333;border-radius:50%;opacity:.25;cursor:pointer}.flickity-page-dots .dot.is-selected{opacity:1} \ No newline at end of file diff --git a/public/CSS/vcarousel.css b/public/CSS/vcarousel.css deleted file mode 100644 index 0c02cd0..0000000 --- a/public/CSS/vcarousel.css +++ /dev/null @@ -1,31 +0,0 @@ -body -{ -text-align:center; -background-color:#C0D6D2; -} -#videos -{ -border:1px solid; -width:800px; -margin:auto; -padding:1em; -text-align:center; -} -#video figure -{ -padding-top:2em; -} -#videos video -{ -width:600px; -} -nav ul -{ -margin-left:0; -padding-left:0; -} -nav li -{ -list-style:none; -margin-bottom:0.5em; -} \ No newline at end of file diff --git a/public/cd_catalog.xml b/public/cd_catalog.xml deleted file mode 100644 index 2df1d5a..0000000 --- a/public/cd_catalog.xml +++ /dev/null @@ -1,211 +0,0 @@ - - - - Empire Burlesque - Bob Dylan - USA - Columbia - 10.90 - 1985 - - - Hide your heart - Bonnie Tyler - UK - CBS Records - 9.90 - 1988 - - - Greatest Hits - Dolly Parton - USA - RCA - 9.90 - 1982 - - - Still got the blues - Gary Moore - UK - Virgin records - 10.20 - 1990 - - - Eros - Eros Ramazzotti - EU - BMG - 9.90 - 1997 - - - One night only - Bee Gees - UK - Polydor - 10.90 - 1998 - - - Sylvias Mother - Dr.Hook - UK - CBS - 8.10 - 1973 - - - Maggie May - Rod Stewart - UK - Pickwick - 8.50 - 1990 - - - Romanza - Andrea Bocelli - EU - Polydor - 10.80 - 1996 - - - When a man loves a woman - Percy Sledge - USA - Atlantic - 8.70 - 1987 - - - Black angel - Savage Rose - EU - Mega - 10.90 - 1995 - - - 1999 Grammy Nominees - Many - USA - Grammy - 10.20 - 1999 - - - For the good times - Kenny Rogers - UK - Mucik Master - 8.70 - 1995 - - - Big Willie style - Will Smith - USA - Columbia - 9.90 - 1997 - - - Tupelo Honey - Van Morrison - UK - Polydor - 8.20 - 1971 - - - Soulsville - Jorn Hoel - Norway - WEA - 7.90 - 1996 - - - The very best of - Cat Stevens - UK - Island - 8.90 - 1990 - - - Stop - Sam Brown - UK - A and M - 8.90 - 1988 - - - Bridge of Spies - T'Pau - UK - Siren - 7.90 - 1987 - - - Private Dancer - Tina Turner - UK - Capitol - 8.90 - 1983 - - - Midt om natten - Kim Larsen - EU - Medley - 7.80 - 1983 - - - Pavarotti Gala Concert - Luciano Pavarotti - UK - DECCA - 9.90 - 1991 - - - The dock of the bay - Otis Redding - USA - Stax Records - 7.90 - 1968 - - - Picture book - Simply Red - EU - Elektra - 7.20 - 1985 - - - Red - The Communards - UK - London - 7.80 - 1987 - - - Unchain my heart - Joe Cocker - USA - EMI - 8.20 - 1987 - - \ No newline at end of file diff --git a/public/index.html b/public/index.html index 393ac5f..daec025 100644 --- a/public/index.html +++ b/public/index.html @@ -5,21 +5,22 @@ - + + XPath Trainer

XPath Trainer

-
+


- -
+
+
\ No newline at end of file diff --git a/src/messages.js b/src/messages.js index e184b49..fd70eb8 100644 --- a/src/messages.js +++ b/src/messages.js @@ -1,9 +1,12 @@ module.exports = { - emptyXPathError: "

Votre XPath est vide !

", - exceptionError: "

Bug imprévu.

", + emptyXPathError: "

Votre XPath est vide !

", + exceptionError: "

Il vient d'arriver une exception de nature exceptionnelle !

", gitSources: "Hello, les dev !\nLe code source TypeScript utilisé pour faire fonctionner cette page est lisible ici : :\nhttps://forge.chapril.org/Fab_Blab/xPathTrainer/src/branch/master/src/xpathTrainer.ts", needXMLFile : "Commencer pour sélectionner un fichier", needXPath: "Saisissez votre XPath", - notXMLError: "

Le fichier que vous avez sélectionné ne semble pas être un fichier XML.

" + noResultForXPath: "

Aucun résultat pour votre recherche.

", + notXMLError: "

Le fichier que vous avez sélectionné ne semble pas être un fichier XML.

", + resultsTitle: "

Résultats

", + xpathError: "

La syntaxe du XPath saisi ne semble pas correcte.

" }; \ No newline at end of file diff --git a/src/xpathTrainer.ts b/src/xpathTrainer.ts index 3d00868..a656cde 100644 --- a/src/xpathTrainer.ts +++ b/src/xpathTrainer.ts @@ -7,7 +7,7 @@ const initialise = () => const myXPath=document.getElementById("myXPath") as HTMLInputElement; const testButton=document.getElementById("runTest") as HTMLButtonElement; const myIframe=document.getElementById("display") as HTMLIFrameElement; - const divResult=document.getElementById("result") as HTMLDivElement; + const divResult=document.getElementById("results") as HTMLDivElement; const xpath=require('xpath'); try @@ -17,6 +17,7 @@ const initialise = () => testButton.disabled=true; myXPath.placeholder=messages.needXMLFile; myIframe.style.display="none"; + divResult.style.display="none"; const dom=require('@xmldom/xmldom').DOMParser; myFile.addEventListener("change", function(e) @@ -29,7 +30,7 @@ const initialise = () => // selectedFiles[0].type ne fonctionne pas avec certains navigateurs (Fennec), donc... : const extension=selectedFiles[0].name.substring(selectedFiles[0].name.lastIndexOf(".")+1); if(extension !== "xml") - divResult.innerHTML=messages.notXMLError; + divResult.innerHTML=messages.resultsTitle+messages.notXMLError; else { // Création d'un fichier XML temporaire que l'on va charger dans l'iframe : @@ -53,18 +54,35 @@ const initialise = () => const doc=new dom().parseFromString(xmlDatas, 'text/xml'); myForm.addEventListener("submit", (e) => { - e.preventDefault(); - let xPathTested=myXPath.value.trim(); - if(xPathTested == "") - divResult.innerHTML=messages.emptyXPathError; - else + try { - const nodes=xpath.select(xPathTested , doc); - let resultTxt=""; - divResult.innerHTML=resultTxt; + e.preventDefault(); + divResult.innerHTML=""; + divResult.style.display="block"; + let xPathTested=myXPath.value.trim(); + if(xPathTested == "") + divResult.innerHTML+=messages.resultsTitle+messages.emptyXPathError; + else + { + let resultTxt=messages.resultsTitle; + const nodes=xpath.select(xPathTested , doc); + if(nodes.length === 0) + resultTxt+=messages.noResultForXPath; + else + { + for(let i = 0; i < nodes.length; i++) + resultTxt+=`
  • ${nodes[i].toString().replaceAll("<", "<").replaceAll(">", ">").replaceAll("\n","
    ")}
  • `; + resultTxt=``; + } + divResult.innerHTML=resultTxt; + } + } + catch(e: unknown) + { + if (e instanceof Error && e.message=="XPath parse error" ) + divResult.innerHTML=messages.resultsTitle+messages.xpathError; + else + divResult.innerHTML=messages.resultsTitle+messages.exceptionError; } }); }; @@ -75,7 +93,7 @@ const initialise = () => } catch(e) { - divResult.innerHTML=messages.exceptionError; + divResult.innerHTML=messages.resultsTitle.messages.exceptionError; console.error(e); } } diff --git a/webpack.config.js b/webpack.config.js index 4094ca3..2bf000b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -25,6 +25,13 @@ module.exports = ], }, devServer: { - static: path.join(__dirname, "public") + static: path.join(__dirname, "public"), + client: { + overlay: { + errors: true, + warnings: false, + runtimeErrors: false, + }, + }, }, }; \ No newline at end of file