Nouvelle compilation.
This commit is contained in:
parent
8f236e8854
commit
145383d416
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
@ -10,6 +10,13 @@ var SearchEngine = (function () {
|
|||||||
this.placeholder = "";
|
this.placeholder = "";
|
||||||
this.automaticSearch = false;
|
this.automaticSearch = false;
|
||||||
this._inputValue = "";
|
this._inputValue = "";
|
||||||
|
this.searchMode = {
|
||||||
|
accentOff: true,
|
||||||
|
caseOff: true,
|
||||||
|
separatedWords: true,
|
||||||
|
specialCharsOff: true,
|
||||||
|
specialCharsWhiteList: "",
|
||||||
|
};
|
||||||
if (converter.fields.length === 0 || converter.datas.length === 0)
|
if (converter.fields.length === 0 || converter.datas.length === 0)
|
||||||
throw new Error(errors.filterNeedDatas);
|
throw new Error(errors.filterNeedDatas);
|
||||||
else {
|
else {
|
||||||
@ -49,6 +56,8 @@ var SearchEngine = (function () {
|
|||||||
set: function (txt) {
|
set: function (txt) {
|
||||||
if (txt.trim() !== "" && txt.length <= 30)
|
if (txt.trim() !== "" && txt.length <= 30)
|
||||||
this._btnTxt = txt;
|
this._btnTxt = txt;
|
||||||
|
else
|
||||||
|
console.error(errors.searchBtnTxtFail);
|
||||||
},
|
},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
@ -83,29 +92,60 @@ var SearchEngine = (function () {
|
|||||||
var searchInput = document.getElementById("freeDatas2HTMLSearchTxt"), mySearch = this;
|
var searchInput = document.getElementById("freeDatas2HTMLSearchTxt"), mySearch = this;
|
||||||
searchInput.addEventListener("input", function (e) {
|
searchInput.addEventListener("input", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
mySearch._inputValue = searchInput.value;
|
mySearch._inputValue = searchInput.value.trim();
|
||||||
var searchLength = searchInput.value.length;
|
var searchLength = mySearch._inputValue.length;
|
||||||
if (mySearch.automaticSearch && (mySearch.nbCharsForSearch === 0 || (searchLength === 0) || (searchLength >= mySearch.nbCharsForSearch)))
|
if (mySearch.automaticSearch && (mySearch.nbCharsForSearch === 0 || (searchLength === 0) || (searchLength >= mySearch.nbCharsForSearch)))
|
||||||
mySearch._converter.refreshView();
|
mySearch._converter.refreshView();
|
||||||
});
|
});
|
||||||
var searchBtn = document.getElementById("freeDatas2HTMLSearchBtn");
|
var searchBtn = document.getElementById("freeDatas2HTMLSearchBtn");
|
||||||
searchBtn.addEventListener("click", function (e) {
|
searchBtn.addEventListener("click", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var searchLength = searchInput.value.length;
|
mySearch._converter.refreshView();
|
||||||
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) {
|
SearchEngine.prototype.dataIsOk = function (data) {
|
||||||
if (this._inputValue.length === 0)
|
var realSearch = this.searchPreProcessing(this._inputValue.trim());
|
||||||
|
if (realSearch.length === 0)
|
||||||
return true;
|
return true;
|
||||||
for (var field in data) {
|
var searchedWords = [];
|
||||||
if (this._fields2Search.indexOf(field) !== -1) {
|
if (this.searchMode.separatedWords)
|
||||||
if (data[field].toLowerCase().indexOf(this._inputValue.toLowerCase()) !== -1)
|
searchedWords = realSearch.split(" ");
|
||||||
return true;
|
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;
|
return SearchEngine;
|
||||||
}());
|
}());
|
||||||
|
@ -54,7 +54,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
converter = new FreeDatas2HTML("CSV");
|
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()];
|
return [4, converter.run()];
|
||||||
case 1:
|
case 1:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
|
@ -42,7 +42,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
|
|||||||
case 0:
|
case 0:
|
||||||
_a.trys.push([0, 2, , 3]);
|
_a.trys.push([0, 2, , 3]);
|
||||||
converter = new FreeDatas2HTML("JSON");
|
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()];
|
return [4, converter.run()];
|
||||||
case 1:
|
case 1:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
|
@ -43,7 +43,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
|
|||||||
case 0:
|
case 0:
|
||||||
_a.trys.push([0, 2, , 3]);
|
_a.trys.push([0, 2, , 3]);
|
||||||
converter = new FreeDatas2HTML("JSON");
|
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()];
|
return [4, converter.run()];
|
||||||
case 1:
|
case 1:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
|
@ -43,7 +43,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
|
|||||||
case 0:
|
case 0:
|
||||||
_a.trys.push([0, 2, , 3]);
|
_a.trys.push([0, 2, , 3]);
|
||||||
converter = new FreeDatas2HTML("CSV");
|
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()];
|
return [4, converter.run()];
|
||||||
case 1:
|
case 1:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
|
@ -29,6 +29,7 @@ module.exports =
|
|||||||
remoteSourceNeedUrl: "Merci de fournir une url valide pour la source distante de données.",
|
remoteSourceNeedUrl: "Merci de fournir une url valide pour la source distante de données.",
|
||||||
remoteSourceUrlFail: "L'url fournie ne semble pas valide.",
|
remoteSourceUrlFail: "L'url fournie ne semble pas valide.",
|
||||||
renderNeedFields: "Les noms de champs doivent être fournis avant de demander l'affichage des données.",
|
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.",
|
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.",
|
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",
|
selectorFieldIsEmpty: "Aucune donnée trouvée pour le champ du filtre",
|
||||||
|
Loading…
Reference in New Issue
Block a user