Added DB support
This commit is contained in:
parent
1101c74132
commit
0d5406cfa4
|
@ -13,6 +13,7 @@ block extrajs
|
||||||
script(src="/static/js/prototype/Previewer.js")
|
script(src="/static/js/prototype/Previewer.js")
|
||||||
script(src="/static/js/prototype/ButtonManager.js")
|
script(src="/static/js/prototype/ButtonManager.js")
|
||||||
script(src="/static/js/prototype/Coin.js")
|
script(src="/static/js/prototype/Coin.js")
|
||||||
|
script(src="/static/js/Logger.js")
|
||||||
if cameraStyle == 'arrows'
|
if cameraStyle == 'arrows'
|
||||||
script RecommendedCamera = FixedCamera;
|
script RecommendedCamera = FixedCamera;
|
||||||
else if cameraStyle == 'viewports'
|
else if cameraStyle == 'viewports'
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "4.0",
|
"express": "4.0",
|
||||||
"jade": "1.9.2",
|
"jade": "1.9.2",
|
||||||
"pg": "4.3.0"
|
"pg": "4.3.0",
|
||||||
|
"body-parser": "1.12.4"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
21
server.js
21
server.js
|
@ -7,10 +7,17 @@ var pg = require('pg');
|
||||||
var pgc = require('./private');
|
var pgc = require('./private');
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
var bodyParser = require('body-parser')
|
||||||
var urls = require('./urls');
|
var urls = require('./urls');
|
||||||
|
|
||||||
|
|
||||||
app.set('view engine', 'jade');
|
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) {
|
app.use(function(req, res, next) {
|
||||||
res.locals.title = "3DUI";
|
res.locals.title = "3DUI";
|
||||||
res.locals.urls = urls;
|
res.locals.urls = urls;
|
||||||
|
@ -22,6 +29,20 @@ require('./lib/boot')(app, { verbose: !module.parent });
|
||||||
|
|
||||||
app.use('/static', express.static('static'));
|
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
|
// When error raised
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function(err, req, res, next) {
|
||||||
if (err.status === 404) {
|
if (err.status === 404) {
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
DROP TABLE IF EXISTS users;
|
DROP TABLE IF EXISTS users CASCADE;
|
||||||
|
DROP TABLE IF EXISTS arrowclicked CASCADE;
|
||||||
|
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
name char(50)
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,11 @@ CameraSelecter.prototype.update = function(event) {
|
||||||
CameraSelecter.prototype.click = function(event) {
|
CameraSelecter.prototype.click = function(event) {
|
||||||
var newCamera = this.pointedCamera(event);
|
var newCamera = this.pointedCamera(event);
|
||||||
if (newCamera !== undefined && !(newCamera instanceof Coin)) {
|
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);
|
this.cameras.mainCamera().moveHermite(newCamera);
|
||||||
buttonManager.updateElements();
|
buttonManager.updateElements();
|
||||||
} else if (newCamera instanceof Coin) {
|
} else if (newCamera instanceof Coin) {
|
||||||
|
|
Loading…
Reference in New Issue