From cedffc230bbf641877184b7288c29bba49acaf32 Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Fri, 16 May 2014 15:34:27 -0700 Subject: [PATCH] Group inputs by address --- index.html | 2 +- js/filters.js | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 2daca941d..1782059e2 100644 --- a/index.html +++ b/index.html @@ -468,7 +468,7 @@
-
+

{{vin.addr}}

{{vin.value}}
diff --git a/js/filters.js b/js/filters.js index 044ddbdf8..e726e280b 100644 --- a/js/filters.js +++ b/js/filters.js @@ -2,7 +2,21 @@ angular.module('copay.filters', []) .filter('amTimeAgo', ['amMoment', function(amMoment) { - return function(input) { - return amMoment.preprocessDate(input).fromNow(); - }; -}]); \ No newline at end of file + return function(input) { + return amMoment.preprocessDate(input).fromNow(); + }; + }]) + .filter('groupByAddress', function() { + return function(inputs) { + function reduce(dic, input) { + if(!dic[input.addr]) dic[input.addr] = 0; + dic[input.addr] += input.value; + return dic; + } + + var dic = inputs.reduce(reduce, {}); + return Object.keys(dic).map(function(key) { + return { addr: key, value: dic[key] }; + }); + }; + }); \ No newline at end of file