Big commit

This commit is contained in:
Thomas FORGIONE
2015-07-29 11:04:38 +02:00
parent a914ed2a2d
commit c690accd4b
22 changed files with 238 additions and 12 deletions

View File

@@ -506,10 +506,11 @@ DBReq.UserCreator.prototype.finish = function() {
* @memberof DBReq
* @constructor
*/
DBReq.ExpCreator = function(user_id, scene_id, finishAction) {
DBReq.ExpCreator = function(user_id, scene_id, template, finishAction) {
this.finishAction = finishAction;
this.user_id = user_id;
this.scene_id = scene_id;
this.template = template;
// Connect to db
var self = this;
@@ -526,8 +527,8 @@ DBReq.ExpCreator = function(user_id, scene_id, finishAction) {
DBReq.ExpCreator.prototype.execute = function() {
var self = this;
this.client.query(
"INSERT INTO experiment(user_id, scene_id) VALUES($1,$2);",
[self.user_id, self.scene_id],
"INSERT INTO experiment(user_id, scene_id, template) VALUES($1,$2,$3);",
[self.user_id, self.scene_id, self.template],
function(err, result) {
self.client.query("SELECT MAX(id) AS id FROM experiment;", function(err, result) {
self.finalResult = result.rows[0].id;
@@ -776,8 +777,8 @@ DBReq.createUser = function(callback) {
* @param scene_id {Number} id of the scene on which the experiment is
* @param callback {function} callback called on the new experiment id
*/
DBReq.createExp = function(id, scene_id, callback) {
new DBReq.ExpCreator(id, scene_id, callback);
DBReq.createExp = function(id, scene_id, template, callback) {
new DBReq.ExpCreator(id, scene_id, template, callback);
};
/**

View File

@@ -32,6 +32,18 @@ function randomArray() {
return arr;
}
function randomReco() {
var recoStyles = [
'prototype_empty.jade',
'prototype_viewports.jade',
'prototype_arrows.jade'
];
return shuffle(recoStyles);
}
module.exports.index = function(req, res) {
res.setHeader('Content-Type', 'text/html');
@@ -51,6 +63,15 @@ var generateSceneNumber = function(req, res) {
return req.session.scenes[req.session.currentSceneIndex];
};
var generateRecommendationStyle = function(req, res) {
if (req.session.recos === undefined) {
req.session.recos = randomReco();
}
return req.session.recos.shift();
}
var sceneToFunction = function(scene) {
switch (scene) {
case 2:
@@ -65,14 +86,23 @@ var sceneToFunction = function(scene) {
};
var protoHelper = function(template) {
return function(req, res) {
template = generateRecommendationStyle(req, res);
if (template === undefined) {
res.redirect('/feedback');
return;
}
db.tryUser(req.session.user_id, function(id) {
// Get random scene number
var scene = generateSceneNumber(req, res);
res.locals.scene = sceneToFunction(scene);
req.session.user_id = id;
db.createExp(id, req.session.scenes[req.session.currentSceneIndex], function(id) {
db.createExp(id, req.session.scenes[req.session.currentSceneIndex], template, function(id) {
req.session.exp_id = id;
req.session.save();
res.setHeader('Content-Type','text/html');
@@ -87,6 +117,7 @@ var protoHelper = function(template) {
module.exports.arrows = protoHelper('prototype_arrows.jade');
module.exports.viewports = protoHelper('prototype_viewports.jade');
module.exports.reverse = protoHelper('prototype_reverse.jade');
module.exports.empty = protoHelper('prototype_empty.jade');
module.exports.sponza = function(req, res) {
res.setHeader('Content-Type', 'text/html');
@@ -143,7 +174,7 @@ module.exports.tutorial = function(req, res) {
req.session.user_id = id;
// 1 is the ID of peach scene
db.createExp(id, 1, function(id) {
db.createExp(id, 1, null, function(id) {
req.session.exp_id = id;
req.session.save();

View File

@@ -2,6 +2,7 @@ module.exports = {
'/prototype': 'index',
'/prototype/arrows': 'arrows',
'/prototype/viewports': 'viewports',
'/prototype/empty': 'empty',
'/prototype/reverse': 'reverse',
'/prototype/replay': 'replay_index',
'/prototype/replay/:id': 'replay',

View File

@@ -40,8 +40,10 @@ block content
input#lock(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked)
label(for="lock" style={'margin-right':'10px'}) Pointer lock
input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked)
label(for="showarrows" style={'margin-right':'10px'}) Show arrows
input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px', 'display':'none'}, checked)
label(for="showarrows" style={'margin-right':'10px', 'display': 'none'}) Show arrows
block lastbutton
//-input#recommendation(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'})
//-label(for="recommendation" style={'margin-right':'10px'}) Fixed prev

View File

@@ -5,6 +5,17 @@ block title
block configjs
script Recommendation = L3D.ArrowRecommendation;
script.
Coin.onLastCoin = function() {
$('#next').show();
$('#next').click(function() {
window.location = '/prototype/arrows';
});
};
block lastbutton
button#next.btn.btn-success.navbar-btn(style={'margin-right':'10px', 'margin-bottom':'10px', 'display':'none'})
span Go to the next step
//-block preciseDescription
p

View File

@@ -0,0 +1,25 @@
extends ./prototype_interactive
block title
title #{title} - Prototype - Arrows
block configjs
script Recommendation = L3D.EmptyRecommendation;
script.
Coin.onLastCoin = function() {
$('#next').show();
$('#next').click(function() {
window.location = '/prototype/arrows';
});
};
block lastbutton
button#next.btn.btn-success.navbar-btn(style={'margin-right':'10px', 'margin-bottom':'10px', 'display':'none'})
span Go to the next step
//-block preciseDescription
p
| Recommended views are displayed with a
| transparent blue arrow. They disappear when you
| come closer to them, and shows the motion between
| your current position and the recommendation.

View File

@@ -5,6 +5,17 @@ block title
block configjs
script Recommendation = L3D.ViewportRecommendation;
script.
Coin.onLastCoin = function() {
$('#next').show();
$('#next').click(function() {
window.location = '/prototype/arrows';
});
};
block lastbutton
button#next.btn.btn-success.navbar-btn(style={'margin-right':'10px', 'margin-bottom':'10px', 'display':'none'})
span Go to the next step
//-block preciseDescription
p