diff --git a/controllers/prototype/index.js b/controllers/prototype/index.js index cf45b68..0d4e221 100644 --- a/controllers/prototype/index.js +++ b/controllers/prototype/index.js @@ -168,6 +168,27 @@ var addPreviousNextFromId = function(client, req, res, callback, id) { ); } +var addHoveredFromId = function(client, req, res, callback, id) { + client.query( + "SELECT start, time, arrow_id FROM hovered WHERE id = $1", + [id], + function(err, result) { + res.locals.path = res.locals.path || []; + for (var i in result.rows) { + res.locals.path.push( + { + type: "hovered", + time: result.rows[i].time, + start: result.rows[i].start, + id: result.rows[i].arrow_id + } + ); + } + callback(); + } + ); +} + var getAllUsers = function(req, res, callback) { pg.connect(pgc.url, function(err, client, release) { client.query( @@ -238,15 +259,17 @@ module.exports.replay_info = function(req, res) { addArrowsFromId(client, req, res, function() { addResetsFromId(client, req, res, function() { addPreviousNextFromId(client, req, res, function() { - res.locals.path.sort(function(elt1, elt2) { - // Dates as string can be compared - if (elt1.time < elt2.time) - return -1; - if (elt1.time > elt2.time) - return 1; - return 0; - }); - res.send(JSON.stringify(res.locals.path)); + addHoveredFromId(client, req, res, function() { + res.locals.path.sort(function(elt1, elt2) { + // Dates as string can be compared + if (elt1.time < elt2.time) + return -1; + if (elt1.time > elt2.time) + return 1; + return 0; + }); + res.send(JSON.stringify(res.locals.path)); + }, id); }, id); }, id); }, id); diff --git a/posts/hovered/index.js b/posts/hovered/index.js new file mode 100644 index 0000000..00e633f --- /dev/null +++ b/posts/hovered/index.js @@ -0,0 +1,27 @@ +var pg = require('pg'); +var secret = require('../../private'); + +module.exports.index = function(req, res) { + + var user_id = req.session.user_id; + + pg.connect(secret.url, function(err, client, release) { + client.query( + "INSERT INTO hovered(user_id, time, start, arrow_id)" + + "VALUES($1, to_timestamp($2), $3, $4);" , + [ + user_id, + req.body.time, + req.body.start ? true : false, + req.body.arrow_id + ], + function(err, result) { + release(); + } + ); + }); + + res.setHeader('Content-Type', 'text/html'); + res.send("user_id = " + user_id); + +} diff --git a/posts/hovered/urls.js b/posts/hovered/urls.js new file mode 100644 index 0000000..378b256 --- /dev/null +++ b/posts/hovered/urls.js @@ -0,0 +1,3 @@ +module.exports = { + '/hovered': 'index' +} diff --git a/sql/backup.pgsql b/sql/backup.pgsql index 6707b69..0d376e5 100644 --- a/sql/backup.pgsql +++ b/sql/backup.pgsql @@ -4,6 +4,7 @@ DROP TABLE IF EXISTS coinclicked CASCADE; DROP TABLE IF EXISTS keyboardevent CASCADE; DROP TABLE IF EXISTS resetclicked CASCADE; DROP TABLE IF EXISTS previousnextclicked CASCADE; +DROP TABLE IF EXISTS hovered CASCADE; DROP TYPE IF EXISTS VECTOR3 CASCADE; DROP TYPE IF EXISTS CAMERA CASCADE; @@ -63,3 +64,11 @@ CREATE TABLE previousnextclicked( time TIMESTAMP DEFAULT NOW(), camera CAMERA ); + +CREATE TABLE hovered( + id SERIAL PRIMARY KEY, + user_id SERIAL REFERENCES users (id), + start BOOLEAN NOT NULL, + time TIMESTAMP DEFAULT NOW(), + arrow_id INT +); diff --git a/static/js/Logger.js b/static/js/Logger.js index b54c46d..7f847db 100644 --- a/static/js/Logger.js +++ b/static/js/Logger.js @@ -77,3 +77,14 @@ BD.Event.PreviousNextClicked.prototype.send = function() { BD.Private.sendData(url, data); } + +BD.Event.Hovered = function() {}; +BD.Event.Hovered.prototype.send = function() { + var url = "/hovered"; + var data = { + start: this.start, + arrow_id: this.arrow_id + }; + + BD.Private.sendData(url, data); +} diff --git a/static/js/prototype/raycasterTools.js b/static/js/prototype/raycasterTools.js index 38e75fd..3ffcc9d 100644 --- a/static/js/prototype/raycasterTools.js +++ b/static/js/prototype/raycasterTools.js @@ -66,12 +66,25 @@ CameraSelecter.prototype.update = function(event) { if (hovered !== undefined && !(hovered instanceof Coin)) { if (hovered !== previousCamera) { + // log it + var event = new BD.Event.Hovered(); + event.start = true; + event.arrow_id = cameras.cameras.indexOf(this.currentPointedCamera); + event.send(); + this.prev.x = this.mouse.x; this.prev.y = this.mouse.y; } this.prev.camera = hovered; this.prev.go = true; } else { + if (this.prev.go) { + // Log if previous was not null + var event = new BD.Event.Hovered(); + event.start = false; + event.arrow_id = null; + event.send(); + } this.prev.go = false; } }