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

@ -14,6 +14,9 @@
<!-- <body ng&#45;cloak class="ng&#45;cloak"> -->
<body >
<ion-nav-bar class="bar-stable">
</ion-nav-bar>
<!-- <div notifications="right top"></div> -->
<!-- ng&#45;class="{ 'main': index.hasProfile }" -->
<!-- <ion&#45;nav&#45;bar class="bar&#45;positive"> -->

View file

@ -1,29 +1,28 @@
<ion-view view-title="Home">
<ion-view cache-view="false">
<ion-nav-title>Send</ion-nav-title>
<ion-content class="send" ng-controller="tabSendController" ng-init="init()">
<h2>Recipient</h2>
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" placeholder="Search" ng-model="search" ng-change="findContact()">
</label>
<h2>Contacts</h2>
<h2>Contacts & Wallets</h2>
<div class="list card">
<a class="item item-icon-left" ng-repeat="item in list" ng-click="openInputAmountModal(item)">
<div ng-show="!item.id">
<i class="icon ion-ios-person-outline"></i>
{{item.label}}
</div>
<ul class="pr">
<li class="item item-icon-left" ng-repeat="item in list" ng-click="openInputAmountModal(item)">
<div ng-show="item.id">
<i class="icon icon-wallet size-21" ng-style="{'color':item.color}"></i>
{{item.name || item.alias}}
<span class="item-note">
{{item.balance || '123,999.91 bits'}}
</span>
</div>
</a>
<i ng-show="item.isWallet" class="icon ion-briefcase size-21" ng-style="{'color':item.color}"></i>
<i ng-show="!item.isWallet" class="icon ion-ios-person-outline"></i>
{{item.label}}
</li>
</ul>
</div>
</ion-content>
</ion-view>

View file

@ -1,7 +1,5 @@
<ion-view ng-controller="tabSettingsController" cache-view="false" ng-init="init()">
<ion-nav-bar class="bar-stable">
<ion-nav-title>Global Settings</ion-nav-title>
</ion-nav-bar>
<ion-content class="has-header">
<div class="item item-divider">
</div>

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));
});
});
};