Skip to content

Commit

Permalink
store bindings information in ERC.yaml o2r-project#224
Browse files Browse the repository at this point in the history
  • Loading branch information
njakuschona committed Jun 15, 2021
1 parent 0d86fd3 commit 52f1672
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ui/bindings/controllers/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ bindings.start = (conf) => {
bindings.createBinding(req.body, res);
});



app.get('/api/v1/compendium/:compendium/binding/:binding', function(req, res) {
let compendium = req.params.compendium;
let binding = req.params.binding;
Expand Down Expand Up @@ -178,6 +180,7 @@ bindings.createBinding = function(binding, response) {
bindingCode = fn.replaceVariable( bindingCode, binding.sourcecode.parameter );
let wrappedBindingCode = fn.wrapCode( bindingCode, binding.computationalResult.result, binding.sourcecode.parameter, figureSize );
fn.saveResult( wrappedBindingCode, binding.id, binding.computationalResult.result.replace(/\s/g, '').toLowerCase() );
fn.accessYaml(binding.id, binding)
binding.codesnippet = binding.computationalResult.result.replace(/\s/g, '').toLowerCase() + '.R';
response.send({
callback: 'ok',
Expand Down
24 changes: 24 additions & 0 deletions ui/bindings/controllers/generalFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const fs = require('fs');
const debug = require('debug')('bindings');
const path = require('path');
const exec = require('child_process').exec;
const yaml = require('yaml')

let fn = {};

Expand Down Expand Up @@ -280,6 +281,29 @@ fn.array2Json = function (array) {
return jsonObject;
};

fn.accessYaml= function(compendiumId, binding ){
debug('Start reading YAML from the compendium %s', compendiumId);
if ( !compendiumId ) {
throw new Error('File does not exist.');
}
let paper = path.join(config.fs.compendium, compendiumId, "erc.yml");
console.log(paper)
if(fs.existsSync(paper)) {
debug('Start reading YMAL from %s', paper);
let file =fs.readFileSync(paper, 'utf8');
let yamlFile = yaml.parse(file);
let element = {interactive: true, bindings:binding}
yamlFile.ui_bindings = element
file = yaml.stringify(yamlFile)
fs.writeFileSync(paper, file)
} else {
debug('Cannot open file %s', paper);
response.status(401).send({
callback: 'fileNotFound',});
};

}



module.exports = fn;
5 changes: 5 additions & 0 deletions ui/bindings/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ui/bindings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"net": "^1.0.2",
"node-cron": "^2.0.3",
"r-script": "git+https://github.com/MarkusKonk/r-script.git",
"request": "^2.88.0"
"request": "^2.88.0",
"yaml": "^1.10.2"
},
"devDependencies": {
"eslint": "^4.16.0",
Expand Down
2 changes: 1 addition & 1 deletion ui/bindings/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "bindingsTests.js",
"scripts": {
"test": "echo \"Error: no test was specified\" && exit 1"
"test": "mocha"
},
"author": "",
"license": "ISC",
Expand Down

0 comments on commit 52f1672

Please sign in to comment.