diff --git a/controllers/prototype/views/prototype.jade b/controllers/prototype/views/prototype.jade index 5f22af7..171ec0c 100644 --- a/controllers/prototype/views/prototype.jade +++ b/controllers/prototype/views/prototype.jade @@ -13,6 +13,7 @@ block extrajs script(src="/static/js/prototype/Previewer.js") script(src="/static/js/prototype/ButtonManager.js") script(src="/static/js/prototype/Coin.js") + script(src="/static/js/Logger.js") if cameraStyle == 'arrows' script RecommendedCamera = FixedCamera; else if cameraStyle == 'viewports' diff --git a/package.json b/package.json index fe876cf..a51f9b6 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "dependencies": { "express": "4.0", "jade": "1.9.2", - "pg": "4.3.0" + "pg": "4.3.0", + "body-parser": "1.12.4" }, "repository": { "type": "git", diff --git a/server.js b/server.js index cbfa750..eb00aa2 100644 --- a/server.js +++ b/server.js @@ -7,10 +7,17 @@ var pg = require('pg'); var pgc = require('./private'); var app = express(); +var bodyParser = require('body-parser') var urls = require('./urls'); + app.set('view engine', 'jade'); +app.use(bodyParser.text()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(bodyParser.json()); +// app.use(bodyParser.text({ type: 'text/html' })) + app.use(function(req, res, next) { res.locals.title = "3DUI"; res.locals.urls = urls; @@ -22,6 +29,20 @@ require('./lib/boot')(app, { verbose: !module.parent }); app.use('/static', express.static('static')); +app.post('/post', function(req, res) { + var user_id = req.body.user_id; + var arrow_id = req.body.arrow_id; + + pg.connect(pgc.url, function(err, client, done) { + client.query("INSERT INTO arrowclicked(user_id, arrow_id) VALUES($1,$2);", [user_id, arrow_id], function(err, result) { + console.log(err); + }); + }); + + res.setHeader('Content-Type', 'text/html'); + res.send("Hello"); +}); + // When error raised app.use(function(err, req, res, next) { if (err.status === 404) { diff --git a/sql/backup.pgsql b/sql/backup.pgsql index 3f59a8e..89c17b6 100644 --- a/sql/backup.pgsql +++ b/sql/backup.pgsql @@ -1,6 +1,18 @@ -DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS arrowclicked CASCADE; CREATE TABLE users ( id SERIAL PRIMARY KEY, name char(50) ); + +-- Create dummy user +INSERT INTO users(name) VALUES('Thomas'); + +CREATE TABLE arrowclicked( + id SERIAL PRIMARY KEY, + user_id SERIAL REFERENCES users (id), + time TIMESTAMP DEFAULT NOW(), + arrow_id INTEGER +); + diff --git a/static/js/prototype/raycasterTools.js b/static/js/prototype/raycasterTools.js index 0984eb6..dbff63a 100644 --- a/static/js/prototype/raycasterTools.js +++ b/static/js/prototype/raycasterTools.js @@ -75,6 +75,11 @@ CameraSelecter.prototype.update = function(event) { CameraSelecter.prototype.click = function(event) { var newCamera = this.pointedCamera(event); if (newCamera !== undefined && !(newCamera instanceof Coin)) { + var event = new BD.Event.ArrowClicked(); + event.arrow_id = cameras.cameras.indexOf(newCamera); + event.user_id = 1; + event.send(); + this.cameras.mainCamera().moveHermite(newCamera); buttonManager.updateElements(); } else if (newCamera instanceof Coin) {