Don't inject kredits service in models
This commit is contained in:
@@ -1,11 +1,8 @@
|
|||||||
import Component from '@ember/component';
|
import Component from '@ember/component';
|
||||||
import { computed } from '@ember/object';
|
import { computed } from '@ember/object';
|
||||||
import { and, notEmpty } from '@ember/object/computed';
|
import { and, notEmpty } from '@ember/object/computed';
|
||||||
import { inject as injectService } from '@ember/service';
|
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
kredits: injectService(),
|
|
||||||
|
|
||||||
// Default attributes used by reset
|
// Default attributes used by reset
|
||||||
attributes: {
|
attributes: {
|
||||||
contributorId: null,
|
contributorId: null,
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import EmberObject from '@ember/object';
|
import EmberObject from '@ember/object';
|
||||||
import { computed } from '@ember/object';
|
|
||||||
import { alias } from '@ember/object/computed';
|
import { alias } from '@ember/object/computed';
|
||||||
import { inject as injectService } from '@ember/service';
|
|
||||||
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,
|
||||||
@@ -26,10 +22,4 @@ export default EmberObject.extend({
|
|||||||
details: {},
|
details: {},
|
||||||
url: null,
|
url: null,
|
||||||
ipfsData: '',
|
ipfsData: '',
|
||||||
|
|
||||||
// Relationships
|
|
||||||
// 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.contributorId);
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|||||||
+23
-22
@@ -1,15 +1,17 @@
|
|||||||
import { getOwner } from '@ember/application';
|
|
||||||
import ethers from 'npm:ethers';
|
|
||||||
import Kredits from 'kredits-web/lib/kredits';
|
|
||||||
import RSVP from 'rsvp';
|
|
||||||
import Service from '@ember/service';
|
import Service from '@ember/service';
|
||||||
import { computed } from '@ember/object';
|
import { computed } from '@ember/object';
|
||||||
import { alias } from '@ember/object/computed';
|
import { alias } from '@ember/object/computed';
|
||||||
import { isEmpty, isPresent } from '@ember/utils';
|
import { isEmpty, isPresent } from '@ember/utils';
|
||||||
|
import RSVP from 'rsvp';
|
||||||
|
import Kredits from 'kredits-web/lib/kredits';
|
||||||
|
import Contributor from 'kredits-web/models/contributor'
|
||||||
|
import Proposal from 'kredits-web/models/proposal'
|
||||||
|
import ethers from 'npm:ethers';
|
||||||
|
|
||||||
import config from 'kredits-web/config/environment';
|
import config from 'kredits-web/config/environment';
|
||||||
|
|
||||||
export default Service.extend({
|
export default Service.extend({
|
||||||
|
|
||||||
ethProvider: null,
|
ethProvider: null,
|
||||||
currentUserAccounts: null, // default to not having an account. this is the wen web3 is loaded.
|
currentUserAccounts: null, // default to not having an account. this is the wen web3 is loaded.
|
||||||
currentUser: null,
|
currentUser: null,
|
||||||
@@ -76,23 +78,20 @@ export default Service.extend({
|
|||||||
proposals: [],
|
proposals: [],
|
||||||
|
|
||||||
loadContributorsAndProposals() {
|
loadContributorsAndProposals() {
|
||||||
return RSVP.hash({
|
return this.getContributors()
|
||||||
contributors: this.getContributors(),
|
.then(contributors => this.contributors.pushObjects(contributors))
|
||||||
proposals: this.getProposals(),
|
.then(() => this.getProposals())
|
||||||
}).then(({ contributors, proposals }) => {
|
.then(proposals => this.proposals.pushObjects(proposals))
|
||||||
this.contributors.pushObjects(contributors);
|
|
||||||
this.proposals.pushObjects(proposals);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: Only assign valid attributes
|
// TODO: Only assign valid attributes
|
||||||
buildModel(name, attributes) {
|
// buildModel(name, attributes) {
|
||||||
console.debug('[kredits] build', name, attributes);
|
// console.debug('[kredits] build', name, attributes);
|
||||||
let model = getOwner(this).lookup(`model:${name}`);
|
// let model = getOwner(this).lookup(`model:${name}`);
|
||||||
|
//
|
||||||
model.setProperties(attributes);
|
// model.setProperties(attributes);
|
||||||
return model;
|
// return model;
|
||||||
},
|
// },
|
||||||
|
|
||||||
addContributor(attributes) {
|
addContributor(attributes) {
|
||||||
console.debug('[kredits] add contributor', attributes);
|
console.debug('[kredits] add contributor', attributes);
|
||||||
@@ -100,7 +99,7 @@ export default Service.extend({
|
|||||||
return this.kredits.Contributor.add(attributes)
|
return this.kredits.Contributor.add(attributes)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.debug('[kredits] add contributor response', data);
|
console.debug('[kredits] add contributor response', data);
|
||||||
return this.buildModel('contributor', attributes);
|
return Contributor.create(attributes);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -108,7 +107,7 @@ export default Service.extend({
|
|||||||
return this.kredits.Contributor.all()
|
return this.kredits.Contributor.all()
|
||||||
.then((contributors) => {
|
.then((contributors) => {
|
||||||
return contributors.map((contributor) => {
|
return contributors.map((contributor) => {
|
||||||
return this.buildModel('contributor', contributor);
|
return Contributor.create(contributor);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -119,7 +118,8 @@ export default Service.extend({
|
|||||||
return this.kredits.Operator.addProposal(attributes)
|
return this.kredits.Operator.addProposal(attributes)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.debug('[kredits] add proposal response', data);
|
console.debug('[kredits] add proposal response', data);
|
||||||
return this.buildModel('proposal', attributes);
|
attributes.contributor = this.contributors.findBy('id', attributes.contributorId);
|
||||||
|
return Proposal.create(attributes);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -127,7 +127,8 @@ export default Service.extend({
|
|||||||
return this.kredits.Operator.all()
|
return this.kredits.Operator.all()
|
||||||
.then((proposals) => {
|
.then((proposals) => {
|
||||||
return proposals.map((proposal) => {
|
return proposals.map((proposal) => {
|
||||||
return this.buildModel('proposal', proposal);
|
proposal.contributor = this.contributors.findBy('id', proposal.contributorId.toString());
|
||||||
|
return Proposal.create(proposal);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { isEmpty, isPresent } from '@ember/utils';
|
import { isEmpty, isPresent } from '@ember/utils';
|
||||||
import Contributor from 'kredits-web/models/contributor';
|
|
||||||
import { module, test } from 'qunit';
|
import { module, test } from 'qunit';
|
||||||
import { setupTest } from 'ember-qunit';
|
import { setupTest } from 'ember-qunit';
|
||||||
|
import Contributor from 'kredits-web/models/contributor';
|
||||||
|
|
||||||
module('Unit | Controller | index', function(hooks) {
|
module('Unit | Controller | index', function(hooks) {
|
||||||
setupTest(hooks);
|
setupTest(hooks);
|
||||||
|
|||||||
Reference in New Issue
Block a user