Basic GET listener at root in server.js; basic index.hbs template.

This commit is contained in:
jkaplon 2015-08-25 14:02:23 -04:00
parent 5595dd474f
commit f43d6a9d19
2 changed files with 18 additions and 53 deletions

View File

@ -68,11 +68,10 @@ app.get('/', function(req, res){
var d = new Date();
console.log("GET /, " + JSON.stringify(d, 4));
var devIndexQry =
"select al.coreId, max(co.coreName) as coreName, max(co.locationDesc) as locationDesc, mpub.MaxPub, al.status as MaxStatus " +
"from Alerts al " +
"inner join (select coreId, max(published_at) as MaxPub from Alerts group by coreId) mpub on al.coreId = mpub.coreId and al.published_at = mpub.MaxPub " +
"left join Cores co on al.coreId = co.coreId " +
"group by al.coreId ";
"select status, published_at " +
"from Alerts " +
"order by published_at desc " +
"limit 2"
db.all(devIndexQry, function(err, rows){
if(err !== null) {
console.log(err);
@ -81,15 +80,12 @@ app.get('/', function(req, res){
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
rows.forEach(function(row){
row.MaxPubDate = courtsopenUtils.getLocDateFromUTC(row.MaxPub);
row.MaxPubTime = courtsopenUtils.getLocTimeFromUTC(row.MaxPub);
if(row.MaxStatus.toLowerCase().indexOf('alert') > -1){
row.rowClass = 'alert-row';
} else { row.rowClass = 'non-alert-row'; }
if(row.status.toLowerCase().indexOf('closed') > -1){
row.statusClass = 'closed';
} else { row.statusClass = 'open'; }
});
res.render('index', {cores: rows}, function(err, html) {
res.render('index', {values: rows}, function(err, html) {
if(err !== null) {
console.log(err);
} else {

View File

@ -1,43 +1,12 @@
{{!< default}}
<h1>Select a monitor device:</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Device Name</th>
<th>Location</th>
<th>Last Update</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{{#each cores}}
<tr class="{{this.rowClass}}">
<td>
{{#if this.coreName}}
<a href="https://particle.kaplon.us/core/{{this.coreId}}">{{this.coreName}}</a>
{{else}}
<a href="https://particle.kaplon.us/core/{{this.coreId}}"># No Name #</a>
</br>
</br>
<a href="https://particle.kaplon.us/core/edit/{{this.coreId}}" class="btn btn-primary">Edit Details</a>
{{/if}}
</td>
<td>
{{#if this.locationDesc}}
{{this.locationDesc}}
{{else}}
# No Location #
</br>
</br>
<a href="https://particle.kaplon.us/core/edit/{{this.coreId}}" class="btn btn-primary">Edit Details</a>
{{/if}}
</td>
<td>{{this.MaxPubDate}}</td>
<td>{{this.MaxPubTime}}</td>
<td>{{this.MaxStatus}}</td>
</tr>
{{/each}}
</tbody>
</table>
<h1>TT Tennis Courts Are...</h1>
{{! Index-0 is the most recent message. }}
<div class="jumbotron-{{values.0.statusClass}}">
<h2>{{values.0.status}}</h2>
</div>
<br />
<h3>Update received, {{values.0.published_at}}</h3>
<br />
<h4>Prior update was, {{values.1.status}} at {{values.1.published_at}}</h4>