Nouvelle compilation.

This commit is contained in:
Fabrice PENHOËT 2022-02-21 17:19:09 +01:00
parent 8f236e8854
commit 145383d416
12 changed files with 62 additions and 21 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,6 +10,13 @@ var SearchEngine = (function () {
this.placeholder = "";
this.automaticSearch = false;
this._inputValue = "";
this.searchMode = {
accentOff: true,
caseOff: true,
separatedWords: true,
specialCharsOff: true,
specialCharsWhiteList: "",
};
if (converter.fields.length === 0 || converter.datas.length === 0)
throw new Error(errors.filterNeedDatas);
else {
@ -49,6 +56,8 @@ var SearchEngine = (function () {
set: function (txt) {
if (txt.trim() !== "" && txt.length <= 30)
this._btnTxt = txt;
else
console.error(errors.searchBtnTxtFail);
},
enumerable: true,
configurable: true
@ -83,29 +92,60 @@ var SearchEngine = (function () {
var searchInput = document.getElementById("freeDatas2HTMLSearchTxt"), mySearch = this;
searchInput.addEventListener("input", function (e) {
e.preventDefault();
mySearch._inputValue = searchInput.value;
var searchLength = searchInput.value.length;
mySearch._inputValue = searchInput.value.trim();
var searchLength = mySearch._inputValue.length;
if (mySearch.automaticSearch && (mySearch.nbCharsForSearch === 0 || (searchLength === 0) || (searchLength >= mySearch.nbCharsForSearch)))
mySearch._converter.refreshView();
});
var searchBtn = document.getElementById("freeDatas2HTMLSearchBtn");
searchBtn.addEventListener("click", function (e) {
e.preventDefault();
var searchLength = searchInput.value.length;
if ((mySearch.nbCharsForSearch === 0 || (searchLength === 0) || (searchLength >= mySearch.nbCharsForSearch)))
mySearch._converter.refreshView();
});
};
SearchEngine.prototype.searchPreProcessing = function (searchElement) {
var finalString = searchElement;
if (this.searchMode.accentOff)
finalString = finalString.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
if (this.searchMode.caseOff)
finalString = finalString.toLowerCase();
if (this.searchMode.specialCharsOff) {
var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 " + this.searchMode.specialCharsWhiteList;
var validString = "";
for (var _i = 0, finalString_1 = finalString; _i < finalString_1.length; _i++) {
var letter = finalString_1[_i];
if (validChars.indexOf(letter) !== -1)
validString += letter;
}
finalString = validString;
}
return finalString;
};
SearchEngine.prototype.dataIsOk = function (data) {
if (this._inputValue.length === 0)
var realSearch = this.searchPreProcessing(this._inputValue.trim());
if (realSearch.length === 0)
return true;
var searchedWords = [];
if (this.searchMode.separatedWords)
searchedWords = realSearch.split(" ");
else
searchedWords[0] = realSearch;
var nbFound = 0;
for (var _i = 0, searchedWords_1 = searchedWords; _i < searchedWords_1.length; _i++) {
var word = searchedWords_1[_i];
for (var field in data) {
if (this._fields2Search.indexOf(field) !== -1) {
if (data[field].toLowerCase().indexOf(this._inputValue.toLowerCase()) !== -1)
return true;
if (this.searchPreProcessing(data[field]).indexOf(word.trim()) !== -1) {
nbFound++;
break;
}
}
}
}
if (nbFound < searchedWords.length)
return false;
else
return true;
};
return SearchEngine;
}());

View File

@ -54,7 +54,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
return 0;
};
converter = new FreeDatas2HTML("CSV");
converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/elements-chimiques.csv" });
converter.parser.setRemoteSource({ url: "https://freedatas2html.le-fab-lab.com/datas/elements-chimiques.csv" });
return [4, converter.run()];
case 1:
_a.sent();

View File

@ -42,7 +42,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
case 0:
_a.trys.push([0, 2, , 3]);
converter = new FreeDatas2HTML("JSON");
converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/posts2.json", withCredentials: true, headers: [{ key: "Authorization", value: "Token YWxhZGRpbjpvcGVuc2VzYW1l" }] });
converter.parser.setRemoteSource({ url: "https://freedatas2html.le-fab-lab.com/datas/posts2.json" });
return [4, converter.run()];
case 1:
_a.sent();

View File

@ -43,7 +43,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
case 0:
_a.trys.push([0, 2, , 3]);
converter = new FreeDatas2HTML("JSON");
converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/links.json" });
converter.parser.setRemoteSource({ url: "https://freedatas2html.le-fab-lab.com/datas/links.json" });
return [4, converter.run()];
case 1:
_a.sent();

View File

@ -43,7 +43,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
case 0:
_a.trys.push([0, 2, , 3]);
converter = new FreeDatas2HTML("CSV");
converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/elements-chimiques.csv" });
converter.parser.setRemoteSource({ url: "https://freedatas2html.le-fab-lab.com/datas/elements-chimiques.csv" });
return [4, converter.run()];
case 1:
_a.sent();

View File

@ -29,6 +29,7 @@ module.exports =
remoteSourceNeedUrl: "Merci de fournir une url valide pour la source distante de données.",
remoteSourceUrlFail: "L'url fournie ne semble pas valide.",
renderNeedFields: "Les noms de champs doivent être fournis avant de demander l'affichage des données.",
searchBtnTxtFail: "Le texte du bouton du moteur de recherche doit contenir au maximum 30 caractères.",
searchFieldNotFound: "Au moins un des champs devant être utilisés par le moteur de recherche n'existe pas dans les données.",
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.",
selectorFieldIsEmpty: "Aucune donnée trouvée pour le champ du filtre",