diff --git a/karma.conf.js b/karma.conf.js
index d02c611..9f4a8b3 100644
--- a/karma.conf.js
+++ b/karma.conf.js
@@ -12,7 +12,7 @@ module.exports = function(config) {
frameworks: ["jasmine", "karma-typescript"],
// list of files / patterns to load in the browser
- files: [ "src/freeCSV2HTML.ts", "tests/*.ts" , { pattern: 'tests/datas/*.csv', watched: true, included: false, served: true } ],
+ files: [ "src/freeDatas2HTML.ts", "tests/*.ts" , { pattern: 'tests/datas/*.csv', watched: true, included: false, served: true } ],
proxies: { "/datas/": "http://localhost:9876/base/tests/datas/" },
@@ -57,4 +57,4 @@ module.exports = function(config) {
// how many browser instances should be started simultaneously
concurrency: Infinity
})
-}
+}
\ No newline at end of file
diff --git a/src/build/freeCSV2HTML.js b/src/build/freeCSV2HTML.js
deleted file mode 100644
index e2d4fab..0000000
--- a/src/build/freeCSV2HTML.js
+++ /dev/null
@@ -1,208 +0,0 @@
-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
-};
-var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
-};
-var Papa = require("papaparse");
-var errors = require("./errors.js");
-var freeCSV2HTML = (function () {
- function freeCSV2HTML() {
- this._datasViewElt = { id: "", eltDOM: undefined };
- this._datasSourceUrl = "";
- this._datasSelectors = [];
- this.parseMeta = undefined;
- this.parseDatas = [];
- this.parseErrors = [];
- this.datasHTML = "";
- }
- Object.defineProperty(freeCSV2HTML.prototype, "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(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 (selectionElts) {
- var checkContainerExist;
- for (var i = 0; i < selectionElts.length; i++) {
- checkContainerExist = document.getElementById(selectionElts[i].id);
- if (checkContainerExist === null)
- throw new Error(errors.elementNotFound + selectionElts[i].id);
- else if (Number.isInteger(selectionElts[i].colCSV) === false || selectionElts[i].colCSV < 0)
- throw new Error(errors.needNaturalNumber);
- else
- selectionElts[i].eltDOM = checkContainerExist;
- }
- this._datasSelectors = selectionElts;
- },
- enumerable: true,
- configurable: true
- });
- freeCSV2HTML.prototype.parse = function () {
- return __awaiter(this, void 0, void 0, function () {
- var converter;
- return __generator(this, function (_a) {
- converter = this;
- return [2, new Promise(function (resolve, reject) {
- if (converter._datasSourceUrl !== "") {
- Papa.parse(converter._datasSourceUrl, {
- quoteChar: '"',
- header: true,
- complete: function (results) {
- converter.parseMeta = results.meta;
- converter.parseErrors = results.errors;
- converter.parseDatas = results.data;
- resolve(true);
- },
- error: function (error) {
- reject(new Error(errors.parserFail));
- },
- download: true,
- skipEmptyLines: true,
- });
- }
- else
- reject(new Error(errors.needUrl));
- })];
- });
- });
- };
- freeCSV2HTML.prototype.run = function () {
- return __awaiter(this, void 0, void 0, function () {
- var converter_1, selectorsHTML, i, values, colName, row, j, selectElement;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (this._datasViewElt.eltDOM === undefined)
- throw new Error(errors.needDatasElt);
- else if (this._datasSourceUrl === "")
- throw new Error(errors.needUrl);
- return [4, this.parse()];
- case 1:
- _a.sent();
- if (this.parseDatas.length === 0 || this.parseMeta === undefined || this.parseMeta.fields === undefined) {
- this._datasViewElt.eltDOM.innerHTML = errors.datasNotFound;
- return [2, false];
- }
- else {
- converter_1 = this;
- this.datasHTML = this.createDatasHTML(this.parseMeta.fields, this.parseDatas);
- this._datasViewElt.eltDOM.innerHTML = this.datasHTML;
- 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] = "";
- 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];
- }
- });
- });
- };
- 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 = "
";
- for (var i in fields)
- datasHTML += "" + fields[i] + " | ";
- datasHTML += "";
- 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 += "";
- for (var field in datas[row]) {
- if (fields.indexOf(field) !== -1)
- datasHTML += "" + datas[row][field] + " | ";
- }
- datasHTML += "
";
- }
- }
- datasHTML += "
";
- return datasHTML;
- };
- return freeCSV2HTML;
-}());
-export { freeCSV2HTML };
diff --git a/src/firstExample.ts b/src/firstExample.ts
index a4f998a..2727573 100644
--- a/src/firstExample.ts
+++ b/src/firstExample.ts
@@ -1,12 +1,12 @@
-import { freeCSV2HTML } from "./freeCSV2HTML";
+import { freeDatas2HTML } from "./freeDatas2HTML";
const initialise = async () =>
{
try
{
- let converter=new freeCSV2HTML();
+ let converter=new freeDatas2HTML();
converter.datasViewElt={ id:"datas" };
- converter.datasSelectors=[{ colCSV:3, id:"filtre1"},{ colCSV:4, id:"filtre2"}];
+ converter.datasSelectors=[{ datasFielNb:3, id:"filtre1"},{ datasFielNb:4, id:"filtre2"}];
converter.datasSourceUrl="http://localhost:8080/datas/elements-chimiques.csv";
await converter.run();
}
diff --git a/src/freeCSV2HTML.ts b/src/freeDatas2HTML.ts
similarity index 93%
rename from src/freeCSV2HTML.ts
rename to src/freeDatas2HTML.ts
index 7af6f70..0c3dcdc 100644
--- a/src/freeCSV2HTML.ts
+++ b/src/freeDatas2HTML.ts
@@ -2,9 +2,9 @@ const Papa = require("papaparse");
const errors = require("./errors.js");
import { papaParseDatas, papaParseErrors, papaParseMeta } from "./papaParseInterfaces";
-import { domElement, selectors } from "./freeCSV2HTMLInterfaces";
+import { domElement, selectors } from "./freeDatas2HTMLInterfaces";
-export class freeCSV2HTML
+export class freeDatas2HTML
{
private _datasViewElt: domElement = { id:"", eltDOM:undefined };
private _datasSourceUrl: string = "";
@@ -45,7 +45,7 @@ export class freeCSV2HTML
checkContainerExist=document.getElementById(selectionElts[i].id);
if(checkContainerExist === null)
console.error(errors.elementNotFound+selectionElts[i].id);
- else if(Number.isInteger( selectionElts[i].colCSV) === false || selectionElts[i].colCSV < 0)
+ else if(Number.isInteger( selectionElts[i].datasFielNb) === false || selectionElts[i].datasFielNb < 0)
console.error(errors.needNaturalNumber);
else
{
@@ -126,11 +126,11 @@ export class freeCSV2HTML
let selectorsHTML : string [] = [];
for(let i in this._datasSelectors)
{
- if(this._datasSelectors[i].colCSV > (this.parseMeta!.fields.length-1))
+ if(this._datasSelectors[i].datasFielNb > (this.parseMeta!.fields.length-1))
throw new Error(errors.selectorFieldNotFound);
else
{
- let values=[], colName=this.parseMeta!.fields[this._datasSelectors[i].colCSV];
+ let values=[], colName=this.parseMeta!.fields[this._datasSelectors[i].datasFielNb];
for (let row in this.parseDatas)
{
if(values.indexOf(this.parseDatas[row][colName].trim()) === -1)
@@ -143,12 +143,12 @@ export class freeCSV2HTML
values.sort(); // à revoir, car gère mal la casse, les nombres, etc.
this._datasSelectors[i].name=colName;
this._datasSelectors[i].values=values;
- selectorsHTML[i]="