Nouvelle compilation en .js des scripts source.

This commit is contained in:
Fabrice PENHOËT 2021-08-11 17:27:26 +02:00
parent 733ba413dc
commit 11b292ee60
2 changed files with 80 additions and 32 deletions

View File

@ -43,6 +43,7 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function
_a.trys.push([0, 2, , 3]); _a.trys.push([0, 2, , 3]);
converter = new freeCSV2HTML(); converter = new freeCSV2HTML();
converter.datasViewElt = { id: "datas" }; converter.datasViewElt = { id: "datas" };
converter.datasSelectors = [{ colCSV: 3, id: "filtre1" }, { colCSV: 4, id: "filtre2" }];
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.run()];
case 1: case 1:

View File

@ -70,18 +70,18 @@ var freeCSV2HTML = (function () {
configurable: true configurable: true
}); });
Object.defineProperty(freeCSV2HTML.prototype, "datasSelectors", { Object.defineProperty(freeCSV2HTML.prototype, "datasSelectors", {
set: function (selectors) { set: function (selectionElts) {
var checkContainerExist; var checkContainerExist;
for (var i = 0; i < selectors.length; i++) { for (var i = 0; i < selectionElts.length; i++) {
checkContainerExist = document.getElementById(selectors[i].id); checkContainerExist = document.getElementById(selectionElts[i].id);
if (checkContainerExist === null) if (checkContainerExist === null)
throw new Error(errors.elementNotFound + selectors[i].id); throw new Error(errors.elementNotFound + selectionElts[i].id);
else if (Number.isInteger(selectors[i].colCSV) === false || selectors[i].colCSV < 0) else if (Number.isInteger(selectionElts[i].colCSV) === false || selectionElts[i].colCSV < 0)
throw new Error(errors.needNaturalNumber); throw new Error(errors.needNaturalNumber);
else else
selectors[i].eltDOM = checkContainerExist; selectionElts[i].eltDOM = checkContainerExist;
} }
this._datasSelectors = selectors; this._datasSelectors = selectionElts;
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
@ -89,12 +89,11 @@ var freeCSV2HTML = (function () {
freeCSV2HTML.prototype.parse = function () { freeCSV2HTML.prototype.parse = function () {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var converter; var converter;
var _this = this;
return __generator(this, function (_a) { return __generator(this, function (_a) {
converter = this; converter = this;
return [2, new Promise(function (resolve, reject) { return [2, new Promise(function (resolve, reject) {
if (_this._datasSourceUrl !== "") { if (converter._datasSourceUrl !== "") {
Papa.parse(_this._datasSourceUrl, { Papa.parse(converter._datasSourceUrl, {
quoteChar: '"', quoteChar: '"',
header: true, header: true,
complete: function (results) { complete: function (results) {
@ -111,51 +110,99 @@ var freeCSV2HTML = (function () {
}); });
} }
else else
resolve(new Error(errors.needUrl)); reject(new Error(errors.needUrl));
})]; })];
}); });
}); });
}; };
freeCSV2HTML.prototype.run = function () { freeCSV2HTML.prototype.run = function () {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var i, row, field; var converter_1, selectorsHTML, i, values, colName, row, j, selectElement;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
if (this._datasViewElt.eltDOM === undefined) if (this._datasViewElt.eltDOM === undefined)
throw new Error(errors.needDatasElt); throw new Error(errors.needDatasElt);
if (this._datasSourceUrl === "") else if (this._datasSourceUrl === "")
throw new Error(errors.needUrl); throw new Error(errors.needUrl);
return [4, this.parse()]; return [4, this.parse()];
case 1: case 1:
if ((_a.sent()) === true) { _a.sent();
if (this.parseDatas.length === 0 || this.parseMeta === undefined || this.parseMeta.fields === undefined) { if (this.parseDatas.length === 0 || this.parseMeta === undefined || this.parseMeta.fields === undefined) {
this._datasViewElt.eltDOM.innerHTML = errors.datasNotFound; this._datasViewElt.eltDOM.innerHTML = errors.datasNotFound;
return [2, false]; return [2, false];
} }
else { else {
this.datasHTML = "<table><thead>"; converter_1 = this;
for (i in this.parseMeta.fields) this.datasHTML = this.createDatasHTML(this.parseMeta.fields, this.parseDatas);
this.datasHTML += "<th>" + this.parseMeta.fields[i] + "</th>";
this.datasHTML += "</thead><tbody>";
for (row in this.parseDatas) {
this.datasHTML += "<tr>";
for (field in this.parseDatas[row]) {
if (this.parseMeta.fields.indexOf(field) !== -1)
this.datasHTML += "<td>" + this.parseDatas[row][field] + "</td>";
}
this.datasHTML += "</tr>";
}
this.datasHTML += "</tbody></table>";
this._datasViewElt.eltDOM.innerHTML = this.datasHTML; this._datasViewElt.eltDOM.innerHTML = this.datasHTML;
return [2, true]; if (this._datasSelectors.length > 0) {
selectorsHTML = [];
for (i in this._datasSelectors) {
if (this._datasSelectors[i].colCSV > (this.parseMeta.fields.length - 1))
throw new Error(errors.selectorFieldNotFound);
else {
values = [], colName = this.parseMeta.fields[this._datasSelectors[i].colCSV];
for (row in this.parseDatas) {
if (values.indexOf(this.parseDatas[row][colName]) === -1)
values.push(this.parseDatas[row][colName]);
} }
if (values.length > 0) {
values.sort();
this._datasSelectors[i].name = colName;
this._datasSelectors[i].values = values;
selectorsHTML[i] = "<label for='CSVDatasSelector" + i + "'>" + colName + " : </label><select name='CSVDatasSelector" + i + "' id='CSVDatasSelector" + 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("CSVDatasSelector" + i);
selectElement.addEventListener('change', function (e) {
converter_1.datasHTML = converter_1.createDatasHTML(converter_1.parseMeta.fields, converter_1.parseDatas);
converter_1._datasViewElt.eltDOM.innerHTML = converter_1.datasHTML;
});
}
}
}
}
return [2, true];
} }
return [2]; return [2];
} }
}); });
}); });
}; };
freeCSV2HTML.prototype.createDatasHTML = function (fields, datas) {
var checkContainerExist, filters = [];
for (var i in this._datasSelectors) {
checkContainerExist = document.querySelector("#" + this._datasSelectors[i].id + " select");
if (checkContainerExist != null && checkContainerExist.value != "0")
filters.push({ field: this._datasSelectors[i].name, value: this._datasSelectors[i].values[checkContainerExist.selectedIndex - 1] });
}
var datasHTML = "<table><thead>";
for (var i in fields)
datasHTML += "<th>" + fields[i] + "</th>";
datasHTML += "</thead><tbody>";
for (var row in datas) {
var view = true;
if (filters.length !== 0) {
for (var i in filters) {
if (datas[row][filters[i].field] != filters[i].value)
view = false;
}
}
if (view) {
datasHTML += "<tr>";
for (var field in datas[row]) {
if (fields.indexOf(field) !== -1)
datasHTML += "<td>" + datas[row][field] + "</td>";
}
datasHTML += "</tr>";
}
}
datasHTML += "</tbody></table>";
return datasHTML;
};
return freeCSV2HTML; return freeCSV2HTML;
}()); }());
export { freeCSV2HTML }; export { freeCSV2HTML };