From aa71a34decda700398656c2b1b58bf2d122a0d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Mon, 22 Feb 2016 11:29:27 -0300 Subject: [PATCH] show more in search box --- public/views/walletHome.html | 16 +++++++++---- src/js/controllers/index.js | 46 +++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 497c10f45..64f8f257d 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -280,11 +280,17 @@
- Show more ({{index.completeHistory.length - index.txHistory.length}}) - - + ng-show="index.historyShowMore && !index.isSearching" + ng-click="index.showMore()" > + {{index.completeHistory.length - index.txHistory.length}}more + + + + {{index.result.length - index.txHistoryToList.length}} more + +
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 146027147..3f1a19420 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -896,8 +896,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.completeHistory = newHistory; self.setCompactTxHistory(); self.txHistory = newHistory.slice(0, self.historyShowLimit); - self.historyShowMore = newHistory.length > self.historyShowLimit; self.txHistoryToList = self.txHistory; + self.historyShowMore = newHistory.length > self.historyShowLimit; } return storageService.setTxHistory(JSON.stringify(newHistory), walletId, function() { @@ -910,27 +910,36 @@ angular.module('copayApp.controllers').controller('indexController', function($r } self.showMore = function() { - $timeout(function() { - self.txHistory = self.completeHistory.slice(0, self.nextTxHistory); - self.txHistoryToList = self.txHistory; - $log.debug('Total txs: ', self.txHistory.length + '/' + self.completeHistory.length); - self.nextTxHistory += self.historyShowMoreLimit; - if (self.txHistory.length >= self.completeHistory.length) - self.historyShowMore = false; - }, 100); + if (self.isSearching) { + $timeout(function() { + self.txHistoryToList = self.result.slice(0, self.nextTxHistory); + $log.debug('Total txs: ', self.txHistoryToList.length + '/' + self.result.length); + self.nextTxHistory += self.historyShowMoreLimit; + if (self.txHistoryToList.length >= self.result.length) + self.historyShowMore = false; + }, 100); + } else { + $timeout(function() { + self.txHistory = self.completeHistory.slice(0, self.nextTxHistory); + self.txHistoryToList = self.txHistory; + $log.debug('Total txs: ', self.txHistory.length + '/' + self.completeHistory.length); + self.nextTxHistory += self.historyShowMoreLimit; + if (self.txHistory.length >= self.completeHistory.length) + self.historyShowMore = false; + }, 100); + } }; self.startSearch = function(){ self.isSearching = true; self.txHistoryToList = []; - if(self.historyShowShowAll) self.txHistory = self.completeHistory; + self.historyShowMore = false; } self.cancelSearch = function(){ self.isSearching = false; - if(self.txHistory.length > self.historyShowLimit) - self.txHistoryToList = self.txHistory.slice(0, self.historyShowLimit); - else self.txHistoryToList = self.txHistory; + self.txHistoryToList = self.completeHistory.slice(0, self.historyShowLimit); + self.historyShowMore = self.completeHistory.length > self.historyShowLimit; } self.updateSearchInput = function(search){ @@ -943,7 +952,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.throttleSearch = lodash.throttle(function() { function filter(search) { - var result = []; + self.result = []; function formatDate(date) { var day = ('0' + date.getDate()).slice(-2).toString(); var month = ('0' + (date.getMonth() + 1)).slice(-2).toString(); @@ -953,7 +962,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r if (lodash.isEmpty(search)) return; - result = lodash.filter(self.txHistory, function(tx) { + self.result = lodash.filter(self.completeHistory, function(tx) { return lodash.includes(tx.amountStr, search) || lodash.includes(tx.message, search) || lodash.includes(self.addressbook ? self.addressbook[tx.addressTo] : null, search) || @@ -961,10 +970,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r lodash.isEqual(formatDate(new Date(tx.time * 1000)), search); }); - return result; + if (self.result.length > self.historyShowLimit) self.historyShowMore = true; + else self.historyShowMore = false; + + return self.result; }; - self.txHistoryToList = filter(self.search); + self.txHistoryToList = filter(self.search).slice(0, self.historyShowLimit); if (isCordova) window.plugins.toast.showShortBottom(gettextCatalog.getString('Matches: ' + self.txHistoryToList.length));