From 54c28a395db853c601d3592c967f322c7f09e1d4 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 12 Nov 2012 23:25:09 -0800 Subject: Making progress on transactions report --- app.coffee | 20 ++++++++++++++------ public/js/report.coffee | 29 ++++++++++++++++------------- views/report.html | 8 +------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/app.coffee b/app.coffee index d18ab470..cdc8c313 100644 --- a/app.coffee +++ b/app.coffee @@ -20,8 +20,8 @@ app.get('/', (req, res) -> res.render('index', js: (-> global.js), css: (-> global.css)) ) -app.get('/report', (req, res) -> - res.render('report', js: (-> global.js), css: (-> global.css)) +app.get('/:user/report', (req, res) -> + res.render('report', user: req.params.user, js: (-> global.js), css: (-> global.css)) ) app.get('/:user.json', (req, res) -> @@ -35,16 +35,24 @@ app.get('/:user.json', (req, res) -> app.get('/:user/transactions', (req, res) -> db = require("redis").createClient() user = req.params.user + r = 'transactions': [] db.lrange("#{user}:transactions", 0, -1, (err, transactions) -> - for i in transactions - db.hgetall("#{user}:transactions:#{i}", (err, t) -> - res.write(JSON.stringify(t)) + process = (err, t) -> + r.transactions.push t + + if i >= transactions.length + res.write(JSON.stringify(r)) res.end() - ) + else + db.hgetall("#{user}:transactions:#{transactions[i++]}", process) + + i = 0 + db.hgetall("#{user}:transactions:#{transactions[i++]}", process) ) ) + app.get('/ticker', (req, res) -> symbol = req.params.symbol symbol or= 'virtexCAD' diff --git a/public/js/report.coffee b/public/js/report.coffee index 650e25b4..e045454e 100644 --- a/public/js/report.coffee +++ b/public/js/report.coffee @@ -1,29 +1,32 @@ +#= require jquery-1.8.2.min.js +#= require jquery-ui-1.9.0.custom.min.js + $(-> $('.date').datepicker() $.getJSON('transactions', (data) -> $.each(data.transactions, -> - keys = Object.keys(this) - transaction = this - - $.each(keys, (i,v) -> - $('tbody tr:last td:eq(' + i + ')').html(transaction[v]) - }) - - $('tbody:last').append($('tbody tr:last').clone()) - }) - $('tbody tr:last').remove() + $('tbody').append(""" + + #{this.date} + #{this.address} + #{this.exchange} + #{this.received} + #{(this.received * this.exchange).toFixed(2)} + + """) + ) btc = 0 $('td:nth-child(4)').each(-> btc += parseFloat($(this).html()) - }) + ) $('#btc').html(btc) cad = 0 $('td:nth-child(5)').each(-> cad += parseFloat($(this).html()) - }) + ) $('#cad').html(cad) - }) + ) ) diff --git a/views/report.html b/views/report.html index 762ce7d9..70fbe81c 100644 --- a/views/report.html +++ b/views/report.html @@ -11,6 +11,7 @@

Transactions Report

+ From: To: @@ -25,13 +26,6 @@ - - - - - - - -- cgit v1.2.3