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.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);
 | 
			
		||||
    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){
 | 
			
		||||
        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){
 | 
			
		||||
    //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('core', {alerts: rows}, function(err, html) {
 | 
			
		||||
            res.send(html);
 | 
			
		||||
        });
 | 
			
		||||
    var coreId = req.params.id;
 | 
			
		||||
    console.log("GET /core/" + coreId + ", " + JSON.stringify(d, 4));
 | 
			
		||||
    db.all("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;", function(err, rows){
 | 
			
		||||
        if(err !== null) {
 | 
			
		||||
            console.log(err);
 | 
			
		||||
        } 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;
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -1,30 +1,27 @@
 | 
			
		||||
<!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" />
 | 
			
		||||
    <title>Alert Monitor</title>
 | 
			
		||||
 | 
			
		||||
    <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"}}">
 | 
			
		||||
    <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>
 | 
			
		||||
<body class="{{body_class}}">
 | 
			
		||||
<body>
 | 
			
		||||
 | 
			
		||||
    {{! Everything else gets inserted here }}
 | 
			
		||||
    {{{body}}}
 | 
			
		||||
 | 
			
		||||
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
<ul>
 | 
			
		||||
    {{#each cores}}
 | 
			
		||||
        <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}}
 | 
			
		||||
            </a>
 | 
			
		||||
        </li>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user