From fa95376fda71bc10c67a9cc2586981223e0eb28e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 25 Apr 2019 13:24:36 +0100 Subject: [PATCH] WIP: Fix/update adding contributors --- app/components/add-contributor/component.js | 25 ++++++++++++--------- app/components/add-contributor/template.hbs | 20 ++++++++--------- app/controllers/index.js | 6 +++-- app/services/kredits.js | 9 ++++++-- package-lock.json | 12 +++++----- package.json | 2 +- 6 files changed, 41 insertions(+), 33 deletions(-) diff --git a/app/components/add-contributor/component.js b/app/components/add-contributor/component.js index 32800c1..7e3b821 100644 --- a/app/components/add-contributor/component.js +++ b/app/components/add-contributor/component.js @@ -2,7 +2,6 @@ import Component from '@ember/component'; import { and, notEmpty } from '@ember/object/computed'; import { inject as service } from '@ember/service'; - export default Component.extend({ kredits: service(), @@ -14,6 +13,7 @@ export default Component.extend({ isValidURL: notEmpty('url'), isValidGithubUID: notEmpty('github_uid'), isValidGithubUsername: notEmpty('github_username'), + isValidGiteaUsername: notEmpty('gitea_username'), isValidWikiUsername: notEmpty('wiki_username'), isValid: and( 'isValidAccount', @@ -21,10 +21,11 @@ export default Component.extend({ 'isValidGithubUID' ), + inProgress: false, + init () { this._super(...arguments); - // Default attributes used by reset this.set('attributes', { account: null, name: null, @@ -32,8 +33,8 @@ export default Component.extend({ url: null, github_username: null, github_uid: null, - wiki_username: null, - isCore: false + gitea_username: null, + wiki_username: null }); }, @@ -53,17 +54,19 @@ export default Component.extend({ return; } - let attributes = Object.keys(this.attributes); - let contributor = this.getProperties(attributes); - let saved = this.save(contributor); + const attributes = Object.keys(this.attributes); + const contributor = this.getProperties(attributes); - // The promise handles inProgress - this.set('inProgress', saved); + this.set('inProgress', true); - saved.then(() => { + this.save(contributor).then(() => { this.reset(); window.scroll(0,0); - window.alert('Contributor added.'); + }).catch(err => { + console.log(err); + window.alert('Something went wrong. Please check the browser console.'); + }).finally(() => { + this.set('inProgress', false); }); } } diff --git a/app/components/add-contributor/template.hbs b/app/components/add-contributor/template.hbs index 235c535..fe98c5f 100644 --- a/app/components/add-contributor/template.hbs +++ b/app/components/add-contributor/template.hbs @@ -1,13 +1,4 @@
-

- {{input name="is-core" - type="checkbox" - id="is-core" - checked=isCore}} - -

{{input name="account" type="text" @@ -49,6 +40,13 @@ value=github_username class=(if isValidGithubUsername "valid" "")}}

+

+ {{input name="gitea_username" + type="text" + placeholder="Gitea username" + value=gitea_username + class=(if isValidGiteaUsername "valid" "")}} +

{{input name="wiki_username" type="text" @@ -58,7 +56,7 @@

{{input type="submit" - disabled=(is-pending inProgress) - value=(if (is-pending inProgress) "Processing" "Save")}} + disabled=inProgress + value=(if inProgress "Processing" "Save")}}

diff --git a/app/controllers/index.js b/app/controllers/index.js index 825a03d..7b2cc77 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -2,6 +2,7 @@ import Controller from '@ember/controller'; import { alias, filter, sort } from '@ember/object/computed'; import { inject as service } from '@ember/service'; import { computed } from '@ember/object'; +import { isPresent } from '@ember/utils'; export default Controller.extend({ kredits: service(), @@ -9,7 +10,8 @@ export default Controller.extend({ contributors: alias('kredits.contributors'), contributorsWithKredits: filter('contributors', function(contributor) { - return contributor.get('totalKreditsEarnedRaw').gt(0); + return isPresent(contributor.totalKreditsEarnedRaw) && + contributor.totalKreditsEarnedRaw.gt(0); }), contributorsSorting: Object.freeze(['totalKreditsEarned:desc']), contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'), @@ -47,7 +49,7 @@ export default Controller.extend({ save (contributor) { return this.kredits.addContributor(contributor) - .then((contributor) => { + .then(contributor => { this.contributors.pushObject(contributor); return contributor; }); diff --git a/app/services/kredits.js b/app/services/kredits.js index 87d2fed..2ad20f9 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -130,10 +130,15 @@ export default Service.extend({ }, addContributor(attributes) { + if (attributes.github_uid) { + const uidInt = parseInt(attributes.github_uid); + attributes.github_uid = uidInt; + } + console.debug('[kredits] add contributor', attributes); - return this.kredits.Contributor.add(attributes) - .then((data) => { + return this.kredits.Contributor.add(attributes, { gasLimit: 350000 }) + .then(data => { console.debug('[kredits] add contributor response', data); return Contributor.create(attributes); }); diff --git a/package-lock.json b/package-lock.json index b20efe9..cc8d49b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10911,9 +10911,9 @@ } }, "kredits-contracts": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.2.0.tgz", - "integrity": "sha512-XS8PN01SEiSNDKUhH28KVmGJ7hS3HlhT+CsaAMgqvU9ACcE1Wizqd0AxoRutUmJkILic6W6bQQ5gRqSHcBpPBA==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.3.0.tgz", + "integrity": "sha512-Wz4zuA6yo0Q4WbVEO61fvFin+6VTNjkBqHPhHCqq6dIoGdFSjUZ3BCKan1ei0axIAda7ZDP+eebe2vCr+eqcHg==", "dev": true, "requires": { "ethers": "^4.0.27", @@ -17139,9 +17139,9 @@ "dev": true }, "pull-to-stream": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/pull-to-stream/-/pull-to-stream-0.1.0.tgz", - "integrity": "sha512-LMvdE0JwT7XQZMFjc7JDl/G9gmoZ8Zo8e86SG4ZZUcjuwvod803KxpAK8WrmdxzHsMRK9DETlIzuA0tbEVv6jg==", + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/pull-to-stream/-/pull-to-stream-0.1.1.tgz", + "integrity": "sha512-thZkMv6F9PILt9zdvpI2gxs19mkDrlixYKX6cOBxAW16i1NZH+yLAmF4r8QfJ69zuQh27e01JZP9y27tsH021w==", "dev": true, "requires": { "readable-stream": "^3.1.1" diff --git a/package.json b/package.json index 980bd03..bf43f95 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "eslint-plugin-ember": "^5.2.0", "ethers": "^4.0.27", "kosmos-schemas": "^2.0.0", - "kredits-contracts": "^5.2.0", + "kredits-contracts": "^5.3.0", "loader.js": "^4.7.0", "qunit-dom": "^0.8.0", "tv4": "^1.3.0"