Skip to content

Commit

Permalink
cleaning start page for production
Browse files Browse the repository at this point in the history
  • Loading branch information
jcnade committed Jul 28, 2018
1 parent 01c739c commit 8d936cd
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 140 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ Client side, any device with javascript, HTML5 and a webcam
Admin interface and client can run on smartphone Android too.


## Alpha

This version doesn't work yet
## 2018 Updated Edition

* Pug v2
* Bootstrap v4
* Jquery v3
* Express v4


## How it's work
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"qr": "0.2.4",
"qrcode": "1.2.0",
"redis": "2.8.0",
"shortid": "^2.2.12",
"stylus": "*"
}
}
27 changes: 18 additions & 9 deletions qr-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ app.use(function(req, res, next) {
*/


//
// URL
//



// First Page for visitors
app.get('/',
routes.index);
routes.init,
routes.index,
routes.done);


// Starting a new party (form)
app.get('/start/:pid',
routes.init,
routes.partyForm,
routes.done);

// Starting a new party (saving data)
app.post('/start/:pid',
routes.init,
routes.partyStore,
routes.done);

app.get('/scan/:partytag',
routes.scan);
Expand All @@ -80,8 +94,6 @@ app.get('/images/:id',
app.get('/qr/:userid/:number',
routes.qr);

app.get('/make',
routes.make);

app.get('/admin/:partytag',
routes.admin);
Expand All @@ -101,9 +113,6 @@ app.get('/publish/:partytag/:setID',
app.get('/delete/:partytag/:setID',
routes.delete );

app.post('/make',
routes.make);

app.post('/addset',
routes.addset);

Expand Down
199 changes: 109 additions & 90 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,121 @@


var pug = require("pug");
var redis = require("redis");
var config = require("config");
var uuid = require('node-uuid');
var Encoder = require('qr').Encoder;

redis = redis.createClient(config.redis.port, config.redis.host);
var shortid = require('shortid');
var pug = require("pug");
var redis = require("redis");
var config = require("config");
var uuid = require('node-uuid');
var Encoder = require('qr').Encoder;

redis.on("error", function (err) {
console.log(" Can't connect to redis " + err);
});


// Starting Redis

/*
* GET home page.
*/
redis = redis.createClient(config.redis.port, config.redis.host);
redis.on("error", function (err) {
console.log(" Can't connect to redis " + err);
});


exports.index = function(req, res){

var html = pug.renderFile('./views/index.pug', {});
res.send(html);
};



exports.init = function(req, res, next ) {
res.locals.html = "";
next()
};


exports.done = function(req, res) {
res.send(res.locals.html);
};


exports.index = function(req, res, next){

// Generate a new uniq ID
var options = {
'pid' : shortid.generate()
}
res.locals.html = pug.renderFile('./views/index.pug', options);
next();
};


// Start a new party ID
exports.partyForm = function(req, res, next){

var options = {
pid : req.params.pid
};
res.locals.html = pug.renderFile('./views/partyForm.pug', options);
next();

};


// Start a new party ID
exports.partyStore = function(req, res){

if (req.params.pid) {

// we build a list of user key for this party
console.log(req.body.partytag);
console.log(req.body.djpass);
console.log(req.body.usermaxr);
console.log(req.body.choicemax);

//
// Step 1) save the party config info on redis
// the partyTag is the key

redis.set( 'config/'+req.body.partytag, JSON.stringify( { 'partytag' : req.body.partytag,
'djpass': req.body.djpass,
'usermax': req.body.usermax,
'choicemaxx': req.body.choicemax } ) , function(err){
if (err) { console.log('Cant save on redis'); }
});


//
// step 2) Generate x uniq user ID
//


for (var i = 0 ; i < req.body.usermax ; i++)
{


(function(i){

var userID = uuid.v4();
console.log(userID);

redis.set( 'user/'+userID, req.body.partytag);

redis.rpush( 'user/'+req.body.partytag, userID , function(err){
if (err) { console.log('Cant save on redis'); }
});

})(i);
}


// 80s Basic style : we jump to admin interface
res.redirect('/admin/'+ req.body.partytag );

} else {
//
//
//
var options = {};
var html = pug.renderFile('./views/make.pug', options);
res.send(html);
}

};




Expand Down Expand Up @@ -212,74 +303,6 @@ exports.admin = function(req, res){



/*-----------------------------------------
*
* Star a new Party, make a new partyTag
*
*-----------------------------------------
*/

exports.make = function(req, res){


if (req.body.partytag) {

// we build a list of user key for this party
console.log(req.body.partytag);
console.log(req.body.djpass);
console.log(req.body.usermaxr);
console.log(req.body.choicemax);

//
// Step 1) save the party config info on redis
// the partyTag is the key

redis.set( 'config/'+req.body.partytag, JSON.stringify( { 'partytag' : req.body.partytag,
'djpass': req.body.djpass,
'usermax': req.body.usermax,
'choicemaxx': req.body.choicemax } ) , function(err){
if (err) { console.log('Cant save on redis'); }
});


//
// step 2) Generate x uniq user ID
//


for (var i = 0 ; i < req.body.usermax ; i++)
{


(function(i){

var userID = uuid.v4();
console.log(userID);

redis.set( 'user/'+userID, req.body.partytag);

redis.rpush( 'user/'+req.body.partytag, userID , function(err){
if (err) { console.log('Cant save on redis'); }
});

})(i);
}


// 80s Basic style : we jump to admin interface
res.redirect('/admin/'+ req.body.partytag );

} else {
//
//
//
var options = {};
var html = pug.renderFile('./views/make.pug', options);
res.send(html);
}

};




Expand Down Expand Up @@ -682,11 +705,7 @@ exports.encoder = function(req, res){
table4print += "<td valgn=top width=25% height=100 align=center><img src=/images/qr" + data[k] + '2.png ></td>';
table4print += "<td valgn=top width=25% height=100 align=center><img src=/images/qr" + data[k] + '3.png ></td>';
table4print += "<td valgn=top width=25% height=100 >"+
"<P><font size=-1 > Vote for your favorite LineUP."+
"Find a terminal and pressent the appropriate QR code"+
"in front of the WebCam."+
"If screen flash green, you have voted."+
"If screen flash gray, you vote has allready been validate."+
"<P><font size=-1 > ici"+
"</font></P></td>";

table4print += "</tr></table></div>";
Expand Down
2 changes: 1 addition & 1 deletion views/admin.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ html

.container
.row-fluid
.span5
.col(class="justify-content-md-center")
h2 DJ Console #{partytag}

hr
Expand Down
2 changes: 1 addition & 1 deletion views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ html
.container(class="text-center")
.row.pt9.pb8
.col(class="justify-content-md-center")
a(href="/make" rel="nofollow" class="btn btn-sq-lg btn-success")
a(href="/start/"+pid rel="nofollow" class="btn btn-sq-lg btn-success")
i(class="fa fa-music fa-3x")
br
| Party Start
Expand Down
37 changes: 0 additions & 37 deletions views/make.pug

This file was deleted.

Loading

0 comments on commit 8d936cd

Please sign in to comment.