Skip to content
Snippets Groups Projects
Commit 17bac469 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] Wot lookup: add results count

parent 789b48ef
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
};
});
},
......
......@@ -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>
......@@ -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">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment