diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js index 125666c4b4d96b6274526d3a3b144d555374461b..5ff0912cae3c569eb6087038211971ae0b35ce25 100644 --- a/www/js/controllers/wot-controllers.js +++ b/www/js/controllers/wot-controllers.js @@ -124,7 +124,7 @@ angular.module('cesium.wot.controllers', ['cesium.services']) ; -function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $location, +function WotLookupController($scope, $state, $q, $timeout, $focus, $ionicPopover, $location, UIUtils, csConfig, csCurrency, csSettings, Device, BMA, csWallet, csWot) { 'ngInject'; @@ -274,16 +274,17 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $l $scope.doRefreshLocationHref(); } - return csWot.newcomers(offset, size) - .then(function(idties){ + return csWot.newcomers(offset, size) + .then(function(res){ if ($scope.search.type != 'newcomers') return false; // could have change - $scope.doDisplayResult(idties, offset, size); + $scope.doDisplayResult(res && res.hits, offset, size, res && res.total); return true; }) .catch(function(err) { $scope.search.loading = false; $scope.search.results = (offset > 0) ? $scope.search.results : []; $scope.search.hasMore = false; + $scope.search.total = undefined; UIUtils.onError('ERROR.LOAD_NEWCOMERS_FAILED')(err); }); }; @@ -307,9 +308,9 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $l } return searchFunction(offset, size) - .then(function(idties){ + .then(function(res){ if ($scope.search.type != 'pending') return false; // could have change - $scope.doDisplayResult(idties, offset, size); + $scope.doDisplayResult(res && res.hits, offset, size, res && res.total); // Always disable "more" on initphase $scope.search.hasMore = !csCurrency.data.initPhase && $scope.search.hasMore; return true; @@ -317,6 +318,7 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $l .catch(function(err) { $scope.search.loading = false; $scope.search.results = (offset > 0) ? $scope.search.results : []; + $scope.search.total = undefined; $scope.search.hasMore = false; UIUtils.onError('ERROR.LOAD_PENDING_FAILED')(err); }); @@ -451,7 +453,7 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $l }); }; - $scope.doDisplayResult = function(res, offset, size) { + $scope.doDisplayResult = function(res, offset, size, total) { res = res || []; // pre-check result if already in selection @@ -470,6 +472,7 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $l else { $scope.search.results = $scope.search.results.concat(res); } + $scope.search.total = angular.isDefined(total) ? total : undefined; $scope.search.loading = false; $scope.search.hasMore = $scope.search.results.length >= offset + size; diff --git a/www/js/services/wot-services.js b/www/js/services/wot-services.js index e1f8be17e592e445d3e984ebf3081f6b4562b5ad..80bb313cc0281a29db3fd272be8c0cab14e673cf 100644 --- a/www/js/services/wot-services.js +++ b/www/js/services/wot-services.js @@ -694,8 +694,16 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c getNewcomers = function(offset, size) { offset = offset || 0; size = size || 20; - return BMA.blockchain.stats.newcomers() + var total; + return $q.all([ + csCurrency.blockchain.current(true) + .then(function(block) { + total = block.membersCount; + }), + BMA.blockchain.stats.newcomers() + ]) .then(function(res) { + res = res[1]; if (!res.result.blocks || !res.result.blocks.length) { return null; } @@ -712,7 +720,14 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c // Extension point return extendAll(idties, 'pubkey', true/*skipAddUid*/); - }); + }) + .then(function(idties) { + return { + hits: idties, + total: total + }; + }) + ; }, @@ -771,6 +786,7 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c getPending = function(offset, size) { offset = offset || 0; size = size || 20; + var now = new Date().getTime(); return $q.all([ BMA.wot.member.uids(), BMA.wot.member.pending() @@ -817,7 +833,11 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c } } }); - var idties = _sortAndSliceIdentities(_.values(idtiesByPubkey), offset, size); + + var idties = _.values(idtiesByPubkey); + var total = idties.length; // get total BEFORE slice + + idties = _sortAndSliceIdentities(idties, offset, size); var blocks = idties.reduce(function(res, aidty) { return res.concat(aidty.block); }, []); @@ -842,7 +862,11 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c extendAll(idties, 'pubkey', true/*skipAddUid*/) ]) .then(function() { - return idties; + console.debug("[ES] [wot] Loaded {0}/{1} pending identities in {2} ms".format(idties && idties.length || 0, total, new Date().getTime() - now)); + return { + hits: idties, + total: total + }; }); }); }, @@ -851,10 +875,14 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c var letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','u','v','w','x','y','z']; return getAllRecursive(letters, 0, BMA.constants.LIMIT_REQUEST_COUNT) .then(function(idties) { - return extendAll(idties, 'pubkey', true/*skipAddUid*/) - .then(function() { - return _addUniqueIds(idties); - }); + return extendAll(idties, 'pubkey', true/*skipAddUid*/); + }) + .then(_addUniqueIds) + .then(function() { + return { + hits: idties, + total: idties.length + }; }); }, diff --git a/www/templates/wot/lookup.html b/www/templates/wot/lookup.html index a4ffcfbd7ea9398dde2a939d609905ce0b67335e..01d2e21616aa8933fd5d002fc29f6f785288fffd 100644 --- a/www/templates/wot/lookup.html +++ b/www/templates/wot/lookup.html @@ -15,6 +15,6 @@ </ion-nav-buttons> <ion-content class="padding no-padding-xs" scroll="true"> - <ng-include src="'templates/wot/lookup_form.html'"/> + <ng-include src="'templates/wot/lookup_form.html'"></ng-include> </ion-content> </ion-view> diff --git a/www/templates/wot/lookup_form.html b/www/templates/wot/lookup_form.html index 2f0f12786bd8fe4dea0f6205ed8fcd78682c3c03..960dd2cb3849f0503af85a396714207d2b8f3f89 100644 --- a/www/templates/wot/lookup_form.html +++ b/www/templates/wot/lookup_form.html @@ -40,18 +40,16 @@ <div class="padding-top padding-xs" style="display: block; height: 60px;" ng-class="::{'hidden-xs': !showResultLabel}"> <div class="pull-left" ng-if="!search.loading && showResultLabel"> - <h4 - ng-if="search.type=='newcomers'" translate> + <h4 ng-if="search.type=='newcomers'" translate> WOT.LOOKUP.NEWCOMERS </h4> - <h4 - ng-if="search.type=='pending'" translate> + <h4 ng-if="search.type=='pending'" translate> WOT.LOOKUP.PENDING </h4> - <h4 - ng-if="search.type=='text'" translate> + <h4 ng-if="search.type=='text'" translate> COMMON.RESULTS_LIST </h4> + <h5 ng-if="search.total" class="dark">{{'COMMON.RESULTS_COUNT'|translate:{count: search.total} }}</h5> </div> <div class="pull-right hidden-xs hidden-sm">