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 @@
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}} +{{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 @@
+