Move contributors + proposals to service #49
@@ -1,6 +1,6 @@
|
|||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import Controller from 'ember-controller';
|
import Controller from 'ember-controller';
|
||||||
import computed, { alias, filter, filterBy, sort } from 'ember-computed';
|
import { alias, filter, filterBy, sort } from 'ember-computed';
|
||||||
import injectService from 'ember-service/inject';
|
import injectService from 'ember-service/inject';
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
@@ -15,24 +15,14 @@ export default Controller.extend({
|
|||||||
// TODO: transfer on the token contract
|
// TODO: transfer on the token contract
|
||||||
},
|
},
|
||||||
|
|
||||||
contributors: alias('model.contributors'),
|
contributors: alias('kredits.contributors'),
|
||||||
contributorsWithKredits: filter('contributors', function(contributor) {
|
contributorsWithKredits: filter('contributors', function(contributor) {
|
||||||
return contributor.get('balance') !== 0;
|
return contributor.get('balance') !== 0;
|
||||||
}),
|
}),
|
||||||
contributorsSorting: ['balance:desc'],
|
contributorsSorting: ['balance:desc'],
|
||||||
contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'),
|
contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'),
|
||||||
|
|
||||||
proposals: computed('model.proposals.[]', 'contributors.[]', function() {
|
proposals: alias('kredits.proposals'),
|
||||||
return this.get('model.proposals')
|
|
||||||
.map((proposal) => {
|
|
||||||
let contributor = this.get('contributors')
|
|
||||||
.findBy('id', proposal.get('contributorId'));
|
|
||||||
|
|
||||||
proposal.set('contributor', contributor);
|
|
||||||
|
|
||||||
return proposal;
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
proposalsOpen: filterBy('proposals', 'isExecuted', false),
|
proposalsOpen: filterBy('proposals', 'isExecuted', false),
|
||||||
proposalsClosed: filterBy('proposals', 'isExecuted', true),
|
proposalsClosed: filterBy('proposals', 'isExecuted', true),
|
||||||
proposalsSorting: ['id:desc'],
|
proposalsSorting: ['id:desc'],
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import Controller from 'ember-controller';
|
import Controller from 'ember-controller';
|
||||||
import { filterBy } from 'ember-computed';
|
import { alias, filterBy } from 'ember-computed';
|
||||||
import injectService from 'ember-service/inject';
|
import injectService from 'ember-service/inject';
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
kredits: injectService(),
|
kredits: injectService(),
|
||||||
|
|
||||||
contributors: [],
|
contributors: alias('kredits.contributors'),
|
||||||
minedContributors: filterBy('contributors', 'id'),
|
minedContributors: filterBy('contributors', 'id'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import EmberObject from 'ember-object';
|
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';
|
import bignumber from 'kredits-web/utils/cps/bignumber';
|
||||||
|
|
||||||
export default EmberObject.extend({
|
export default EmberObject.extend({
|
||||||
|
kredits: injectService(),
|
||||||
|
|
||||||
// Contract
|
// Contract
|
||||||
id: bignumber('idRaw', 'toString'),
|
id: bignumber('idRaw', 'toString'),
|
||||||
creatorAccount: null,
|
creatorAccount: null,
|
||||||
@@ -24,5 +27,8 @@ export default EmberObject.extend({
|
|||||||
ipfsData: '',
|
ipfsData: '',
|
||||||
|
|
||||||
// Relationships
|
// Relationships
|
||||||
contributor: null,
|
// TODO: Optimize it. We don't need to find the contributor every time we add a new one
|
||||||
|
contributor: computed('contributorId', 'kredits.contributors.[]', function() {
|
||||||
|
return this.get('kredits.contributors').findBy('id', this.get('contributorId'));
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,4 +17,8 @@ export default Route.extend({
|
|||||||
console.log('Error initializing Kredits', error);
|
console.log('Error initializing Kredits', error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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
|
// TODO: Only assign valid attributes
|
||||||
buildModel(name, attributes) {
|
buildModel(name, attributes) {
|
||||||
debug('[kredits] build', name, attributes);
|
debug('[kredits] build', name, attributes);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
{{contributor-list contributors=contributorsSorted}}
|
{{contributor-list contributors=contributorsSorted}}
|
||||||
|
|
||||||
<p class="stats">
|
<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.
|
<span class="number">{{contributorsWithKredits.length}}</span> contributors.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{{#if kredits.currentUser.isCore}}
|
{{#if kredits.currentUser.isCore}}
|
||||||
{{add-contributor contributors=model.contributors save=(action 'save')}}
|
{{add-contributor contributors=contributors save=(action 'save')}}
|
||||||
{{else}}
|
{{else}}
|
||||||
Only core team members can add new contributors. Please ask someone to set you up.
|
Only core team members can add new contributors. Please ask someone to set you up.
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
@@ -12,18 +12,13 @@ moduleFor('controller:index', 'Unit | Controller | index', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let addFixtures = function(controller) {
|
let addFixtures = function(controller) {
|
||||||
controller.set('model', {
|
|
||||||
contributors: [],
|
|
||||||
proposals: []
|
|
||||||
});
|
|
||||||
|
|
||||||
[
|
[
|
||||||
{ github_username: "neo", github_uid: "318", balance: 10000 },
|
{ github_username: "neo", github_uid: "318", balance: 10000 },
|
||||||
{ github_username: "morpheus", github_uid: "843", balance: 15000 },
|
{ github_username: "morpheus", github_uid: "843", balance: 15000 },
|
||||||
{ github_username: "trinity", github_uid: "123", balance: 5000 },
|
{ github_username: "trinity", github_uid: "123", balance: 5000 },
|
||||||
{ github_username: "mouse", github_uid: "696", balance: 0 }
|
{ github_username: "mouse", github_uid: "696", balance: 0 }
|
||||||
].forEach(fixture => {
|
].forEach(fixture => {
|
||||||
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