Browse Source

menu list

bob
P.BARRY 10 years ago
parent
commit
3cb60f4b32
2 changed files with 150 additions and 7 deletions
  1. 52
      routes/index.js
  2. 105
      views/view.ejs

52
routes/index.js

@ -3,6 +3,9 @@ var BOB_mod_router = BOB_mod_express.Router();
var BOB_mod_path = require('path'); var BOB_mod_path = require('path');
var BOB_mod_mkdirp = require('mkdirp'); var BOB_mod_mkdirp = require('mkdirp');
var BOB_mod_os = require('os'); var BOB_mod_os = require('os');
var BOB_mod_fs = require('fs');
// var BOB_mod_fsExtra = require('fs-extra')
var BOB_tol_gphotos = null; var BOB_tol_gphotos = null;
var BOB_tol_booth = null; var BOB_tol_booth = null;
@ -12,6 +15,11 @@ var BOB_var_boothInProgress = 0;
var BOB_var_gamepad = require("gamepad"); var BOB_var_gamepad = require("gamepad");
var BOB_var_ipAddress = '127.0.0.1'; var BOB_var_ipAddress = '127.0.0.1';
var BOB_var_path = "/home/troll/workspace/bobinoscope";
BOB_mod_mkdirp.sync("public/printer/todo");
BOB_mod_mkdirp.sync("public/printer/done");
/* GET home page. */ /* GET home page. */
BOB_mod_router.get('/bobinoscope', function(req, res, next) { BOB_mod_router.get('/bobinoscope', function(req, res, next) {
res.render('index', {serverIpAddress: BOB_var_ipAddress}); res.render('index', {serverIpAddress: BOB_var_ipAddress});
@ -47,9 +55,51 @@ BOB_mod_router.get('/dslr/takepicture/:boothId/:pictId', function(req, res, next
/* GET view page. */ /* GET view page. */
BOB_mod_router.get('/download/final/hd/:pictId', function(req, res, next) { BOB_mod_router.get('/download/final/hd/:pictId', function(req, res, next) {
res.download('/home/cocoon/workspace/bobinoscope/public/img/final/'+req.params.pictId);
res.download(BOB_var_path+'/public/img/final/'+req.params.pictId);
});
/* GET view page. */
BOB_mod_router.get('/print/bobinogramme/:pictId', function(req, res, next) {
var srcPath = BOB_mod_path.join(BOB_var_path, '/public/img/final/'+req.params.pictId);
var dstPath = BOB_mod_path.join(BOB_var_path, '/public/printer/todo/'+req.params.pictId);
copyFile(srcPath, dstPath, function(pErr) {
res.json({error: pErr})
})
}); });
BOB_mod_router.get('/print/list/todo', function(req, res, next) {
var todoPath = BOB_mod_path.join(BOB_var_path, '/public/img/final/'+req.params.pictId);
BOB_mod_fs.readdir(todoPath, function(pErr, pList) {
res.json({error: pErr, todos: pList})
})
})
function copyFile(source, target, cb) {
var cbCalled = false;
var rd = BOB_mod_fs.createReadStream(source);
rd.on("error", function(err) {
done(err);
});
var wr = BOB_mod_fs.createWriteStream(target);
wr.on("error", function(err) {
done(err);
});
wr.on("close", function(ex) {
done();
});
rd.pipe(wr);
function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
}
// Initialize the library // Initialize the library
BOB_var_gamepad.init() BOB_var_gamepad.init()

105
views/view.ejs

@ -10,13 +10,22 @@
</head> </head>
<body> <body>
<div id="idMain" style="width:400px; margin: auto"> <div id="idMain" style="width:400px; margin: auto">
<p>Cliquez sur le <i>bobinogramme</i> qui vous intéresse<br/>pour afficher le menu</p>
<div id="idViewLoading"> <div id="idViewLoading">
<img src='/img/common/294.GIF'/> <img src='/img/common/294.GIF'/>
</div> </div>
<div id="idViewContainer"> <div id="idViewContainer">
</div> </div>
</div>
<div id="idMenu" style="display:none">
<div id="idMenu-title">Bobinoscope</div>
<img id="idMenu-preview" src=""/>
<br/>
<div>
<button id="idMenu-btnDownload">Télécharger</button>
<button id="idMenu-btnPrint">Imprimer</button>
</div>
</div> </div>
</body> </body>
<!-- Latest compiled and minified JQuery --> <!-- Latest compiled and minified JQuery -->
@ -25,6 +34,30 @@
<script src="/js/socket.io-1.3.4.js"></script> <script src="/js/socket.io-1.3.4.js"></script>
</html> </html>
<style type="text/css">
#idMenu {
background: #000;
opacity: 1;
position: fixed;
width: 100%;
padding: 1em;
top:0;
left:0;
bottom: 0;
right: 0;
font-size: 1.2em;
}
#idMenu button{
padding: 0.5em;
}
#idMenu-title {
padding: 0.3em;
font-size: 1.3em;
}
</style>
<script type="text/javascript"> <script type="text/javascript">
var socket = io('http://<%= serverIpAddress %>:3000'); var socket = io('http://<%= serverIpAddress %>:3000');
@ -40,15 +73,57 @@ $(document).ready(function() {
if( $(window).width() < 500 ) { if( $(window).width() < 500 ) {
$('#idMain').css('width' ,'100%'); $('#idMain').css('width' ,'100%');
$('#idMenu-preview').css('width', 60 * $(window).width() / 100 )
} else {
$('#idMenu-preview').css('width', 500 )
} }
$('#idMenu').click(function() {
$(this).fadeOut();
})
$('#idMenu-btnDownload').click(function() {
if( confirm("Télécharger le bobinogramme ?\n\nPour les iPhone-istes, un nouvel onglet va s'ouvrir avec le bobinogramme voulu. Un click long sur celui-ci permet de la télécharger définitivement.") ) {
window.open("/download/final/hd/"+BOB_var_selectedBoothId, "_blank");
}
})
$('#idMenu-btnPrint').click(function() {
if( BOB_var_printer.todos.indexOf(BOB_var_selectedBoothId) !== -1 ) {
if( confirm("Envoyer une demande d'impression du bobinogramme pour le livre d'Or?\n\nPour que tout le monde puisse mettre sa bobine, faites qu'une seul demande par groupe.") ) {
$.get("/print/bobinogramme/"+BOB_var_selectedBoothId, function(pResponse) {
if( pResponse.error ) {
console.log("Printer: ", pResponse.error)
alert("Echec ! Essayez d'envoyer une nouvelle demande")
} else {
alert("Demande prise en compte !\n\nVotre bobinogramme sera disponible près du Livre d'Or d'ici 1 heure")
}
})
}
} else {
alert("Une demande a déjà été envoyée.\nVérifiez près du Livre d'Or si votre bobinogramme ne s'y trouve pas.")
}
})
}) })
var BOB_var_lastBooth = "0"; var BOB_var_lastBooth = "0";
var BOB_var_selectedBoothId = "";
var BOB_var_printer = {
todos : []
}
function BOB_getBooths() { function BOB_getBooths() {
var boothList = $(".classBoothItem"); var boothList = $(".classBoothItem");
var jqBoothContainer = $('#idViewContainer'); var jqBoothContainer = $('#idViewContainer');
$.get('/print/list/todo', function(pResponse) {
if( pResponse.error ) {
console.log('Printer: ', pResponse.error)
} else {
BOB_var_printer.todos = pResponse.todos
}
})
$.get('/booth/list/'+BOB_var_lastBooth, function(pResponse) { $.get('/booth/list/'+BOB_var_lastBooth, function(pResponse) {
if( pResponse.inProgress > 0 ) { if( pResponse.inProgress > 0 ) {
$('#idViewLoading').fadeIn(); $('#idViewLoading').fadeIn();
@ -58,19 +133,35 @@ function BOB_getBooths() {
pResponse.booths.forEach(function(pBoothName) { pResponse.booths.forEach(function(pBoothName) {
var jqImg = $('<img>'); var jqImg = $('<img>');
var jqMenu = $('<div>');
var jqBtnDownload = $('<button>');
var jqBtnPrint = $('<button>');
jqImg.css('width', '100%'); jqImg.css('width', '100%');
jqImg.css('opacity', '0'); jqImg.css('opacity', '0');
jqImg.css('display', 'block');
jqImg.css('position', 'relative');
jqImg.css('transition', 'opacity 1s'); jqImg.css('transition', 'opacity 1s');
jqImg.data('booth', pBoothName); jqImg.data('booth', pBoothName);
jqImg.attr('src', "/img/final_ld/"+pBoothName); jqImg.attr('src', "/img/final_ld/"+pBoothName);
jqImg.addClass('classBoothItem'); jqImg.addClass('classBoothItem');
jqBtnDownload.html("Télécharger");
jqBtnPrint.html("Imprimer");
jqMenu.css({
position: 'absolute',
top: 0,
left: 0,
width : "100%",
height : "100px"
})
jqMenu.append(jqBtnDownload);
jqMenu.append(jqBtnPrint);
jqImg.on('click', function() { jqImg.on('click', function() {
jqImg.css('opacity', '0.4');
if( confirm("Télécharger ?") ) {
window.open("/download/final/hd/"+pBoothName, "_blank");
}
jqImg.css('opacity', '1');
BOB_var_selectedBoothId = pBoothName;
$('#idMenu-preview').attr('src', "/img/final_ld/"+pBoothName);
$('#idMenu').fadeIn();
}) })
jqImg.on('load', function() { jqImg.on('load', function() {
@ -81,6 +172,8 @@ function BOB_getBooths() {
BOB_var_lastBooth = pBoothName; BOB_var_lastBooth = pBoothName;
} }
jqImg.append(jqMenu);
jqBoothContainer.prepend(jqImg); jqBoothContainer.prepend(jqImg);
}) })
}) })

Loading…
Cancel
Save