From 45044c0f6192e1bf60c354633b9b440b517c0b46 Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Sun, 8 Apr 2018 01:57:54 +0200 Subject: [PATCH] Refactor controller and route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’m not sure how the queryParams are used so I removed them. I’m happy to readd them. --- app/controllers/proposals/new.js | 39 ++++++++++++++------------------ app/routes/proposals/new.js | 38 +++++++------------------------ 2 files changed, 25 insertions(+), 52 deletions(-) diff --git a/app/controllers/proposals/new.js b/app/controllers/proposals/new.js index fc6c6da..dbea973 100644 --- a/app/controllers/proposals/new.js +++ b/app/controllers/proposals/new.js @@ -1,29 +1,24 @@ -import Ember from 'ember'; -import QueryParams from 'ember-parachute'; +import Controller from 'ember-controller'; +import { filterBy } from 'ember-computed'; +import injectService from 'ember-service/inject'; -export const queryParams = new QueryParams({ - recipient: { - defaultValue: '' - }, - amount: { - defaultValue: '' - }, - url: { - defaultValue: '' - }, - ipfsHash: { - defaultValue: '' - } -}); +export default Controller.extend({ + kredits: injectService(), -export default Ember.Controller.extend(queryParams.Mixin, { - - contributors: null, + contributors: [], + minedContributors: filterBy('contributors', 'id'), actions: { - onSave() { - this.transitionToRoute('index'); + save(proposal) { + // 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; + }); } } - }); diff --git a/app/routes/proposals/new.js b/app/routes/proposals/new.js index f5870d9..4c3110c 100644 --- a/app/routes/proposals/new.js +++ b/app/routes/proposals/new.js @@ -1,37 +1,15 @@ -import Ember from 'ember'; -import Proposal from 'kredits-web/models/proposal'; - -const { - Route, - RSVP, - inject: { - service - } -} = Ember; +import injectService from 'ember-service/inject'; +import Route from 'ember-route'; export default Route.extend({ - - 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() - }); - }, + kredits: injectService(), 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); + }); } - });