Begin restructure to handle multiple cores; probably horribly broken...interim commit

This commit is contained in:
jkaplon 2015-07-06 22:08:08 -04:00
parent eea9567b9b
commit 61df30ae84
6 changed files with 71 additions and 31 deletions

View File

@ -1,8 +0,0 @@
<html !DOCTYPE=html>
<head>
</head>
<body>
<h1>Test page for Alert Monitor app:</h1>
</body>
</html>

View File

@ -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);
});
});

17
views/core.hbs Normal file
View File

@ -0,0 +1,17 @@
{{!< default}}
<h1>Alerts from a single Particle Core:</h1>
<ul>
{{! try to add header to list pretty core name and locale text (not sure how to pass this from node}}
{{#each alerts}}
<li>{{this.coreId}}: {{this.published_at}}</li>
{{/each}}
</ul>
<script>
setTimeout(
function() {
location.reload();
}, 5000
);
</script>

30
views/default.hbs Normal file
View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
{{! Document Settings }}
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
{{! Page Meta }}
<title>{{meta_title}}</title>
<meta name="description" content="{{meta_description}}" />
<link rel="shortcut icon" href="/assets/images/favicon.png" />
<meta name="HandheldFriendly" content="True" />
<meta name="MobileOptimized" content="320" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="{{asset "favicon.ico"}}">
{{! Styles'n'Scripts }}
{{! Ghost outputs important style and meta data with this tag }}
{{ghost_head}}
</head>
<body class="{{body_class}}">
{{! Everything else gets inserted here }}
{{{body}}}
</body>
</html>

View File

@ -1,22 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Alert Monitor</title>
</head>
<body>
<h1>Alerts from a single Particle Core:</h1>
<ul>
{{#each alerts}}
<li>{{this.coreId}}: {{this.published_at}}</li>
{{/each}}
</ul>
<script>
setTimeout(
function() {
location.reload();
}, 5000
);
</script>
</body
</html>

12
views/index.hbs Normal file
View File

@ -0,0 +1,12 @@
{{!< default}}
<h1>Select a monitor device:</h1>
<ul>
{{#each cores}}
<li>
<a href="https://particle.kaplon.us/core/{{this.coreName}}">
{{this.coreName}} ({{this.coreId}}), {{this.locationDesc}}
</a>
</li>
{{/each}}
</ul>