diff --git a/app.js b/app.js index e04f5ea682ee47ebaea148f08ad1484281ff1e5e..3b92e43ccf09eee04cbc7b65b85fd726c058501b 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,6 @@ var express = require('express'); var bodyParser = require('body-parser'); +var cookieParser = require('cookie-parser'); var exec = require('child_process').exec; @@ -21,28 +22,38 @@ app.use(bodyParser.urlencoded({ })); app.use(bodyParser.json()); app.use(logger("short")); +app.use(cookieParser()); + //set handlebars as view engine app.engine('.hbs', exphbs({extname: '.hbs'})); app.set('view engine', '.hbs'); +//routes app.get('/', function(req, res){ res.render('home', {downloadFiles: downloadNames}); }); -app.post('/waiting', function(req, res){ -console.log("frontend in /waiting", req.body['explorviz-ui-backend']); +app.post('/', function(req, res, next){ var checkedFiles = Object.keys(req.body); -console.log("checkedFiles", checkedFiles); - res.render('download', {test: checkedFiles}); + +if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ + console.log('files were checked'); + //set cookie to pass checked files for download + res.cookie('fileCookie', checkedFiles).render('download'); +} + else { + console.log('files were not checked'); + res.render('home', {downloadFiles: downloadNames}); + } }); app.get('/download', function(req, res){ -console.log("frontend in /download", req.body); +console.log("checkedFiles in /download", req.cookies.fileCookie); // if (typeof req.body.backend !== 'undefined'){ console.log("inside backend branch"); exec('cd /home/jweg/git/explorviz-ui-backend && mvn compile war:war', (error, stdout, stderr) => { diff --git a/package.json b/package.json index 28ca170e86dcf648e0f80c3a5b1630718e89ace6..91673648e251fb82417059931724f1d3afc41efc 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "adm-zip": "^0.4.7", "body-parser": "^1.17.1", "child_process": "^1.0.2", + "cookie-parser": "^1.4.3", "express": "^4.15.2", "express-handlebars": "^3.0.0", "fs": "0.0.1-security", diff --git a/views/home.hbs b/views/home.hbs index 5ec61303d44e050aff47c86510d1b04d47841bfb..c795eef4d5ad843471dc69e0c2c0cbcda8ad7a50 100644 --- a/views/home.hbs +++ b/views/home.hbs @@ -1,9 +1,8 @@ -<form action="/waiting" method="post"> +<form action="/" method="post"> Choose which files to compile into your custom build of ExplorViz:<br> {{#each downloadFiles as |item|}} <input type="checkbox" name={{item}} value={{item}}>{{item}}<br> {{/each}} <br> - <a > - <button type="submit">Create Build and Download Zip</a> + <button type="submit">Create Build and Download Zip</button> </form> \ No newline at end of file