Move contributors + proposals to service
With this change we have all the contributors + proposals all the time in one place and can update them via events.
This commit is contained in:
@@ -15,24 +15,14 @@ export default Controller.extend({
|
||||
// TODO: transfer on the token contract
|
||||
},
|
||||
|
||||
contributors: alias('model.contributors'),
|
||||
contributors: alias('kredits.contributors'),
|
||||
contributorsWithKredits: filter('contributors', function(contributor) {
|
||||
return contributor.get('balance') !== 0;
|
||||
}),
|
||||
contributorsSorting: ['balance:desc'],
|
||||
contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'),
|
||||
|
||||
proposals: computed('model.proposals.[]', 'contributors.[]', function() {
|
||||
return this.get('model.proposals')
|
||||
.map((proposal) => {
|
||||
let contributor = this.get('contributors')
|
||||
.findBy('id', proposal.get('recipientId'));
|
||||
|
||||
proposal.set('contributor', contributor);
|
||||
|
||||
return proposal;
|
||||
});
|
||||
}),
|
||||
proposals: alias('kredits.proposals'),
|
||||
proposalsOpen: filterBy('proposals', 'isExecuted', false),
|
||||
proposalsClosed: filterBy('proposals', 'isExecuted', true),
|
||||
proposalsSorting: ['id:desc'],
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Controller from 'ember-controller';
|
||||
import { filterBy } from 'ember-computed';
|
||||
import { alias, filterBy } from 'ember-computed';
|
||||
import injectService from 'ember-service/inject';
|
||||
|
||||
export default Controller.extend({
|
||||
kredits: injectService(),
|
||||
|
||||
contributors: [],
|
||||
contributors: alias('kredits.contributors'),
|
||||
minedContributors: filterBy('contributors', 'id'),
|
||||
|
||||
actions: {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import EmberObject from 'ember-object';
|
||||
import { alias } from 'ember-computed';
|
||||
import computed, { alias } from 'ember-computed';
|
||||
import injectService from 'ember-service/inject';
|
||||
import bignumber from 'kredits-web/utils/cps/bignumber';
|
||||
|
||||
export default EmberObject.extend({
|
||||
kredits: injectService(),
|
||||
|
||||
// Contract
|
||||
id: bignumber('idRaw', 'toString'),
|
||||
creatorAddress: null,
|
||||
@@ -24,5 +27,8 @@ export default EmberObject.extend({
|
||||
ipfsData: '',
|
||||
|
||||
// Relationships
|
||||
contributor: null,
|
||||
// TODO: Optimize it. We don't need to find the contributor every time we add a new one
|
||||
contributor: computed('recipientId', 'kredits.contributors.[]', function() {
|
||||
return this.get('kredits.contributors').findBy('id', this.get('recipientId'));
|
||||
})
|
||||
});
|
||||
|
||||
@@ -15,4 +15,8 @@ export default Route.extend({
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
afterModel() {
|
||||
return this.get('kredits').loadContributorsAndProposals();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
|
||||
kredits: Ember.inject.service(),
|
||||
|
||||
model() {
|
||||
let newContributor = Ember.getOwner(this).lookup('model:contributor');
|
||||
newContributor.set('kind', 'person');
|
||||
|
||||
let kredits = this.get('kredits');
|
||||
let totalSupply = kredits.get('kredits').Token.functions.totalSupply();
|
||||
|
||||
return Ember.RSVP.hash({
|
||||
contributors: kredits.getContributors(),
|
||||
proposals: kredits.getProposals(),
|
||||
totalSupply,
|
||||
newContributor: newContributor,
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
import injectService from 'ember-service/inject';
|
||||
import Route from 'ember-route';
|
||||
|
||||
export default Route.extend({
|
||||
kredits: injectService(),
|
||||
|
||||
setupController(controller) {
|
||||
this._super(...arguments);
|
||||
|
||||
this.get('kredits').getContributors()
|
||||
.then((contributors) => {
|
||||
controller.set('contributors', contributors);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -74,6 +74,23 @@ export default Service.extend({
|
||||
});
|
||||
},
|
||||
|
||||
totalSupply: computed(function() {
|
||||
return this.get('kredits').Token.functions.totalSupply();
|
||||
}),
|
||||
|
||||
contributors: [],
|
||||
proposals: [],
|
||||
|
||||
loadContributorsAndProposals() {
|
||||
return RSVP.hash({
|
||||
contributors: this.getContributors(),
|
||||
proposals: this.getProposals(),
|
||||
}).then(({ contributors, proposals }) => {
|
||||
this.set('contributors', contributors);
|
||||
this.set('proposals', proposals);
|
||||
});
|
||||
},
|
||||
|
||||
// TODO: Only assign valid attributes
|
||||
buildModel(name, attributes) {
|
||||
debug('[kredits] build', name, attributes);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
{{contributor-list contributors=contributorsSorted}}
|
||||
|
||||
<p class="stats">
|
||||
<span class="number">{{model.totalSupply}}</span> kredits issued and distributed among
|
||||
<span class="number">{{await kredits.totalSupply}}</span> kredits issued and distributed among
|
||||
<span class="number">{{contributorsWithKredits.length}}</span> contributors.
|
||||
</p>
|
||||
</div>
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
<div class="content">
|
||||
{{#if kredits.currentUser.isCore}}
|
||||
{{add-contributor contributors=model.contributors save=(action 'save')}}
|
||||
{{add-contributor contributors=contributors save=(action 'save')}}
|
||||
{{else}}
|
||||
Only core team members can add new contributors. Please ask someone to set you up.
|
||||
{{/if}}
|
||||
|
||||
@@ -26,7 +26,7 @@ let addFixtures = function(controller) {
|
||||
// we expect a bignumer but I don't want to add the bignumber dependency here... so this is some hack to return an object that looks good enough for the test
|
||||
let fakeBignumber = function(balance) { return { toNumber: function() { return balance; } }; };
|
||||
fixture.balance = fakeBignumber(fixture.balance);
|
||||
controller.get('model.contributors').push(Contributor.create(fixture));
|
||||
controller.get('kredits.contributors').push(Contributor.create(fixture));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { moduleFor, test } from 'ember-qunit';
|
||||
|
||||
moduleFor('route:index', 'Unit | Route | index', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['controller:foo']
|
||||
});
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.subject();
|
||||
assert.ok(route);
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
import { moduleFor, test } from 'ember-qunit';
|
||||
|
||||
moduleFor('route:proposals/new', 'Unit | Route | proposals/new', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['controller:foo']
|
||||
});
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.subject();
|
||||
assert.ok(route);
|
||||
});
|
||||
Reference in New Issue
Block a user