From 4c1d8790a8daf158b0f4278ab2fe0eaa12f183f3 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <me@adhisimon.org>
Date: Tue, 30 Aug 2016 16:53:13 +0700
Subject: [PATCH] json.stringify

---
 index.js         | 29 +++++++++++++++--------------
 views/index.json |  4 +---
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/index.js b/index.js
index a16c576..9a89fba 100644
--- a/index.js
+++ b/index.js
@@ -42,52 +42,52 @@ app.engine('.json', whiskers.__express);
 app.set('views', __dirname+'/views');
 
 function getBalances(suppliers, thousands, callback) {
-    
+
     var kw = [];
     var count = suppliers.length;
-    
+
     for (var i=0; i < count; i++) {
         var supplier = suppliers[i];
         kw.push('balance.gw:' + supplier);
     }
-    
+
     redis.mget(kw, function(err, res) {
         var balances = [];
-        
+
         for (var i=0; i<count; i++) {
             var value = res[i];
             if (!value) {
                 value = 0;
             }
-            
+
             if (thousands) {
                 value = numeral(res[i]).format('0,0');
             }
-            
+
             var url = null;
             var supplier = suppliers[i];
-            
+
             if (config.expresso_urls[supplier]) {
                 url = config.expresso_urls[supplier];
             }
-            
+
             balances.push({
                 title: supplier,
                 balance: value,
                 url: url,
             });
         }
-        
+
         callback(null, balances);
     });
 }
 
 app.get('/', function(req, res) {
-    
+
     Sync(function() {
         var template_file;
         var thousands = true;
-        
+
         res.format({
             html: function() {
                 template_file = 'index.html';
@@ -102,16 +102,17 @@ app.get('/', function(req, res) {
             'default': function() {
                 template_file = 'index.html';
             },
-            
+
         });
-        
+
         var balances = getBalances.sync(null, suppliers, thousands);
         //balances = getBalances(suppliers);
-        
+
         res.render(template_file, {
             logo: 'http://reload97.com/sites/default/files/web-reload97.png',
             title: 'Supplier Balances',
             balances: balances,
+            json_string: JSON.stringify(balances),
             timestamp: new Date(),
         });
     })
diff --git a/views/index.json b/views/index.json
index 1bc3c38..dca3c85 100644
--- a/views/index.json
+++ b/views/index.json
@@ -1,3 +1 @@
-{
-{for balance in balances}"{balance.title}": {balance.balance},
-{/for}}
+{balances}
-- 
1.9.0