Modification noms fichier, variables, etc. suite modification nom du projet.
This commit is contained in:
parent
0b3392cbd8
commit
a2b90bb70f
@ -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
|
||||
})
|
||||
}
|
||||
}
|
@ -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] = "<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];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
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;
|
||||
}());
|
||||
export { freeCSV2HTML };
|
@ -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();
|
||||
}
|
||||
|
@ -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]="<label for='CSVDatasSelector"+i+"'>"+colName+" : </label><select name='CSVDatasSelector"+i+"' id='CSVDatasSelector"+i+"'><option value='0'>----</option>";
|
||||
selectorsHTML[i]="<label for='freeDatas2HTMLSelector"+i+"'>"+colName+" : </label><select name='freeDatas2HTMLSelector"+i+"' id='freeDatas2HTMLSelector"+i+"'><option value='0'>----</option>";
|
||||
for(let j in values)
|
||||
selectorsHTML[i]+="<option value='"+(Number(j)+1)+"'>"+values[j]+"</option>";
|
||||
selectorsHTML[i]+="</select>";
|
||||
this._datasSelectors[i].eltDOM!.innerHTML=selectorsHTML[i];
|
||||
let selectElement = document.getElementById("CSVDatasSelector"+i) as HTMLInputElement;
|
||||
let selectElement = document.getElementById("freeDatas2HTMLSelector"+i) as HTMLInputElement;
|
||||
selectElement.addEventListener('change', function(e)
|
||||
{
|
||||
converter.datasHTML=converter.createDatasHTML(converter.parseMeta!.fields as string[], converter.parseDatas);
|
@ -5,7 +5,7 @@ export interface domElement
|
||||
}
|
||||
export interface selectors extends domElement
|
||||
{
|
||||
colCSV: number;
|
||||
datasFielNb: number;
|
||||
name?: string;
|
||||
values? : string[];
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -1,14 +1,14 @@
|
||||
import { freeCSV2HTML } from "../src/freeCSV2HTML";
|
||||
import { freeDatas2HTML } from "../src/freeDatas2HTML";
|
||||
const errors=require("../src/errors.js");
|
||||
const fixtures=require("./fixtures.js");
|
||||
|
||||
describe("freeCSV2HTML", () =>
|
||||
describe("freeDatas2HTML", () =>
|
||||
{
|
||||
let converter: freeCSV2HTML;
|
||||
let converter: freeDatas2HTML;
|
||||
|
||||
beforeEach( () =>
|
||||
{
|
||||
converter=new freeCSV2HTML();
|
||||
converter=new freeDatas2HTML();
|
||||
document.body.insertAdjacentHTML('afterbegin', fixtures.datasViewEltHTML);
|
||||
});
|
||||
|
||||
@ -17,9 +17,9 @@ describe("freeCSV2HTML", () =>
|
||||
document.body.removeChild(document.getElementById('fixture'));
|
||||
});
|
||||
|
||||
it("Doit avoir créé une instance de freeCSV2HTML", () =>
|
||||
it("Doit avoir créé une instance de freeDatas2HTML", () =>
|
||||
{
|
||||
expect(converter).toBeInstanceOf(freeCSV2HTML);
|
||||
expect(converter).toBeInstanceOf(freeDatas2HTML);
|
||||
});
|
||||
|
||||
describe("Test des données de configuration reçues.", () =>
|
||||
@ -36,24 +36,24 @@ describe("freeCSV2HTML", () =>
|
||||
|
||||
it("Ne doit accepter que les sélecteurs pour lesquels un élément a été trouvé dans la page pour l'id fourni.", () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:2, id:"selector2" },{ colCSV:3, id:"selector3" }];
|
||||
converter.datasSelectors=[{ datasFielNb:2, id:"selector2" },{ datasFielNb:3, id:"selector3" }];
|
||||
expect(converter.datasSelectors.length).toEqual(1);
|
||||
expect(converter.datasSelectors[0].id).toEqual("selector2");
|
||||
});
|
||||
|
||||
it("Ne doit accepter que les sélecteurs pour lesquels les numéros de colonne fourrnis sont des nombres naturels.", () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:2.3, id:"selector1" },{ colCSV:3, id:"selector2" }];
|
||||
converter.datasSelectors=[{ datasFielNb:2.3, id:"selector1" },{ datasFielNb:3, id:"selector2" }];
|
||||
expect(converter.datasSelectors.length).toEqual(1);
|
||||
expect(converter.datasSelectors[0].id).toEqual("selector2");
|
||||
converter.datasSelectors=[{ colCSV:2, id:"selector1" },{ colCSV:-1, id:"selector2" }];
|
||||
converter.datasSelectors=[{ datasFielNb:2, id:"selector1" },{ datasFielNb:-1, id:"selector2" }];
|
||||
expect(converter.datasSelectors.length).toEqual(1);
|
||||
expect(converter.datasSelectors[0].id).toEqual("selector1");
|
||||
});
|
||||
|
||||
it("Doit accepter tous les sélecteurs si leurs informations sont valides.", () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:0, id:"selector1" },{ colCSV:3, id:"selector2" }];
|
||||
converter.datasSelectors=[{ datasFielNb:0, id:"selector1" },{ datasFielNb:3, id:"selector2" }];
|
||||
expect(converter.datasSelectors.length).toEqual(2);
|
||||
});
|
||||
|
||||
@ -158,19 +158,19 @@ describe("freeCSV2HTML", () =>
|
||||
|
||||
it("Doit générer une erreur si au moins un des numéros de colonne fournis pour les sélecteurs ne correspond pas à une des colonne du fichier.", async () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:0, id:"selector1"},{ colCSV:5, id:"selector2"}];
|
||||
converter.datasSelectors=[{ datasFielNb:0, id:"selector1"},{ datasFielNb:5, id:"selector2"}];
|
||||
await expectAsync(converter.run()).toBeRejectedWith(new Error(errors.selectorFieldNotFound));
|
||||
});
|
||||
|
||||
it("Ne doit pas pas générer d'erreur si tous les numéros de colonne des sélecteurs correspondent pas à une des colonne du fichier.", async () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:3, id:"selector1"},{ colCSV:4, id:"selector2"}];
|
||||
converter.datasSelectors=[{ datasFielNb:3, id:"selector1"},{ datasFielNb:4, id:"selector2"}];
|
||||
await expectAsync(converter.run()).not.toBeRejected();
|
||||
});
|
||||
|
||||
it("Pour chaque sélecteur demandé, doit générer un élement <select> listant les valeurs distinctes du fichier, classées par ordre alphabétique.", async () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:3, id:"selector1"},{ colCSV:4, id:"selector2"}];
|
||||
converter.datasSelectors=[{ datasFielNb:3, id:"selector1"},{ datasFielNb:4, id:"selector2"}];
|
||||
await converter.run();
|
||||
expect(document.getElementById("selector1").innerHTML).toEqual(fixtures.selector1HTML);
|
||||
expect(document.getElementById("selector2").innerHTML).toEqual(fixtures.selector2HTML);
|
||||
@ -178,10 +178,10 @@ describe("freeCSV2HTML", () =>
|
||||
|
||||
it("Le choix d'un option dans un des sélecteurs doit modifier le contenu du tableau pour ne garder que les données correspondantes ou les afficher toutes si sélection 0.", async () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:3, id:"selector1"},{ colCSV:4, id:"selector2"}];
|
||||
converter.datasSelectors=[{ datasFielNb:3, id:"selector1"},{ datasFielNb:4, id:"selector2"}];
|
||||
await converter.run();
|
||||
|
||||
let selectElement = document.getElementById("CSVDatasSelector0") as HTMLInputElement;
|
||||
let selectElement = document.getElementById("freeDatas2HTMLSelector0") as HTMLInputElement;
|
||||
selectElement.value="4";
|
||||
selectElement.dispatchEvent(new Event('change'));
|
||||
let txtDatasViewsElt=document.getElementById("datas").innerHTML;
|
||||
@ -195,12 +195,12 @@ describe("freeCSV2HTML", () =>
|
||||
|
||||
it("Si plusieurs sélecteurs sont utilisés, seules les données correspondant aux différents choix doivent être affichées. Il peut n'y avoir aucun résultat.", async () =>
|
||||
{
|
||||
converter.datasSelectors=[{ colCSV:3, id:"selector1"},{ colCSV:4, id:"selector2"}];
|
||||
converter.datasSelectors=[{ datasFielNb:3, id:"selector1"},{ datasFielNb:4, id:"selector2"}];
|
||||
await converter.run();
|
||||
|
||||
let selectElement = document.getElementById("CSVDatasSelector0") as HTMLInputElement;
|
||||
let selectElement = document.getElementById("freeDatas2HTMLSelector0") as HTMLInputElement;
|
||||
selectElement.value="2";
|
||||
selectElement = document.getElementById("CSVDatasSelector1") as HTMLInputElement;
|
||||
selectElement = document.getElementById("freeDatas2HTMLSelector1") as HTMLInputElement;
|
||||
selectElement.value="1";
|
||||
selectElement.dispatchEvent(new Event('change'));
|
||||
let txtDatasViewsElt=document.getElementById("datas").innerHTML;
|
Loading…
Reference in New Issue
Block a user