Nouvelle compilation des fichiers

This commit is contained in:
Fabrice PENHOËT 2021-08-10 16:01:30 +02:00
parent 04b4bc2389
commit 630fba499d
2 changed files with 68 additions and 30 deletions

View File

@ -36,18 +36,24 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}; };
import { freeCSV2HTML } from "./freeCSV2HTML"; import { freeCSV2HTML } from "./freeCSV2HTML";
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; var converter, e_1;
return __generator(this, function (_a) { return __generator(this, function (_a) {
try { switch (_a.label) {
converter = new freeCSV2HTML(); case 0:
converter.datasViewElt = { id: "datas" }; _a.trys.push([0, 2, , 3]);
converter.datasSourceUrl = "http://localhost:8080/datas/elements-chimiques.csv"; converter = new freeCSV2HTML();
console.log(converter); converter.datasViewElt = { id: "datas" };
converter.datasSourceUrl = "http://localhost:8080/datas/elements-chimiques.csv";
return [4, converter.run()];
case 1:
_a.sent();
return [3, 3];
case 2:
e_1 = _a.sent();
console.error(e_1);
return [3, 3];
case 3: return [2];
} }
catch (e) {
console.error(e);
}
return [2];
}); });
}); }; }); };
initialise(); initialise();

View File

@ -42,8 +42,9 @@ var freeCSV2HTML = (function () {
this._datasSourceUrl = ""; this._datasSourceUrl = "";
this._datasSelectors = []; this._datasSelectors = [];
this.parseMeta = undefined; this.parseMeta = undefined;
this.parseErrors = [];
this.parseDatas = []; this.parseDatas = [];
this.parseErrors = [];
this.datasHTML = "";
} }
Object.defineProperty(freeCSV2HTML.prototype, "datasViewElt", { Object.defineProperty(freeCSV2HTML.prototype, "datasViewElt", {
set: function (elt) { set: function (elt) {
@ -58,6 +59,16 @@ var freeCSV2HTML = (function () {
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(freeCSV2HTML.prototype, "datasSourceUrl", {
set: function (url) {
if (url.trim().length === 0)
throw new Error(errors.needUrl);
else
this._datasSourceUrl = url.trim();
},
enumerable: true,
configurable: true
});
Object.defineProperty(freeCSV2HTML.prototype, "datasSelectors", { Object.defineProperty(freeCSV2HTML.prototype, "datasSelectors", {
set: function (selectors) { set: function (selectors) {
var checkContainerExist; var checkContainerExist;
@ -75,23 +86,6 @@ var freeCSV2HTML = (function () {
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(freeCSV2HTML.prototype, "datasSourceUrl", {
set: function (url) {
if (url.trim().length === 0)
throw new Error(errors.needUrl);
else
this._datasSourceUrl = url.trim();
},
enumerable: true,
configurable: true
});
freeCSV2HTML.prototype.checkParameters = function () {
if (this._datasViewElt === undefined)
throw new Error(errors.needDatasElt);
if (this._datasSourceUrl === "")
throw new Error(errors.needUrl);
return true;
};
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;
@ -99,7 +93,7 @@ var freeCSV2HTML = (function () {
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.checkParameters()) { if (_this._datasSourceUrl !== "") {
Papa.parse(_this._datasSourceUrl, { Papa.parse(_this._datasSourceUrl, {
quoteChar: '"', quoteChar: '"',
header: true, header: true,
@ -109,18 +103,56 @@ var freeCSV2HTML = (function () {
converter.parseDatas = results.data; converter.parseDatas = results.data;
resolve(true); resolve(true);
}, },
error: function (error) {
reject(new Error(errors.parserFail));
},
download: true, download: true,
skipEmptyLines: true, skipEmptyLines: true,
}); });
} }
else
resolve(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;
return __generator(this, function (_a) { return __generator(this, function (_a) {
return [2, true]; switch (_a.label) {
case 0:
if (this._datasViewElt.eltDOM === undefined)
throw new Error(errors.needDatasElt);
if (this._datasSourceUrl === "")
throw new Error(errors.needUrl);
return [4, this.parse()];
case 1:
if ((_a.sent()) === true) {
if (this.parseDatas.length === 0 || this.parseMeta === undefined || this.parseMeta.fields === undefined) {
this._datasViewElt.eltDOM.innerHTML = errors.datasNotFound;
return [2, false];
}
else {
this.datasHTML = "<table><thead>";
for (i in this.parseMeta.fields)
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;
return [2, true];
}
}
return [2];
}
}); });
}); });
}; };