Added hovered events
This commit is contained in:
parent
2a5ae4d985
commit
8e592c87b5
|
@ -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) {
|
var getAllUsers = function(req, res, callback) {
|
||||||
pg.connect(pgc.url, function(err, client, release) {
|
pg.connect(pgc.url, function(err, client, release) {
|
||||||
client.query(
|
client.query(
|
||||||
|
@ -238,15 +259,17 @@ module.exports.replay_info = function(req, res) {
|
||||||
addArrowsFromId(client, req, res, function() {
|
addArrowsFromId(client, req, res, function() {
|
||||||
addResetsFromId(client, req, res, function() {
|
addResetsFromId(client, req, res, function() {
|
||||||
addPreviousNextFromId(client, req, res, function() {
|
addPreviousNextFromId(client, req, res, function() {
|
||||||
res.locals.path.sort(function(elt1, elt2) {
|
addHoveredFromId(client, req, res, function() {
|
||||||
// Dates as string can be compared
|
res.locals.path.sort(function(elt1, elt2) {
|
||||||
if (elt1.time < elt2.time)
|
// Dates as string can be compared
|
||||||
return -1;
|
if (elt1.time < elt2.time)
|
||||||
if (elt1.time > elt2.time)
|
return -1;
|
||||||
return 1;
|
if (elt1.time > elt2.time)
|
||||||
return 0;
|
return 1;
|
||||||
});
|
return 0;
|
||||||
res.send(JSON.stringify(res.locals.path));
|
});
|
||||||
|
res.send(JSON.stringify(res.locals.path));
|
||||||
|
}, id);
|
||||||
}, id);
|
}, id);
|
||||||
}, id);
|
}, id);
|
||||||
}, id);
|
}, id);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
'/hovered': 'index'
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ DROP TABLE IF EXISTS coinclicked CASCADE;
|
||||||
DROP TABLE IF EXISTS keyboardevent CASCADE;
|
DROP TABLE IF EXISTS keyboardevent CASCADE;
|
||||||
DROP TABLE IF EXISTS resetclicked CASCADE;
|
DROP TABLE IF EXISTS resetclicked CASCADE;
|
||||||
DROP TABLE IF EXISTS previousnextclicked CASCADE;
|
DROP TABLE IF EXISTS previousnextclicked CASCADE;
|
||||||
|
DROP TABLE IF EXISTS hovered CASCADE;
|
||||||
|
|
||||||
DROP TYPE IF EXISTS VECTOR3 CASCADE;
|
DROP TYPE IF EXISTS VECTOR3 CASCADE;
|
||||||
DROP TYPE IF EXISTS CAMERA CASCADE;
|
DROP TYPE IF EXISTS CAMERA CASCADE;
|
||||||
|
@ -63,3 +64,11 @@ CREATE TABLE previousnextclicked(
|
||||||
time TIMESTAMP DEFAULT NOW(),
|
time TIMESTAMP DEFAULT NOW(),
|
||||||
camera CAMERA
|
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
|
||||||
|
);
|
||||||
|
|
|
@ -77,3 +77,14 @@ BD.Event.PreviousNextClicked.prototype.send = function() {
|
||||||
|
|
||||||
BD.Private.sendData(url, data);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -66,12 +66,25 @@ CameraSelecter.prototype.update = function(event) {
|
||||||
|
|
||||||
if (hovered !== undefined && !(hovered instanceof Coin)) {
|
if (hovered !== undefined && !(hovered instanceof Coin)) {
|
||||||
if (hovered !== previousCamera) {
|
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.x = this.mouse.x;
|
||||||
this.prev.y = this.mouse.y;
|
this.prev.y = this.mouse.y;
|
||||||
}
|
}
|
||||||
this.prev.camera = hovered;
|
this.prev.camera = hovered;
|
||||||
this.prev.go = true;
|
this.prev.go = true;
|
||||||
} else {
|
} 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;
|
this.prev.go = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue