Nouvelle compilation des fichiers
This commit is contained in:
parent
04b4bc2389
commit
630fba499d
@ -36,18 +36,24 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
};
|
||||
import { freeCSV2HTML } from "./freeCSV2HTML";
|
||||
var initialise = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var converter;
|
||||
var converter, e_1;
|
||||
return __generator(this, function (_a) {
|
||||
try {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
_a.trys.push([0, 2, , 3]);
|
||||
converter = new freeCSV2HTML();
|
||||
converter.datasViewElt = { id: "datas" };
|
||||
converter.datasSourceUrl = "http://localhost:8080/datas/elements-chimiques.csv";
|
||||
console.log(converter);
|
||||
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();
|
||||
|
@ -42,8 +42,9 @@ var freeCSV2HTML = (function () {
|
||||
this._datasSourceUrl = "";
|
||||
this._datasSelectors = [];
|
||||
this.parseMeta = undefined;
|
||||
this.parseErrors = [];
|
||||
this.parseDatas = [];
|
||||
this.parseErrors = [];
|
||||
this.datasHTML = "";
|
||||
}
|
||||
Object.defineProperty(freeCSV2HTML.prototype, "datasViewElt", {
|
||||
set: function (elt) {
|
||||
@ -58,6 +59,16 @@ var freeCSV2HTML = (function () {
|
||||
enumerable: 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", {
|
||||
set: function (selectors) {
|
||||
var checkContainerExist;
|
||||
@ -75,23 +86,6 @@ var freeCSV2HTML = (function () {
|
||||
enumerable: 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 () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var converter;
|
||||
@ -99,7 +93,7 @@ var freeCSV2HTML = (function () {
|
||||
return __generator(this, function (_a) {
|
||||
converter = this;
|
||||
return [2, new Promise(function (resolve, reject) {
|
||||
if (_this.checkParameters()) {
|
||||
if (_this._datasSourceUrl !== "") {
|
||||
Papa.parse(_this._datasSourceUrl, {
|
||||
quoteChar: '"',
|
||||
header: true,
|
||||
@ -109,18 +103,56 @@ var freeCSV2HTML = (function () {
|
||||
converter.parseDatas = results.data;
|
||||
resolve(true);
|
||||
},
|
||||
error: function (error) {
|
||||
reject(new Error(errors.parserFail));
|
||||
},
|
||||
download: true,
|
||||
skipEmptyLines: true,
|
||||
});
|
||||
}
|
||||
else
|
||||
resolve(new Error(errors.needUrl));
|
||||
})];
|
||||
});
|
||||
});
|
||||
};
|
||||
freeCSV2HTML.prototype.run = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var i, row, field;
|
||||
return __generator(this, function (_a) {
|
||||
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];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user