Persistent state and values from config

This commit is contained in:
2017-03-20 23:10:24 +01:00
parent 860a4328db
commit db2173cfcb
8 changed files with 74 additions and 39 deletions

View File

@ -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);
});

View File

@ -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);
});