From c6234212f50209d38a877edcae6f4bba72fdbab7 Mon Sep 17 00:00:00 2001 From: Johann Schumann Date: Wed, 6 Oct 2021 05:10:58 -0700 Subject: [PATCH] Export of requirements to json and simple MD table format --- .../components/ExportRequirementsDialog.js | 62 +++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/fret-electron/app/components/ExportRequirementsDialog.js b/fret-electron/app/components/ExportRequirementsDialog.js index 9d48ff7d..6a548e3a 100644 --- a/fret-electron/app/components/ExportRequirementsDialog.js +++ b/fret-electron/app/components/ExportRequirementsDialog.js @@ -75,6 +75,23 @@ class ExportRequirementsDialog extends React.Component { projects:[] }; + export_to_md = (R, P) => { + var s="# Requirements for Project `"+ P + "`\n"; + + s = s + "|ID|P-ID| Text | Rationale |" + "\n"; + s = s + "|---|---|---|---|" + "\n"; +// ({reqid, parent_reqid, project, rationale, comments, fulltext, semantics, input}))(r.doc) + + R.forEach((r) => { + s=s + "| " + r.reqid + + " | " + r.parent_reqid + + " | " + r.fulltext.replace(/\|/g,",").replace(/\n/g," ") + + " | " + r.rationale.replace(/\|/g,",").replace(/\n/g," "); + s=s + "\n"; + }) + + return s; + } handleClose = () => { this.setState({ open: false }); @@ -89,7 +106,7 @@ class ExportRequirementsDialog extends React.Component { }; handleExport = () => { - const {project} = this.state; + const {project, output_format} = this.state; const filterOff = project == "All Projects"; var homeDir = app.getPath('home'); var filepath = dialog.showSaveDialogSync( @@ -98,7 +115,7 @@ class ExportRequirementsDialog extends React.Component { title : 'Export Requirements', buttonLabel : 'Export', filters: [ - { name: "Documents", extensions: ['json'] } + { name: "Documents", extensions: [ output_format ] } ], }) if (filepath) { @@ -115,7 +132,21 @@ class ExportRequirementsDialog extends React.Component { doc._id = uuidv1() filteredResult.push(doc) }) - var content = JSON.stringify(filteredResult, null, 4) + // + // produce output + // + var content; + console.log(output_format) + if (output_format === "md"){ + console.log("MD") + content=this.export_to_md(filteredResult, project) + } + else { + console.log("JSON") + content = JSON.stringify(filteredResult, null, 4) + } + console.log(content) + fs.writeFile(filepath, content, (err) => { if(err) { return console.log(err); @@ -134,7 +165,8 @@ class ExportRequirementsDialog extends React.Component { open: props.open, projects: props.fretProjects, dialogCloseListener : props.handleDialogClose, - project: '' + project: '', + output_format: 'json' }) } @@ -182,6 +214,28 @@ class ExportRequirementsDialog extends React.Component { ))} + + + JSON + + + Markdown (MD) + +