diff --git a/app.js b/app.js index 433a824..1ce5938 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,14 @@ logger = require('morgan'), cookieParser = require('cookie-parser'), bodyParser = require('body-parser'), socketio = require('socket.io'), -session = require('express-session'); +session = require('express-session'), +low = require('lowdb'); + +let config = low('config.json'); +let db = low('db.json'); + +let tbdLabel = config.get('mainConfig').chain().find({ param: 'tbdLabel' }).value()['value']; +//let tbdLabel = config.get('mainConfig').chain().find({ param: 'tbdLabel' }).value()['value']; let routes = require('./routes/routes'), app = express(); @@ -13,8 +20,9 @@ app = express(); let io = socketio(); app.io = io; +let state = db.getState(); -let state = { +let resetState = { teams : [ ["Team 1", "Team 2"], /* first matchup */ ["Team 3", null], /* second matchup */ @@ -35,7 +43,13 @@ app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); -app.use(session({secret: 'thisIsTheSessionSecret'})); +app.use(session({ + secret: 'thisIsTheSessionSecret', + name: 'uniScoreCookie', + resave: true, + saveUninitialized: true + })); + app.use(express.static(path.join(__dirname, 'public'))); app.use('/', routes); @@ -89,6 +103,7 @@ io.on('connection', function (socket) { socket.on('editState', function (newState) { state = newState; + db.setState(state); io.emit('stateChange', state); // Push state to all clients console.log("updated state"); }); @@ -97,7 +112,4 @@ io.on('connection', function (socket) { - - - module.exports = app; diff --git a/public/css/style.css b/public/css/style.css index 68d6c88..74f7d34 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1,5 +1,5 @@ body { - font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; + /*font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;*/ } a { @@ -22,3 +22,8 @@ margin:0 auto; #refresh { margin:0 auto; } + +.label{ +font-size:100%; +color: black; +} diff --git a/public/js/back_client.js b/public/js/back_client.js index 95f73d4..7436ff9 100644 --- a/public/js/back_client.js +++ b/public/js/back_client.js @@ -1,16 +1,16 @@ 'use strict'; // This is the backend client js -let iosocket = io.connect(); +var iosocket = io.connect(); -let tbdLable = 'To be determined', +var tbdLable = 'To be determined', noTeam = 'Kein Team'; // setup all my handlers -iosocket.on('clientrefresh', () => { +iosocket.on('adminrefresh', function(){ location.reload(); }); -iosocket.on('stateChange', (state) => { +iosocket.on('stateChange', function(state){ $('#team-container').bracket({ init: state, save: saveFn, @@ -18,15 +18,20 @@ iosocket.on('stateChange', (state) => { decorator: { edit: edit_fn, render: render_fn - } + }, + teamWidth: 130, + scoreWidth: 20, + matchMargin: 20, + roundMargin: 20 }); $('.increment').click(function() { - alert('haha'); + //alert('haha'); // trigger a state update? + //TODO: Focus unfocus on first }); $('.decrement').click(function() { - alert('haha'); + //alert('haha'); }); }); @@ -92,6 +97,7 @@ function saveFn(data, userData) { iosocket.emit('editState', data); } + $(function() { // Dom is loaded $('#refresh').click(function() { @@ -102,6 +108,6 @@ $(function() { noTeam = $('#NoT').val(); // get my state - let context = 'admin'; + var context = 'admin'; iosocket.emit('loadState', context); }); diff --git a/public/js/front_client.js b/public/js/front_client.js index 3cb6e53..a33bd3d 100644 --- a/public/js/front_client.js +++ b/public/js/front_client.js @@ -1,29 +1,32 @@ 'use strict'; -let iosocket = io.connect(); +var iosocket = io.connect(); -let tbdLable = 'To be determined', +var tbdLable = 'To be determined', noTeam = 'Kein Team'; // setup all my handlers -iosocket.on('clientrefresh', () => { +iosocket.on('clientrefresh', function(){ location.reload(); }); -iosocket.on('stateChange', (state) => { +iosocket.on('stateChange', function(state){ console.log(state); // basically the server tracks the state since it is the same for al clients // So we know that we HAVE to update at this point $('#team-container').bracket({ init: state, decorator: { - edit: ()=>{}, + edit: function(){}, render: render_fn - } + }, + teamWidth: 130, + scoreWidth: 20, + matchMargin: 20, + roundMargin: 20 }); }); -function lolz() { -} + function render_fn(container, data, score, state) { switch (state) { case "empty-bye": @@ -31,7 +34,7 @@ function render_fn(container, data, score, state) { return; case "empty-tbd": container.append(tbdLable) - retrun; + return; case "entry-no-score": console.log('no score');// no return case "entry-default-win": @@ -47,6 +50,6 @@ function render_fn(container, data, score, state) { tbdLable = $('#TBD').val(); noTeam = $('#NoT').val(); // get my state - let context = 'main'; + var context = 'main'; iosocket.emit('loadState',context); }); diff --git a/routes/routes.js b/routes/routes.js index 057d38f..c4724eb 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -4,7 +4,7 @@ let passwd = 'insecure'; /* GET home page. */ router.get('/', function(req, res, next) { - res.render('index', { mainHeader: '🍺🍺🍺 Aktueller Spielstand 🍺🍺🍺🍺', TBD:'I am TBD', NoTeam:'No TeamYet' }); + res.render('index', { mainHeader: '🍺🍺🍺 Aktueller Spielstand 🍺🍺🍺🍺', TBD:'???', NoTeam:'Kein Team' }); }); router.get('/login', function(req, res, next) { @@ -31,7 +31,7 @@ router.get('/admin', function(req, res, next) { console.log(req.session.passwd); console.log(req.session); if(req.session.passwd=='insecure'){ - res.render('admin', { mainHeader: 'Admin Interface', TBD:'I am TBD', NoTeam:'No TeamYet' }); + res.render('admin', { mainHeader: 'Admin Interface', TBD:'???', NoTeam:'Kein Team' }); }else{ res.redirect('/login'); } diff --git a/views/admin.hbs b/views/admin.hbs index 5738592..5ac5197 100644 --- a/views/admin.hbs +++ b/views/admin.hbs @@ -3,9 +3,9 @@