From 39a2c801334f8a43a356928ac1e87c7644add7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 13 Dec 2016 16:48:22 -0300 Subject: [PATCH] search box for currency --- src/js/controllers/preferencesAltCurrency.js | 36 ++++++++++++++------ www/views/preferencesAltCurrency.html | 7 ++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/preferencesAltCurrency.js b/src/js/controllers/preferencesAltCurrency.js index 421e2ad16..5f5b83a6e 100644 --- a/src/js/controllers/preferencesAltCurrency.js +++ b/src/js/controllers/preferencesAltCurrency.js @@ -12,23 +12,36 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl isoCode: 'BTC' }]; - var config = configService.getSync(); - $scope.currentCurrency = config.wallet.settings.alternativeIsoCode; + function init() { + var config = configService.getSync(); + $scope.currentCurrency = config.wallet.settings.alternativeIsoCode; - rateService.whenAvailable(function() { - storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) { + rateService.whenAvailable(function() { + storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) { - $scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || []; + $scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || []; - var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); - var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode'); + var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); + var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode'); - completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { - return idx[c.isoCode] || idx2[c.isoCode]; + $scope.completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { + return idx[c.isoCode] || idx2[c.isoCode]; + }); + $scope.altCurrencyList = $scope.completeAlternativeList; }); - $scope.altCurrencyList = completeAlternativeList; }); - }); + } + + $scope.findCurrency = function(search) { + if (!search) init(); + $scope.altCurrencyList = lodash.filter($scope.completeAlternativeList, function(item) { + var val = item.name; + return lodash.includes(val.toLowerCase(), search.toLowerCase()); + }); + $timeout(function() { + $scope.$apply(); + }); + }; $scope.save = function(newAltCurrency) { var opts = { @@ -58,4 +71,5 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {}); }; + init(); }); diff --git a/www/views/preferencesAltCurrency.html b/www/views/preferencesAltCurrency.html index 322f58402..dc51757a2 100644 --- a/www/views/preferencesAltCurrency.html +++ b/www/views/preferencesAltCurrency.html @@ -7,6 +7,13 @@ +
+ +
{{lastUsedAltCurrency.name}}