From ec40bd49f0513a34c6008557af0cb13daa4b6512 Mon Sep 17 00:00:00 2001 From: Santiago Siri Date: Fri, 27 Oct 2017 16:01:33 -0400 Subject: [PATCH] delegation list displays unilateral received delegations --- imports/ui/modules/menu.js | 20 ++++++++++++++++++- imports/ui/templates/layout/main.js | 2 -- .../ui/templates/layout/sidebar/sidebar.js | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/imports/ui/modules/menu.js b/imports/ui/modules/menu.js index 23ca8cebc..df5826b9f 100644 --- a/imports/ui/modules/menu.js +++ b/imports/ui/modules/menu.js @@ -234,9 +234,27 @@ const _getDelegatesMenu = () => { let sent; let received; let source; + let contracts = []; const politics = []; + + // unilaterally received delegations + if (Meteor.user()) { + contracts = _.pluck(Contracts.find({ signatures: { $elemMatch: { username: Meteor.user().username } } }).fetch(), '_id'); + } + + // sent delegations const transactions = _.filter(Transactions.find({ kind: 'DELEGATION' }).fetch(), - (item) => { return (item.input.entityId === Meteor.userId() || item.output.entityId === Meteor.userId()); }, 0); + (item) => { + if (contracts.length > 0) { + for (const signed in contracts) { + if (item.input.entityId === contracts[signed] || item.output.entityId === contracts[signed]) { + return true; + } + } + } + return (item.input.entityId === Meteor.userId() || item.output.entityId === Meteor.userId()); + }, 0); + if (transactions.length > 0) { delegations = _.uniq(_.pluck(transactions, 'contractId')); diff --git a/imports/ui/templates/layout/main.js b/imports/ui/templates/layout/main.js index ee157399c..fa9c1ac6b 100644 --- a/imports/ui/templates/layout/main.js +++ b/imports/ui/templates/layout/main.js @@ -79,8 +79,6 @@ Meteor.startup(() => { }); // geographical Info - // HTTP.get(Meteor.absoluteUrl('data/geo.json'), (err, result) => { - // }); globalObj.geoJSON = geo; Session.set('filteredCountries', geo.country); }); diff --git a/imports/ui/templates/layout/sidebar/sidebar.js b/imports/ui/templates/layout/sidebar/sidebar.js index 29f9734f5..3260285ad 100644 --- a/imports/ui/templates/layout/sidebar/sidebar.js +++ b/imports/ui/templates/layout/sidebar/sidebar.js @@ -70,6 +70,7 @@ function getList(db, sort) { */ function getDelegates() { const delegates = _.sortBy(getDelegatesMenu(), (user) => { return parseInt(0 - (user.sent + user.received), 10); }); + console.log(delegates); const delegateList = []; for (const i in delegates) { delegateList.push(Meteor.users.find({ _id: delegates[i].userId }).fetch()[0]);