From c1867cc47ff42f3e634761b462e6460521713632 Mon Sep 17 00:00:00 2001 From: jkaplon <jody@kaplon.us> Date: Thu, 16 Jul 2015 13:31:21 -0400 Subject: [PATCH] Add most recent status message and published_at date to device index. --- server.js | 7 ++++++- views/index.hbs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index fc6eb18..26398b6 100644 --- a/server.js +++ b/server.js @@ -59,7 +59,12 @@ app.set('views', __dirname + '/views'); app.get('/', function(req, res){ var d = new Date(); console.log("GET /, " + JSON.stringify(d, 4)); - db.all("SELECT coreId, coreName, locationDesc FROM Alerts GROUP BY coreId, coreName, locationDesc;", function(err, rows){ + var devIndexQry = + "select coreId, coreName, locationDesc, max(published_at) as MaxPub, max(status) as MaxStatus " + + "from Alerts otbl " + + "where published_at = (select max(published_at) from Alerts where coreId = otbl.coreId) " + + "group by coreId, coreName, locationDesc;"; + db.all(devIndexQry, function(err, rows){ if(err !== null) { console.log(err); } else { diff --git a/views/index.hbs b/views/index.hbs index aa80fbf..dc50c61 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -6,9 +6,9 @@ <li> <a href="https://particle.kaplon.us/core/{{this.coreId}}"> {{#if this.coreName}} - {{this.coreName}}, {{this.locationDesc}} + {{this.coreName}}, {{this.locationDesc}}, {{this.MaxPub}}, {{this.MaxStatus}} {{else}} - {{this.coreId}}, {{this.locationDesc}} + {{this.coreId}}, {{this.locationDesc}}, {{this.MaxPub}}, {{this.MaxStatus}} {{/if}} </a> </li>