diff --git a/app.js b/app.js index 67a5a73df1d9fdfb41c6f985ce2c4bf7e5d04a30..e04f5ea682ee47ebaea148f08ad1484281ff1e5e 100644 --- a/app.js +++ b/app.js @@ -7,9 +7,12 @@ var fs = require('fs'); var path = require('path'); var Zip = require('node-zip'); +var exphbs = require('express-handlebars'); +var logger = require('morgan'); - - +//load names of available download files +var downloadFiles = require('./downloadFiles.json'); +var downloadNames = Object.keys(downloadFiles); var app = express(); @@ -17,53 +20,32 @@ app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); +app.use(logger("short")); +//set handlebars as view engine +app.engine('.hbs', exphbs({extname: '.hbs'})); +app.set('view engine', '.hbs'); app.get('/', function(req, res){ - - var html = '<form action="/" method="post">' + - 'Choose your builds:<br>' + - '<input type="checkbox" name="frontend" value="frontend">Frontend<br>' + - '<input type="checkbox" name="backend" value="backend">Backend<br>' + - '<br>' + - '<button type="submit">Create Build & Download Zip</button>' + - '</form>'; - - res.send(html); - +res.render('home', {downloadFiles: downloadNames}); }); - -var test; - -app.post('/', function(req, res){ - - console.log(req.body); - - test = req.body.frontend; - var html = - 'Your download is being prepared. This may take a moment. ' + - 'Do not close the window.' + - '<script> location.href="/download" </script>'; - - // discouraged by WC3 - //'<meta http-equiv="refresh" content="1; url=/download" />'; - - res.send(html); +app.post('/waiting', function(req, res){ +console.log("frontend in /waiting", req.body['explorviz-ui-backend']); +var checkedFiles = Object.keys(req.body); +console.log("checkedFiles", checkedFiles); + res.render('download', {test: checkedFiles}); }); - - - app.get('/download', function(req, res){ - - console.log(test); - - exec('cd /home/akr/eclipse-workspace/explorviz-ui-backend && mvn compile war:war', (error, stdout, stderr) => { +console.log("frontend in /download", req.body); + // 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) => { var response = 'There was an error during your build. ' + @@ -85,7 +67,7 @@ app.get('/download', function(req, res){ zip.file('README.txt', fs.readFileSync(path.join(__dirname, 'README.txt'))); zip.file('explorviz-backend.war', - fs.readFileSync('/home/akr/eclipse-workspace/explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war')); + fs.readFileSync('/home/jweg/git/explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war')); var options = {base64: false, compression:'DEFLATE'}; @@ -108,7 +90,16 @@ app.get('/download', function(req, res){ }); }); +// } +// else if (typeof req.body.frontend !== 'undefined'){ +// console.log("inside frontend branch"); +// res.send(req.body.frontend); +// } else { +// console.log("inside else branch"); +// res.send("nix ausgewählt"); +// } }); -app.listen(8080); \ No newline at end of file +app.listen(8080); +console.log("Downloader started on port 8080."); \ No newline at end of file diff --git a/downloadFiles.json b/downloadFiles.json new file mode 100644 index 0000000000000000000000000000000000000000..0de3dca589db046db4e36433727aef7498d94460 --- /dev/null +++ b/downloadFiles.json @@ -0,0 +1,5 @@ +{ "explorviz-ui-frontend": "https://github.com/ExplorViz/explorviz-ui-frontend.git", + "explorviz-ui-backend": "https://github.com/ExplorViz/explorviz-ui-backend.git", + "explorviz-frontend-plugin-example": "https://github.com/ExplorViz/explorviz-frontend-plugin-example.git", + "explorviz-backend-plugin-example": "https://github.com/ExplorViz/explorviz-backend-plugin-example.git" +} \ No newline at end of file diff --git a/package.json b/package.json index 68c9667348f5f2a5bee097618d2132ba44f2a9e7..28ca170e86dcf648e0f80c3a5b1630718e89ace6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,9 @@ "body-parser": "^1.17.1", "child_process": "^1.0.2", "express": "^4.15.2", + "express-handlebars": "^3.0.0", "fs": "0.0.1-security", + "morgan": "^1.8.2", "node-zip": "^1.1.1", "path": "^0.12.7" } diff --git a/views/download.hbs b/views/download.hbs new file mode 100644 index 0000000000000000000000000000000000000000..d84a31569fc9b188420889f3a9f2ac95e54ee432 --- /dev/null +++ b/views/download.hbs @@ -0,0 +1,2 @@ +<div class="container">Your download is being prepared. This may take a moment. Do not close the window.</div> +<script> location.href="/download" </script> diff --git a/views/home.hbs b/views/home.hbs new file mode 100644 index 0000000000000000000000000000000000000000..5ec61303d44e050aff47c86510d1b04d47841bfb --- /dev/null +++ b/views/home.hbs @@ -0,0 +1,9 @@ +<form action="/waiting" 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> + </form> \ No newline at end of file