Functional templates to list devices, select device, load device template
This commit is contained in:
		
							parent
							
								
									61df30ae84
								
							
						
					
					
						commit
						b11667581d
					
				
							
								
								
									
										39
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								server.js
									
									
									
									
									
								
							@ -56,25 +56,40 @@ app.set('view engine', 'hbs');
 | 
				
			|||||||
app.set('views', __dirname + '/views');
 | 
					app.set('views', __dirname + '/views');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.get('/', function(req, res){
 | 
					app.get('/', function(req, res){
 | 
				
			||||||
    db.all("SELECT coreId, coreName, published_at FROM Alerts GROUP BY coreId, coreName, published_at;", function(err, rows){
 | 
					    var d = new Date();
 | 
				
			||||||
    //console.log(rows);
 | 
					    console.log("GET /, " + JSON.stringify(d, 4));
 | 
				
			||||||
    res.render('index', {cores: rows}, function(err, html) {
 | 
					    db.all("SELECT coreId, coreName, locationDesc FROM Alerts GROUP BY coreId, coreName, locationDesc;", function(err, rows){
 | 
				
			||||||
        res.send(html);
 | 
					        if(err !== null) {
 | 
				
			||||||
 | 
					            console.log(err);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            //console.log(rows);
 | 
				
			||||||
 | 
					            res.render('index', {cores: rows}, function(err, html) {
 | 
				
			||||||
 | 
					                if(err !== null) {
 | 
				
			||||||
 | 
					                    console.log(err);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    res.send(html);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// not sure if this ':id' notaction is correct
 | 
					 | 
				
			||||||
app.get('/core/:id', function(req, res){
 | 
					app.get('/core/:id', function(req, res){
 | 
				
			||||||
    //res.sendFile("/usr/src/app/index.html");
 | 
					    //res.sendFile("/usr/src/app/index.html");
 | 
				
			||||||
    //fs.createReadStream('./log.log').pipe(res);
 | 
					    //fs.createReadStream('./log.log').pipe(res);
 | 
				
			||||||
    var d = new Date();
 | 
					    var d = new Date();
 | 
				
			||||||
    console.log("GET request at, " + JSON.stringify(d, 4));
 | 
					    var coreId = req.params.id;
 | 
				
			||||||
    // add WHERE clause w/core ID value from URL
 | 
					    console.log("GET /core/" + coreId + ", " + JSON.stringify(d, 4));
 | 
				
			||||||
    db.all("SELECT coreId, published_at FROM Alerts ORDER BY published_at DESC LIMIT 30;", function(err, rows){
 | 
					    db.all("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;", function(err, rows){
 | 
				
			||||||
        //console.log(rows);
 | 
					        if(err !== null) {
 | 
				
			||||||
        res.render('core', {alerts: rows}, function(err, html) {
 | 
					            console.log(err);
 | 
				
			||||||
            res.send(html);
 | 
					        } else {
 | 
				
			||||||
        });
 | 
					            console.log("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;");
 | 
				
			||||||
 | 
					            console.log(rows);
 | 
				
			||||||
 | 
					            res.render('core', {alerts: rows}, function(err, html) {
 | 
				
			||||||
 | 
					                res.send(html);
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    //res.send;
 | 
					    //res.send;
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -1,30 +1,27 @@
 | 
				
			|||||||
<!DOCTYPE html>
 | 
					<!DOCTYPE html>
 | 
				
			||||||
<html>
 | 
					<html>
 | 
				
			||||||
<head>
 | 
					<head>
 | 
				
			||||||
    {{! Document Settings }}
 | 
					 | 
				
			||||||
    <meta charset="utf-8" />
 | 
					    <meta charset="utf-8" />
 | 
				
			||||||
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 | 
					    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {{! Page Meta }}
 | 
					    <title>Alert Monitor</title>
 | 
				
			||||||
    <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="HandheldFriendly" content="True" />
 | 
				
			||||||
    <meta name="MobileOptimized" content="320" />
 | 
					    <meta name="MobileOptimized" content="320" />
 | 
				
			||||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <link rel="shortcut icon" href="{{asset "favicon.ico"}}">
 | 
					    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Optional theme -->
 | 
				
			||||||
 | 
					    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {{! Styles'n'Scripts }}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {{! Ghost outputs important style and meta data with this tag }}
 | 
					 | 
				
			||||||
    {{ghost_head}}
 | 
					 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body class="{{body_class}}">
 | 
					<body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {{! Everything else gets inserted here }}
 | 
					    {{! Everything else gets inserted here }}
 | 
				
			||||||
    {{{body}}}
 | 
					    {{{body}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,7 @@
 | 
				
			|||||||
<ul>
 | 
					<ul>
 | 
				
			||||||
    {{#each cores}}
 | 
					    {{#each cores}}
 | 
				
			||||||
        <li>
 | 
					        <li>
 | 
				
			||||||
            <a href="https://particle.kaplon.us/core/{{this.coreName}}">
 | 
					            <a href="https://particle.kaplon.us/core/{{this.coreId}}">
 | 
				
			||||||
                {{this.coreName}} ({{this.coreId}}), {{this.locationDesc}}
 | 
					                {{this.coreName}} ({{this.coreId}}), {{this.locationDesc}}
 | 
				
			||||||
            </a>
 | 
					            </a>
 | 
				
			||||||
        </li>
 | 
					        </li>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user