From 16ee3b6b6b6fdfcbad6b7988eefdcd4811f39279 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 23 May 2019 14:17:33 +0200 Subject: [PATCH] Move contributor-creation form for separate view closes #74 --- app/components/add-contributor/component.js | 10 ++++----- app/controllers/contributors/new.js | 23 +++++++++++++++++++++ app/controllers/index.js | 8 ------- app/router.js | 3 +++ app/services/kredits.js | 4 +++- app/templates/contributors/new.hbs | 13 ++++++++++++ app/templates/index.hbs | 23 ++++++--------------- 7 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 app/controllers/contributors/new.js create mode 100644 app/templates/contributors/new.hbs diff --git a/app/components/add-contributor/component.js b/app/components/add-contributor/component.js index 7e3b821..954ca99 100644 --- a/app/components/add-contributor/component.js +++ b/app/components/add-contributor/component.js @@ -3,6 +3,7 @@ import { and, notEmpty } from '@ember/object/computed'; import { inject as service } from '@ember/service'; export default Component.extend({ + kredits: service(), attributes: null, @@ -36,10 +37,7 @@ export default Component.extend({ gitea_username: null, wiki_username: null }); - }, - didInsertElement() { - this._super(...arguments); this.reset(); }, @@ -48,7 +46,8 @@ export default Component.extend({ }, actions: { - submit() { + + submit () { if (!this.isValid) { alert('Invalid data. Please review and try again.'); return; @@ -63,12 +62,13 @@ export default Component.extend({ this.reset(); window.scroll(0,0); }).catch(err => { - console.log(err); + console.warn(err); window.alert('Something went wrong. Please check the browser console.'); }).finally(() => { this.set('inProgress', false); }); } + } }); diff --git a/app/controllers/contributors/new.js b/app/controllers/contributors/new.js new file mode 100644 index 0000000..ed7a1f6 --- /dev/null +++ b/app/controllers/contributors/new.js @@ -0,0 +1,23 @@ +import Controller from '@ember/controller'; +import { alias } from '@ember/object/computed'; +import { inject as service } from '@ember/service'; + +export default Controller.extend({ + + kredits: service(), + + contributors: alias('kredits.contributors'), + + actions: { + + save (contributor) { + return this.kredits.addContributor(contributor) + .then(contributor => { + this.transitionToRoute('index'); + return contributor; + }); + } + + } + +}); diff --git a/app/controllers/index.js b/app/controllers/index.js index 9c614c7..dd7bb56 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -37,14 +37,6 @@ export default Controller.extend({ this.kredits.vote(proposalId).then(transaction => { console.debug('[controllers:index] Vote submitted to Ethereum blockhain: '+transaction.hash); }); - }, - - save (contributor) { - return this.kredits.addContributor(contributor) - .then(contributor => { - this.contributors.pushObject(contributor); - return contributor; - }); } } diff --git a/app/router.js b/app/router.js index 7a49d13..afa8660 100644 --- a/app/router.js +++ b/app/router.js @@ -13,6 +13,9 @@ Router.map(function() { this.route('contributions', function() { this.route('new'); }); + this.route('contributors', function() { + this.route('new'); + }); }); export default Router; diff --git a/app/services/kredits.js b/app/services/kredits.js index 58996b6..8eb6bbb 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -190,7 +190,9 @@ export default Service.extend({ return this.kredits.Contributor.add(attributes, { gasLimit: 350000 }) .then(data => { console.debug('[kredits] add contributor response', data); - return Contributor.create(attributes); + const contributor = Contributor.create(attributes); + this.contributors.pushObject(contributor); + return contributor; }); }, diff --git a/app/templates/contributors/new.hbs b/app/templates/contributors/new.hbs new file mode 100644 index 0000000..8351f57 --- /dev/null +++ b/app/templates/contributors/new.hbs @@ -0,0 +1,13 @@ +
+ +
+
+

Add contributor profile

+
+ +
+ {{add-contributor contributors=contributors save=(action "save")}} +
+
+ +
diff --git a/app/templates/index.hbs b/app/templates/index.hbs index 4f8c82b..58fc3f0 100644 --- a/app/templates/index.hbs +++ b/app/templates/index.hbs @@ -2,8 +2,13 @@
-
+

Contributors

+ {{#if kredits.hasAccounts}} + + {{/if}}
{{contributor-list contributorList=kreditsToplist @@ -61,20 +66,4 @@
- {{#if kredits.hasAccounts}} -
-
-

Add Contributor

-
- -
- {{#if kredits.currentUser.isCore}} - {{add-contributor contributors=contributors save=(action "save")}} - {{else}} - Only core team members can add new contributors. Please ask someone to set you up. - {{/if}} -
-
- {{/if}} -