UNPKG

ndc-suez

Version:

Generate standard ndc UI

542 lines (540 loc) 29.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ndcNetModule = void 0; const schematics_1 = require("@angular-devkit/schematics"); const core_1 = require("@angular-devkit/core"); const XLSX = require("xlsx"); function ndcNetModule(options) { const matlabInput = {}; const matlabOutput = {}; const exportArray = {}; // for labels and units const dataLabelArray = {}; // for labels and units const unitArray = {}; // for labels and units const exportDtoArray = {}; // for exportDto class const exportDtoResultArray = {}; const casesValues = []; const precisions = []; const updatable = []; const casesRules = []; const reportRules = {}; let blockingRules = {}; let nonBlockingRules = {}; const resultTags = {}; let favOrder = 0; return () => { const workbook = XLSX.readFile(options.filename); //------------------------------MatlabInput------------------------------------------ let matlabInputSheetName = 'matlabinput'; if (options.page) { matlabInputSheetName = 'matlabinput_' + options.page; } const matlabInputSheet = workbook.Sheets[matlabInputSheetName]; const variables = XLSX.utils.sheet_to_json(matlabInputSheet, { header: 3 }); variables.forEach((row) => { matlabInput[row.Name] = row.Type; }); //------------------------------MatlabOutput------------------------------------------ let matlabOutputSheetName = 'matlaboutput'; if (options.page) { matlabOutputSheetName = 'matlaboutput_' + options.page; } const matlabOutputSheet = workbook.Sheets[matlabOutputSheetName]; const outputs = XLSX.utils.sheet_to_json(matlabOutputSheet, { header: 3 }); outputs.forEach((row) => { matlabOutput[row.Name] = row.Type; }); //------------------------------BDD------------------------------------------------- const bddSheet = workbook.Sheets['bdd']; const bddConstants = XLSX.utils.sheet_to_json(bddSheet, { header: 2 }); //------------------------------Export---------------------------------------------- //Todo: to Remove const labelSheet = workbook.Sheets['label']; const labels = XLSX.utils.sheet_to_json(labelSheet, { header: 2 }); labels.forEach((row) => { exportArray[row.Name] = 'string'; }); //------------------------------Data export label sheet-------------------------------------- const datalabelSheet = workbook.Sheets['datalabel']; const dataLabels = XLSX.utils.sheet_to_json(datalabelSheet, { header: 2 }); dataLabels.forEach((row) => { if (row.Name) { if (row.Name.endsWith('_Box')) { dataLabelArray[row.Name] = 'string'; } else { dataLabelArray[row.Name.replace('_lbl', '')] = 'ReType'; } } }); //---------------------------------Units-------------------------------------- const unitSheet = workbook.Sheets['unit']; const units = XLSX.utils.sheet_to_json(unitSheet, { header: 2 }); units.forEach((row) => { exportArray[row.Name] = 'string'; unitArray[row.Name] = 'string'; }); /*const expSheet = workbook.Sheets['export']; const exportDto = XLSX.utils.sheet_to_json(expSheet, { header: 2 }); exportDto.forEach((row: any) => { if (['double', 'int', 'string'].includes(row.Type)) { if (row.User == 'Input') { exportDtoArray[row.Name] = row.Type; } if (row.User == 'Result') { exportDtoResultArray[row.Name] = row.Type; } } });*/ const exportDto = []; const types = ['TextBox', 'ListBox', 'ListBox2', 'Result', 'Report', 'Graph']; for (let screen of workbook.SheetNames) { if (screen == 'Recap') { continue; } const screenWorkbook = workbook.Sheets[screen]; const screenData = XLSX.utils.sheet_to_json(screenWorkbook, { header: 2 }); if (!screenData) { continue; } if (!screenData[0]) { continue; } if (!screenData[0].hasOwnProperty('Line')) { // then it's not a screen continue; } screenData.forEach((row) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u; try { if (row.Tool == 'Result' || types.includes(row.Tool) && !row.hasOwnProperty('Visibility')) { resultTags[row.Variable] = row.Type; } if (['H4', 'H3', 'H2', 'H1'].includes(row.Tool)) { resultTags[row.Label] = row.Type; const isExist = exportDto.some(item => item.Variable == row.Label); if (!isExist) exportDto.push({ Variable: row.Label, User: 'Label', Type: 'string' }); } // ------------------------exportDto----------------------------------- if (types.includes(row.Tool)) { const isNombre = row.Type == 'Nombre' || row.Type == 'Entier'; const isResult = row.Tool == 'Result' || row.Tool == 'Report' || row.Tool == 'Graph'; const targetArray = isResult ? exportDtoArray : exportDtoResultArray; targetArray[row.Variable] = isNombre || row.Tool == 'ListBox' || row.Tool == 'ListBox2' ? 'double' : 'string'; const isExist = exportDto.some(item => item.Variable == row.Variable); if (!isExist) { exportDto.push({ Variable: row.Variable, User: isResult ? 'Result' : 'Input', Type: targetArray[row.Variable] }); } } // ------------------------Json Config-------------------------------- const isExistUpdatable = updatable.some(item => item.name == row.Variable); if (row.NonBlockingRule) { if (['H1', 'H2', 'H3', 'H4'].includes(row.Tool)) { nonBlockingRules[row.Label] = row.NonBlockingRule; } else { nonBlockingRules[row.Variable] = row.NonBlockingRule; } } if (row.BlockingRule) { if (['H1', 'H2', 'H3', 'H4'].includes(row.Tool)) { blockingRules[row.Label] = row.BlockingRule; } else { if (row.Mandatory == '1') { blockingRules[row.Variable] = row.BlockingRule; } else { blockingRules[row.Variable] = updateNonMandatoryRules(row.Variable, row.BlockingRule); } if (row.Type == 'Entier') { if (row.Tool == 'TextBox') { const a = row.BlockingRule.split(';'); a.push('gen_mess_err_bloq_int_only:' + row.Variable + ' != INTEGER'); blockingRules[row.Variable] = a.join(';'); } } if (row.Mandatory) { if (row.Tool == 'TextBox') { let a = row.BlockingRule.split(';'); if (row.Type == 'Entier') { a = blockingRules[row.Variable].split(';'); } if (row.Mandatory == '1') { a.push('required:' + row.Variable + ' = VIDE ET ' + row.Variable + ' = isUpdatable'); } else { a.push('required:' + row.Mandatory + ' ET ' + row.Variable + ' = isUpdatable'); // conditional mandatory } blockingRules[row.Variable] = a.join(';'); } } } } else { if (row.Tool == 'TextBox') { const isEntier = row.Type == 'Entier'; if (isEntier) { blockingRules[row.Variable] = 'gen_mess_err_bloq_int_only:' + row.Variable + ' != INTEGER'; } if (row.Mandatory) { if (isEntier) { // blockingRules[row.Variable] += ';required: ' + row.Mandatory == '1' ? row.Variable + ' = VIDE' : row.Mandatory; blockingRules[row.Variable] += (row.Mandatory == '1') ? ';required: ' + row.Variable + ' = VIDE ET ' + row.Variable + ' = isUpdatable' : row.Mandatory; } else { blockingRules[row.Variable] = 'required:' + row.Variable + ' = VIDE ET ' + row.Variable + ' = isUpdatable'; } } } } if (row.hasOwnProperty('Precision') && !isNaN(safeNumberConvert(row.Precision)) && row.Variable && ['Result', 'TextBox'].includes(row.Tool)) { const isExistPrecision = precisions.some(item => item.name == row.Variable); if (!isExistPrecision) precisions.push({ name: row.Variable, precision: row.Precision }); } if (row.Updatable && !isExistUpdatable) { updatable.push({ name: row.Variable, // rule: row.Updatable == 1 ? true : `"${row.Updatable?.replace(/\\r\\n/g, " ")}"`, rule: !isNaN(Number(row.Updatable)) ? row.Updatable == 1 : `"${(_a = row.Updatable) === null || _a === void 0 ? void 0 : _a.replace(/\\r\\n/g, " ")}"`, }); } const isExistCaseValues = casesValues.some(item => item.name == row.Variable); const isExistCasesRules = casesRules.some(item => item.name == row.Variable); // let nBr = undefined; /*if(row.NonBlockingRule) { nBr = explodeObject({ [row.Variable]: row.NonBlockingRule }, {}, true); nBr = nBr[row.Variable]; }*/ switch (row.Tool) { case 'ListBox': case 'ListBox2': // const listValues = transformStringToArray(row.Listbox); if (!isExistCaseValues) casesValues.push({ name: row.Variable, //defaultValue: row.DefaultValue?.length > 0 ? row.DefaultValue?.replace(/\r\n/g, " ") : listValues[0]?.split(':').length > 1 ? listValues[0]?.split(':')[0] : listValues[0] defaultValue: stringOrNull(row.DefaultValue) }); if (!isExistCasesRules) casesRules.push({ name: row.Variable, isVisible: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : row.hasOwnProperty('Visibility') ? (_b = row.Visibility) === null || _b === void 0 ? void 0 : _b.replace(/\r\n/g, " ") : false }); if (row.Mandatory == '1' && !row.DefaultValue) { if (blockingRules[row.Variable] && blockingRules[row.Variable].length > 0) { blockingRules[row.Variable] += ';required:' + row.Variable + ' = null'; } else { blockingRules[row.Variable] = 'required:' + row.Variable + ' = null'; } } if (!reportRules.hasOwnProperty(row.Variable)) { reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : (_c = row.Visibility) === null || _c === void 0 ? void 0 : _c.replace(/\r\n/g, " "), line: row.Line, unit: row.Unit, [((_d = row.PreLabel) === null || _d === void 0 ? void 0 : _d.indexOf(':')) > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel, [((_e = row.PostLabel) === null || _e === void 0 ? void 0 : _e.indexOf(':')) > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel, screen: screen, isBox: true, recap: numberConvert(row.Recap), tool: 'ListBox', type2: row.Tool == 'ListBox2', tooltip: stringOrUndefined(row.Tooltip), favOrder: favOrder++, level: 5, expert: isExpertModeOnly(row.Visibility) ? true : undefined, required: row.Mandatory == '1' ? true : undefined, defaultValue: stringOrUndefined(row.DefaultValue) }; } break; // @ts-ignore case 'Result': /*const isExistPrecision = precisions.some(item => item.name == row.Variable); if (!isExistPrecision) precisions.push({ name: row.Variable, precision: row.Precision });*/ case 'TextBox': if (!isExistCaseValues) casesValues.push({ name: row.Variable, defaultValue: stringOrNull(row.DefaultValue) }); if (!isExistCasesRules) casesRules.push({ name: row.Variable, isVisible: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : (_f = row.Visibility) === null || _f === void 0 ? void 0 : _f.replace(/\r\n/g, " ") }); if (!reportRules.hasOwnProperty(row.Variable)) { reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : (_g = row.Visibility) === null || _g === void 0 ? void 0 : _g.replace(/\r\n/g, " "), line: row.Line, unit: row.Unit, [((_h = row.PreLabel) === null || _h === void 0 ? void 0 : _h.indexOf(':')) > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel, [((_j = row.PostLabel) === null || _j === void 0 ? void 0 : _j.indexOf(':')) > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel, screen: screen, recap: numberConvert(row.Recap), tool: row.Tool, type: row.Tool == 'Result' ? row.Type : undefined, tooltip: stringOrUndefined(row.Tooltip), favOrder: favOrder++, level: 5, expert: isExpertModeOnly(row.Visibility) ? true : undefined, required: row.Mandatory == '1' ? true : undefined, defaultValue: stringOrUndefined(row.DefaultValue) }; } break; case 'Graph': if (!reportRules.hasOwnProperty(row.Variable)) { reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : (_k = row.Visibility) === null || _k === void 0 ? void 0 : _k.replace(/\r\n/g, " "), line: row.Line, unit: row.Unit, [((_l = row.PreLabel) === null || _l === void 0 ? void 0 : _l.indexOf(':')) > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel, [((_m = row.PostLabel) === null || _m === void 0 ? void 0 : _m.indexOf(':')) > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel, screen: screen, tool: row.Tool, tooltip: stringOrUndefined(row.Tooltip), favOrder: favOrder++, level: 5, expert: isExpertModeOnly(row.Visibility) ? true : undefined, }; } break; case 'Report': reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : (_o = row.Visibility) === null || _o === void 0 ? void 0 : _o.replace(/\r\n/g, " "), line: row.Line, unit: row.Unit, [((_p = row.PreLabel) === null || _p === void 0 ? void 0 : _p.indexOf(':')) > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel, [((_q = row.PostLabel) === null || _q === void 0 ? void 0 : _q.indexOf(':')) > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel, screen: screen, isReportOnly: true }; if (!isExistCasesRules) casesRules.push({ name: row.Variable, isVisible: false }); break; case 'H1': case 'H2': case 'H3': case 'H4': if (!isExistCasesRules) { casesRules.push({ name: row.Label, isVisible: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : (_r = row.Visibility) === null || _r === void 0 ? void 0 : _r.replace(/\r\n/g, " ") }); } reportRules[row.Label] = { visibility: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : (_s = row.Visibility) === null || _s === void 0 ? void 0 : _s.replace(/\r\n/g, " "), line: row.Line, screen: screen, [((_t = row.PreLabel) === null || _t === void 0 ? void 0 : _t.indexOf(':')) > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel, [((_u = row.PostLabel) === null || _u === void 0 ? void 0 : _u.indexOf(':')) > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel, header: row.Tool, recap: numberConvert(row.Recap), tooltip: stringOrUndefined(row.Tooltip), level: getDigitFromString(row.Tool), expert: isExpertModeOnly(row.Visibility) ? true : undefined, }; break; } } catch (e) { console.error(e.message + ' (see line) ' + row.Line); throw e; } }); } // parameters const controllerTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/controller'), [ (0, schematics_1.applyTemplates)({ name: options.name, classify: core_1.strings.classify }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); // parameters const parameterTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/parameter'), [ (0, schematics_1.applyTemplates)({ name: options.name, classify: core_1.strings.classify, mInputs: matlabInput }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); // parametersDto const parameterDtoTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/parameterdto'), [ (0, schematics_1.applyTemplates)({ name: options.name, classify: core_1.strings.classify, mInputs: matlabInput }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); // resultDto const resultDtoTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/resultdto'), [ (0, schematics_1.applyTemplates)({ name: options.name, classify: core_1.strings.classify, mOutputs: matlabOutput }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); // bdd const bddTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/bdd'), [ (0, schematics_1.applyTemplates)({ name: options.name, classify: core_1.strings.classify, bdd: bddConstants }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); // config const configTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/config'), [ (0, schematics_1.applyTemplates)({ name: options.name, stringify: JSON.stringify, casesValues: casesValues, precisions: precisions, updatable: updatable, casesRules: casesRules, blockingRules: explodeObject(blockingRules, resultTags), nonBlockingRules: explodeObject(nonBlockingRules, resultTags), reportRules: reportRules, }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); // export const exportTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/export'), [ (0, schematics_1.applyTemplates)({ name: options.name, classify: core_1.strings.classify, toLower: toLower, labels: exportArray, dataLabels: dataLabelArray, units: unitArray, inputs: exportDtoArray, outputs: exportDtoResultArray, exportDto: exportDto }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); return (0, schematics_1.chain)([ (0, schematics_1.mergeWith)(parameterTemplateSource, schematics_1.MergeStrategy.Overwrite), (0, schematics_1.mergeWith)(parameterDtoTemplateSource, schematics_1.MergeStrategy.Overwrite), (0, schematics_1.mergeWith)(resultDtoTemplateSource, schematics_1.MergeStrategy.Overwrite), (0, schematics_1.mergeWith)(bddTemplateSource, schematics_1.MergeStrategy.Overwrite), (0, schematics_1.mergeWith)(exportTemplateSource, schematics_1.MergeStrategy.Overwrite), (0, schematics_1.mergeWith)(controllerTemplateSource, schematics_1.MergeStrategy.Overwrite), (0, schematics_1.mergeWith)(configTemplateSource, schematics_1.MergeStrategy.Overwrite) ]); }; } exports.ndcNetModule = ndcNetModule; function toLower(s) { return s.toLowerCase(); } // @ts-ignore function transformStringToArray(input) { // Remove the curly braces at the beginning and end of the string const strippedString = input.slice(1, -1); // Split the string by semicolon and trim any whitespace const stringArray = strippedString.split(';').map(item => item === null || item === void 0 ? void 0 : item.trim()); return stringArray; } function stringOrNull(value) { const isNull = value === null || value === undefined || value === ''; if (isNull) { return null; } if (typeof value == 'number') { return String(value); } return value.replace(/\r\n/g, " "); } function stringOrUndefined(value) { const isNull = value === null || value === undefined || value === ''; if (isNull) { return undefined; } if (typeof value == 'number') { return String(value); } return value.replace(/\r\n/g, " "); } function getDigitFromString(str) { const digit = str.match(/\d/); return digit ? parseInt(digit[0], 10) : null; } function updateNonMandatoryRules(key, conditions) { const conditionArray = conditions === null || conditions === void 0 ? void 0 : conditions.split(';'); // Prepend "key != VIDE ET" after the field name in each condition const transformedConditions = conditionArray === null || conditionArray === void 0 ? void 0 : conditionArray.map(condition => { // Split on the first occurrence of ':' to separate field from condition const [field, ...rest] = condition.split(':'); const conditionBody = rest.join(':'); return `${field}:${key} != VIDE ET ${conditionBody}`; }); return transformedConditions.join('; '); } function explodeObject(original, result = {}, removeAlert = false) { const message = {}; for (const key in original) { const value = original[key]; const parts = value === null || value === void 0 ? void 0 : value.split(';'); //ts-ignore message[key] = {}; if (!Array.isArray(parts)) { continue; } parts.forEach((part) => { const [messageKey, messageValue] = part.split(':'); if (messageValue) { let rule = messageValue.trim().replace(/\r\n/g, " "); if (removeAlert) { rule = rule.replace(/\s*alerte\s*=\s*[1-5]\s*ET\s*/g, ''); } if (result.hasOwnProperty(key)) { rule = 'isResult = true ET ' + rule; } message[key][messageKey.trim()] = rule; } }); } return message; } function safeNumberConvert(value) { return value === "" ? NaN : Number(value); } function numberConvert(value) { return value === "" || isNaN(Number(value)) ? undefined : Number(value); } function isExpertModeOnly(str) { if (str == '1') { return false; } if (str == '2') { return true; } return /^mode\s*=\s*expert(?:\s+ET|$)/.test(str === null || str === void 0 ? void 0 : str.trim()); } //# sourceMappingURL=index.js.map