UNPKG

ndc-suez

Version:

Generate standard ndc UI

773 lines (771 loc) 43.1 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"); const utils_1 = require("../utils/utils"); 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 = {}; // let modifiedKeys: any = {}; 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 }); //------------------------------Tooltips------------------------------------------------- const tooltipSheet = workbook.Sheets['tooltip']; const tooltips = XLSX.utils.sheet_to_json(tooltipSheet, { header: 2 }); //------------------------------Listbox------------------------------------------------- const listBoxSheet = workbook.Sheets['listbox']; const listBoxes = XLSX.utils.sheet_to_json(listBoxSheet, { header: 2 }); //------------------------------Blocking && NonBlockin------------------------------------ const nonBlockingSheet = workbook.Sheets['nonblocking']; const nonblocking = XLSX.utils.sheet_to_json(nonBlockingSheet, { header: 2 }); const blockingSheet = workbook.Sheets['blocking']; const blocking = XLSX.utils.sheet_to_json(blockingSheet, { header: 2 }); const allBlockingAndnonBlocking = [...blocking, ...nonblocking]; //------------------------------Export---------------------------------------------- const labelSheet = workbook.Sheets['label']; const labels = XLSX.utils.sheet_to_json(labelSheet, { header: 2 }); //Todo: to Remove labels.forEach((row) => { exportArray[row.Name] = 'string'; }); //------------------------------Data export label sheet-------------------------------------- //Todo: to Remove 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 excludeFromValidationParams = [...units, ...labels, ...listBoxes]; /*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) => { 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) { try { row.NonBlockingRule = normalizeOps(row.NonBlockingRule + ''); } catch (e) { console.log(' voir non blocking rule sur ' + row.Label); throw e; } if (['H1', 'H2', 'H3', 'H4'].includes(row.Tool)) { nonBlockingRules[row.Label] = parseAlertsByLevel(row.NonBlockingRule + ''); } else { // nonBlockingRules[row.Variable] = row.NonBlockingRule; nonBlockingRules[row.Variable] = parseAlertsByLevel(row.NonBlockingRule, row.Tool == 'Result'); } } if (row.BlockingRule) { try { //------------------patch row updatable----------------------- if (row.Updatable && row.Updatable.length > 1) { // donc c une règle const a = row.BlockingRule.split(';'); const b = []; for (let i = 0; i < a.length; i++) { const [key, rule1] = a[i].split(':'); const newRule = `${key}:${rule1} ET isUpdatable ${row.Variable}`; b.push(newRule); } row.BlockingRule = b.join(';'); } row.BlockingRule = normalizeOps(row.BlockingRule + ''); } catch (e) { console.log(' voir blocking rule sur ' + row.Label); throw e; } if (['H1', 'H2', 'H3', 'H4'].includes(row.Tool)) { blockingRules[row.Label] = row.BlockingRule; dumpBlockingIntoNonBlockingRules(row.Label, row.BlockingRule + '', nonBlockingRules, row.Tool == 'Result'); } else { if (row.Mandatory == '1') { blockingRules[row.Variable] = row.BlockingRule; dumpBlockingIntoNonBlockingRules(row.Variable, row.BlockingRule + '', nonBlockingRules, row.Tool == 'Result'); } else { blockingRules[row.Variable] = updateNonMandatoryRules(row.Variable, row.BlockingRule); dumpBlockingIntoNonBlockingRules(row.Variable, updateNonMandatoryRules(row.Variable, row.BlockingRule), nonBlockingRules, row.Tool == 'Result'); } if (row.Type == 'Entier') { if (row.Tool == 'TextBox') { const a = row.BlockingRule.split(';'); let b = `gen_mess_err_bloq_int_only:${row.Variable} != null AND NOT isInteger ${row.Variable}`; if (row.Mandatory == '' || row.Mandatory == undefined) { b = updateNonMandatoryRules(row.Variable, b); } a.push(b); blockingRules[row.Variable] = a.join(';'); dumpBlockingIntoNonBlockingRules(row.Variable, a.join(';') + '', nonBlockingRules, row.Tool == 'Result'); } } if (row.Mandatory) { if (row.Tool == 'TextBox' || row.Tool == 'ListBox') { let a = row.BlockingRule.split(';'); if (row.Type == 'Entier') { a = blockingRules[row.Variable].split(';'); } if (row.Mandatory == '1') { a.push(`required: ${row.Variable} = null ET isUpdatable ` + row.Variable); } else { a.push('required:(' + row.Mandatory + ') ET isUpdatable ' + row.Variable); // conditional mandatory } blockingRules[row.Variable] = a.join(';'); dumpBlockingIntoNonBlockingRules(row.Variable, a.join(';') + '', nonBlockingRules, row.Tool == 'Result'); } } } } else { if (row.Tool == 'TextBox' || row.Tool == 'ListBox') { const isEntier = row.Type == 'Entier'; if (isEntier) { const r = `gen_mess_err_bloq_int_only:${row.Variable} != null AND NOT isInteger ${row.Variable}`; blockingRules[row.Variable] = r; dumpBlockingIntoNonBlockingRules(row.Variable, r, nonBlockingRules, row.Tool == 'Result'); } 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} = null ET isUpdatable ${row.Variable}` : row.Mandatory; dumpBlockingIntoNonBlockingRules(row.Variable, blockingRules[row.Variable], nonBlockingRules, row.Tool == 'Result'); } else { const u = `required:${row.Variable} = null ET isUpdatable ${row.Variable}`; blockingRules[row.Variable] = u; dumpBlockingIntoNonBlockingRules(row.Variable, u, nonBlockingRules, row.Tool == 'Result'); } } } } if (row.hasOwnProperty('Precision') && !isNaN(safeNumberConvert(row.Precision)) && row.Variable && ['Result', 'TextBox', 'Report'].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 : `"${row.Updatable?.replace(/\\r\\n/g, " ")}"`, }); } if (['TextBox', 'ListBox', 'ListBox2'].includes(row.Tool) && row.Updatable === undefined) { updatable.push({ name: row.Variable, rule: false }); } const isExistCaseValues = casesValues.some(item => item.name == row.Variable); const isExistCasesRules = casesRules.some(item => item.name == row.Variable); const isExistLabelRules = casesValues.some(item => item.name == row.Label); // 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: null }); if (!isExistCasesRules) casesRules.push({ name: row.Variable, isVisible: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : row.hasOwnProperty('Visibility') ? row.Visibility?.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)) { let defaultValue = stringOrUndefined(row.DefaultValue); if (defaultValue) { defaultValue = normalizeOps(defaultValue); if (defaultValue.indexOf('ALORS') != -1) { defaultValue = convertOuToSiSinon(defaultValue); } } const rowBoxItems = parseToArray(normalizeOps(row.Listbox)); const resultItems = []; for (const item of rowBoxItems) { const [it, rule] = item.split(':'); const box = listBoxes.find(x => x.Name == it); if (!box) continue; const token = (0, utils_1.getTokenFullyWrapped)(box.Fr ?? ''); if (defaultValue && token && !token.endsWith('_lbl')) { if ((defaultValue + '').split(/\s+/).includes(it)) { const r = "'" + it?.replace(/-?\d+$/, '') + "' + " + token; // console.log(r + ' / ' + defaultValue + ' / ' + it); defaultValue = (defaultValue + '').replaceAll(it, r); } } if (rule) { if (token && !token.endsWith('_lbl')) { // push something like : 'aaaaaa' + AA_Bdd_BB[0]:mode=expert resultItems.push("'" + it?.replace(/-?\d+$/, '') + "' + " + token + ':' + rule); } else { resultItems.push(item); } } else { // Todo: factorize this piece if (token && !token.endsWith('_lbl')) { // push something like : 'aaaaaa' + AA_Bdd_BB[0] resultItems.push("'" + it?.replace(/-?\d+$/, '') + "' + " + token); } else { resultItems.push(item); } } } reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? (row.Visibility == 1 ? "yes" : row.Visibility) : row.Visibility ? normalizeOps(row.Visibility + '') : undefined, line: row.Line, unit: row.Unit, [row.PreLabel?.indexOf(':') > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel ? normalizeOps(row.PreLabel + '') : undefined, [row.PostLabel?.indexOf(':') > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel ? normalizeOps(row.PostLabel + '') : undefined, screen: screen, isBox: true, items: resultItems, recap: numberConvert(row.Recap), tool: 'ListBox', type2: row.Tool == 'ListBox2', tooltip: stringOrUndefined(row.Tooltip), tooltipParams: (0, utils_1.tooltipParams)(tooltips, row.Tooltip), favOrder: favOrder++, level: 5, expert: isExpertModeOnly(row.Visibility) ? true : undefined, expertUpdate: !isExpertModeOnly(row.Visibility) && isExpertModeOnly(row.Updatable) ? true : undefined, required: row.Mandatory == '1' ? true : undefined, updatable: row.Updatable == '1' ? "yes" : row.Updatable ? normalizeOps(row.Updatable) : undefined, defaultValue: defaultValue, validationParams: (0, utils_1.validationParams)(allBlockingAndnonBlocking, [row.BlockingRule, row.NonBlockingRule].filter(Boolean).join(";"), excludeFromValidationParams) }; } 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) defaultValue: null }); if (!isExistCasesRules) casesRules.push({ name: row.Variable, isVisible: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : row.Visibility?.replace(/\r\n/g, " ") }); if (!reportRules.hasOwnProperty(row.Variable)) { let defaultValue = stringOrUndefined(row.DefaultValue); if (defaultValue && defaultValue.indexOf('ALORS') != -1) { defaultValue = convertOuToSiSinon(defaultValue); } reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? (row.Visibility == 1 ? "yes" : row.Visibility) : row.Visibility ? normalizeOps(row.Visibility + '') : undefined, line: row.Line, unit: row.Unit, [row.PreLabel?.indexOf(':') > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel ? normalizeOps(row.PreLabel + '') : undefined, [row.PostLabel?.indexOf(':') > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel ? normalizeOps(row.PostLabel + '') : undefined, screen: screen, recap: numberConvert(row.Recap), tool: row.Tool, type: row.Type, tooltip: stringOrUndefined(row.Tooltip), tooltipParams: (0, utils_1.tooltipParams)(tooltips, row.Tooltip), favOrder: favOrder++, level: 5, expert: isExpertModeOnly(row.Visibility) ? true : undefined, expertUpdate: !isExpertModeOnly(row.Visibility) && isExpertModeOnly(row.Updatable) ? true : undefined, required: row.Mandatory == '1' ? true : undefined, defaultValue: defaultValue, updatable: row.Updatable == '1' ? "yes" : row.Updatable ? normalizeOps(row.Updatable + '') : undefined, validationParams: (0, utils_1.validationParams)(allBlockingAndnonBlocking, [row.BlockingRule, row.NonBlockingRule].filter(Boolean).join(";"), excludeFromValidationParams), precision: row.Precision }; } break; case 'Graph': if (!reportRules.hasOwnProperty(row.Variable)) { reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? (row.Visibility == 1 ? "yes" : row.Visibility) : row.Visibility ? normalizeOps(row.Visibility + '') : undefined, line: row.Line, unit: row.Unit, [row.PreLabel?.indexOf(':') > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel ? normalizeOps(row.PreLabel + '') : undefined, [row.PostLabel?.indexOf(':') > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel ? normalizeOps(row.PostLabel + '') : undefined, screen: screen, tool: row.Tool, tooltip: stringOrUndefined(row.Tooltip), tooltipParams: (0, utils_1.tooltipParams)(tooltips, row.Tooltip), favOrder: favOrder++, level: 5, expert: isExpertModeOnly(row.Visibility) ? true : undefined, validationParams: (0, utils_1.validationParams)(allBlockingAndnonBlocking, [row.BlockingRule, row.NonBlockingRule].filter(Boolean).join(";"), excludeFromValidationParams) }; } if (!isExistCasesRules) casesRules.push({ name: row.Variable, isVisible: !isNaN(Number(row.Visibility)) ? row.Visibility == 1 : row.hasOwnProperty('Visibility') ? row.Visibility?.replace(/\r\n/g, " ") : false }); break; case 'Report': reportRules[row.Variable] = { visibility: !isNaN(Number(row.Visibility)) ? (row.Visibility == 1 ? "yes" : row.Visibility) : row.Visibility ? normalizeOps(row.Visibility + '') : undefined, line: row.Line, unit: row.Unit, [row.PreLabel?.indexOf(':') > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel ? normalizeOps(row.PreLabel + '') : undefined, [row.PostLabel?.indexOf(':') > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel ? normalizeOps(row.PostLabel + '') : undefined, screen: screen, isReportOnly: true, recap: numberConvert(row.Recap), validationParams: (0, utils_1.validationParams)(allBlockingAndnonBlocking, [row.BlockingRule, row.NonBlockingRule].filter(Boolean).join(";"), excludeFromValidationParams), precision: row.Precision }; if (!isExistCasesRules) casesRules.push({ name: row.Variable, isVisible: false }); break; case 'H1': case 'H2': case 'H3': case 'H4': if (!isExistLabelRules && (row.BlockingRule || row.NonBlockingRule)) { casesValues.push({ name: row.Label, defaultValue: null }); } reportRules[row.Label] = { visibility: !isNaN(Number(row.Visibility)) ? (row.Visibility == 1 ? "yes" : row.Visibility) : row.Visibility ? normalizeOps(row.Visibility + '') : undefined, line: row.Line, screen: screen, [row.PreLabel?.indexOf(':') > 0 ? 'ruledPreLabel' : 'preLabel']: row.PreLabel ? normalizeOps(row.PreLabel + '') : undefined, [row.PostLabel?.indexOf(':') > 0 ? 'ruledPostLabel' : 'postLabel']: row.PostLabel ? normalizeOps(row.PostLabel + '') : undefined, header: row.Tool, recap: numberConvert(row.Recap), tooltip: stringOrUndefined(row.Tooltip), tooltipParams: (0, utils_1.tooltipParams)(tooltips, row.Tooltip), level: getDigitFromString(row.Tool), expert: isExpertModeOnly(row.Visibility) ? true : undefined, favOrder: favOrder++, validationParams: (0, utils_1.validationParams)(allBlockingAndnonBlocking, [row.BlockingRule, row.NonBlockingRule].filter(Boolean).join(";"), excludeFromValidationParams) }; break; } } catch (e) { console.error(e.message + ' (see line) ' + row.Line + ' Label ' + row.Label + ' Variable ' + row.Variable); throw e; } }); } // controller const controllerTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/controller'), [ (0, schematics_1.applyTemplates)({ name: options.name, pageindex: options.pageindex, pagenames: options.pagenames, 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)}`)) ]); // constants 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: nonBlockingRules, stringifyAlertLevel, 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)}`)) ]); const chainArray = [ (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) ]; if (options.pageindex == 0) { // create these files once chainArray.push((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)); } return (0, schematics_1.chain)(chainArray); /*return chain([ mergeWith(parameterTemplateSource, MergeStrategy.Overwrite), mergeWith(parameterDtoTemplateSource, MergeStrategy.Overwrite), mergeWith(resultDtoTemplateSource, MergeStrategy.Overwrite), mergeWith(bddTemplateSource, MergeStrategy.Overwrite), mergeWith(exportTemplateSource, MergeStrategy.Overwrite), mergeWith(controllerTemplateSource, MergeStrategy.Overwrite), mergeWith(configTemplateSource, MergeStrategy.Overwrite) ]);*/ }; } exports.ndcNetModule = ndcNetModule; function toLower(s) { return s.toLowerCase(); } function parseToArray(input) { return input .replace(/[{}]/g, "") .split(";") .map(item => item.trim()) .filter(Boolean); } function convertOuToSiSinon(input) { const trimmed = input.trim(); // Already starts with SI → leave as-is if (/^SI\s+/i.test(trimmed)) { return trimmed; } // Split top-level branches on ") OU (" (only if parentheses exist) if (trimmed.includes(") OU (")) { const parts = trimmed.split(/\)\s*OU\s*\(/i).map(p => p.trim()); return parts .map((part, index) => { const cleaned = part.replace(/^\(+|\)+$/g, "").trim(); return index === 0 ? `SI ${cleaned}` : `SINON SI ${cleaned}`; }) .join(" "); } // No top-level ") OU (", just a simple condition → prepend SI if (!/^SI\s+/i.test(trimmed)) { return `SI ${trimmed}`; } return trimmed; // fallback } // @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?.trim()); return stringArray; } // @ts-ignore 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?.split(';'); // Prepend "key != null ET" after the field name in each condition const transformedConditions = 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} != null ET (${conditionBody})`; }); return transformedConditions.join('; '); } function explodeObject(original, result = {}, removeAlert = false, modifiedKeys = {}) { const message = {}; for (const key in original) { const value = original[key]; const parts = 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 = 'hasResults ET (' + rule + ')'; } message[key][messageKey.trim()] = rule; } }); } (0, utils_1.deduplicateNestedKeys)(message, modifiedKeys); 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(String(str).trim()); } function parseAlertsByLevel(input, _isResult = false) { const result = {}; const entries = input .split(";") .map(e => e.trim()) .filter(Boolean); for (const entry of entries) { const match = entry.match(/^([^:]+):\s*alerte\s*=\s*(\d+)\s+ET\s+(.+)$/i); if (!match) continue; const [, msg, levelStr, expr] = match; const level = Number(levelStr); if (!result[level]) { result[level] = []; } result[level].push({ msg: msg.trim(), // expr: isResult ? 'hasResults ET (' + expr.trim() + ')' : expr.trim(), expr: expr.trim(), }); } // Ensure descending alert level order return Object.fromEntries(Object.keys(result) .map(Number) .sort((a, b) => b - a) .map(level => [level, result[level]])); } function stringifyAlertLevel(levelObj) { return Object.entries(levelObj) .map(([level, rules]) => { const inlineRules = rules .map(r => `{ "msg": "${r.msg}", "expr": "${r.expr}" }`) .join(", "); return `"${level}": [ ${inlineRules} ]`; }) .join(",\n "); } /*function removeAllAlertes(input: string): string { return input.replace(/alerte\s*=\s*\d+\s*ET\s*!/gi, ""); }*/ function dumpBlockingIntoNonBlockingRules(variable, blockingRule, nonBlockingRules, isResult = false) { // dump blocking into nonBlocking with level 4: nonBlockingRules[variable] ??= {}; const rules = blockingRule.replace(/:\s*/g, ":alerte = 4 ET "); // add alerte = 4 to make them blocking in ndc const parsed = parseAlertsByLevel(rules, isResult); nonBlockingRules[variable]['4'] = parsed['4']; } // remove or add space around operators and replace VIDE by null function normalizeOps(str) { const OPS = ['<=', '>=', '!=', '=', '<', '>']; const re = new RegExp(`(${OPS.map(op => op.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})`, 'g'); return str.replace(re, ' $1 ') .replace(/\s+/g, ' ') // space .replace(/\r\n/g, " ") // retour chariot et saut .trim() .replaceAll('VIDE', 'null'); } //# sourceMappingURL=index.js.map