BillBoard now Flyer. Changes to API and view logic

Fix to replace of null error. Changed Flyer to flyer
This commit is contained in:
benmcmahon100
2016-04-13 00:05:13 +01:00
parent 2b2b359514
commit d53a2eec86
4 changed files with 15 additions and 52 deletions

View File

@ -134,7 +134,7 @@ main = (function(main, global) {
localStorage.setItem(item, input); localStorage.setItem(item, input);
return input; return input;
} else { } else {
let data = localStorage.getItem(item); let data = typeof localStorage.getItem(item) !== 'undefined' && localStorage.getItem(item) !== null ? localStorage.getItem(item) : "";
try { try {
data = JSON.parse(data); data = JSON.parse(data);
} catch (e) { } catch (e) {
@ -637,9 +637,11 @@ $(document).ready(function() {
function getCurrentBillBoard(cb) { function getCurrentBillBoard(cb) {
$.ajax({ $.ajax({
url: '/billboard', url: '/api/Flyers/findOne?'
+ 'filter=%7B%22order%22%3A%20%20%22id%20DESC%22%7D',
method: 'GET', method: 'GET',
dataType: 'JSON' dataType: 'JSON',
data: {'order': 'id DESC'}
}).done((resp) => { }).done((resp) => {
cb(resp); cb(resp);
}); });
@ -657,9 +659,14 @@ $(document).ready(function() {
}); });
} }
function handleNewBillBoard(message) { function handleNewBillBoard(resp) {
if (main.localStorageIO('lastBillBoardSeen') !== message.data) { const data = typeof main.localStorageIO('lastBillBoardSeen') !== "undefined" && main.localStorageIO('lastBillBoardSeen') !== null ? main.localStorageIO('lastBillBoardSeen') : "";
$('#billContent').text(message.data); if (
data.replace(/\s/gi, '')
!== resp.message.replace(/\s/gi, '')
&& resp.active
) {
$('#billContent').html(resp.message);
$('#billBoard').fadeIn(); $('#billBoard').fadeIn();
} }
} }

View File

@ -1,5 +1,5 @@
{ {
"name": "BillBoard", "name": "Flyer",
"base": "PersistedModel", "base": "PersistedModel",
"idInjection": true, "idInjection": true,
"trackChanges": false, "trackChanges": false,

View File

@ -7,7 +7,6 @@ import secrets from '../../config/secrets';
module.exports = function(app) { module.exports = function(app) {
const router = app.loopback.Router(); const router = app.loopback.Router();
const User = app.models.User; const User = app.models.User;
const BillBoard = app.models.BillBoard;
router.get('/api/github', githubCalls); router.get('/api/github', githubCalls);
router.get('/api/blogger', bloggerCalls); router.get('/api/blogger', bloggerCalls);
router.get('/api/trello', trelloCalls); router.get('/api/trello', trelloCalls);
@ -39,7 +38,6 @@ module.exports = function(app) {
'/the-fastest-web-page-on-the-internet', '/the-fastest-web-page-on-the-internet',
theFastestWebPageOnTheInternet theFastestWebPageOnTheInternet
); );
router.get('/billBoard', billBoard);
app.use(router); app.use(router);
@ -84,48 +82,6 @@ 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
});
} else {
if (data.active) {
res.send({
err: null,
data: data.message
});
} else {
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
});
}
}
function theFastestWebPageOnTheInternet(req, res) { function theFastestWebPageOnTheInternet(req, res) {
res.render('resources/the-fastest-web-page-on-the-internet', { res.render('resources/the-fastest-web-page-on-the-internet', {
title: 'This is the fastest web page on the internet' title: 'This is the fastest web page on the internet'

View File

@ -67,7 +67,7 @@
"dataSource": "db", "dataSource": "db",
"public": true "public": true
}, },
"BillBoard": { "flyer": {
"dataSource": "db", "dataSource": "db",
"public": true "public": true
} }