From 61df30ae840777c038a7ebe386467c0c3b11fd35 Mon Sep 17 00:00:00 2001 From: jkaplon Date: Mon, 6 Jul 2015 22:08:08 -0400 Subject: [PATCH] Begin restructure to handle multiple cores; probably horribly broken...interim commit --- index.html | 8 -------- server.js | 13 ++++++++++++- views/core.hbs | 17 +++++++++++++++++ views/default.hbs | 30 ++++++++++++++++++++++++++++++ views/home.hbs | 22 ---------------------- views/index.hbs | 12 ++++++++++++ 6 files changed, 71 insertions(+), 31 deletions(-) delete mode 100644 index.html create mode 100644 views/core.hbs create mode 100644 views/default.hbs delete mode 100644 views/home.hbs create mode 100644 views/index.hbs diff --git a/index.html b/index.html deleted file mode 100644 index b808d96..0000000 --- a/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - -

Test page for Alert Monitor app:

- - diff --git a/server.js b/server.js index 8c72541..d8c634c 100644 --- a/server.js +++ b/server.js @@ -39,6 +39,7 @@ db.serialize(function() { "CREATE TABLE Alerts (" + "origJSON TEXT," + "coreId TEXT," + + "coreName TEXT," + "locationDesc TEXT," + "status TEXT," + "published_at TEXT)" @@ -55,13 +56,23 @@ app.set('view engine', 'hbs'); app.set('views', __dirname + '/views'); app.get('/', function(req, res){ + db.all("SELECT coreId, coreName, published_at FROM Alerts GROUP BY coreId, coreName, published_at;", function(err, rows){ + //console.log(rows); + res.render('index', {cores: rows}, function(err, html) { + res.send(html); + }); +}); + +// not sure if this ':id' notaction is correct +app.get('/core/:id', function(req, res){ //res.sendFile("/usr/src/app/index.html"); //fs.createReadStream('./log.log').pipe(res); var d = new Date(); console.log("GET request at, " + JSON.stringify(d, 4)); + // add WHERE clause w/core ID value from URL db.all("SELECT coreId, published_at FROM Alerts ORDER BY published_at DESC LIMIT 30;", function(err, rows){ //console.log(rows); - res.render('home', {alerts: rows}, function(err, html) { + res.render('core', {alerts: rows}, function(err, html) { res.send(html); }); }); diff --git a/views/core.hbs b/views/core.hbs new file mode 100644 index 0000000..a0a1d1d --- /dev/null +++ b/views/core.hbs @@ -0,0 +1,17 @@ +{{!< default}} + +

Alerts from a single Particle Core:

+ + + diff --git a/views/default.hbs b/views/default.hbs new file mode 100644 index 0000000..bce3f17 --- /dev/null +++ b/views/default.hbs @@ -0,0 +1,30 @@ + + + + {{! Document Settings }} + + + + {{! Page Meta }} + {{meta_title}} + + + + + + + + + + {{! Styles'n'Scripts }} + + {{! Ghost outputs important style and meta data with this tag }} + {{ghost_head}} + + + + {{! Everything else gets inserted here }} + {{{body}}} + + + diff --git a/views/home.hbs b/views/home.hbs deleted file mode 100644 index ad09dee..0000000 --- a/views/home.hbs +++ /dev/null @@ -1,22 +0,0 @@ - - - - Alert Monitor - - -

Alerts from a single Particle Core:

- - - - diff --git a/views/index.hbs b/views/index.hbs new file mode 100644 index 0000000..9fed922 --- /dev/null +++ b/views/index.hbs @@ -0,0 +1,12 @@ +{{!< default}} + +

Select a monitor device:

+