Commit f55010072fc163bece5c8953855a277e4d18473a

Authored by Adhidarma Hadiwinoto
1 parent ee4b9bcb3d
Exists in master

logo diatas, close #1

Showing 2 changed files with 7 additions and 1 deletions Inline Diff

1 var iniparser = require('iniparser'); 1 var iniparser = require('iniparser');
2 var config = iniparser.parseSync('./config.ini'); 2 var config = iniparser.parseSync('./config.ini');
3 var whiskers = require('whiskers'); 3 var whiskers = require('whiskers');
4 4
5 var numeral = require('numeral'); 5 var numeral = require('numeral');
6 6
7 var Sync = require('sync'); 7 var Sync = require('sync');
8 var redis = require('redis').createClient(config.globals.redis_port, config.globals.redis_host); 8 var redis = require('redis').createClient(config.globals.redis_port, config.globals.redis_host);
9 9
10 var express = require('express'); 10 var express = require('express');
11 var app = express(); 11 var app = express();
12 12
13 var suppliers = config.globals.suppliers.split(','); 13 var suppliers = config.globals.suppliers.split(',');
14 14
15 app.engine('.html', whiskers.__express); 15 app.engine('.html', whiskers.__express);
16 app.set('views', __dirname+'/views'); 16 app.set('views', __dirname+'/views');
17 17
18 function getBalances(suppliers, callback) { 18 function getBalances(suppliers, callback) {
19 19
20 var kw = []; 20 var kw = [];
21 var count = suppliers.length; 21 var count = suppliers.length;
22 22
23 for (var i=0; i < count; i++) { 23 for (var i=0; i < count; i++) {
24 var supplier = suppliers[i]; 24 var supplier = suppliers[i];
25 kw.push('balance.gw:' + supplier); 25 kw.push('balance.gw:' + supplier);
26 } 26 }
27 27
28 redis.mget(kw, function(err, res) { 28 redis.mget(kw, function(err, res) {
29 var balances = []; 29 var balances = [];
30 30
31 for (var i=0; i<count; i++) { 31 for (var i=0; i<count; i++) {
32 balances.push({ 32 balances.push({
33 title: suppliers[i], 33 title: suppliers[i],
34 balance: numeral(res[i]).format('0,0') 34 balance: numeral(res[i]).format('0,0')
35 }); 35 });
36 } 36 }
37 37
38 callback(null, balances); 38 callback(null, balances);
39 }); 39 });
40 } 40 }
41 41
42 app.get('/', function(req, res) { 42 app.get('/', function(req, res) {
43 43
44 Sync(function() { 44 Sync(function() {
45 45
46 var balances = getBalances.sync(null, suppliers); 46 var balances = getBalances.sync(null, suppliers);
47 //balances = getBalances(suppliers); 47 //balances = getBalances(suppliers);
48 48
49 res.render('basic_template.html', { 49 res.render('basic_template.html', {
50 // logo, berdasar isu #1
51 logo: 'http://reload97.com/sites/default/files/web-reload97.png',
50 title: 'Supplier Balances', 52 title: 'Supplier Balances',
51 balances: balances, 53 balances: balances,
52 timestamp: new Date(), 54 timestamp: new Date(),
53 }); 55 });
54 }) 56 })
55 57
56 }); 58 });
57 59
58 var server = app.listen(config.globals.http_port, function () { 60 var server = app.listen(config.globals.http_port, function () {
59 var host = server.address().address; 61 var host = server.address().address;
60 var port = server.address().port; 62 var port = server.address().port;
61 63
62 console.log('Example app listening at http://%s:%s', host, port); 64 console.log('Example app listening at http://%s:%s', host, port);
63 }); 65 });
64 66
views/basic_template.html
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html lang="en"> 2 <html lang="en">
3 <head> 3 <head>
4 <meta charset="utf-8"> 4 <meta charset="utf-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 <meta name="viewport" content="width=device-width, initial-scale=1"> 6 <meta name="viewport" content="width=device-width, initial-scale=1">
7 <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 7 <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
8 <title>{title}</title> 8 <title>{title}</title>
9 9
10 <!-- Latest compiled and minified CSS --> 10 <!-- Latest compiled and minified CSS -->
11 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 11 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
12 12
13 <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 13 <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
14 <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 14 <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
15 <!--[if lt IE 9]> 15 <!--[if lt IE 9]>
16 <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 16 <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
17 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 17 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
18 <![endif]--> 18 <![endif]-->
19 </head> 19 </head>
20 <body> 20 <body>
21 <h1>{title}</h1> 21 <h1>
22 <img src="{logo}">
23 <br/><br/>
24 {title}
25 </h1>
22 26
23 <table class="table table-hover table-striped"> 27 <table class="table table-hover table-striped">
24 {for balance in balances} 28 {for balance in balances}
25 <tr> 29 <tr>
26 <td>{balance.title}</td> 30 <td>{balance.title}</td>
27 <td> 31 <td>
28 <div class="pull-right"> 32 <div class="pull-right">
29 {balance.balance} 33 {balance.balance}
30 </div> 34 </div>
31 </td> 35 </td>
32 </tr> 36 </tr>
33 {/for} 37 {/for}
34 </table> 38 </table>
35 39
36 Generated on {timestamp} 40 Generated on {timestamp}
37 41
38 42
39 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 43 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
40 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 44 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
41 <!-- Latest compiled and minified JavaScript --> 45 <!-- Latest compiled and minified JavaScript -->
42 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 46 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
43 </body> 47 </body>
44 </html> 48 </html>
45 49