Compilation + nouveaux fichiers front
This commit is contained in:
parent
26f3967729
commit
f753a6abfb
35
public/CSS/style.css
Normal file
35
public/CSS/style.css
Normal file
@ -0,0 +1,35 @@
|
||||
body
|
||||
{
|
||||
background-color:#DCEEA9;
|
||||
}
|
||||
#trainerForm
|
||||
{
|
||||
width :90%;
|
||||
line-height:2em;
|
||||
}
|
||||
#frame, #results
|
||||
{
|
||||
width:45%;
|
||||
margin:2em;
|
||||
}
|
||||
#frame
|
||||
{
|
||||
float:left;
|
||||
}
|
||||
#results
|
||||
{
|
||||
float:right;
|
||||
}
|
||||
#display
|
||||
{
|
||||
padding:0.5em;
|
||||
width:100%;
|
||||
}
|
||||
#results li
|
||||
{
|
||||
margin : 2em 0;
|
||||
}
|
||||
.error
|
||||
{
|
||||
color:red;
|
||||
}
|
File diff suppressed because one or more lines are too long
BIN
public/images/favicon.ico
Normal file
BIN
public/images/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
13
src/build/messages.js
Normal file
13
src/build/messages.js
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
module.exports =
|
||||
{
|
||||
emptyXPathError: "<p class='error'>Votre XPath est vide !</p>",
|
||||
exceptionError: "<p class='error'>Il vient d'arriver une exception de nature exceptionnelle !</p>",
|
||||
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",
|
||||
noResultForXPath: "<p>Aucun résultat pour votre recherche.</p>",
|
||||
notXMLError: "<p class='error'>Le fichier que vous avez sélectionné ne semble pas être un fichier XML.</p>",
|
||||
resultsTitle: "<h4>Résultats</h4>",
|
||||
xpathError: "<p class='error'>La syntaxe du XPath saisi ne semble pas correcte.</p>"
|
||||
};
|
@ -35,25 +35,28 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var messages = require("./messages.js");
|
||||
var initialise = function () {
|
||||
var myForm = document.getElementById("trainerForm");
|
||||
var myFile = document.getElementById("myFile");
|
||||
var myXPath = document.getElementById("myXPath");
|
||||
var testButton = document.getElementById("runTest");
|
||||
var myIframe = document.getElementById("display");
|
||||
var divResult = document.getElementById("results");
|
||||
var xpath = require('xpath');
|
||||
try {
|
||||
var myFile_1 = document.getElementById("myFile");
|
||||
var myXPath_1 = document.getElementById("myXPath");
|
||||
var testButton_1 = document.getElementById("runTest");
|
||||
var myIframe_1 = document.getElementById("display");
|
||||
var divResult_1 = document.getElementById("result");
|
||||
myXPath_1.disabled = true;
|
||||
testButton_1.disabled = true;
|
||||
myXPath_1.placeholder = "Commencer pour sélectionner un fichier";
|
||||
myIframe_1.style.display = "none";
|
||||
var xpath_1 = require('xpath');
|
||||
myXPath.disabled = true;
|
||||
testButton.disabled = true;
|
||||
myXPath.placeholder = messages.needXMLFile;
|
||||
myIframe.style.display = "none";
|
||||
divResult.style.display = "none";
|
||||
var dom_1 = require('@xmldom/xmldom').DOMParser;
|
||||
myFile_1.addEventListener("change", function (e) {
|
||||
var selectedFiles = myFile_1.files;
|
||||
myFile.addEventListener("change", function (e) {
|
||||
var selectedFiles = myFile.files;
|
||||
if (selectedFiles !== null && selectedFiles.length === 1) {
|
||||
var extension = selectedFiles[0].name.substring(selectedFiles[0].name.lastIndexOf(".") + 1);
|
||||
if (extension !== "xml")
|
||||
divResult_1.innerHTML = "<p>Le fichier que vous avez s\u00E9lectionn\u00E9 ne semble pas \u00EAtre un fichier XML.</p>";
|
||||
divResult.innerHTML = messages.resultsTitle + messages.notXMLError;
|
||||
else {
|
||||
var reader_1 = new FileReader();
|
||||
reader_1.onload = function (e) {
|
||||
@ -65,23 +68,40 @@ var initialise = function () {
|
||||
type: "application/xml",
|
||||
});
|
||||
iframeURL = URL.createObjectURL(xmlTmp);
|
||||
myIframe_1.src = iframeURL;
|
||||
myIframe_1.style.display = "block";
|
||||
myXPath_1.disabled = false;
|
||||
testButton_1.disabled = false;
|
||||
myXPath_1.placeholder = "Saisir l'XPath à tester";
|
||||
myIframe.src = iframeURL;
|
||||
myIframe.style.display = "block";
|
||||
myXPath.disabled = false;
|
||||
myXPath.placeholder = messages.needXPath;
|
||||
testButton.disabled = false;
|
||||
myXPath.value = "";
|
||||
myXPath.placeholder = messages.needXPath;
|
||||
doc = new dom_1().parseFromString(xmlDatas, 'text/xml');
|
||||
testButton_1.addEventListener("click", function (e) {
|
||||
var xPathTested = myXPath_1.value.trim();
|
||||
myForm.addEventListener("submit", function (e) {
|
||||
try {
|
||||
e.preventDefault();
|
||||
divResult.innerHTML = "";
|
||||
divResult.style.display = "block";
|
||||
var xPathTested = myXPath.value.trim();
|
||||
if (xPathTested == "")
|
||||
divResult_1.innerHTML = "<p>XPath vide !</p>";
|
||||
divResult.innerHTML += messages.resultsTitle + messages.emptyXPathError;
|
||||
else {
|
||||
var resultTxt = messages.resultsTitle;
|
||||
var nodes = xpath.select(xPathTested, doc);
|
||||
if (nodes.length === 0)
|
||||
resultTxt += messages.noResultForXPath;
|
||||
else {
|
||||
var nodes = xpath_1.select(xPathTested, doc);
|
||||
var resultTxt = "<ul>";
|
||||
for (var i = 0; i < nodes.length; i++)
|
||||
resultTxt += "<li>" + nodes[i].toString() + "</li>";
|
||||
resultTxt += "</ul>";
|
||||
divResult_1.innerHTML = resultTxt;
|
||||
resultTxt += "<li>".concat(nodes[i].toString().replaceAll("<", "<").replaceAll(">", ">").replaceAll("\n", "<br>"), "</li>");
|
||||
resultTxt = "<ul>".concat(resultTxt, "</ul>");
|
||||
}
|
||||
divResult.innerHTML = resultTxt;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof Error && e.message == "XPath parse error")
|
||||
divResult.innerHTML = messages.resultsTitle + messages.xpathError;
|
||||
else
|
||||
divResult.innerHTML = messages.resultsTitle + messages.exceptionError;
|
||||
}
|
||||
});
|
||||
return [2];
|
||||
@ -94,9 +114,9 @@ var initialise = function () {
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
divResult.innerHTML = messages.resultsTitle.messages.exceptionError;
|
||||
console.error(e);
|
||||
document.getElementById("result").innerHTML = "<p>D\u00E9sol\u00E9, mais un probl\u00E8me technique emp\u00EAche le fonctionnement normal de cette page.</p>";
|
||||
}
|
||||
};
|
||||
console.log("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");
|
||||
console.log(messages.gitSources);
|
||||
initialise();
|
||||
|
Loading…
Reference in New Issue
Block a user