admin template working; error on handling POST though.
This commit is contained in:
		
							parent
							
								
									81bba63e1a
								
							
						
					
					
						commit
						0277ae81ee
					
				
							
								
								
									
										50
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								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;
 | 
			
		||||
 | 
			
		||||
@ -4,17 +4,23 @@
 | 
			
		||||
    <h1 class="text-center">TT Tennis Courts Are...</h1>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<table class="table lead">
 | 
			
		||||
    <th>Location:</th> <th>Current Status:</th>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <td><a href="https://tenniscourtsopen.com/tt">Temple Terrace Recreation Center, clay courts</a></td>
 | 
			
		||||
        <td class="label label-info.{{values.statusclass}}">{{values.status}}</td>
 | 
			
		||||
    </tr>
 | 
			
		||||
</table>
 | 
			
		||||
{{! Index-0 is the most recent message. }}
 | 
			
		||||
<div class="jumbotron {{values.0.statusclass}}">
 | 
			
		||||
    <h1 class="text-center"><b>{{values.0.status}}</b></h1>
 | 
			
		||||
</div>
 | 
			
		||||
<div>
 | 
			
		||||
    <h3 class="text-center">Update received: {{values.0.pubdate}}, {{values.0.pubtime}}</h3>
 | 
			
		||||
</div>
 | 
			
		||||
<hr></hr>
 | 
			
		||||
<div>
 | 
			
		||||
    <h4 class="text-center">Prior update was: {{values.1.status}} at {{values.1.pubdate}}, {{values.1.pubtime}}</h4>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<hr></hr>
 | 
			
		||||
 | 
			
		||||
<div>
 | 
			
		||||
    <form action="/" method="post">
 | 
			
		||||
        <input type="submit" class="btn btn-primary" value="Change Status to {{values.oppstatus}}"/>
 | 
			
		||||
        <input type="text hidden" value="{{values.oppstatus}}"/>
 | 
			
		||||
        <button type="submit" class="jumbotron {{values.0.oppstatus}} col-xs-4 col-xs-offset-4 btn btn-primary"><h2>Change Status to: {{values.0.oppstatus}}</h2></button>
 | 
			
		||||
        <input type="text" class="hidden" value="{{values.0.oppstatus}}"/>
 | 
			
		||||
    </form>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user