From 692ae9fa86f0e18db14d07b438806208f26677bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20PENHO=C3=8BT?= Date: Wed, 22 Sep 2021 17:37:36 +0200 Subject: [PATCH] Nouvelle compilation --- public/JS/firstExample.app.js | 12 +++---- src/build/firstExample.js | 24 ++++--------- src/build/freeDatas2HTML.js | 42 ++++++++++++++-------- src/build/freeDatas2HTMLPagination.js | 22 +++++------- src/build/freeDatas2HTMLSelector.js | 48 +++++++++++-------------- src/build/freeDatas2HTMLSortingField.js | 18 ++++++---- 6 files changed, 80 insertions(+), 86 deletions(-) diff --git a/public/JS/firstExample.app.js b/public/JS/firstExample.app.js index f1b4696..4f28b8b 100644 --- a/public/JS/firstExample.app.js +++ b/public/JS/firstExample.app.js @@ -37,7 +37,7 @@ eval("var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPAC /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./freeDatas2HTML */ \"./src/freeDatas2HTML.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\n\nvar initialise = function () { return __awaiter(void 0, void 0, void 0, function () {\n var mySort, converter, pagination, filtre1, filtre2, filtre3, sortingField1, sortingField2, sortingField3, sortingField4, e_1;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 3, , 4]);\n mySort = function (a, b, order) {\n if (order === void 0) { order = \"asc\"; }\n var values = [\"> 100000\", \"> 1 et < 100 000\", \"≤ 1\", \"Traces\", \"Inexistant\"];\n if (order === \"desc\")\n values.reverse();\n if (values.indexOf(a) > values.indexOf(b))\n return -1;\n else if (values.indexOf(a) < values.indexOf(b))\n return 1;\n else\n return 0;\n };\n converter = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.FreeDatas2HTML();\n converter.datasViewElt = { id: \"datas\" };\n converter.datasSourceUrl = \"http://localhost:8080/datas/elements-chimiques.csv\";\n return [4, converter.parse()];\n case 1:\n _a.sent();\n converter.datasSortingFunctions = [{ datasFieldNb: 4, sort: mySort }];\n pagination = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Pagination(converter, { id: \"pages\" }, \"Page à afficher :\");\n pagination.options = { displayElement: { id: \"paginationOptions\" }, values: [10, 20, 50, 500], name: \"Choix de pagination :\" };\n pagination.selectedValue = 10;\n converter.pagination = pagination;\n pagination.rend2HTML();\n return [4, converter.run()];\n case 2:\n _a.sent();\n filtre1 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Selector(converter);\n filtre1.datasViewElt = { id: \"filtre1\" };\n filtre1.datasFieldNb = 3;\n filtre1.selector2HTML();\n filtre2 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Selector(converter);\n filtre2.datasViewElt = { id: \"filtre2\" };\n filtre2.datasFieldNb = 4;\n filtre2.selector2HTML();\n filtre3 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Selector(converter);\n filtre3.datasViewElt = { id: \"filtre3\" };\n filtre3.datasFieldNb = 5;\n filtre3.separator = \",\";\n filtre3.selector2HTML();\n converter.datasSelectors = [filtre1, filtre2, filtre3];\n sortingField1 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter);\n sortingField1.datasFieldNb = 0;\n sortingField1.field2HTML();\n sortingField2 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter);\n sortingField2.datasFieldNb = 1;\n sortingField2.field2HTML();\n sortingField3 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter);\n sortingField3.datasFieldNb = 2;\n sortingField3.field2HTML();\n sortingField4 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter);\n sortingField4.datasFieldNb = 4;\n sortingField4.field2HTML();\n converter.datasSortingFields = [sortingField1, sortingField2, sortingField3, sortingField4];\n return [3, 4];\n case 3:\n e_1 = _a.sent();\n console.error(e_1);\n if (document.getElementById(\"datas\") !== null)\n document.getElementById(\"datas\").innerHTML = \"Désolé, mais un problème technique empêche l'affichage des données.\";\n return [3, 4];\n case 4: return [2];\n }\n });\n}); };\ninitialise();\n\n\n//# sourceURL=webpack://freedatas2html/./src/firstExample.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./freeDatas2HTML */ \"./src/freeDatas2HTML.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\n\nvar initialise = function () { return __awaiter(void 0, void 0, void 0, function () {\n var mySort, converter, pagination, filtre1, filtre2, filtre3, sortingField1, sortingField2, sortingField3, sortingField4, e_1;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 3, , 4]);\n mySort = function (a, b, order) {\n if (order === void 0) { order = \"asc\"; }\n var values = [\"> 100000\", \"> 1 et < 100 000\", \"≤ 1\", \"Traces\", \"Inexistant\"];\n if (order === \"desc\")\n values.reverse();\n if (values.indexOf(a) > values.indexOf(b))\n return -1;\n else if (values.indexOf(a) < values.indexOf(b))\n return 1;\n else\n return 0;\n };\n converter = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.FreeDatas2HTML();\n converter.datasViewElt = { id: \"datas\" };\n converter.datasSourceUrl = \"http://localhost:8080/datas/elements-chimiques.csv\";\n return [4, converter.parse()];\n case 1:\n _a.sent();\n converter.datasSortingFunctions = [{ datasFieldNb: 4, sort: mySort }];\n pagination = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Pagination(converter, { id: \"pages\" }, \"Page à afficher :\");\n pagination.options = { displayElement: { id: \"paginationOptions\" }, values: [10, 20, 50, 500], name: \"Choix de pagination :\" };\n pagination.selectedValue = 10;\n converter.pagination = pagination;\n pagination.rend2HTML();\n return [4, converter.run()];\n case 2:\n _a.sent();\n filtre1 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Selector(converter, 3, { id: \"filtre1\" });\n filtre1.selector2HTML();\n filtre2 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Selector(converter, 4, { id: \"filtre2\" });\n filtre2.selector2HTML();\n filtre3 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.Selector(converter, 5, { id: \"filtre3\" });\n filtre3.separator = \",\";\n filtre3.selector2HTML();\n converter.datasSelectors = [filtre1, filtre2, filtre3];\n sortingField1 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter, 0);\n sortingField1.field2HTML();\n sortingField2 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter, 1);\n sortingField2.field2HTML();\n sortingField3 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter, 2);\n sortingField3.field2HTML();\n sortingField4 = new _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.SortingField(converter, 4);\n sortingField4.field2HTML();\n converter.datasSortingFields = [sortingField1, sortingField2, sortingField3, sortingField4];\n return [3, 4];\n case 3:\n e_1 = _a.sent();\n console.error(e_1);\n if (document.getElementById(\"datas\") !== null)\n document.getElementById(\"datas\").innerHTML = \"Désolé, mais un problème technique empêche l'affichage des données.\";\n return [3, 4];\n case 4: return [2];\n }\n });\n}); };\ninitialise();\n\n\n//# sourceURL=webpack://freedatas2html/./src/firstExample.ts?"); /***/ }), @@ -48,7 +48,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _fre /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"FreeDatas2HTML\": () => (/* binding */ FreeDatas2HTML),\n/* harmony export */ \"Pagination\": () => (/* reexport safe */ _freeDatas2HTMLPagination__WEBPACK_IMPORTED_MODULE_0__.Pagination),\n/* harmony export */ \"Selector\": () => (/* reexport safe */ _freeDatas2HTMLSelector__WEBPACK_IMPORTED_MODULE_1__.Selector),\n/* harmony export */ \"SortingField\": () => (/* reexport safe */ _freeDatas2HTMLSortingField__WEBPACK_IMPORTED_MODULE_2__.SortingField)\n/* harmony export */ });\n/* harmony import */ var _freeDatas2HTMLPagination__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./freeDatas2HTMLPagination */ \"./src/freeDatas2HTMLPagination.ts\");\n/* harmony import */ var _freeDatas2HTMLSelector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./freeDatas2HTMLSelector */ \"./src/freeDatas2HTMLSelector.ts\");\n/* harmony import */ var _freeDatas2HTMLSortingField__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./freeDatas2HTMLSortingField */ \"./src/freeDatas2HTMLSortingField.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar Papa = __webpack_require__(/*! papaparse */ \"./node_modules/papaparse/papaparse.min.js\");\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\nvar compare = __webpack_require__(/*! natural-orderby */ \"./node_modules/natural-orderby/esm/natural-orderby.js\").compare;\nvar FreeDatas2HTML = (function () {\n function FreeDatas2HTML() {\n this._datasViewElt = { id: \"\", eltDOM: undefined };\n this.datasHTML = \"\";\n this._datasSourceUrl = \"\";\n this._datasSortingFunctions = [];\n this.parseMetas = undefined;\n this.parseDatas = [];\n this.parseErrors = [];\n this.stopIfParseErrors = false;\n this.datasSelectors = [];\n this.datasSortingFields = [];\n }\n Object.defineProperty(FreeDatas2HTML.prototype, \"datasViewElt\", {\n set: function (elt) {\n var checkContainerExist = document.getElementById(elt.id);\n if (checkContainerExist === null)\n throw new Error(errors.elementNotFound + elt.id);\n else {\n this._datasViewElt.id = elt.id;\n this._datasViewElt.eltDOM = checkContainerExist;\n }\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(FreeDatas2HTML.prototype, \"datasSourceUrl\", {\n set: function (url) {\n if (url.trim().length === 0)\n throw new Error(errors.needUrl);\n else\n this._datasSourceUrl = url.trim();\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(FreeDatas2HTML.prototype, \"datasSortingFunctions\", {\n set: function (SortingFunctions) {\n this._datasSortingFunctions = [];\n for (var i = 0; i < SortingFunctions.length; i++) {\n this._datasSortingFunctions.push(SortingFunctions[i]);\n }\n },\n enumerable: false,\n configurable: true\n });\n FreeDatas2HTML.prototype.getSortingFunctionForField = function (datasFieldNb) {\n for (var i in this._datasSortingFunctions) {\n if (this._datasSortingFunctions[i].datasFieldNb === datasFieldNb)\n return this._datasSortingFunctions[i];\n }\n return undefined;\n };\n FreeDatas2HTML.prototype.parse = function () {\n return __awaiter(this, void 0, void 0, function () {\n var converter;\n return __generator(this, function (_a) {\n converter = this;\n return [2, new Promise(function (resolve, reject) {\n if (converter._datasSourceUrl !== \"\") {\n Papa.parse(converter._datasSourceUrl, {\n quoteChar: '\"',\n header: true,\n complete: function (results) {\n converter.parseErrors = results.errors;\n converter.parseDatas = results.data;\n var realFields = [];\n for (var i in results.meta.fields) {\n if (results.meta.fields[i].trim() !== \"\")\n realFields.push(results.meta.fields[i]);\n }\n results.meta.fields = realFields;\n converter.parseMetas = results.meta;\n resolve(true);\n },\n error: function (error) {\n reject(new Error(errors.parserFail));\n },\n download: true,\n skipEmptyLines: true,\n });\n }\n else\n reject(new Error(errors.needUrl));\n })];\n });\n });\n };\n FreeDatas2HTML.prototype.run = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this._datasViewElt.eltDOM === undefined)\n throw new Error(errors.needDatasElt);\n if (this._datasSourceUrl === \"\")\n throw new Error(errors.needUrl);\n return [4, this.parse()];\n case 1:\n _a.sent();\n if (this.parseDatas.length === 0 || this.parseMetas.fields === undefined)\n throw new Error(errors.datasNotFound);\n else if (this.stopIfParseErrors && this.parseErrors.length !== 0)\n console.error(this.parseErrors);\n else {\n this.refreshView();\n return [2, true];\n }\n return [2];\n }\n });\n });\n };\n FreeDatas2HTML.prototype.refreshView = function () {\n if (this.parseMetas === undefined || this.parseMetas.fields === undefined || this._datasViewElt.eltDOM === undefined)\n throw new Error(errors.refreshFail);\n this.datasHTML = this.createDatasHTML(this.parseMetas.fields, this.parseDatas);\n this._datasViewElt.eltDOM.innerHTML = this.datasHTML;\n for (var i in this.datasSortingFields) {\n var field = this.datasSortingFields[i];\n field.field2HTML();\n }\n };\n FreeDatas2HTML.prototype.createDatasHTML = function (fields, datas) {\n if (this.datasSortedField !== undefined && this.datasSortedField.datasFieldNb !== undefined) {\n var field_1 = fields[this.datasSortedField.datasFieldNb];\n var fieldOrder_1 = this.datasSortedField.order;\n if (this.getSortingFunctionForField(this.datasSortedField.datasFieldNb) !== undefined) {\n var myFunction_1 = this.getSortingFunctionForField(this.datasSortedField.datasFieldNb);\n datas.sort(function (a, b) { return myFunction_1.sort(a[field_1], b[field_1], fieldOrder_1); });\n }\n else\n datas.sort(function (a, b) { return compare({ order: fieldOrder_1 })(a[field_1], b[field_1]); });\n }\n var firstData = 0;\n if (this.pagination !== undefined && this.pagination.selectedValue !== undefined && this.pagination.pages !== undefined && this.pagination.pages.selectedValue !== undefined)\n firstData = this.pagination.selectedValue * (this.pagination.pages.selectedValue - 1);\n var maxData = (this.pagination !== undefined && this.pagination.selectedValue !== undefined) ? this.pagination.selectedValue : datas.length + 1;\n var datasHTML = \"\";\n for (var i in fields)\n datasHTML += \"\";\n datasHTML += \"\";\n var nbVisible = 0, nbTotal = 0;\n for (var row in datas) {\n var visible = true;\n if (this.datasSelectors.length !== 0) {\n var i = 0;\n while (this.datasSelectors[i] !== undefined && visible === true) {\n visible = this.datasSelectors[i].dataIsOk(datas[row]);\n i++;\n }\n }\n if (visible && nbTotal >= firstData && nbVisible < maxData) {\n datasHTML += \"\";\n for (var field in datas[row]) {\n if (fields.indexOf(field) !== -1)\n datasHTML += \"\";\n }\n datasHTML += \"\";\n nbVisible++;\n nbTotal++;\n }\n else if (visible)\n nbTotal++;\n }\n datasHTML += \"
\" + fields[i] + \"
\" + datas[row][field] + \"
\";\n if (this.pagination !== undefined)\n this.pagination.creaPageSelector(nbTotal);\n return datasHTML;\n };\n return FreeDatas2HTML;\n}());\n\n\n\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTML.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"FreeDatas2HTML\": () => (/* binding */ FreeDatas2HTML),\n/* harmony export */ \"Pagination\": () => (/* reexport safe */ _freeDatas2HTMLPagination__WEBPACK_IMPORTED_MODULE_0__.Pagination),\n/* harmony export */ \"Selector\": () => (/* reexport safe */ _freeDatas2HTMLSelector__WEBPACK_IMPORTED_MODULE_1__.Selector),\n/* harmony export */ \"SortingField\": () => (/* reexport safe */ _freeDatas2HTMLSortingField__WEBPACK_IMPORTED_MODULE_2__.SortingField)\n/* harmony export */ });\n/* harmony import */ var _freeDatas2HTMLPagination__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./freeDatas2HTMLPagination */ \"./src/freeDatas2HTMLPagination.ts\");\n/* harmony import */ var _freeDatas2HTMLSelector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./freeDatas2HTMLSelector */ \"./src/freeDatas2HTMLSelector.ts\");\n/* harmony import */ var _freeDatas2HTMLSortingField__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./freeDatas2HTMLSortingField */ \"./src/freeDatas2HTMLSortingField.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar Papa = __webpack_require__(/*! papaparse */ \"./node_modules/papaparse/papaparse.min.js\");\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\nvar compare = __webpack_require__(/*! natural-orderby */ \"./node_modules/natural-orderby/esm/natural-orderby.js\").compare;\nvar FreeDatas2HTML = (function () {\n function FreeDatas2HTML() {\n this._datasViewElt = { id: \"\", eltDOM: undefined };\n this.datasHTML = \"\";\n this._datasSourceUrl = \"\";\n this.parseMetas = undefined;\n this.parseDatas = [];\n this.parseErrors = [];\n this.stopIfParseErrors = false;\n this._datasSortingFunctions = [];\n this.datasSelectors = [];\n this.datasSortingFields = [];\n }\n FreeDatas2HTML.checkInDOMById = function (checkedElt) {\n var searchEltInDOM = document.getElementById(checkedElt.id);\n if (searchEltInDOM === null)\n throw new Error(errors.converterElementNotFound + checkedElt.id);\n else {\n checkedElt.eltDOM = searchEltInDOM;\n return checkedElt;\n }\n };\n FreeDatas2HTML.prototype.checkFieldExist = function (nb) {\n if (this.parseMetas === undefined || this.parseMetas.fields === undefined || this.parseMetas.fields[nb] === undefined)\n return false;\n else\n return true;\n };\n Object.defineProperty(FreeDatas2HTML.prototype, \"datasViewElt\", {\n set: function (elt) {\n this._datasViewElt = FreeDatas2HTML.checkInDOMById(elt);\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(FreeDatas2HTML.prototype, \"datasSourceUrl\", {\n set: function (url) {\n if (url.trim().length === 0)\n throw new Error(errors.parserNeedUrl);\n else\n this._datasSourceUrl = url.trim();\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(FreeDatas2HTML.prototype, \"datasSortingFunctions\", {\n set: function (SortingFunctions) {\n this._datasSortingFunctions = [];\n for (var i = 0; i < SortingFunctions.length; i++) {\n if (!this.checkFieldExist(SortingFunctions[i].datasFieldNb))\n throw new Error(errors.converterFieldNotFound);\n else\n this._datasSortingFunctions.push(SortingFunctions[i]);\n }\n },\n enumerable: false,\n configurable: true\n });\n FreeDatas2HTML.prototype.getSortingFunctionForField = function (datasFieldNb) {\n for (var i in this._datasSortingFunctions) {\n if (this._datasSortingFunctions[i].datasFieldNb === datasFieldNb)\n return this._datasSortingFunctions[i];\n }\n return undefined;\n };\n FreeDatas2HTML.prototype.parse = function () {\n return __awaiter(this, void 0, void 0, function () {\n var converter;\n return __generator(this, function (_a) {\n converter = this;\n return [2, new Promise(function (resolve, reject) {\n if (converter._datasSourceUrl !== \"\") {\n Papa.parse(converter._datasSourceUrl, {\n quoteChar: '\"',\n header: true,\n complete: function (results) {\n converter.parseErrors = results.errors;\n converter.parseDatas = results.data;\n var realFields = [];\n for (var i in results.meta.fields) {\n if (results.meta.fields[i].trim() !== \"\")\n realFields.push(results.meta.fields[i]);\n }\n results.meta.fields = realFields;\n converter.parseMetas = results.meta;\n resolve(true);\n },\n error: function (error) {\n reject(new Error(errors.parserFail));\n },\n download: true,\n skipEmptyLines: true,\n });\n }\n else\n reject(new Error(errors.parserNeedUrl));\n })];\n });\n });\n };\n FreeDatas2HTML.prototype.run = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this._datasViewElt.eltDOM === undefined)\n throw new Error(errors.converterNeedDatasElt);\n if (this._datasSourceUrl === \"\")\n throw new Error(errors.parserNeedUrl);\n return [4, this.parse()];\n case 1:\n _a.sent();\n if (this.parseDatas.length === 0 || this.parseMetas.fields === undefined)\n throw new Error(errors.parserDatasNotFound);\n else if (this.stopIfParseErrors && this.parseErrors.length !== 0)\n console.error(this.parseErrors);\n else {\n this.refreshView();\n return [2, true];\n }\n return [2];\n }\n });\n });\n };\n FreeDatas2HTML.prototype.refreshView = function () {\n if (this.parseMetas === undefined || this.parseMetas.fields === undefined || this._datasViewElt.eltDOM === undefined)\n throw new Error(errors.converterRefreshFail);\n this.datasHTML = this.createDatasHTML(this.parseMetas.fields, this.parseDatas);\n this._datasViewElt.eltDOM.innerHTML = this.datasHTML;\n for (var i in this.datasSortingFields) {\n var field = this.datasSortingFields[i];\n field.field2HTML();\n }\n };\n FreeDatas2HTML.prototype.createDatasHTML = function (fields, datas) {\n if (this.datasSortedField !== undefined && this.datasSortedField.datasFieldNb !== undefined) {\n var field_1 = fields[this.datasSortedField.datasFieldNb];\n var fieldOrder_1 = this.datasSortedField.order;\n if (this.getSortingFunctionForField(this.datasSortedField.datasFieldNb) !== undefined) {\n var myFunction_1 = this.getSortingFunctionForField(this.datasSortedField.datasFieldNb);\n datas.sort(function (a, b) { return myFunction_1.sort(a[field_1], b[field_1], fieldOrder_1); });\n }\n else\n datas.sort(function (a, b) { return compare({ order: fieldOrder_1 })(a[field_1], b[field_1]); });\n }\n var firstData = 0;\n if (this.pagination !== undefined && this.pagination.selectedValue !== undefined && this.pagination.pages !== undefined && this.pagination.pages.selectedValue !== undefined)\n firstData = this.pagination.selectedValue * (this.pagination.pages.selectedValue - 1);\n var maxData = (this.pagination !== undefined && this.pagination.selectedValue !== undefined) ? this.pagination.selectedValue : datas.length + 1;\n var datasHTML = \"\";\n for (var i in fields)\n datasHTML += \"\";\n datasHTML += \"\";\n var nbVisible = 0, nbTotal = 0;\n for (var row in datas) {\n var visible = true;\n if (this.datasSelectors.length !== 0) {\n var i = 0;\n while (this.datasSelectors[i] !== undefined && visible === true) {\n visible = this.datasSelectors[i].dataIsOk(datas[row]);\n i++;\n }\n }\n if (visible && nbTotal >= firstData && nbVisible < maxData) {\n datasHTML += \"\";\n for (var field in datas[row]) {\n if (fields.indexOf(field) !== -1)\n datasHTML += \"\";\n }\n datasHTML += \"\";\n nbVisible++;\n nbTotal++;\n }\n else if (visible)\n nbTotal++;\n }\n datasHTML += \"
\" + fields[i] + \"
\" + datas[row][field] + \"
\";\n if (this.pagination !== undefined)\n this.pagination.creaPageSelector(nbTotal);\n return datasHTML;\n };\n return FreeDatas2HTML;\n}());\n\n\n\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTML.ts?"); /***/ }), @@ -59,7 +59,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Pagination\": () => (/* binding */ Pagination)\n/* harmony export */ });\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\nvar Pagination = (function () {\n function Pagination(converter, pagesElt, pagesName) {\n if (pagesName === void 0) { pagesName = \"Pages\"; }\n if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined)\n throw new Error(errors.paginationNeedDatas);\n else {\n var checkContainerExist = document.getElementById(pagesElt.id);\n if (checkContainerExist === null)\n throw new Error(errors.elementNotFound + pagesElt.id);\n else {\n this._converter = converter;\n this._pages = { displayElement: { id: pagesElt.id, eltDOM: checkContainerExist }, name: pagesName };\n }\n }\n }\n Pagination.isPositiveInteger = function (nb) {\n return (Number.isInteger(nb) === false || nb <= 0) ? false : true;\n };\n Object.defineProperty(Pagination.prototype, \"selectedValue\", {\n get: function () {\n return this._selectedValue;\n },\n set: function (value) {\n if (value === undefined || !Pagination.isPositiveInteger(value))\n throw new Error(errors.needPositiveInteger);\n if (this.options !== undefined && this.options.values.indexOf(value) === -1)\n throw new Error(errors.needPaginationByDefaultBeInOptions);\n this._selectedValue = value;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Pagination.prototype, \"options\", {\n get: function () {\n return this._options;\n },\n set: function (options) {\n if (options !== undefined) {\n var checkContainerExist = document.getElementById(options.displayElement.id);\n if (checkContainerExist === null)\n throw new Error(errors.elementNotFound + options.displayElement.id);\n else\n options.displayElement.eltDOM = checkContainerExist;\n if (options.values.length === 0)\n throw new Error(errors.needPaginationOptionsValues);\n for (var i in options.values) {\n if (!Pagination.isPositiveInteger(options.values[i]))\n throw new Error(errors.needPositiveInteger);\n }\n options.name = (options.name === undefined) ? \"Pagination\" : options.name;\n this._options = options;\n }\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Pagination.prototype, \"pages\", {\n get: function () {\n return this._pages;\n },\n enumerable: false,\n configurable: true\n });\n Pagination.prototype.rend2HTML = function () {\n if (this._converter === undefined || this._options === undefined)\n throw new Error(errors.pagination2HTMLFail);\n else {\n var selectorsHTML = \"\";\n this._options.displayElement.eltDOM.innerHTML = selectorsHTML;\n var selectElement_1 = document.getElementById(\"freeDatas2HTMLPaginationSelector\");\n if (this._selectedValue !== undefined) {\n var indexSelectedValue = this._options.values.indexOf(this._selectedValue) + 1;\n selectElement_1.value = \"\" + indexSelectedValue;\n }\n var pagination_1 = this;\n selectElement_1.addEventListener(\"change\", function (e) {\n if (selectElement_1.value === \"0\")\n pagination_1._selectedValue = undefined;\n else\n pagination_1._selectedValue = pagination_1._options.values[Number(selectElement_1.value) - 1];\n pagination_1._converter.refreshView();\n });\n }\n };\n Pagination.prototype.creaPageSelector = function (nbTotal) {\n if (this.selectedValue !== undefined) {\n if (nbTotal > this.selectedValue) {\n var nbPages = Math.ceil(nbTotal / this.selectedValue);\n var selectorsHTML = \"\";\n this.pages.displayElement.eltDOM.innerHTML = selectorsHTML;\n var selectElement_2 = document.getElementById(\"freeDatas2HTMLPagesSelector\");\n if (this.pages.selectedValue !== undefined)\n selectElement_2.value = \"\" + this.pages.selectedValue;\n this.pages.selectedValue = 1;\n var pagination_2 = this;\n selectElement_2.addEventListener('change', function (e) {\n pagination_2.pages.selectedValue = Number(selectElement_2.value);\n pagination_2._converter.refreshView();\n });\n }\n else\n this.pages.displayElement.eltDOM.innerHTML = \"\";\n }\n else\n this.pages.displayElement.eltDOM.innerHTML = \"\";\n };\n return Pagination;\n}());\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTMLPagination.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Pagination\": () => (/* binding */ Pagination)\n/* harmony export */ });\n/* harmony import */ var _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./freeDatas2HTML */ \"./src/freeDatas2HTML.ts\");\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\n\nvar Pagination = (function () {\n function Pagination(converter, pagesElt, pagesName) {\n if (pagesName === void 0) { pagesName = \"Pages\"; }\n if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined)\n throw new Error(errors.paginationNeedDatas);\n else {\n this._pages = { displayElement: _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.FreeDatas2HTML.checkInDOMById(pagesElt), name: pagesName };\n this._converter = converter;\n }\n }\n Pagination.isPositiveInteger = function (nb) {\n return (Number.isInteger(nb) === false || nb <= 0) ? false : true;\n };\n Object.defineProperty(Pagination.prototype, \"selectedValue\", {\n get: function () {\n return this._selectedValue;\n },\n set: function (value) {\n if (value === undefined || !Pagination.isPositiveInteger(value))\n throw new Error(errors.needPositiveInteger);\n if (this.options !== undefined && this.options.values.indexOf(value) === -1)\n throw new Error(errors.paginationNeedByfaultValueBeInOptions);\n this._selectedValue = value;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Pagination.prototype, \"options\", {\n get: function () {\n return this._options;\n },\n set: function (options) {\n if (options !== undefined) {\n options.displayElement = _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.FreeDatas2HTML.checkInDOMById(options.displayElement);\n if (options.values.length === 0)\n throw new Error(errors.paginationNeedOptionsValues);\n for (var i in options.values) {\n if (!Pagination.isPositiveInteger(options.values[i]))\n throw new Error(errors.needPositiveInteger);\n }\n if (this.selectedValue !== undefined && options.values.indexOf(this.selectedValue) === -1)\n throw new Error(errors.paginationNeedByfaultValueBeInOptions);\n options.name = (options.name === undefined) ? \"Pagination\" : options.name;\n this._options = options;\n }\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Pagination.prototype, \"pages\", {\n get: function () {\n return this._pages;\n },\n enumerable: false,\n configurable: true\n });\n Pagination.prototype.rend2HTML = function () {\n if (this._converter === undefined || this._options === undefined)\n throw new Error(errors.pagination2HTMLFail);\n else {\n var selectorsHTML = \"\";\n this._options.displayElement.eltDOM.innerHTML = selectorsHTML;\n var selectElement_1 = document.getElementById(\"freeDatas2HTMLPaginationSelector\");\n if (this._selectedValue !== undefined) {\n var indexSelectedValue = this._options.values.indexOf(this._selectedValue) + 1;\n selectElement_1.value = \"\" + indexSelectedValue;\n }\n var pagination_1 = this;\n selectElement_1.addEventListener(\"change\", function (e) {\n if (selectElement_1.value === \"0\")\n pagination_1._selectedValue = undefined;\n else\n pagination_1._selectedValue = pagination_1._options.values[Number(selectElement_1.value) - 1];\n pagination_1._converter.refreshView();\n });\n }\n };\n Pagination.prototype.creaPageSelector = function (nbTotal) {\n if (this.selectedValue !== undefined) {\n if (nbTotal > this.selectedValue) {\n var nbPages = Math.ceil(nbTotal / this.selectedValue);\n var selectorsHTML = \"\";\n this.pages.displayElement.eltDOM.innerHTML = selectorsHTML;\n var selectElement_2 = document.getElementById(\"freeDatas2HTMLPagesSelector\");\n if (this.pages.selectedValue !== undefined)\n selectElement_2.value = \"\" + this.pages.selectedValue;\n this.pages.selectedValue = 1;\n var pagination_2 = this;\n selectElement_2.addEventListener('change', function (e) {\n pagination_2.pages.selectedValue = Number(selectElement_2.value);\n pagination_2._converter.refreshView();\n });\n }\n else\n this.pages.displayElement.eltDOM.innerHTML = \"\";\n }\n else\n this.pages.displayElement.eltDOM.innerHTML = \"\";\n };\n return Pagination;\n}());\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTMLPagination.ts?"); /***/ }), @@ -70,7 +70,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Selector\": () => (/* binding */ Selector)\n/* harmony export */ });\nvar compare = __webpack_require__(/*! natural-orderby */ \"./node_modules/natural-orderby/esm/natural-orderby.js\").compare;\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\nvar Selector = (function () {\n function Selector(converter) {\n this._datasViewElt = { id: \"\", eltDOM: undefined };\n this.name = \"\";\n this.values = [];\n if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined || converter.parseDatas.length === 0)\n throw new Error(errors.selectorNeedDatas);\n else\n this._converter = converter;\n }\n Object.defineProperty(Selector.prototype, \"datasViewElt\", {\n get: function () {\n return this._datasViewElt;\n },\n set: function (elt) {\n var checkContainerExist = document.getElementById(elt.id);\n if (checkContainerExist === null)\n throw new Error(errors.elementNotFound + elt.id);\n else {\n this._datasViewElt.id = elt.id;\n this._datasViewElt.eltDOM = checkContainerExist;\n }\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Selector.prototype, \"datasFieldNb\", {\n get: function () {\n return this._datasFieldNb;\n },\n set: function (datasFieldNb) {\n if (datasFieldNb !== undefined && this._converter.parseMetas.fields[datasFieldNb] === undefined)\n throw new Error(errors.selectorFieldNotFound);\n else\n this._datasFieldNb = datasFieldNb;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Selector.prototype, \"separator\", {\n set: function (separator) {\n if (separator === \"\")\n this._separator = undefined;\n else\n this._separator = separator;\n },\n enumerable: false,\n configurable: true\n });\n Selector.prototype.selector2HTML = function () {\n if (this._converter === undefined || this._datasViewElt.eltDOM === undefined || this._datasFieldNb === undefined)\n throw new Error(errors.selector2HTMLFail);\n else {\n this.name = this._converter.parseMetas.fields[this._datasFieldNb];\n for (var row in this._converter.parseDatas) {\n if (this._separator === undefined) {\n var checkedValue = String(this._converter.parseDatas[row][this.name]).trim();\n if (checkedValue !== \"\" && this.values.indexOf(checkedValue) === -1)\n this.values.push(checkedValue);\n }\n else {\n var checkedValues = String(this._converter.parseDatas[row][this.name]).split(this._separator);\n for (var i in checkedValues) {\n var checkedValue = checkedValues[i].trim();\n if (checkedValue !== \"\" && this.values.indexOf(checkedValue) === -1)\n this.values.push(checkedValue);\n }\n }\n }\n if (this.values.length > 0) {\n if (this._converter.getSortingFunctionForField(this._datasFieldNb) !== undefined)\n this.values.sort(this._converter.getSortingFunctionForField(this._datasFieldNb).sort);\n else\n this.values.sort(compare());\n var selectorsHTML = \"\";\n this._datasViewElt.eltDOM.innerHTML = selectorsHTML;\n var selectElement = document.getElementById(\"freeDatas2HTML_\" + this._datasViewElt.id), mySelector_1 = this;\n selectElement.addEventListener(\"change\", function (e) {\n mySelector_1._converter.refreshView();\n });\n }\n }\n };\n Selector.prototype.getSelectionnedId = function () {\n var selectElement = document.getElementById(\"freeDatas2HTML_\" + this._datasViewElt.id);\n if (selectElement === undefined)\n return 0;\n else\n return parseInt(selectElement.value, 10);\n };\n Selector.prototype.dataIsOk = function (data) {\n if (this.name === undefined || this.name === \"\")\n throw new Error(errors.selectorCheckIsOkFail);\n var selectedValue = this.getSelectionnedId();\n if (selectedValue === 0)\n return true;\n else\n selectedValue = selectedValue - 1;\n if (this.values[selectedValue] === undefined)\n throw new Error(errors.selectorSelectedIndexNotFound);\n if (data[this.name] === undefined)\n return false;\n var selectedValueTxt = this.values[selectedValue];\n if (this._separator === undefined) {\n if (data[this.name].trim() !== selectedValueTxt)\n return false;\n else\n return true;\n }\n else {\n var find = false;\n var checkedValues = String(data[this.name]).split(this._separator);\n for (var j in checkedValues) {\n if (checkedValues[j].trim() === selectedValueTxt) {\n find = true;\n break;\n }\n }\n return find;\n }\n };\n return Selector;\n}());\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTMLSelector.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Selector\": () => (/* binding */ Selector)\n/* harmony export */ });\n/* harmony import */ var _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./freeDatas2HTML */ \"./src/freeDatas2HTML.ts\");\nvar compare = __webpack_require__(/*! natural-orderby */ \"./node_modules/natural-orderby/esm/natural-orderby.js\").compare;\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\n\nvar Selector = (function () {\n function Selector(converter, datasFieldNb, elt) {\n this._datasViewElt = { id: \"\", eltDOM: undefined };\n this.name = \"\";\n this.values = [];\n if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined || converter.parseDatas.length === 0)\n throw new Error(errors.selectorNeedDatas);\n else if (!converter.checkFieldExist(Number(datasFieldNb)))\n throw new Error(errors.selectorFieldNotFound);\n else {\n this._datasViewElt = _freeDatas2HTML__WEBPACK_IMPORTED_MODULE_0__.FreeDatas2HTML.checkInDOMById(elt);\n this._converter = converter;\n this._datasFieldNb = datasFieldNb;\n }\n }\n Object.defineProperty(Selector.prototype, \"separator\", {\n get: function () {\n return this._separator;\n },\n set: function (separator) {\n if (separator === \"\")\n this._separator = undefined;\n else\n this._separator = separator;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Selector.prototype, \"datasViewElt\", {\n get: function () {\n return this._datasViewElt;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(Selector.prototype, \"datasFieldNb\", {\n get: function () {\n return this._datasFieldNb;\n },\n enumerable: false,\n configurable: true\n });\n Selector.prototype.selector2HTML = function () {\n if (this._converter === undefined || this._datasViewElt.eltDOM === undefined || this._datasFieldNb === undefined)\n throw new Error(errors.selector2HTMLFail);\n else {\n this.name = this._converter.parseMetas.fields[this._datasFieldNb];\n for (var row in this._converter.parseDatas) {\n if (this._separator === undefined) {\n var checkedValue = String(this._converter.parseDatas[row][this.name]).trim();\n if (checkedValue !== \"\" && this.values.indexOf(checkedValue) === -1)\n this.values.push(checkedValue);\n }\n else {\n var checkedValues = String(this._converter.parseDatas[row][this.name]).split(this._separator);\n for (var i in checkedValues) {\n var checkedValue = checkedValues[i].trim();\n if (checkedValue !== \"\" && this.values.indexOf(checkedValue) === -1)\n this.values.push(checkedValue);\n }\n }\n }\n if (this.values.length > 0) {\n if (this._converter.getSortingFunctionForField(this._datasFieldNb) !== undefined)\n this.values.sort(this._converter.getSortingFunctionForField(this._datasFieldNb).sort);\n else\n this.values.sort(compare());\n var selectorsHTML = \"\";\n this._datasViewElt.eltDOM.innerHTML = selectorsHTML;\n var selectElement = document.getElementById(\"freeDatas2HTML_\" + this._datasViewElt.id), mySelector_1 = this;\n selectElement.addEventListener(\"change\", function (e) {\n mySelector_1._converter.refreshView();\n });\n }\n }\n };\n Selector.prototype.getSelectionnedId = function () {\n var selectElement = document.getElementById(\"freeDatas2HTML_\" + this._datasViewElt.id);\n if (selectElement === undefined)\n return 0;\n else\n return parseInt(selectElement.value, 10);\n };\n Selector.prototype.dataIsOk = function (data) {\n if (this.name === undefined || this.name === \"\")\n throw new Error(errors.selectorCheckIsOkFail);\n var selectedValue = this.getSelectionnedId();\n if (selectedValue === 0)\n return true;\n else\n selectedValue = selectedValue - 1;\n if (this.values[selectedValue] === undefined)\n throw new Error(errors.selectorSelectedIndexNotFound);\n if (data[this.name] === undefined)\n return false;\n var selectedValueTxt = this.values[selectedValue];\n if (this._separator === undefined) {\n if (data[this.name].trim() !== selectedValueTxt)\n return false;\n else\n return true;\n }\n else {\n var find = false;\n var checkedValues = String(data[this.name]).split(this._separator);\n for (var j in checkedValues) {\n if (checkedValues[j].trim() === selectedValueTxt) {\n find = true;\n break;\n }\n }\n return find;\n }\n };\n return Selector;\n}());\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTMLSelector.ts?"); /***/ }), @@ -81,7 +81,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"SortingField\": () => (/* binding */ SortingField)\n/* harmony export */ });\nvar compare = __webpack_require__(/*! natural-orderby */ \"./node_modules/natural-orderby/esm/natural-orderby.js\").compare;\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\nvar SortingField = (function () {\n function SortingField(converter, fieldsDOMSelector) {\n if (fieldsDOMSelector === void 0) { fieldsDOMSelector = \"th\"; }\n this._order = undefined;\n if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined)\n throw new Error(errors.sortingFieldNeedDatas);\n else {\n var fields = document.querySelectorAll(fieldsDOMSelector);\n if (fields === undefined)\n throw new Error(errors.sortingFieldsNotInHTML);\n else if (fields.length !== converter.parseMetas.fields.length)\n throw new Error(errors.sortingFieldsNbFail);\n else {\n this._converter = converter;\n this._fieldsDOMSelector = fieldsDOMSelector;\n }\n }\n }\n Object.defineProperty(SortingField.prototype, \"datasFieldNb\", {\n get: function () {\n return this._datasFieldNb;\n },\n set: function (datasFieldNb) {\n if (datasFieldNb !== undefined && this._converter.parseMetas.fields[datasFieldNb] === undefined)\n throw new Error(errors.sortingFieldFieldNotFound);\n else\n this._datasFieldNb = datasFieldNb;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(SortingField.prototype, \"order\", {\n get: function () {\n return this._order;\n },\n enumerable: false,\n configurable: true\n });\n SortingField.prototype.field2HTML = function () {\n if (this._converter === undefined || this._fieldsDOMSelector === \"\" || this._datasFieldNb === undefined)\n throw new Error(errors.sortingField2HTMLFail);\n else {\n var fields = document.querySelectorAll(this._fieldsDOMSelector);\n var htmlContent = fields[this._datasFieldNb].innerHTML;\n htmlContent = \"\" + htmlContent + \"\";\n fields[this._datasFieldNb].innerHTML = htmlContent;\n var sortingElement = document.getElementById(\"freeDatas2HTMLSorting\" + this._datasFieldNb), field_1 = this;\n sortingElement.addEventListener(\"click\", function (e) {\n e.preventDefault();\n var order = field_1._order;\n if (order === undefined || order === \"desc\")\n field_1._order = \"asc\";\n else\n field_1._order = \"desc\";\n field_1._converter.datasSortedField = field_1;\n field_1._converter.refreshView();\n });\n }\n };\n return SortingField;\n}());\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTMLSortingField.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"SortingField\": () => (/* binding */ SortingField)\n/* harmony export */ });\nvar compare = __webpack_require__(/*! natural-orderby */ \"./node_modules/natural-orderby/esm/natural-orderby.js\").compare;\nvar errors = __webpack_require__(/*! ./errors.js */ \"./src/errors.js\");\nvar SortingField = (function () {\n function SortingField(converter, datasFieldNb, fieldsDOMSelector) {\n if (fieldsDOMSelector === void 0) { fieldsDOMSelector = \"th\"; }\n this._order = undefined;\n if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined)\n throw new Error(errors.sortingFieldNeedDatas);\n else if (!converter.checkFieldExist(Number(datasFieldNb)))\n throw new Error(errors.sortingFieldFieldNotFound);\n else {\n var fields = document.querySelectorAll(fieldsDOMSelector);\n if (fields === undefined)\n throw new Error(errors.sortingFieldsNotInHTML);\n else if (fields.length !== converter.parseMetas.fields.length)\n throw new Error(errors.sortingFieldsNbFail);\n else {\n this._converter = converter;\n this._datasFieldNb = datasFieldNb;\n this._fieldsDOMSelector = fieldsDOMSelector;\n }\n }\n }\n Object.defineProperty(SortingField.prototype, \"fieldsDOMSelector\", {\n get: function () {\n return this._fieldsDOMSelector;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(SortingField.prototype, \"datasFieldNb\", {\n get: function () {\n return this._datasFieldNb;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(SortingField.prototype, \"order\", {\n get: function () {\n return this._order;\n },\n enumerable: false,\n configurable: true\n });\n SortingField.prototype.field2HTML = function () {\n if (this._converter === undefined || this._fieldsDOMSelector === \"\" || this._datasFieldNb === undefined)\n throw new Error(errors.sortingField2HTMLFail);\n else {\n var fields = document.querySelectorAll(this._fieldsDOMSelector);\n var htmlContent = fields[this._datasFieldNb].innerHTML;\n htmlContent = \"\" + htmlContent + \"\";\n fields[this._datasFieldNb].innerHTML = htmlContent;\n var sortingElement = document.getElementById(\"freeDatas2HTMLSorting\" + this._datasFieldNb), field_1 = this;\n sortingElement.addEventListener(\"click\", function (e) {\n e.preventDefault();\n var order = field_1._order;\n if (order === undefined || order === \"desc\")\n field_1._order = \"asc\";\n else\n field_1._order = \"desc\";\n field_1._converter.datasSortedField = field_1;\n field_1._converter.refreshView();\n });\n }\n };\n return SortingField;\n}());\n\n\n\n//# sourceURL=webpack://freedatas2html/./src/freeDatas2HTMLSortingField.ts?"); /***/ }), @@ -91,7 +91,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \***********************/ /***/ ((module) => { -eval("module.exports =\n{\n datasNotFound : \"Aucune donnée n'a été trouvée.\",\n elementNotFound : \"Aucun élément HTML n'a été trouvé ayant comme \\\"id\\\" : \",\n needDatasElt: \"Merci de fournir un id valide pour l'élément où afficher les données.\",\n needPagesSelectorElt: \"Merci de fournir l'id de l'élément où afficher le sélecteur de pages.\",\n needPaginationByDefaultBeInOptions: \"La valeur de pagination par défaut doit faire partie des options proposées.\",\n needPaginationOptionsValues: \"Vous n'avez fourni aucune options possibles pour la pagination.\", \n needPositiveInteger: \"Merci de fournir un nombre entier supérieur à zéro pour désigner chaque option de pagination.\",\n needUrl: \"Merci de fournir une url valide pour le fichier CSV à parser.\",\n paginationNeedDatas: \"Il ne peut y avoir de pagination, si les données n'ont pas été récupérées.\",\n pagination2HTMLFail : \"Toutes les donnée nécessaires à la création des sélecteurs de pagination n'ont pas été fournies.\",\n parserFail: \"La lecture des données du fichier a échoué.\",\n refreshFail: \"Le nom des champs et l'élement du DOM receveur sont nécessaires à l'affichage des données.\",\n selector2HTMLFail: \"Le création d'un filtre dans le DOM nécessite l'initialisation de l'élément HTML et du numéro du champs à filter.\",\n selectorCheckIsOkFail: \"Le test est lancé sur un filtre incorrectement initialisé ou sur un attribut absent de la donnée à tester.\",\n selectorFieldNotFound: \"Au moins une des colonnes devant servir à filtrer les données n'existe pas dans le fichier.\",\n selectorNeedDatas: \"Le création d'un filtre nécessite la transmission des données à filtrer.\",\n selectorSelectedIndexNotFound: \"La valeur sélectionnée n'a pas été trouvée dans la liste des champs.\",\n sortingField2HTMLFail: \"Toutes les donnée nécessaires à la création du lien de classement n'ont pas été fournies.\",\n sortingFieldNeedDatas: \"Le création d'un champ de classement nécessite la transmission de la liste des champs.\",\n sortingFieldsNbFail: \"Le nombre de champs trouvés dans le DOM ne correspond pas à celui des données à classer.\",\n sortingFieldsNotInHTML: \"Les champs pouvant servir à classer les données n'ont pas été trouvés dans le DOM.\",\n};\n\n//# sourceURL=webpack://freedatas2html/./src/errors.js?"); +eval("module.exports =\n{\n converterElementNotFound : \"Aucun élément HTML n'a été trouvé ayant comme \\\"id\\\" : \",\n converterFieldNotFound : \"Le champ n'existe pas dans les données ou les données n'ont pas encore été chargées.\",\n converterNeedDatasElt: \"Merci de fournir un id valide pour l'élément où afficher les données.\",\n converterRefreshFail: \"Le nom des champs et l'élement du DOM receveur sont nécessaires à l'affichage des données.\",\n pagination2HTMLFail : \"Toutes les donnée nécessaires à la création des sélecteurs de pagination n'ont pas été fournies.\",\n paginationNeedByfaultValueBeInOptions: \"La valeur de pagination par défaut doit faire partie des options proposées.\",\n paginationNeedDatas: \"Il ne peut y avoir de pagination, si les données n'ont pas été récupérées.\",\n paginationNeedOptionsValues: \"Vous n'avez fourni aucune options possibles pour la pagination.\", \n paginationNeedPositiveInteger: \"Merci de fournir un nombre entier supérieur à zéro pour désigner chaque option de pagination.\",\n parserDatasNotFound : \"Aucune donnée n'a été trouvée.\",\n parserFail: \"La lecture des données du fichier a échoué.\",\n parserNeedUrl: \"Merci de fournir une url valide pour le fichier à parser.\",\n selector2HTMLFail: \"Le création d'un filtre dans le DOM nécessite l'initialisation de l'élément HTML et du numéro du champs à filter.\",\n selectorCheckIsOkFail: \"Le test est lancé sur un filtre incorrectement initialisé ou sur un attribut absent de la donnée à tester.\",\n selectorFieldNotFound: \"Au moins un des champs devant servir à filtrer les données n'existe pas dans le fichier.\",\n selectorNeedDatas: \"Le création d'un filtre nécessite la transmission des données à filtrer.\",\n selectorSelectedIndexNotFound: \"La valeur sélectionnée n'a pas été trouvée dans la liste des champs.\",\n sortingField2HTMLFail: \"Toutes les donnée nécessaires à la création du lien de classement n'ont pas été fournies.\",\n sortingFieldNeedDatas: \"Le création d'un champ de classement nécessite la transmission de la liste des champs.\",\n sortingFieldFieldNotFound: \"Au moins un des champs devant permettre de classer les données n'existe pas dans le fichier.\",\n sortingFieldsNbFail: \"Le nombre de champs trouvés dans le DOM ne correspond pas à celui des données à classer.\",\n sortingFieldsNotInHTML: \"Les champs pouvant servir à classer les données n'ont pas été trouvés dans le DOM.\",\n};\n\n//# sourceURL=webpack://freedatas2html/./src/errors.js?"); /***/ }) diff --git a/src/build/firstExample.js b/src/build/firstExample.js index 8e3720d..d4cc78d 100644 --- a/src/build/firstExample.js +++ b/src/build/firstExample.js @@ -68,31 +68,21 @@ var initialise = function () { return __awaiter(void 0, void 0, void 0, function return [4, converter.run()]; case 2: _a.sent(); - filtre1 = new Selector(converter); - filtre1.datasViewElt = { id: "filtre1" }; - filtre1.datasFieldNb = 3; + filtre1 = new Selector(converter, 3, { id: "filtre1" }); filtre1.selector2HTML(); - filtre2 = new Selector(converter); - filtre2.datasViewElt = { id: "filtre2" }; - filtre2.datasFieldNb = 4; + filtre2 = new Selector(converter, 4, { id: "filtre2" }); filtre2.selector2HTML(); - filtre3 = new Selector(converter); - filtre3.datasViewElt = { id: "filtre3" }; - filtre3.datasFieldNb = 5; + filtre3 = new Selector(converter, 5, { id: "filtre3" }); filtre3.separator = ","; filtre3.selector2HTML(); converter.datasSelectors = [filtre1, filtre2, filtre3]; - sortingField1 = new SortingField(converter); - sortingField1.datasFieldNb = 0; + sortingField1 = new SortingField(converter, 0); sortingField1.field2HTML(); - sortingField2 = new SortingField(converter); - sortingField2.datasFieldNb = 1; + sortingField2 = new SortingField(converter, 1); sortingField2.field2HTML(); - sortingField3 = new SortingField(converter); - sortingField3.datasFieldNb = 2; + sortingField3 = new SortingField(converter, 2); sortingField3.field2HTML(); - sortingField4 = new SortingField(converter); - sortingField4.datasFieldNb = 4; + sortingField4 = new SortingField(converter, 4); sortingField4.field2HTML(); converter.datasSortingFields = [sortingField1, sortingField2, sortingField3, sortingField4]; return [3, 4]; diff --git a/src/build/freeDatas2HTML.js b/src/build/freeDatas2HTML.js index 7a7e9e3..8a2dd5d 100644 --- a/src/build/freeDatas2HTML.js +++ b/src/build/freeDatas2HTML.js @@ -42,23 +42,32 @@ var FreeDatas2HTML = (function () { this._datasViewElt = { id: "", eltDOM: undefined }; this.datasHTML = ""; this._datasSourceUrl = ""; - this._datasSortingFunctions = []; this.parseMetas = undefined; this.parseDatas = []; this.parseErrors = []; this.stopIfParseErrors = false; + this._datasSortingFunctions = []; this.datasSelectors = []; this.datasSortingFields = []; } + FreeDatas2HTML.checkInDOMById = function (checkedElt) { + var searchEltInDOM = document.getElementById(checkedElt.id); + if (searchEltInDOM === null) + throw new Error(errors.converterElementNotFound + checkedElt.id); + else { + checkedElt.eltDOM = searchEltInDOM; + return checkedElt; + } + }; + FreeDatas2HTML.prototype.checkFieldExist = function (nb) { + if (this.parseMetas === undefined || this.parseMetas.fields === undefined || this.parseMetas.fields[nb] === undefined) + return false; + else + return true; + }; Object.defineProperty(FreeDatas2HTML.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; - } + this._datasViewElt = FreeDatas2HTML.checkInDOMById(elt); }, enumerable: true, configurable: true @@ -66,7 +75,7 @@ var FreeDatas2HTML = (function () { Object.defineProperty(FreeDatas2HTML.prototype, "datasSourceUrl", { set: function (url) { if (url.trim().length === 0) - throw new Error(errors.needUrl); + throw new Error(errors.parserNeedUrl); else this._datasSourceUrl = url.trim(); }, @@ -77,7 +86,10 @@ var FreeDatas2HTML = (function () { set: function (SortingFunctions) { this._datasSortingFunctions = []; for (var i = 0; i < SortingFunctions.length; i++) { - this._datasSortingFunctions.push(SortingFunctions[i]); + if (!this.checkFieldExist(SortingFunctions[i].datasFieldNb)) + throw new Error(errors.converterFieldNotFound); + else + this._datasSortingFunctions.push(SortingFunctions[i]); } }, enumerable: true, @@ -120,7 +132,7 @@ var FreeDatas2HTML = (function () { }); } else - reject(new Error(errors.needUrl)); + reject(new Error(errors.parserNeedUrl)); })]; }); }); @@ -131,14 +143,14 @@ var FreeDatas2HTML = (function () { switch (_a.label) { case 0: if (this._datasViewElt.eltDOM === undefined) - throw new Error(errors.needDatasElt); + throw new Error(errors.converterNeedDatasElt); if (this._datasSourceUrl === "") - throw new Error(errors.needUrl); + throw new Error(errors.parserNeedUrl); return [4, this.parse()]; case 1: _a.sent(); if (this.parseDatas.length === 0 || this.parseMetas.fields === undefined) - throw new Error(errors.datasNotFound); + throw new Error(errors.parserDatasNotFound); else if (this.stopIfParseErrors && this.parseErrors.length !== 0) console.error(this.parseErrors); else { @@ -152,7 +164,7 @@ var FreeDatas2HTML = (function () { }; FreeDatas2HTML.prototype.refreshView = function () { if (this.parseMetas === undefined || this.parseMetas.fields === undefined || this._datasViewElt.eltDOM === undefined) - throw new Error(errors.refreshFail); + throw new Error(errors.converterRefreshFail); this.datasHTML = this.createDatasHTML(this.parseMetas.fields, this.parseDatas); this._datasViewElt.eltDOM.innerHTML = this.datasHTML; for (var i in this.datasSortingFields) { diff --git a/src/build/freeDatas2HTMLPagination.js b/src/build/freeDatas2HTMLPagination.js index 0a295f7..a00fcfb 100644 --- a/src/build/freeDatas2HTMLPagination.js +++ b/src/build/freeDatas2HTMLPagination.js @@ -1,17 +1,13 @@ var errors = require("./errors.js"); +import { FreeDatas2HTML } from "./freeDatas2HTML"; var Pagination = (function () { function Pagination(converter, pagesElt, pagesName) { if (pagesName === void 0) { pagesName = "Pages"; } if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined) throw new Error(errors.paginationNeedDatas); else { - var checkContainerExist = document.getElementById(pagesElt.id); - if (checkContainerExist === null) - throw new Error(errors.elementNotFound + pagesElt.id); - else { - this._converter = converter; - this._pages = { displayElement: { id: pagesElt.id, eltDOM: checkContainerExist }, name: pagesName }; - } + this._pages = { displayElement: FreeDatas2HTML.checkInDOMById(pagesElt), name: pagesName }; + this._converter = converter; } } Pagination.isPositiveInteger = function (nb) { @@ -25,7 +21,7 @@ var Pagination = (function () { if (value === undefined || !Pagination.isPositiveInteger(value)) throw new Error(errors.needPositiveInteger); if (this.options !== undefined && this.options.values.indexOf(value) === -1) - throw new Error(errors.needPaginationByDefaultBeInOptions); + throw new Error(errors.paginationNeedByfaultValueBeInOptions); this._selectedValue = value; }, enumerable: true, @@ -37,17 +33,15 @@ var Pagination = (function () { }, set: function (options) { if (options !== undefined) { - var checkContainerExist = document.getElementById(options.displayElement.id); - if (checkContainerExist === null) - throw new Error(errors.elementNotFound + options.displayElement.id); - else - options.displayElement.eltDOM = checkContainerExist; + options.displayElement = FreeDatas2HTML.checkInDOMById(options.displayElement); if (options.values.length === 0) - throw new Error(errors.needPaginationOptionsValues); + throw new Error(errors.paginationNeedOptionsValues); for (var i in options.values) { if (!Pagination.isPositiveInteger(options.values[i])) throw new Error(errors.needPositiveInteger); } + if (this.selectedValue !== undefined && options.values.indexOf(this.selectedValue) === -1) + throw new Error(errors.paginationNeedByfaultValueBeInOptions); options.name = (options.name === undefined) ? "Pagination" : options.name; this._options = options; } diff --git a/src/build/freeDatas2HTMLSelector.js b/src/build/freeDatas2HTMLSelector.js index e44d6bc..8194dbc 100644 --- a/src/build/freeDatas2HTMLSelector.js +++ b/src/build/freeDatas2HTMLSelector.js @@ -1,28 +1,38 @@ var compare = require('natural-orderby').compare; var errors = require("./errors.js"); +import { FreeDatas2HTML } from "./freeDatas2HTML"; var Selector = (function () { - function Selector(converter) { + function Selector(converter, datasFieldNb, elt) { this._datasViewElt = { id: "", eltDOM: undefined }; this.name = ""; this.values = []; if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined || converter.parseDatas.length === 0) throw new Error(errors.selectorNeedDatas); - else + else if (!converter.checkFieldExist(Number(datasFieldNb))) + throw new Error(errors.selectorFieldNotFound); + else { + this._datasViewElt = FreeDatas2HTML.checkInDOMById(elt); this._converter = converter; + this._datasFieldNb = datasFieldNb; + } } + Object.defineProperty(Selector.prototype, "separator", { + get: function () { + return this._separator; + }, + set: function (separator) { + if (separator === "") + this._separator = undefined; + else + this._separator = separator; + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Selector.prototype, "datasViewElt", { get: function () { return this._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 }); @@ -30,22 +40,6 @@ var Selector = (function () { get: function () { return this._datasFieldNb; }, - set: function (datasFieldNb) { - if (datasFieldNb !== undefined && this._converter.parseMetas.fields[datasFieldNb] === undefined) - throw new Error(errors.selectorFieldNotFound); - else - this._datasFieldNb = datasFieldNb; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Selector.prototype, "separator", { - set: function (separator) { - if (separator === "") - this._separator = undefined; - else - this._separator = separator; - }, enumerable: true, configurable: true }); diff --git a/src/build/freeDatas2HTMLSortingField.js b/src/build/freeDatas2HTMLSortingField.js index f44128a..ba5279e 100644 --- a/src/build/freeDatas2HTMLSortingField.js +++ b/src/build/freeDatas2HTMLSortingField.js @@ -1,11 +1,13 @@ var compare = require('natural-orderby').compare; var errors = require("./errors.js"); var SortingField = (function () { - function SortingField(converter, fieldsDOMSelector) { + function SortingField(converter, datasFieldNb, fieldsDOMSelector) { if (fieldsDOMSelector === void 0) { fieldsDOMSelector = "th"; } this._order = undefined; if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined) throw new Error(errors.sortingFieldNeedDatas); + else if (!converter.checkFieldExist(Number(datasFieldNb))) + throw new Error(errors.sortingFieldFieldNotFound); else { var fields = document.querySelectorAll(fieldsDOMSelector); if (fields === undefined) @@ -14,20 +16,22 @@ var SortingField = (function () { throw new Error(errors.sortingFieldsNbFail); else { this._converter = converter; + this._datasFieldNb = datasFieldNb; this._fieldsDOMSelector = fieldsDOMSelector; } } } + Object.defineProperty(SortingField.prototype, "fieldsDOMSelector", { + get: function () { + return this._fieldsDOMSelector; + }, + enumerable: true, + configurable: true + }); Object.defineProperty(SortingField.prototype, "datasFieldNb", { get: function () { return this._datasFieldNb; }, - set: function (datasFieldNb) { - if (datasFieldNb !== undefined && this._converter.parseMetas.fields[datasFieldNb] === undefined) - throw new Error(errors.sortingFieldFieldNotFound); - else - this._datasFieldNb = datasFieldNb; - }, enumerable: true, configurable: true });