fix search

This commit is contained in:
Matias Alejo Garcia 2016-08-15 18:11:36 -03:00
commit fb83bbba34
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
5 changed files with 63 additions and 59 deletions

View file

@ -1,57 +1,55 @@
'use strict';
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, addressbookService, profileService, configService, lodash) {
var completeList;
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, configService, lodash) {
var originalList = [];
$scope.search = '';
$scope.init = function() {
var wallets = profileService.getWallets();
lodash.each(wallets, function(v) {
originalList.push({
color: v.color,
label: v.name,
isWallet: true,
});
});
addressbookService.list(function(err, ab) {
if (err) $log.error(err);
// $scope.contactList = lodash.isEmpty(ab) ? null : ab;
$scope.contactList = [{
label: 'Javier',
address: '123456'
}, {
label: 'Javier 2',
address: '654321'
}, {
label: 'Javier 3',
address: '7891011'
}, {
label: 'Javier 4',
address: '1101987'
}];
var contacts = [];
lodash.each(ab, function(v, k) {
contacts.push({
label: k,
address: v,
});
});
originalList = originalList.concat(contacts);
$scope.list = lodash.clone(originalList);
});
var config = configService.getSync();
config.colorFor = config.colorFor || {};
config.aliasFor = config.aliasFor || {};
var credentials = lodash.filter(profileService.profile.credentials, 'walletName');
var ret = lodash.map(credentials, function(c) {
return {
m: c.m,
n: c.n,
name: config.aliasFor[c.walletId] || c.walletName,
id: c.walletId,
color: config.colorFor[c.walletId] || '#4A90E2',
};
});
$scope.wallets = lodash.sortBy(ret, 'name');
$scope.list = completeList = $scope.contactList.concat($scope.wallets);
};
$scope.findContact = function() {
if (!$scope.search || $scope.search.length<2){
$scope.list = originalList;
$timeout(function() {
$scope.$apply();
},10);
return;
}
var result = lodash.filter($scope.list, function(item) {
var val = item.label || item.alias || item.name;
return lodash.includes(val.toLowerCase(), $scope.search.toLowerCase());
});
if (lodash.isEmpty(result) || lodash.isEmpty($scope.search)) {
$scope.list = completeList;
return;
}
$scope.list = result;
};

View file

@ -1,24 +1,30 @@
'use strict';
angular.module('copayApp.services').factory('addressbookService', function(storageService, profileService) {
angular.module('copayApp.services').factory('addressbookService', function(storageService, profileService, lodash) {
var root = {};
root.getLabel = function(addr, cb) {
var fc = profileService.focusedClient;
storageService.getAddressbook(fc.credentials.network, function(err, ab) {
if (!ab) return cb();
ab = JSON.parse(ab);
if (ab[addr]) return cb(ab[addr]);
else return cb();
});
};
root.list = function(cb) {
var fc = profileService.focusedClient;
storageService.getAddressbook(fc.credentials.network, function(err, ab) {
storageService.getAddressbook('testnet', function(err, ab) {
if (err) return cb('Could not get the Addressbook');
if (ab) ab = JSON.parse(ab);
return cb(err, ab);
ab = ab || {};
storageService.getAddressbook('livenet', function(err, ab2) {
if (ab2) ab2 = JSON.parse(ab2);
ab2 = ab2 || {};
return cb(err, lodash.defaults(ab2,ab));
});
});
};