Added DB support

This commit is contained in:
Thomas FORGIONE 2015-05-18 15:33:14 +02:00
parent 1101c74132
commit 0d5406cfa4
5 changed files with 42 additions and 2 deletions

View File

@ -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'

View File

@ -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",

View File

@ -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) {

View File

@ -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
);

View File

@ -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) {