diff --git a/server.js b/server.js index b769278..55801cd 100644 --- a/server.js +++ b/server.js @@ -118,6 +118,12 @@ app.get('/', function(req, res){ }); }); +app.post(':loc/admin', isAuthenticated, function(req, res){ + winston.info('POST by admin at ' + loc); + // possible to forward req to POST to '/'? + var loc = req.params.loc; +}); + app.post('/', function(req, res){ var postEvent = req.body.postEvent; var source = req.body.source; @@ -171,14 +177,48 @@ app.get('/:loc/admin', isAuthenticated, function(req, res) { res.status(404).send('Not found'); } else { // TODO: load admin template - res.status(200).send('admin template here...'); + //res.status(200).send('admin template here...'); + pg.connect(conString, function(err, client, done) { + if(err) { + return winston.error('error fetching client from pool', err); + } + var devIndexQry = + "select status, published_at " + + "from alerts " + + "where status in ('Open', 'Closed') " + + "and coreid = '2a002b000947343432313031' " + + "order by published_at desc " + + "limit 2" + client.query(devIndexQry, function(err, result) { + //call `done()` to release the client back to the pool + done(); + if(err) { + return winston.error('error running query', err); + } + // Loop over elements in rows array, convert ugly UTC times to pretty local times. + result.rows.forEach(function(row){ + row.pubdate = courtsopenUtils.getLocDateFromUTC(row.published_at); + row.pubtime = courtsopenUtils.getLocTimeFromUTC(row.published_at); + if(row.status.toLowerCase().indexOf('closed') > -1){ + row.statusclass = 'closed'; + row.oppstatus = 'open'; + } else { + row.statusclass = 'open'; + row.oppstatus = 'closed'; + } + }); + res.render('admin', {values: result.rows}, function(err, html) { + if(err !== null) { + winston.error(err); + } else { + res.send(html); + } + }); + }); + }); } }); -app.post(':loc/admin', isAuthenticated, function(req, res){ - winston.info('POST by admin at ' + loc); - // possible to forward req to POST to '/'? -}); app.get('/:loc/login', function(req, res){ var loc = req.params.loc; diff --git a/views/admin.hbs b/views/admin.hbs index f13f26f..ef0d2d5 100644 --- a/views/admin.hbs +++ b/views/admin.hbs @@ -4,17 +4,23 @@
Location: | Current Status: | -
---|---|
Temple Terrace Recreation Center, clay courts | -{{values.status}} | -