Refactor controller and route
I’m not sure how the queryParams are used so I removed them. I’m happy to readd them.
This commit is contained in:
@@ -1,29 +1,24 @@
|
|||||||
import Ember from 'ember';
|
import Controller from 'ember-controller';
|
||||||
import QueryParams from 'ember-parachute';
|
import { filterBy } from 'ember-computed';
|
||||||
|
import injectService from 'ember-service/inject';
|
||||||
|
|
||||||
export const queryParams = new QueryParams({
|
export default Controller.extend({
|
||||||
recipient: {
|
kredits: injectService(),
|
||||||
defaultValue: ''
|
|
||||||
},
|
|
||||||
amount: {
|
|
||||||
defaultValue: ''
|
|
||||||
},
|
|
||||||
url: {
|
|
||||||
defaultValue: ''
|
|
||||||
},
|
|
||||||
ipfsHash: {
|
|
||||||
defaultValue: ''
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Ember.Controller.extend(queryParams.Mixin, {
|
contributors: [],
|
||||||
|
minedContributors: filterBy('contributors', 'id'),
|
||||||
contributors: null,
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
onSave() {
|
save(proposal) {
|
||||||
this.transitionToRoute('index');
|
// contributorIpfsHash is needed for the proposal ipfs data. I'm not happy to do this here but I think to load all the contributors in addProposal again is a bit too much. I hope we can refactor it later.
|
||||||
|
let contributor = this.get('contributors').findBy('id', proposal.recipientId);
|
||||||
|
proposal.contributorIpfsHash = contributor.get('ipfsHash');
|
||||||
|
|
||||||
|
return this.get('kredits').addProposal(proposal)
|
||||||
|
.then((proposal) => {
|
||||||
|
this.transitionToRoute('index');
|
||||||
|
return proposal;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,37 +1,15 @@
|
|||||||
import Ember from 'ember';
|
import injectService from 'ember-service/inject';
|
||||||
import Proposal from 'kredits-web/models/proposal';
|
import Route from 'ember-route';
|
||||||
|
|
||||||
const {
|
|
||||||
Route,
|
|
||||||
RSVP,
|
|
||||||
inject: {
|
|
||||||
service
|
|
||||||
}
|
|
||||||
} = Ember;
|
|
||||||
|
|
||||||
export default Route.extend({
|
export default Route.extend({
|
||||||
|
kredits: injectService(),
|
||||||
kredits: service(),
|
|
||||||
|
|
||||||
model(params) {
|
|
||||||
const proposal = Proposal.create({
|
|
||||||
recipientAddress: params.recipient,
|
|
||||||
amount: params.amount,
|
|
||||||
url: params.url,
|
|
||||||
kind: params.kind || 'dev',
|
|
||||||
ipfsHash: params.ipfsHash
|
|
||||||
});
|
|
||||||
|
|
||||||
return RSVP.hash({
|
|
||||||
proposal,
|
|
||||||
contributors: this.get('kredits').getContributors()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
this._super(controller, model.proposal);
|
this._super(...arguments);
|
||||||
|
|
||||||
controller.set('contributors', model.contributors);
|
this.get('kredits').getContributors()
|
||||||
|
.then((contributors) => {
|
||||||
|
this.controller.set('contributors', contributors);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user