forked from samr28/AgendaBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
96 lines (83 loc) · 3.18 KB
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var redis = require('redis');
var client = redis.createClient();
var http = require('http');
var async = require('async');
var l = require('@samr28/log');
const config= require("./config");
l.on();
l.setColors({
web: "magenta"
});
var data;
var agenda;
var html;
http.createServer(function (req, res) {
async.series([
getData,
buildHtml,
function(cb) {
displayPage(res, cb);
}
]);
}).listen(81);
function buildHtml(cb) {
var header = '';
var body = '';
header += '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">';
body += '<nav class="navbar navbar-light bg-light"> <span class="navbar-brand mb-0 h1">Agenda</span> </nav>';
body += '<div class="container">';
for (var i = 1; i <= data.length; i++) {
let color;
if (data[i-1].color === 'good') {
color = 'success';
} else {
color = data[i-1].color;
}
body += '<div class="alert alert-' + color + ' alert-dismissible fade show" role="alert" style="overflow:auto;">';
if(config.DISPLAY_INDEX){
body += i + '. ';
}
body += data[i - 1].value;
if (config.DISPLAY_DUE && data[i - 1].dueDate) {
body += "<span class='text-right float-right' style='margin-right:2rem'>DUE: " + data[i - 1].dueDate.month + "/" + data[i - 1].dueDate.day + "</span>";
body += '<br>';
}
if (config.DISPLAY_ASSIGNED && data[i - 1].assignee) {
body += "<span class='text-right float-right' style='margin-right:2rem'>Assigned: " + data[i - 1].assignee + "</span>";
}
body += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
body += '</div>';
}
body += "<p style='margin-top:1em;'> New Business?</p>";
body += '</div>';
body += `<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>`;
html = '<!DOCTYPE html><html><header>' + header + '</header><body>' + body + '</body></html>';
return cb();
}
function displayPage(res, cb) {
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-Length': html.length,
'Expires': new Date().toUTCString()
});
res.end(html);
}
function getData(cb) {
client.get('hubot:storage', function(err, reply) {
data = JSON.parse(reply);
data = data._private.agenda;
return cb();
});
}
client.on('connect', function() {
l.log('Connected to Redis!', "web");
});
client.exists('hubot:storage', function(err, reply) {
if (reply === 1) {
l.log('Found Data', "web");
} else {
l.log('No Data Found', "web");
}
});