Nouvelle compilation en JS, incluant les nouvelles classes.

This commit is contained in:
Fabrice PENHOËT 2021-09-21 17:51:13 +02:00
parent 4c033616d3
commit 7d6712e244
7 changed files with 437 additions and 306 deletions

File diff suppressed because one or more lines are too long

View File

@ -34,16 +34,13 @@ 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 }; if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
} }
}; };
import { freeDatas2HTML } from "./freeDatas2HTML"; import { FreeDatas2HTML, Pagination, Selector, SortingField } from "./freeDatas2HTML";
var initialise = function () { return __awaiter(void 0, void 0, void 0, function () { var initialise = function () { return __awaiter(void 0, void 0, void 0, function () {
var converter, mySort, e_1; var mySort, converter, pagination, filtre1, filtre2, filtre3, sortingField1, sortingField2, sortingField3, sortingField4, e_1;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
_a.trys.push([0, 2, , 3]); _a.trys.push([0, 3, , 4]);
converter = new freeDatas2HTML();
converter.datasViewElt = { id: "datas" };
converter.datasSelectors = [{ datasFieldNb: 3, id: "filtre1" }, { datasFieldNb: 4, id: "filtre2" }, { datasFieldNb: 5, id: "filtre3", separator: "," }];
mySort = function (a, b, order) { mySort = function (a, b, order) {
if (order === void 0) { order = "asc"; } if (order === void 0) { order = "asc"; }
var values = ["> 100000", "> 1 et < 100 000", "≤ 1", "Traces", "Inexistant"]; var values = ["> 100000", "> 1 et < 100 000", "≤ 1", "Traces", "Inexistant"];
@ -56,33 +53,56 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
else else
return 0; return 0;
}; };
converter.datasSortingColumns = [{ datasFieldNb: 0 }, { datasFieldNb: 1 }, { datasFieldNb: 2 }, { datasFieldNb: 4 }]; converter = new FreeDatas2HTML();
converter.datasSortingFunctions = [{ datasFieldNb: 4, sort: mySort }]; converter.datasViewElt = { id: "datas" };
converter.pagination =
{
selectedValue: 10,
options: {
displayElement: { id: "paginationOptions" },
values: [10, 20, 50, 500],
name: "Choix de pagination :"
},
pages: {
displayElement: { id: "pages" },
name: "Page à afficher :"
}
};
converter.datasSourceUrl = "http://localhost:8080/datas/elements-chimiques.csv"; converter.datasSourceUrl = "http://localhost:8080/datas/elements-chimiques.csv";
return [4, converter.run()]; return [4, converter.parse()];
case 1: case 1:
_a.sent(); _a.sent();
return [3, 3]; converter.datasSortingFunctions = [{ datasFieldNb: 4, sort: mySort }];
pagination = new Pagination(converter, { id: "pages" }, "Page à afficher :");
pagination.options = { displayElement: { id: "paginationOptions" }, values: [10, 20, 50, 500], name: "Choix de pagination :" };
pagination.selectedValue = 10;
converter.pagination = pagination;
pagination.rend2HTML();
return [4, converter.run()];
case 2: case 2:
_a.sent();
filtre1 = new Selector(converter);
filtre1.datasViewElt = { id: "filtre1" };
filtre1.datasFieldNb = 3;
filtre1.selector2HTML();
filtre2 = new Selector(converter);
filtre2.datasViewElt = { id: "filtre2" };
filtre2.datasFieldNb = 4;
filtre2.selector2HTML();
filtre3 = new Selector(converter);
filtre3.datasViewElt = { id: "filtre3" };
filtre3.datasFieldNb = 5;
filtre3.separator = ",";
filtre3.selector2HTML();
converter.datasSelectors = [filtre1, filtre2, filtre3];
sortingField1 = new SortingField(converter);
sortingField1.datasFieldNb = 0;
sortingField1.field2HTML();
sortingField2 = new SortingField(converter);
sortingField2.datasFieldNb = 1;
sortingField2.field2HTML();
sortingField3 = new SortingField(converter);
sortingField3.datasFieldNb = 2;
sortingField3.field2HTML();
sortingField4 = new SortingField(converter);
sortingField4.datasFieldNb = 4;
sortingField4.field2HTML();
converter.datasSortingFields = [sortingField1, sortingField2, sortingField3, sortingField4];
return [3, 4];
case 3:
e_1 = _a.sent(); e_1 = _a.sent();
console.error(e_1); console.error(e_1);
if (document.getElementById("datas") !== null) if (document.getElementById("datas") !== null)
document.getElementById("datas").innerHTML = "<strong>Désolé, mais un problème technique empêche l'affichage des données.</strong>"; document.getElementById("datas").innerHTML = "<strong>Désolé, mais un problème technique empêche l'affichage des données.</strong>";
return [3, 3]; return [3, 4];
case 3: return [2]; case 4: return [2];
} }
}); });
}); }; }); };

View File

@ -37,26 +37,20 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
var Papa = require("papaparse"); var Papa = require("papaparse");
var errors = require("./errors.js"); var errors = require("./errors.js");
var compare = require('natural-orderby').compare; var compare = require('natural-orderby').compare;
var freeDatas2HTML = (function () { var FreeDatas2HTML = (function () {
function freeDatas2HTML() { function FreeDatas2HTML() {
this._datasViewElt = { id: "", eltDOM: undefined }; this._datasViewElt = { id: "", eltDOM: undefined };
this.datasHTML = ""; this.datasHTML = "";
this._datasSelectors = [];
this._datasSortingColumns = [];
this._datasSortingFunctions = [];
this._datasSourceUrl = ""; this._datasSourceUrl = "";
this.parseMeta = undefined; this._datasSortingFunctions = [];
this.parseMetas = undefined;
this.parseDatas = []; this.parseDatas = [];
this.parseErrors = []; this.parseErrors = [];
this.stopIfParseErrors = false; this.stopIfParseErrors = false;
this.datasSelectors = [];
this.datasSortingFields = [];
} }
freeDatas2HTML.isPositiveInteger = function (nb) { Object.defineProperty(FreeDatas2HTML.prototype, "datasViewElt", {
return (Number.isInteger(nb) === false || nb <= 0) ? false : true;
};
freeDatas2HTML.isNaturalNumber = function (nb) {
return (Number.isInteger(nb) === false || nb < 0) ? false : true;
};
Object.defineProperty(freeDatas2HTML.prototype, "datasViewElt", {
set: function (elt) { set: function (elt) {
var checkContainerExist = document.getElementById(elt.id); var checkContainerExist = document.getElementById(elt.id);
if (checkContainerExist === null) if (checkContainerExist === null)
@ -69,7 +63,7 @@ var freeDatas2HTML = (function () {
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(freeDatas2HTML.prototype, "datasSourceUrl", { Object.defineProperty(FreeDatas2HTML.prototype, "datasSourceUrl", {
set: function (url) { set: function (url) {
if (url.trim().length === 0) if (url.trim().length === 0)
throw new Error(errors.needUrl); throw new Error(errors.needUrl);
@ -79,122 +73,24 @@ var freeDatas2HTML = (function () {
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(freeDatas2HTML.prototype, "datasSelectors", { Object.defineProperty(FreeDatas2HTML.prototype, "datasSortingFunctions", {
get: function () { set: function (SortingFunctions) {
return this._datasSelectors;
},
set: function (selectionElts) {
this._datasSelectors = [];
var checkContainerExist;
for (var i in selectionElts) {
checkContainerExist = document.getElementById(selectionElts[i].id);
if (checkContainerExist === null)
console.error(errors.elementNotFound + selectionElts[i].id);
else if (freeDatas2HTML.isNaturalNumber(selectionElts[i].datasFieldNb) === false)
console.error(errors.needNaturalNumber);
else {
selectionElts[i].eltDOM = checkContainerExist;
if (selectionElts[i].separator !== undefined && selectionElts[i].separator === "")
selectionElts[i].separator = undefined;
this._datasSelectors.push(selectionElts[i]);
}
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(freeDatas2HTML.prototype, "datasSortingColumns", {
get: function () {
return this._datasSortingColumns;
},
set: function (sortingColumns) {
this._datasSortingColumns = [];
for (var i = 0; i < sortingColumns.length; i++) {
if (freeDatas2HTML.isNaturalNumber(sortingColumns[i].datasFieldNb) === false)
console.error(errors.needNaturalNumber);
else {
sortingColumns[i].order = undefined;
this._datasSortingColumns.push(sortingColumns[i]);
}
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(freeDatas2HTML.prototype, "datasSortingFunctions", {
set: function (sortingFunctions) {
this._datasSortingFunctions = []; this._datasSortingFunctions = [];
for (var i = 0; i < sortingFunctions.length; i++) { for (var i = 0; i < SortingFunctions.length; i++) {
if (freeDatas2HTML.isNaturalNumber(sortingFunctions[i].datasFieldNb) === false) this._datasSortingFunctions.push(SortingFunctions[i]);
console.error(errors.needNaturalNumber);
else
this._datasSortingFunctions.push(sortingFunctions[i]);
} }
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
freeDatas2HTML.prototype.getSortingFunctionForField = function (datasFieldNb) { FreeDatas2HTML.prototype.getSortingFunctionForField = function (datasFieldNb) {
for (var i in this._datasSortingFunctions) { for (var i in this._datasSortingFunctions) {
if (this._datasSortingFunctions[i].datasFieldNb === datasFieldNb) if (this._datasSortingFunctions[i].datasFieldNb === datasFieldNb)
return this._datasSortingFunctions[i]; return this._datasSortingFunctions[i];
} }
return undefined; return undefined;
}; };
Object.defineProperty(freeDatas2HTML.prototype, "pagination", { FreeDatas2HTML.prototype.parse = function () {
get: function () {
return this._pagination;
},
set: function (config) {
this._pagination = {};
if (config.selectedValue !== undefined || config.options !== undefined) {
if (config.pages === undefined)
throw new Error(errors.needPagesSelectorElt);
var checkContainerExist = document.getElementById(config.pages.displayElement.id);
if (checkContainerExist === null)
throw new Error(errors.elementNotFound + config.pages.displayElement.id);
else {
this.pagination.pages =
{
displayElement: {
id: config.pages.displayElement.id,
eltDOM: checkContainerExist
},
name: (config.pages.name) ? config.pages.name : "Pages :",
selectedValue: 1,
};
}
}
if (config.options !== undefined) {
var checkContainerExist = document.getElementById(config.options.displayElement.id);
if (checkContainerExist === null)
throw new Error(errors.elementNotFound + config.options.displayElement.id);
else {
for (var i = 0; i < config.options.values.length; i++) {
if (freeDatas2HTML.isPositiveInteger(config.options.values[i]) === false)
throw new Error(errors.needPositiveInteger);
}
this._pagination.options =
{
displayElement: { id: config.options.displayElement.id, eltDOM: checkContainerExist },
name: (config.options.name) ? config.options.name : "Pagination :",
values: config.options.values
};
}
}
if (config.selectedValue !== undefined) {
if (config.options !== undefined && (config.options.values.indexOf(config.selectedValue) === -1))
throw new Error(errors.needPaginationByDefaultBeInOptions);
if (freeDatas2HTML.isPositiveInteger(config.selectedValue))
this._pagination.selectedValue = config.selectedValue;
else
throw new Error(errors.needPositiveInteger);
}
},
enumerable: true,
configurable: true
});
freeDatas2HTML.prototype.parse = function () {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var converter; var converter;
return __generator(this, function (_a) { return __generator(this, function (_a) {
@ -213,7 +109,7 @@ var freeDatas2HTML = (function () {
realFields.push(results.meta.fields[i]); realFields.push(results.meta.fields[i]);
} }
results.meta.fields = realFields; results.meta.fields = realFields;
converter.parseMeta = results.meta; converter.parseMetas = results.meta;
resolve(true); resolve(true);
}, },
error: function (error) { error: function (error) {
@ -229,9 +125,8 @@ var freeDatas2HTML = (function () {
}); });
}); });
}; };
freeDatas2HTML.prototype.run = function () { FreeDatas2HTML.prototype.run = function () {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var converter_1, selectorsHTML, i, values, colName, row, checkedValue, checkedValues, i_1, checkedValue, j, selectElement, values_1, selectorsHTML, j, selectElement_1, indexSelectedValue, i;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
@ -242,81 +137,11 @@ var freeDatas2HTML = (function () {
return [4, this.parse()]; return [4, this.parse()];
case 1: case 1:
_a.sent(); _a.sent();
if (this.parseDatas.length === 0 || this.parseMeta.fields === undefined) if (this.parseDatas.length === 0 || this.parseMetas.fields === undefined)
throw new Error(errors.datasNotFound); throw new Error(errors.datasNotFound);
else if (this.stopIfParseErrors && this.parseErrors.length !== 0) else if (this.stopIfParseErrors && this.parseErrors.length !== 0)
console.error(this.parseErrors); console.error(this.parseErrors);
else { else {
converter_1 = this;
if (this._datasSelectors.length > 0) {
selectorsHTML = [];
for (i in this._datasSelectors) {
if (this._datasSelectors[i].datasFieldNb > (this.parseMeta.fields.length - 1))
throw new Error(errors.selectorFieldNotFound);
else {
values = [], colName = this.parseMeta.fields[this._datasSelectors[i].datasFieldNb];
for (row in this.parseDatas) {
if (this._datasSelectors[i].separator === undefined) {
checkedValue = this.parseDatas[row][colName].trim();
if (checkedValue !== "" && values.indexOf(checkedValue) === -1)
values.push(checkedValue);
}
else {
checkedValues = this.parseDatas[row][colName].split(this._datasSelectors[i].separator);
for (i_1 in checkedValues) {
checkedValue = checkedValues[i_1].trim();
if (checkedValue !== "" && values.indexOf(checkedValue) === -1)
values.push(checkedValue);
}
}
}
if (values.length > 0) {
if (this.getSortingFunctionForField(this._datasSelectors[i].datasFieldNb) !== undefined)
values.sort(this.getSortingFunctionForField(this._datasSelectors[i].datasFieldNb).sort);
else
values.sort(compare());
this._datasSelectors[i].name = colName;
this._datasSelectors[i].values = values;
selectorsHTML[i] = "<label for='freeDatas2HTMLSelector" + i + "'>" + colName + " : </label><select name='freeDatas2HTMLSelector" + i + "' id='freeDatas2HTMLSelector" + i + "'><option value='0'>----</option>";
for (j in values)
selectorsHTML[i] += "<option value='" + (Number(j) + 1) + "'>" + values[j] + "</option>";
selectorsHTML[i] += "</select>";
this._datasSelectors[i].eltDOM.innerHTML = selectorsHTML[i];
selectElement = document.getElementById("freeDatas2HTMLSelector" + i);
selectElement.addEventListener('change', function (e) {
converter_1.datasHTML = converter_1.createDatasHTML(converter_1.parseMeta.fields, converter_1.parseDatas);
converter_1.refreshView();
});
}
}
}
}
if (converter_1.pagination !== undefined && converter_1.pagination.options !== undefined && converter_1.pagination.options.values.length > 0) {
values_1 = converter_1.pagination.options.values;
selectorsHTML = "<label for='freeDatas2HTMLPaginationSelector'>" + converter_1.pagination.options.name + " </label><select name='freeDatas2HTMLPaginationSelector' id='freeDatas2HTMLPaginationSelector'><option value='0'>----</option>";
for (j in values_1)
selectorsHTML += "<option value='" + (Number(j) + 1) + "'>" + values_1[j] + "</option>";
selectorsHTML += "</select>";
converter_1.pagination.options.displayElement.eltDOM.innerHTML = selectorsHTML;
selectElement_1 = document.getElementById("freeDatas2HTMLPaginationSelector");
if (converter_1.pagination.selectedValue !== undefined) {
indexSelectedValue = converter_1.pagination.options.values.indexOf(converter_1.pagination.selectedValue) + 1;
selectElement_1.value = "" + indexSelectedValue;
}
selectElement_1.addEventListener('change', function (e) {
if (selectElement_1.value === "0")
converter_1.pagination.selectedValue = undefined;
else
converter_1.pagination.selectedValue = values_1[Number(selectElement_1.value) - 1];
converter_1.datasHTML = converter_1.createDatasHTML(converter_1.parseMeta.fields, converter_1.parseDatas);
converter_1.refreshView();
});
}
for (i in this._datasSortingColumns) {
if (this._datasSortingColumns[i].datasFieldNb > (this.parseMeta.fields.length - 1))
throw new Error(errors.sortingColumnsFieldNotFound);
}
this.datasHTML = this.createDatasHTML(this.parseMeta.fields, this.parseDatas);
this.refreshView(); this.refreshView();
return [2, true]; return [2, true];
} }
@ -325,55 +150,26 @@ var freeDatas2HTML = (function () {
}); });
}); });
}; };
freeDatas2HTML.prototype.refreshView = function () { FreeDatas2HTML.prototype.refreshView = function () {
if (this._datasViewElt.eltDOM !== undefined) { if (this.parseMetas === undefined || this.parseMetas.fields === undefined || this._datasViewElt.eltDOM === undefined)
var converter_2 = this; throw new Error(errors.refreshFail);
this.datasHTML = this.createDatasHTML(this.parseMetas.fields, this.parseDatas);
this._datasViewElt.eltDOM.innerHTML = this.datasHTML; this._datasViewElt.eltDOM.innerHTML = this.datasHTML;
if (this._datasSortingColumns.length > 0) { for (var i in this.datasSortingFields) {
var getTableTh = document.querySelectorAll("table th"); var field = this.datasSortingFields[i];
if (getTableTh !== null) { field.field2HTML();
var _loop_1 = function (i) {
var datasFieldNb = this_1._datasSortingColumns[i].datasFieldNb;
var htmlContent = getTableTh[datasFieldNb].innerHTML;
htmlContent = "<a href='#freeDatas2HTMLSorting" + datasFieldNb + "' id='freeDatas2HTMLSorting" + datasFieldNb + "'>" + htmlContent + "</a>";
getTableTh[datasFieldNb].innerHTML = htmlContent;
var sortingElement = document.getElementById("freeDatas2HTMLSorting" + datasFieldNb);
sortingElement.addEventListener("click", function (e) {
e.preventDefault();
var order = converter_2.datasSortingColumns[i].order;
if (order === undefined || order === "desc")
converter_2.datasSortingColumns[i].order = "asc";
else
converter_2.datasSortingColumns[i].order = "desc";
converter_2._datasSortedColumn = converter_2.datasSortingColumns[i];
converter_2.datasHTML = converter_2.createDatasHTML(converter_2.parseMeta.fields, converter_2.parseDatas);
converter_2.refreshView();
});
};
var this_1 = this;
for (var i in this._datasSortingColumns) {
_loop_1(i);
}
}
}
} }
}; };
freeDatas2HTML.prototype.createDatasHTML = function (fields, datas) { FreeDatas2HTML.prototype.createDatasHTML = function (fields, datas) {
var checkSelectorExist, filters = []; if (this.datasSortedField !== undefined && this.datasSortedField.datasFieldNb !== undefined) {
for (var i in this._datasSelectors) { var field_1 = fields[this.datasSortedField.datasFieldNb];
checkSelectorExist = document.querySelector("#" + this._datasSelectors[i].id + " select"); var fieldOrder_1 = this.datasSortedField.order;
if (checkSelectorExist != null && checkSelectorExist.selectedIndex != 0) if (this.getSortingFunctionForField(this.datasSortedField.datasFieldNb) !== undefined) {
filters.push({ field: this._datasSelectors[i].name, value: this._datasSelectors[i].values[checkSelectorExist.selectedIndex - 1], separator: this._datasSelectors[i].separator }); var myFunction_1 = this.getSortingFunctionForField(this.datasSortedField.datasFieldNb);
} datas.sort(function (a, b) { return myFunction_1.sort(a[field_1], b[field_1], fieldOrder_1); });
if (this._datasSortedColumn !== undefined) {
var col_1 = fields[this._datasSortedColumn.datasFieldNb];
var colOrder_1 = this._datasSortedColumn.order;
if (this.getSortingFunctionForField(this._datasSortedColumn.datasFieldNb) !== undefined) {
var myFunction_1 = this.getSortingFunctionForField(this._datasSortedColumn.datasFieldNb);
datas.sort(function (a, b) { return myFunction_1.sort(a[col_1], b[col_1], colOrder_1); });
} }
else else
datas.sort(function (a, b) { return compare({ order: colOrder_1 })(a[col_1], b[col_1]); }); datas.sort(function (a, b) { return compare({ order: fieldOrder_1 })(a[field_1], b[field_1]); });
} }
var firstData = 0; var firstData = 0;
if (this.pagination !== undefined && this.pagination.selectedValue !== undefined && this.pagination.pages !== undefined && this.pagination.pages.selectedValue !== undefined) if (this.pagination !== undefined && this.pagination.selectedValue !== undefined && this.pagination.pages !== undefined && this.pagination.pages.selectedValue !== undefined)
@ -386,23 +182,10 @@ var freeDatas2HTML = (function () {
var nbVisible = 0, nbTotal = 0; var nbVisible = 0, nbTotal = 0;
for (var row in datas) { for (var row in datas) {
var visible = true; var visible = true;
if (filters.length !== 0) { if (this.datasSelectors.length !== 0) {
var i = 0; var i = 0;
while (filters[i] !== undefined && visible === true) { while (this.datasSelectors[i] !== undefined && visible === true) {
if (filters[i].separator === undefined) { visible = this.datasSelectors[i].dataIsOk(datas[row]);
if (datas[row][filters[i].field].trim() !== filters[i].value)
visible = false;
}
else {
visible = false;
var checkedValues = datas[row][filters[i].field].split(filters[i].separator);
for (var j in checkedValues) {
if (checkedValues[j].trim() === filters[i].value) {
visible = true;
break;
}
}
}
i++; i++;
} }
} }
@ -420,31 +203,13 @@ var freeDatas2HTML = (function () {
nbTotal++; nbTotal++;
} }
datasHTML += "</tbody></table>"; datasHTML += "</tbody></table>";
if (this.pagination !== undefined && this.pagination.selectedValue !== undefined && this.pagination.pages !== undefined && nbTotal > this.pagination.selectedValue) { if (this.pagination !== undefined)
var nbPages = Math.ceil(nbTotal / this.pagination.selectedValue); this.pagination.creaPageSelector(nbTotal);
var selectorsHTML = "<label for='freeDatas2HTMLPagesSelector'>" + this.pagination.pages.name + " </label><select name='freeDatas2HTMLPagesSelector' id='freeDatas2HTMLPagesSelector'><option value='1'>1</option>";
this.pagination.pages.values = [1];
for (var j = 2; j <= nbPages; j++) {
selectorsHTML += "<option value='" + j + "'>" + j + "</option>";
this.pagination.pages.values.push(j);
}
selectorsHTML += "</select>";
this.pagination.pages.displayElement.eltDOM.innerHTML = selectorsHTML;
var selectElement_2 = document.getElementById("freeDatas2HTMLPagesSelector");
if (this.pagination.pages.selectedValue !== undefined)
selectElement_2.value = "" + this.pagination.pages.selectedValue;
var converter_3 = this;
this.pagination.pages.selectedValue = 1;
selectElement_2.addEventListener('change', function (e) {
converter_3.pagination.pages.selectedValue = Number(selectElement_2.value);
converter_3.datasHTML = converter_3.createDatasHTML(converter_3.parseMeta.fields, converter_3.parseDatas);
converter_3.refreshView();
});
}
else if (this.pagination !== undefined && this.pagination.pages !== undefined)
this.pagination.pages.displayElement.eltDOM.innerHTML = "";
return datasHTML; return datasHTML;
}; };
return freeDatas2HTML; return FreeDatas2HTML;
}()); }());
export { freeDatas2HTML }; export { FreeDatas2HTML };
export { Pagination } from "./freeDatas2HTMLPagination";
export { Selector } from "./freeDatas2HTMLSelector";
export { SortingField } from "./freeDatas2HTMLSortingField";

View File

@ -0,0 +1 @@
;

View File

@ -0,0 +1,119 @@
var errors = require("./errors.js");
var Pagination = (function () {
function Pagination(converter, pagesElt, pagesName) {
if (pagesName === void 0) { pagesName = "Pages"; }
if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined)
throw new Error(errors.paginationNeedDatas);
else {
var checkContainerExist = document.getElementById(pagesElt.id);
if (checkContainerExist === null)
throw new Error(errors.elementNotFound + pagesElt.id);
else {
this._converter = converter;
this._pages = { displayElement: { id: pagesElt.id, eltDOM: checkContainerExist }, name: pagesName };
}
}
}
Pagination.isPositiveInteger = function (nb) {
return (Number.isInteger(nb) === false || nb <= 0) ? false : true;
};
Object.defineProperty(Pagination.prototype, "selectedValue", {
get: function () {
return this._selectedValue;
},
set: function (value) {
if (value === undefined || !Pagination.isPositiveInteger(value))
throw new Error(errors.needPositiveInteger);
if (this.options !== undefined && this.options.values.indexOf(value) === -1)
throw new Error(errors.needPaginationByDefaultBeInOptions);
this._selectedValue = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Pagination.prototype, "options", {
get: function () {
return this._options;
},
set: function (options) {
if (options !== undefined) {
var checkContainerExist = document.getElementById(options.displayElement.id);
if (checkContainerExist === null)
throw new Error(errors.elementNotFound + options.displayElement.id);
else
options.displayElement.eltDOM = checkContainerExist;
if (options.values.length === 0)
throw new Error(errors.needPaginationOptionsValues);
for (var i in options.values) {
if (!Pagination.isPositiveInteger(options.values[i]))
throw new Error(errors.needPositiveInteger);
}
options.name = (options.name === undefined) ? "Pagination" : options.name;
this._options = options;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Pagination.prototype, "pages", {
get: function () {
return this._pages;
},
enumerable: true,
configurable: true
});
Pagination.prototype.rend2HTML = function () {
if (this._converter === undefined || this._options === undefined)
throw new Error(errors.pagination2HTMLFail);
else {
var selectorsHTML = "<label for='freeDatas2HTMLPaginationSelector'>" + this._options.name + " </label><select name='freeDatas2HTMLPaginationSelector' id='freeDatas2HTMLPaginationSelector'><option value='0'>----</option>";
for (var j in this._options.values)
selectorsHTML += "<option value='" + (Number(j) + 1) + "'>" + this._options.values[j] + "</option>";
selectorsHTML += "</select>";
this._options.displayElement.eltDOM.innerHTML = selectorsHTML;
var selectElement_1 = document.getElementById("freeDatas2HTMLPaginationSelector");
if (this._selectedValue !== undefined) {
var indexSelectedValue = this._options.values.indexOf(this._selectedValue) + 1;
selectElement_1.value = "" + indexSelectedValue;
}
var pagination_1 = this;
selectElement_1.addEventListener("change", function (e) {
if (selectElement_1.value === "0")
pagination_1._selectedValue = undefined;
else
pagination_1._selectedValue = pagination_1._options.values[Number(selectElement_1.value) - 1];
pagination_1._converter.refreshView();
});
}
};
Pagination.prototype.creaPageSelector = function (nbTotal) {
if (this.selectedValue !== undefined) {
if (nbTotal > this.selectedValue) {
var nbPages = Math.ceil(nbTotal / this.selectedValue);
var selectorsHTML = "<label for='freeDatas2HTMLPagesSelector'>" + this.pages.name + " </label><select name='freeDatas2HTMLPagesSelector' id='freeDatas2HTMLPagesSelector'><option value='1'>1</option>";
this.pages.values = [1];
for (var j = 2; j <= nbPages; j++) {
selectorsHTML += "<option value='" + j + "'>" + j + "</option>";
this.pages.values.push(j);
}
selectorsHTML += "</select>";
this.pages.displayElement.eltDOM.innerHTML = selectorsHTML;
var selectElement_2 = document.getElementById("freeDatas2HTMLPagesSelector");
if (this.pages.selectedValue !== undefined)
selectElement_2.value = "" + this.pages.selectedValue;
this.pages.selectedValue = 1;
var pagination_2 = this;
selectElement_2.addEventListener('change', function (e) {
pagination_2.pages.selectedValue = Number(selectElement_2.value);
pagination_2._converter.refreshView();
});
}
else
this.pages.displayElement.eltDOM.innerHTML = "";
}
else
this.pages.displayElement.eltDOM.innerHTML = "";
};
return Pagination;
}());
export { Pagination };

View File

@ -0,0 +1,129 @@
var compare = require('natural-orderby').compare;
var errors = require("./errors.js");
var Selector = (function () {
function Selector(converter) {
this._datasViewElt = { id: "", eltDOM: undefined };
this.name = "";
this.values = [];
if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined || converter.parseDatas.length === 0)
throw new Error(errors.selectorNeedDatas);
else
this._converter = converter;
}
Object.defineProperty(Selector.prototype, "datasViewElt", {
get: function () {
return this._datasViewElt;
},
set: function (elt) {
var checkContainerExist = document.getElementById(elt.id);
if (checkContainerExist === null)
throw new Error(errors.elementNotFound + elt.id);
else {
this._datasViewElt.id = elt.id;
this._datasViewElt.eltDOM = checkContainerExist;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Selector.prototype, "datasFieldNb", {
get: function () {
return this._datasFieldNb;
},
set: function (datasFieldNb) {
if (datasFieldNb !== undefined && this._converter.parseMetas.fields[datasFieldNb] === undefined)
throw new Error(errors.selectorFieldNotFound);
else
this._datasFieldNb = datasFieldNb;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Selector.prototype, "separator", {
set: function (separator) {
if (separator === "")
this._separator = undefined;
else
this._separator = separator;
},
enumerable: true,
configurable: true
});
Selector.prototype.selector2HTML = function () {
if (this._converter === undefined || this._datasViewElt.eltDOM === undefined || this._datasFieldNb === undefined)
throw new Error(errors.selector2HTMLFail);
else {
this.name = this._converter.parseMetas.fields[this._datasFieldNb];
for (var row in this._converter.parseDatas) {
if (this._separator === undefined) {
var checkedValue = String(this._converter.parseDatas[row][this.name]).trim();
if (checkedValue !== "" && this.values.indexOf(checkedValue) === -1)
this.values.push(checkedValue);
}
else {
var checkedValues = String(this._converter.parseDatas[row][this.name]).split(this._separator);
for (var i in checkedValues) {
var checkedValue = checkedValues[i].trim();
if (checkedValue !== "" && this.values.indexOf(checkedValue) === -1)
this.values.push(checkedValue);
}
}
}
if (this.values.length > 0) {
if (this._converter.getSortingFunctionForField(this._datasFieldNb) !== undefined)
this.values.sort(this._converter.getSortingFunctionForField(this._datasFieldNb).sort);
else
this.values.sort(compare());
var selectorsHTML = "<label for='freeDatas2HTML_" + this._datasViewElt.id + "'>" + this.name + " : </label><select name='freeDatas2HTML_" + this._datasViewElt.id + "' id='freeDatas2HTML_" + this._datasViewElt.id + "'><option value='0'>----</option>";
for (var j in this.values)
selectorsHTML += "<option value='" + (Number(j) + 1) + "'>" + this.values[j] + "</option>";
selectorsHTML += "</select>";
this._datasViewElt.eltDOM.innerHTML = selectorsHTML;
var selectElement = document.getElementById("freeDatas2HTML_" + this._datasViewElt.id), mySelector_1 = this;
selectElement.addEventListener("change", function (e) {
mySelector_1._converter.refreshView();
});
}
}
};
Selector.prototype.getSelectionnedId = function () {
var selectElement = document.getElementById("freeDatas2HTML_" + this._datasViewElt.id);
if (selectElement === undefined)
return 0;
else
return parseInt(selectElement.value, 10);
};
Selector.prototype.dataIsOk = function (data) {
if (this.name === undefined || this.name === "")
throw new Error(errors.selectorCheckIsOkFail);
var selectedValue = this.getSelectionnedId();
if (selectedValue === 0)
return true;
else
selectedValue = selectedValue - 1;
if (this.values[selectedValue] === undefined)
throw new Error(errors.selectorSelectedIndexNotFound);
if (data[this.name] === undefined)
return false;
var selectedValueTxt = this.values[selectedValue];
if (this._separator === undefined) {
if (data[this.name].trim() !== selectedValueTxt)
return false;
else
return true;
}
else {
var find = false;
var checkedValues = String(data[this.name]).split(this._separator);
for (var j in checkedValues) {
if (checkedValues[j].trim() === selectedValueTxt) {
find = true;
break;
}
}
return find;
}
};
return Selector;
}());
export { Selector };

View File

@ -0,0 +1,64 @@
var compare = require('natural-orderby').compare;
var errors = require("./errors.js");
var SortingField = (function () {
function SortingField(converter, fieldsDOMSelector) {
if (fieldsDOMSelector === void 0) { fieldsDOMSelector = "th"; }
this._order = undefined;
if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined)
throw new Error(errors.sortingFieldNeedDatas);
else {
var fields = document.querySelectorAll(fieldsDOMSelector);
if (fields === undefined)
throw new Error(errors.sortingFieldsNotInHTML);
else if (fields.length !== converter.parseMetas.fields.length)
throw new Error(errors.sortingFieldsNbFail);
else {
this._converter = converter;
this._fieldsDOMSelector = fieldsDOMSelector;
}
}
}
Object.defineProperty(SortingField.prototype, "datasFieldNb", {
get: function () {
return this._datasFieldNb;
},
set: function (datasFieldNb) {
if (datasFieldNb !== undefined && this._converter.parseMetas.fields[datasFieldNb] === undefined)
throw new Error(errors.sortingFieldFieldNotFound);
else
this._datasFieldNb = datasFieldNb;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SortingField.prototype, "order", {
get: function () {
return this._order;
},
enumerable: true,
configurable: true
});
SortingField.prototype.field2HTML = function () {
if (this._converter === undefined || this._fieldsDOMSelector === "" || this._datasFieldNb === undefined)
throw new Error(errors.sortingField2HTMLFail);
else {
var fields = document.querySelectorAll(this._fieldsDOMSelector);
var htmlContent = fields[this._datasFieldNb].innerHTML;
htmlContent = "<a href='#freeDatas2HTMLSorting" + this._datasFieldNb + "' id='freeDatas2HTMLSorting" + this._datasFieldNb + "'>" + htmlContent + "</a>";
fields[this._datasFieldNb].innerHTML = htmlContent;
var sortingElement = document.getElementById("freeDatas2HTMLSorting" + this._datasFieldNb), field_1 = this;
sortingElement.addEventListener("click", function (e) {
e.preventDefault();
var order = field_1._order;
if (order === undefined || order === "desc")
field_1._order = "asc";
else
field_1._order = "desc";
field_1._converter.datasSortedField = field_1;
field_1._converter.refreshView();
});
}
};
return SortingField;
}());
export { SortingField };