Skip to content

Commit

Permalink
Export of requirements to json and simple MD table format
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannSchumann authored and andreaskatis committed Apr 29, 2022
1 parent 7434100 commit c623421
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions fret-electron/app/components/ExportRequirementsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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(
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -134,7 +165,8 @@ class ExportRequirementsDialog extends React.Component {
open: props.open,
projects: props.fretProjects,
dialogCloseListener : props.handleDialogClose,
project: ''
project: '',
output_format: 'json'
})
}

Expand Down Expand Up @@ -182,6 +214,28 @@ class ExportRequirementsDialog extends React.Component {
</MenuItem>
))}
</TextField>
<TextField
id="standard-select-format"
select
label="Select output format"
className={classes.textField}
value={this.state.output_format}
onChange={this.handleChange('output_format')}
SelectProps={{
MenuProps: {
className: classes.menu,
},
}}
// helperText="Please select a project"
margin="normal"
>
<MenuItem key={"JSON"} value={"json"}>
JSON
</MenuItem>
<MenuItem key={"MD"} value={"md"}>
Markdown (MD)
</MenuItem>
</TextField>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color="primary">
Expand Down

0 comments on commit c623421

Please sign in to comment.