Skip to content

Commit

Permalink
- WOT: lookup > add newcomers param, to limit list size
Browse files Browse the repository at this point in the history
- WOT: lookup > add registration time
- Currency parameter: link newcomers to wot lookup
- ES: WOT search : do not filter on title, if newcomers request
  • Loading branch information
blavenie committed Sep 16, 2016
1 parent de6c19b commit b09d678
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 50 deletions.
1 change: 1 addition & 0 deletions www/i18n/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"LOOKUP": {
"TITLE": "Registry",
"NEWCOMERS": "Last registrations:",
"REGISTERED": "Registered ",
"BTN_NEWCOMERS": "See last registrations"
},
"MODAL": {
Expand Down
1 change: 1 addition & 0 deletions www/i18n/locale-fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"LOOKUP": {
"TITLE": "Annuaire",
"NEWCOMERS": "Dernières adhésions :",
"REGISTERED": "Inscrit ",
"BTN_NEWCOMERS": "Voir les dernières adhésions"
},
"MODAL": {
Expand Down
32 changes: 18 additions & 14 deletions www/js/controllers/wot-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ angular.module('cesium.wot.controllers', ['cesium.services'])
$stateProvider

.state('app.wot_lookup', {
url: "/wot?q",
url: "/wot?q&newcomers",
views: {
'menuContent': {
templateUrl: "templates/wot/lookup.html",
Expand Down Expand Up @@ -96,18 +96,20 @@ function WotLookupController($scope, BMA, $state, UIUtils, $timeout, Device, Wal
$scope.entered = false;

$scope.$on('$ionicView.enter', function(e, $state) {
if (!$scope.entered && $state.stateParams && $state.stateParams.q) { // Query parameter
$scope.search.text=$state.stateParams.q;
$timeout(function() {
$scope.doSearch();
}, 100);
}
else if (!$scope.entered){
$timeout(function() {
$scope.doGetNewcomers();
}, 100);
if (!$scope.entered) {
if ($state.stateParams && $state.stateParams.q) { // Query parameter
$scope.search.text=$state.stateParams.q;
$timeout(function() {
$scope.doSearch();
}, 100);
}
else { // get new comers
$timeout(function() {
$scope.doGetNewcomers($state.stateParams.newcomers);
}, 100);
}
$scope.entered = true;
}
$scope.entered = true;
// removeIf(device)
// Focus on search text (only if NOT device, to avoid keyboard opening)
$focus('wotSearchText');
Expand Down Expand Up @@ -163,11 +165,13 @@ function WotLookupController($scope, BMA, $state, UIUtils, $timeout, Device, Wal
};
};

$scope.doGetNewcomers= function() {
$scope.doGetNewcomers= function(size) {
$scope.search.looking = true;
$scope.search.newIncomers = true;

WotService.newcomers(10)
size = (size && size > 0) ? size : 10;

WotService.newcomers(size)
.then(function(idties){
if (!$scope.search.newIncomers) return; // could have change
$scope.search.results = idties || [];
Expand Down
34 changes: 23 additions & 11 deletions www/js/services/wot-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,37 +385,40 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic
});
},

getNewcomers = function(count) {
count = count || 20;
getNewcomers = function(size) {
size = size || 20;
return BMA.blockchain.stats.newcomers()
.then(function(res) {
if (!res.result.blocks || !res.result.blocks.length) {
return null;
}
var blocks = _.sortBy(res.result.blocks, function(n){ return -n; });
return getNewcomersRecursive(blocks, 0, 5, count)
return getNewcomersRecursive(blocks, 0, 5, size)
.then(function(idties){
if (idties && !idties.length) {
idties = _.sortBy(idties, function(idty){ return -idty.block; });
if (idties.length > count) {
idties = idties.slice(0, count); // limit if more than expected count
if (idties.length > size) {
idties = idties.slice(0, size); // limit if more than expected size
}
}
return $q(function(resolve) {
api.data.raisePromise.search('$¹@', idties)
return $q(function(resolve, reject) {
api.data.raisePromise.search(null, idties)
.then(function () {
resolve(idties);
})
.catch(function(err){
reject(err);
});
});
})
})
},

getNewcomersRecursive = function(blocks, offset, count, maxResultCount) {
getNewcomersRecursive = function(blocks, offset, size, maxResultSize) {
return $q(function(resolve, reject) {
var result = [];
var jobs = [];
_.each(blocks.slice(offset, offset+count), function(number) {
_.each(blocks.slice(offset, offset+size), function(number) {
jobs.push(
BMA.blockchain.block({block: number})
.then(function(block){
Expand All @@ -430,16 +433,22 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic
});
});
})
.catch(function(err) {
reject(err);
})
)
});

$q.all(jobs)
.then(function() {
if (result.length < maxResultCount && offset < blocks.length - 1) {
if (result.length < maxResultSize && offset < blocks.length - 1) {
$timeout(function() {
getNewcomersRecursive(blocks, offset+count, count, maxResultCount - result.length)
getNewcomersRecursive(blocks, offset+size, size, maxResultSize - result.length)
.then(function(res) {
resolve(result.concat(res));
})
.catch(function(err) {
reject(err);
});
}, 1000);
}
Expand All @@ -451,6 +460,9 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic
if (err && err.ucode === 1006) {
resolve(result);
}
else {
reject(err);
}
});
});
}
Expand Down
43 changes: 22 additions & 21 deletions www/plugins/es/js/services/user-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,12 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se
return;
}

text = text.toLowerCase().trim();
text = text ? text.toLowerCase().trim() : text;
var map = {};

var request = {
query: {},
highlight: {
fields : {
title : {}
}
},
highlight: {fields : {title : {}}},
from: 0,
size: 100,
_source: ["title", "avatar"]
Expand All @@ -126,28 +122,33 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se
}, []);
request.query.constant_score = {
filter: {
bool: {
should: [
{terms : {_id : pubkeys}},
{bool: {
must: [
{match: { title: text}},
{prefix: { title: text}}
]}
}
]
}
bool: {should: [{terms : {_id : pubkeys}}]}
}
};
};
if (!text) {
delete request.highlight; // highlight not need
}
else {
request.query.constant_score.filter.bool.should.push(
{bool: {must: [
{match: {title: text}},
{prefix: {title: text}}
]}});
}
}
else {
else if (text){
request.query.bool = {
should: [
{match: { title: text}},
{prefix: { title: text}}
{match: {title: text}},
{prefix: {title: text}}
]
};
}
else {
// nothing to search: stop here
resolve(datas);
return;
}

var uidsByPubkey;
BMA.wot.member.uids()
Expand Down
3 changes: 2 additions & 1 deletion www/templates/currency/tabs/view_parameters.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<span class="badge badge-assertive">{{Nprev | formatInteger}}</span>
</ion-item>

<ion-item class="item-icon-left">
<ion-item class="item-icon-left"
ui-sref="app.wot_lookup({newcomers: N-Nprev})">
<i class="icon ion-person-add"></i>
<span translate>CURRENCY.VIEW.INCOMING_MEMBERS</span>
<span ng-if="N > Nprev" class="badge badge-balanced">+{{N-Nprev | formatInteger}}</span>
Expand Down
8 changes: 5 additions & 3 deletions www/templates/wot/lookup_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ <h4 class="gray">
<i class="ion-person"></i>
{{::identity.uid}}
</span>
<i class="ion-key"></i>
<b class="ion-key"></b>
{{::identity.pubkey | formatPubkey}}
<i class="ion-calendar" ng-if="identity.sigDate"></i>
{{::identity.sigDate | formatDate}}
</h4>
<p ng-if="identity.sigDate">
<i class="ion-clock"></i>
{{'WOT.LOOKUP.REGISTERED' | translate}}{{::identity.sigDate | formatFromNow}}
</p>
<i class="icon ion-ios-arrow-right visible-xs visible-sm"></i>
<ion-option-button class="button-positive" ng-click="showTransferModal({pubkey: identity.pubkey, uid: identity.name ||identity.uid})" translate>COMMON.BTN_SEND_MONEY_SHORT</ion-option-button>
</ion-item>
Expand Down

0 comments on commit b09d678

Please sign in to comment.