Bill board feature up and running

This commit is contained in:
benmcmahon100
2016-04-12 21:59:57 +01:00
parent a27c5ccdd2
commit 2b2b359514
3 changed files with 70 additions and 28 deletions

View File

@ -124,6 +124,28 @@ main = (function(main, global) {
Mousetrap.bind('g c', toggleMainChat);
});
function localStorageIO(item = '', input = null) {
if (input) {
try {
input = typeof input === 'string' ? input : JSON.stringify(input);
} catch (e) {
// Do Nothing
}
localStorage.setItem(item, input);
return input;
} else {
let data = localStorage.getItem(item);
try {
data = JSON.parse(data);
} catch (e) {
// Do Nothing
}
return data;
}
}
main.localStorageIO = localStorageIO;
return main;
}(main, window));
@ -621,29 +643,26 @@ $(document).ready(function() {
}).done((resp) => {
cb(resp);
});
$('#dismissBill').on('click', (e) => {
const elemData
= e.target.parentNode.parentNode.children;
const res
= elemData[Object.keys(elemData).filter((key)=> {
return elemData[key].id === 'billContent';
})[0]].innerHTML;
main.localStorageIO('lastBillBoardSeen', res);
});
}
function handleNewBillBoard(message) {
const seen = typeof localStorage.getItem('billboardSeen') !== "undefined" ? localStorage.getItem('billboardSeen') : 'false';
let old = typeof localStorage.getItem('billboard') !== "undefined" ? localStorage.getItem('billboard') : 'false';
if(seen !== 'true') {
old = null;
}
if(message.data !== old) {
if(!message.err) {
$('#billContent').text(message.data);
localStorage.setItem('billboard', message.data)
} else {
console.error(message.err);
}
if (main.localStorageIO('lastBillBoardSeen') !== message.data) {
$('#billContent').text(message.data);
$('#billBoard').fadeIn();
}
}
getCurrentBillBoard(handleNewBillBoard);
$('#dismissBill').on('click', () => {
console.log("test");
localStorage.setItem('billboardSeen', 'true');
});
});

View File

@ -85,21 +85,44 @@ module.exports = function(app) {
}
function billBoard(req, res) {
if(req.user && typeof req.user.currentChallenge.challengeId !== "undefined"){
BillBoard.findOne({}, function(err, data){
if(err){
res.send({err: {type: "Error", message: "Database Error"}, data: null});
if (
req.user
&& typeof req.user.currentChallenge.challengeId !== 'undefined'
) {
BillBoard.findOne({}, function(err, data) {
if (err) {
res.send({
err: {
type: 'Error',
message: 'Database Error'
},
data: null
});
} else {
if (data.active) {
res.send({err: null, data: data.message});
res.send({
err: null,
data: data.message
});
} else {
res.send({err: {type: "warning", message: "Bill Board is not active"}, data: null});
res.send({
err: {
type: 'warning',
message: 'Bill Board is not active'
},
data: null
});
}
}
});
}
else {
res.send({err: {type: "warning", message: "User Not Signed In"}, data: null});
} else {
res.send({
err: {
type: 'warning',
message: 'User Not Signed In'
},
data: null
});
}
}

View File

@ -20,7 +20,7 @@
div!= success.msg
.row.flashMessage
.col-xs-12
.alert.alert-success.fade.in
#billBoard.alert.alert-success.fade.in(style="display: none;")
button.close(type='button', data-dismiss='alert')
span.ion-close-circled#dismissBill
#billContent