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 ng&#45;cloak class="ng&#45;cloak"> -->
<body > <body >
<ion-nav-bar class="bar-stable">
</ion-nav-bar>
<!-- <div notifications="right top"></div> --> <!-- <div notifications="right top"></div> -->
<!-- ng&#45;class="{ 'main': index.hasProfile }" --> <!-- ng&#45;class="{ 'main': index.hasProfile }" -->
<!-- <ion&#45;nav&#45;bar class="bar&#45;positive"> --> <!-- <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()"> <ion-content class="send" ng-controller="tabSendController" ng-init="init()">
<h2>Recipient</h2> <h2>Recipient</h2>
<label class="item item-input"> <label class="item item-input">
<i class="icon ion-search placeholder-icon"></i> <i class="icon ion-search placeholder-icon"></i>
<input type="text" placeholder="Search" ng-model="search" ng-change="findContact()"> <input type="text" placeholder="Search" ng-model="search" ng-change="findContact()">
</label> </label>
<h2>Contacts</h2> <h2>Contacts & Wallets</h2>
<div class="list card"> <div class="list card">
<a class="item item-icon-left" ng-repeat="item in list" ng-click="openInputAmountModal(item)"> <ul class="pr">
<div ng-show="!item.id"> <li class="item item-icon-left" ng-repeat="item in list" ng-click="openInputAmountModal(item)">
<i class="icon ion-ios-person-outline"></i>
{{item.label}}
</div>
<div ng-show="item.id"> <i ng-show="item.isWallet" class="icon ion-briefcase size-21" ng-style="{'color':item.color}"></i>
<i class="icon icon-wallet size-21" ng-style="{'color':item.color}"></i> <i ng-show="!item.isWallet" class="icon ion-ios-person-outline"></i>
{{item.name || item.alias}} {{item.label}}
<span class="item-note"> </li>
{{item.balance || '123,999.91 bits'}} </ul>
</span>
</div>
</a>
</div> </div>
</ion-content> </ion-content>
</ion-view> </ion-view>

View file

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

View file

@ -1,57 +1,55 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, addressbookService, profileService, configService, lodash) { angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, configService, lodash) {
var completeList;
var originalList = [];
$scope.search = '';
$scope.init = function() { $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) { addressbookService.list(function(err, ab) {
if (err) $log.error(err); if (err) $log.error(err);
// $scope.contactList = lodash.isEmpty(ab) ? null : ab; var contacts = [];
$scope.contactList = [{ lodash.each(ab, function(v, k) {
label: 'Javier', contacts.push({
address: '123456' label: k,
}, { address: v,
label: 'Javier 2', });
address: '654321' });
}, {
label: 'Javier 3', originalList = originalList.concat(contacts);
address: '7891011' $scope.list = lodash.clone(originalList);
}, {
label: 'Javier 4',
address: '1101987'
}];
}); });
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() { $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 result = lodash.filter($scope.list, function(item) {
var val = item.label || item.alias || item.name; var val = item.label || item.alias || item.name;
return lodash.includes(val.toLowerCase(), $scope.search.toLowerCase()); return lodash.includes(val.toLowerCase(), $scope.search.toLowerCase());
}); });
if (lodash.isEmpty(result) || lodash.isEmpty($scope.search)) {
$scope.list = completeList;
return;
}
$scope.list = result; $scope.list = result;
}; };

View file

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