From c616fa54bfe44235307ddac000d19b419742dbca Mon Sep 17 00:00:00 2001 From: Clement Auger Date: Thu, 30 Jul 2015 10:45:25 +0800 Subject: [PATCH 1/7] Add a webserver to start the trainer in a glance. Add POST action to trainer app to save results as a file. Added jquery dependency to make POST request. Updated gitignore ot ignore the results.json file. --- .gitignore | 3 +- README.md | 3 + express.js | 24 + package.json | 5 +- trainer/index.html | 9 + trainer/jquery.js | 9210 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 9252 insertions(+), 2 deletions(-) create mode 100644 express.js create mode 100644 trainer/jquery.js diff --git a/.gitignore b/.gitignore index 4220ff7..c369af1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ _site node_modules .DS_Store -.idea \ No newline at end of file +.idea +results.json \ No newline at end of file diff --git a/README.md b/README.md index 855652c..118bd0e 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ A gesture training application is available online at [http://uwdata.github.io/g The application is intended to work with both mouse and touch input. The code for the training application is included in this repository under the `trainer` folder. Simply open the `index.html` file in a browser to run locally. +You can use provided `express.js` node script to spawn a webserver that starts the trainer and give you access to a POST method which records the results into a `results.json` file at root of this repo. +This is useful if you intend to produce tablet / mobile gesture. + ## Build Process We use the [gulp](http://gulpjs.com/) build system along with [browserify](http://browserify.org/) to build gestrec.min.js. diff --git a/express.js b/express.js new file mode 100644 index 0000000..27870c9 --- /dev/null +++ b/express.js @@ -0,0 +1,24 @@ +/** + * Created by d1m on 7/28/2015. + */ + +var express = require('express') +var bodyParser = require('body-parser') +var morgan = require('morgan') +var app = express() + +app.use(morgan()) + +var urlencodedParser = bodyParser.urlencoded({ extended: false }) +app.get('/gestrec.min.js', urlencodedParser, function (req, res) { + require('fs').createReadStream('gestrec.min.js').pipe(res) +}) + +app.post('/data', urlencodedParser, function (req, res) { + require('fs').writeFileSync('results.json', JSON.stringify(JSON.parse(req.body.train), null, 2)) + res.send(200) +}) + +app.use(express.static('trainer')); + +app.listen(8080); diff --git a/package.json b/package.json index 2677354..48f7550 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,10 @@ "gulp-rename": "^1.2.2", "gulp-uglify": "^1.2.0", "vinyl-buffer": "^1.0.0", - "vinyl-source-stream": "^1.1.0" + "vinyl-source-stream": "^1.1.0", + "body-parser": "^1.13.2", + "express": "^4.13.1", + "morgan": "^1.6.1" }, "main": "src/index.js" } diff --git a/trainer/index.html b/trainer/index.html index 0660155..bcfef50 100644 --- a/trainer/index.html +++ b/trainer/index.html @@ -4,6 +4,7 @@ Gesture Designer +