From 58bd729acbe920eaa2364597e66b29f6d410d2a3 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 29 May 2019 16:12:48 +0200 Subject: [PATCH 1/2] Formatting --- app/services/kredits.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/services/kredits.js b/app/services/kredits.js index 8eb6bbb..f6d7e5f 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -47,7 +47,7 @@ export default Service.extend({ }); }), - kreditsByContributor: computed('contributionsUnconfirmed.@each.vetoed', 'contributors', function() { + kreditsByContributor: computed('contributionsUnconfirmed.@each.vetoed', 'contributors.[]', function() { const contributionsUnconfirmed = this.contributionsUnconfirmed.filterBy('vetoed', false); const contributionsGrouped = groupBy(contributionsUnconfirmed, 'contributorId'); const contributorsWithUnconfirmed = contributionsGrouped.map(c => c.value.toString()); @@ -87,7 +87,7 @@ export default Service.extend({ // This is called in the application route's beforeModel(). So it is // initialized before everything else, and we can rely on the ethProvider and // the potential currentUserAccounts to be available - getEthProvider: function() { + getEthProvider () { let ethProvider; return new RSVP.Promise(async (resolve) => { @@ -136,7 +136,7 @@ export default Service.extend({ }); }, - setup() { + setup () { return this.getEthProvider().then((providerAndSigner) => { let kredits = new Kredits(providerAndSigner.ethProvider, providerAndSigner.ethSigner, { addresses: { Kernel: config.kreditsKernelAddress }, @@ -172,14 +172,14 @@ export default Service.extend({ }), - loadInitialData() { + loadInitialData () { return this.getContributors() .then(contributors => this.contributors.pushObjects(contributors)) .then(() => this.getContributions()) .then(contributions => this.contributions.pushObjects(contributions)) }, - addContributor(attributes) { + addContributor (attributes) { if (attributes.github_uid) { const uidInt = parseInt(attributes.github_uid); attributes.github_uid = uidInt; @@ -205,7 +205,7 @@ export default Service.extend({ }); }, - addContribution(attributes) { + addContribution (attributes) { console.debug('[kredits] add contribution', attributes); return this.kredits.Contribution.addContribution(attributes, { gasLimit: 300000 }) @@ -220,7 +220,7 @@ export default Service.extend({ }); }, - addProposal(attributes) { + addProposal (attributes) { console.debug('[kredits] add proposal', attributes); return this.kredits.Proposal.addProposal(attributes) @@ -231,7 +231,7 @@ export default Service.extend({ }); }, - getProposals() { + getProposals () { return this.kredits.Proposal.all() .then((proposals) => { return proposals.map((proposal) => { @@ -241,7 +241,7 @@ export default Service.extend({ }); }, - getContributions() { + getContributions () { return this.kredits.Contribution.all({page: {size: 200}}) .then(contributions => { return contributions.map(contribution => { @@ -251,7 +251,7 @@ export default Service.extend({ }); }, - vote(proposalId) { + vote (proposalId) { console.debug('[kredits] vote for', proposalId); return this.kredits.Proposal.functions.vote(proposalId) @@ -261,7 +261,7 @@ export default Service.extend({ }); }, - veto(contributionId) { + veto (contributionId) { console.debug('[kredits] veto against', contributionId); return this.kredits.Contribution.functions.veto(contributionId, { gasLimit: 300000 }) @@ -292,7 +292,7 @@ export default Service.extend({ }, // Contract events - addContractEventHandlers() { + addContractEventHandlers () { this.kredits.Contribution .on('ContributionVetoed', this.handleContributionVetoed.bind(this)) @@ -315,7 +315,7 @@ export default Service.extend({ } }, - handleProposalCreated(proposalId) { + handleProposalCreated (proposalId) { let proposal = this.findProposalById(proposalId); if (proposal) { @@ -331,7 +331,7 @@ export default Service.extend({ }, // TODO: We may want to reload that proposal to show the voter as voted - handleProposalVoted(proposalId, voterId, totalVotes) { + handleProposalVoted (proposalId, voterId, totalVotes) { let proposal = this.findProposalById(proposalId); if (proposal) { @@ -339,7 +339,7 @@ export default Service.extend({ } }, - handleProposalExecuted(proposalId, contributorId, amount) { + handleProposalExecuted (proposalId, contributorId, amount) { let proposal = this.findProposalById(proposalId); if (proposal.get('isExecuted')) { @@ -354,7 +354,7 @@ export default Service.extend({ .incrementProperty('balance', amount); }, - handleTransfer(from, to, value) { + handleTransfer (from, to, value) { value = value.toNumber(); this.contributors From 1c1f772ff562bbeac527b76bf451d4927942bb6c Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 29 May 2019 16:14:11 +0200 Subject: [PATCH 2/2] Update contributor profiles * Adds a new page for updating profiles * Refactors the add-contributor component to allow for updating existing contributors * Adds input labels to the contributor form and improves placeholders * Adds event handlers for all contract contributor changes and uses them for updating the UI refs #122 --- app/components/add-contributor/component.js | 9 ++- app/components/add-contributor/template.hbs | 60 ++++++++------------ app/components/contributor-list/template.hbs | 3 + app/controllers/contributors/edit.js | 18 ++++++ app/controllers/contributors/new.js | 11 +--- app/router.js | 1 + app/routes/contributors/edit.js | 29 ++++++++++ app/services/kredits.js | 42 ++++++++++++-- app/styles/_forms.scss | 11 ++++ app/templates/contributors/edit.hbs | 13 +++++ app/templates/contributors/new.hbs | 2 +- 11 files changed, 147 insertions(+), 52 deletions(-) create mode 100644 app/controllers/contributors/edit.js create mode 100644 app/routes/contributors/edit.js create mode 100644 app/templates/contributors/edit.hbs diff --git a/app/components/add-contributor/component.js b/app/components/add-contributor/component.js index ac9cb57..36c2097 100644 --- a/app/components/add-contributor/component.js +++ b/app/components/add-contributor/component.js @@ -1,6 +1,7 @@ import Component from '@ember/component'; import { and, notEmpty } from '@ember/object/computed'; import { inject as service } from '@ember/service'; +import { isPresent } from '@ember/utils'; export default Component.extend({ @@ -26,6 +27,12 @@ export default Component.extend({ init () { this._super(...arguments); + this.setDefaultAttributes(); + this.reset(); + }, + + setDefaultAttributes () { + if (isPresent(this.attributes)) { return; } this.set('attributes', { account: null, @@ -37,8 +44,6 @@ export default Component.extend({ gitea_username: null, wiki_username: null }); - - this.reset(); }, reset: function() { diff --git a/app/components/add-contributor/template.hbs b/app/components/add-contributor/template.hbs index fe98c5f..ccb34e3 100644 --- a/app/components/add-contributor/template.hbs +++ b/app/components/add-contributor/template.hbs @@ -1,62 +1,50 @@

- {{input name="account" - type="text" + + {{input name="account" id="c-account" + type="text" value=account placeholder="0xF18E631Ea191aE4ebE70046Fcb01a436554421BA4" - value=account class=(if isValidAccount "valid" "")}}

-

- {{input name="name" - type="text" - placeholder="Name" - value=name - class=(if isValidName "valid" "")}} + + {{input name="name" type="text" value=name placeholder="Zero Cool" + class=(if isValidName "valid" "") id="c-name"}}

- {{input name="url" - type="text" - placeholder="URL" - value=url - class=(if isValidURL "valid" "")}} + + {{input name="url" type="text" value=url placeholder="http://zerocool.bit" + class=(if isValidURL "valid" "") id="c-url"}}

- {{input name="github_uid" - type="text" - placeholder="GitHub UID (123)" - value=github_uid - class=(if isValidGithubUID "valid" "")}} + + {{input name="github_uid" type="text" value=github_uid placeholder="2342" + class=(if isValidGithubUID "valid" "") id="c-github-uid"}}

- {{input name="github_username" - type="text" - placeholder="GitHub username" - value=github_username - class=(if isValidGithubUsername "valid" "")}} + + {{input name="github_username" type="text" value=github_username placeholder="zerocool" + class=(if isValidGithubUsername "valid" "") id="c-github-username"}}

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

- {{input name="wiki_username" - type="text" - placeholder="Wiki Username" - value=wiki_username - class=(if isValidWikiUsername "valid" "")}} + + {{input name="wiki_username" type="text" value=wiki_username placeholder="ZeroCool" + class=(if isValidWikiUsername "valid" "") id="c-wiki-username"}}

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

diff --git a/app/components/contributor-list/template.hbs b/app/components/contributor-list/template.hbs index ec319e4..1ecabf6 100644 --- a/app/components/contributor-list/template.hbs +++ b/app/components/contributor-list/template.hbs @@ -26,6 +26,9 @@ Inspect IPFS profile {{/if}} +
  • + {{link-to "Edit profile" "contributors.edit" c.contributor.id}} +
  • {{#if c.showMetadata}}
    {{c.contributor.ipfsData}}
    diff --git a/app/controllers/contributors/edit.js b/app/controllers/contributors/edit.js new file mode 100644 index 0000000..5e42802 --- /dev/null +++ b/app/controllers/contributors/edit.js @@ -0,0 +1,18 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; + +export default Controller.extend({ + + kredits: service(), + + actions: { + + save (attributes) { + return this.kredits + .updateContributor(this.model.id, attributes) + .then(() => this.transitionToRoute('index')) + } + + } + +}); diff --git a/app/controllers/contributors/new.js b/app/controllers/contributors/new.js index ed7a1f6..5bc88f0 100644 --- a/app/controllers/contributors/new.js +++ b/app/controllers/contributors/new.js @@ -1,21 +1,16 @@ 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; - }); + return this.kredits + .addContributor(contributor) + .then(() => this.transitionToRoute('index')) } } diff --git a/app/router.js b/app/router.js index afa8660..e218bb7 100644 --- a/app/router.js +++ b/app/router.js @@ -15,6 +15,7 @@ Router.map(function() { }); this.route('contributors', function() { this.route('new'); + this.route('edit', { path: ':id/edit' }); }); }); diff --git a/app/routes/contributors/edit.js b/app/routes/contributors/edit.js new file mode 100644 index 0000000..5b5f212 --- /dev/null +++ b/app/routes/contributors/edit.js @@ -0,0 +1,29 @@ +import { inject as service } from '@ember/service'; +import Route from '@ember/routing/route'; +import { alias } from '@ember/object/computed'; + +export default Route.extend({ + + kredits: service(), + contributors: alias('kredits.contributors'), + + model(params) { + return this.kredits.contributors.findBy('id', params.id); + }, + + setupController (controller, model) { + this._super(controller, model); + + controller.set('attributes', { + account: model.account, + name: model.name, + kind: model.kind, + url: model.url, + github_username: model.github_username, + github_uid: model.github_uid, + gitea_username: model.gitea_username, + wiki_username: model.wiki_username + }); + } + +}); diff --git a/app/services/kredits.js b/app/services/kredits.js index f6d7e5f..f282164 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -190,13 +190,24 @@ export default Service.extend({ return this.kredits.Contributor.add(attributes, { gasLimit: 350000 }) .then(data => { console.debug('[kredits] add contributor response', data); - const contributor = Contributor.create(attributes); - this.contributors.pushObject(contributor); - return contributor; }); }, - getContributors() { + updateContributor (id, attributes) { + if (attributes.github_uid) { + const uidInt = parseInt(attributes.github_uid); + attributes.github_uid = uidInt; + } + + console.debug('[kredits] update contributor', attributes); + + return this.kredits.Contributor.updateProfile(id, attributes, { gasLimit: 350000 }) + .then(data => { + console.debug('[kredits] updateProfile response', data); + }); + }, + + getContributors () { return this.kredits.Contributor.all() .then((contributors) => { return contributors.map((contributor) => { @@ -293,6 +304,11 @@ export default Service.extend({ // Contract events addContractEventHandlers () { + this.kredits.Contributor + .on('ContributorProfileUpdated', this.handleContributorChange.bind(this)) + .on('ContributorAccountUpdated', this.handleContributorChange.bind(this)) + .on('ContributorAdded', this.handleContributorChange.bind(this)) + this.kredits.Contribution .on('ContributionVetoed', this.handleContributionVetoed.bind(this)) @@ -305,7 +321,23 @@ export default Service.extend({ .on('Transfer', this.handleTransfer.bind(this)); }, - handleContributionVetoed(contributionId) { + async handleContributorChange (contributorId, ...args) { + console.debug('[kredits] Contributor add/update event received for ID', contributorId); + console.debug('[kredits] Event data:', args); + const contributorData = await this.kredits.Contributor.getById(contributorId); + const newContributor = Contributor.create(contributorData); + + const oldContributor = this.contributors.findBy('id', contributorId.toString()); + if (oldContributor) { + console.debug('[kredits] old contributor', oldContributor); + this.contributors.removeObject(oldContributor); + } + + console.debug('[kredits] new contributor', newContributor); + this.contributors.pushObject(newContributor); + }, + + handleContributionVetoed (contributionId) { console.debug('[kredits] ContributionVetoed event received for ', contributionId); const contribution = this.contributions.findBy('id', contributionId); console.debug('[kredits] contribution', contribution); diff --git a/app/styles/_forms.scss b/app/styles/_forms.scss index 6a8debd..f9e3dd9 100644 --- a/app/styles/_forms.scss +++ b/app/styles/_forms.scss @@ -17,6 +17,12 @@ section#add-proposal { } } + label { + display: block; + margin-bottom: 0.5rem; + opacity: 0.7; + } + input[type=text], select { width: 100%; padding: 1rem; @@ -25,9 +31,14 @@ section#add-proposal { background-color: rgba(22, 21, 40, 0.3); color: #fff; font-size: 1.2rem; + transition: border-color 0.1s linear; + &:focus, &.valid { background-color: rgba(22, 21, 40, 0.6); } + &:focus { + border-color: $blue; + } &::placeholder { color: rgba(238, 238, 238, 0.5); } diff --git a/app/templates/contributors/edit.hbs b/app/templates/contributors/edit.hbs new file mode 100644 index 0000000..0d772b1 --- /dev/null +++ b/app/templates/contributors/edit.hbs @@ -0,0 +1,13 @@ +
    + +
    +
    +

    Update contributor profile

    +
    + +
    + {{add-contributor attributes=attributes save=(action "save")}} +
    +
    + +
    diff --git a/app/templates/contributors/new.hbs b/app/templates/contributors/new.hbs index 8351f57..d1a75b2 100644 --- a/app/templates/contributors/new.hbs +++ b/app/templates/contributors/new.hbs @@ -6,7 +6,7 @@
    - {{add-contributor contributors=contributors save=(action "save")}} + {{add-contributor save=(action "save")}}