Browse Source

Nouvelle compilation.

master
Fabrice PENHOËT 4 months ago
parent
commit
145383d416
  1. 2
      public/JS/exampleWithCSV.app.js
  2. 2
      public/JS/exampleWithHTML.app.js
  3. 2
      public/JS/exampleWithJSON.app.js
  4. 2
      public/JS/exampleWithMixedFields.app.js
  5. 2
      public/JS/exampleWithUL.app.js
  6. 2
      public/JS/exampleWithUserFile.app.js
  7. 62
      src/build/SearchEngine.js
  8. 2
      src/build/demo/exampleWithCSV.js
  9. 2
      src/build/demo/exampleWithJSON.js
  10. 2
      src/build/demo/exampleWithMixedFields.js
  11. 2
      src/build/demo/exampleWithUL.js
  12. 1
      src/build/errors.js

2
public/JS/exampleWithCSV.app.js

File diff suppressed because one or more lines are too long

2
public/JS/exampleWithHTML.app.js

File diff suppressed because one or more lines are too long

2
public/JS/exampleWithJSON.app.js

File diff suppressed because one or more lines are too long

2
public/JS/exampleWithMixedFields.app.js

File diff suppressed because one or more lines are too long

2
public/JS/exampleWithUL.app.js

File diff suppressed because one or more lines are too long

2
public/JS/exampleWithUserFile.app.js

File diff suppressed because one or more lines are too long

62
src/build/SearchEngine.js

@ -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();
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;
for (var field in data) {
if (this._fields2Search.indexOf(field) !== -1) {
if (data[field].toLowerCase().indexOf(this._inputValue.toLowerCase()) !== -1)
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 (this.searchPreProcessing(data[field]).indexOf(word.trim()) !== -1) {
nbFound++;
break;
}
}
}
}
return false;
if (nbFound < searchedWords.length)
return false;
else
return true;
};
return SearchEngine;
}());

2
src/build/demo/exampleWithCSV.js

@ -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();

2
src/build/demo/exampleWithJSON.js

@ -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();

2
src/build/demo/exampleWithMixedFields.js

@ -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();

2
src/build/demo/exampleWithUL.js

@ -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();

1
src/build/errors.js

@ -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",

Loading…
Cancel
Save