From 23d86f150208d1a1f1e8f96cfa6dc28eff35c166 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 10 Dec 2019 13:09:30 +0300 Subject: [PATCH 1/6] Add unit test for add-contribution component --- .../unit/components/add-contribution-test.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/unit/components/add-contribution-test.js diff --git a/tests/unit/components/add-contribution-test.js b/tests/unit/components/add-contribution-test.js new file mode 100644 index 0000000..4247ae7 --- /dev/null +++ b/tests/unit/components/add-contribution-test.js @@ -0,0 +1,24 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import moment from 'moment'; + +module('Unit | Component | add-contribution', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let component = this.owner.factoryFor('component:add-contribution').create(); + assert.ok(component); + }); + + test('default attributes', function(assert) { + let component = this.owner.factoryFor('component:add-contribution').create(); + + ['contributorId', 'kind', 'amount', 'description', 'url', 'details'].forEach(a => { + assert.equal(component.attributes[a], null, `sets the default ${a} attribute`); + assert.equal(component.get(a), null, `sets the ${a} property`); + }); + + assert.ok(moment.isDate(component.attributes.date, 'sets the default date attribute')); + assert.ok(moment.isDate(component.date), 'sets the default date'); + }); +}); From 863b542e3ebb0b7debb3b0188679aec7be492298 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 10 Dec 2019 13:18:21 +0300 Subject: [PATCH 2/6] Add failing test for partial attribute override Currently the default attributes are only set correctly when either none or all attributes are handed to the component --- .../unit/components/add-contribution-test.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/unit/components/add-contribution-test.js b/tests/unit/components/add-contribution-test.js index 4247ae7..21a8f9a 100644 --- a/tests/unit/components/add-contribution-test.js +++ b/tests/unit/components/add-contribution-test.js @@ -18,7 +18,24 @@ module('Unit | Component | add-contribution', function(hooks) { assert.equal(component.get(a), null, `sets the ${a} property`); }); - assert.ok(moment.isDate(component.attributes.date, 'sets the default date attribute')); + assert.ok(moment.isDate(component.attributes.date), 'sets the default date attribute'); assert.ok(moment.isDate(component.date), 'sets the default date'); }); + + test('override default attributes', function(assert) { + let component = this.owner.factoryFor('component:add-contribution').create({ + attributes: { contributorId: '1' } + }); + + assert.equal(component.contributorId, '1', `overrides the default property`); + + ['kind', 'amount', 'description', 'url', 'details'].forEach(a => { + assert.equal(component.attributes[a], null, `sets the default ${a} attribute`); + assert.equal(component.get(a), null, `sets the ${a} property`); + }); + + assert.ok(moment.isDate(component.attributes.date), 'sets the default date attribute'); + assert.ok(moment.isDate(component.date), 'sets the default date'); + }); + }); From 04a7f9139df78ab57ea12788b87424c12adbd59e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 10 Dec 2019 13:40:08 +0300 Subject: [PATCH 3/6] Allow partial override of contribution attributes --- app/components/add-contribution/component.js | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/components/add-contribution/component.js b/app/components/add-contribution/component.js index b9533f8..b50b80f 100644 --- a/app/components/add-contribution/component.js +++ b/app/components/add-contribution/component.js @@ -24,18 +24,25 @@ export default Component.extend({ init () { this._super(...arguments); this.set('defaultDate', moment().startOf('hour').toDate()); + this.set('defaultAttr', { + contributorId: null, + kind: null, + date: this.defaultDate, + amount: null, + description: null, + url: null, + details: null + }); // Default attributes used by reset if (isEmpty(this.attributes)) { - this.set('attributes', { - contributorId: null, - kind: null, - date: this.defaultDate, - amount: null, - description: null, - url: null, - details: null - }); + this.set('attributes', this.defaultAttr); + } else { + Object.keys(this.defaultAttr).forEach(a => { + if (typeof this.attributes[a] === 'undefined') { + this.attributes[a] = this.defaultAttr[a]; + } + }) } this.reset(); From 536868002f26c863652635486f664a67a303e2b1 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 10 Dec 2019 18:16:54 +0100 Subject: [PATCH 4/6] Support query params for adding contribution Just contributor ID, kind, and amount for now. --- app/controllers/contributions/new.js | 2 ++ app/router.js | 2 +- app/routes/contributions/new.js | 9 +++++++++ app/templates/contributions/new.hbs | 4 +++- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/routes/contributions/new.js diff --git a/app/controllers/contributions/new.js b/app/controllers/contributions/new.js index 75e00c6..0cab1b8 100644 --- a/app/controllers/contributions/new.js +++ b/app/controllers/contributions/new.js @@ -6,6 +6,8 @@ export default Controller.extend({ kredits: service(), + queryParams: ['contributorId', 'kind', 'amount'], + contributors: alias('kredits.contributors'), minedContributors: filterBy('contributors', 'id'), diff --git a/app/router.js b/app/router.js index 014dbc8..71b14b2 100644 --- a/app/router.js +++ b/app/router.js @@ -20,7 +20,7 @@ Router.map(function() { this.route('new'); }); this.route('contributions', function() { - this.route('new'); + this.route('new', { queryParams: ['contributorId', 'kind', 'amount'] }); this.route('resubmit', { path: ':id/resubmit' }); }); this.route('contributors', function() { diff --git a/app/routes/contributions/new.js b/app/routes/contributions/new.js new file mode 100644 index 0000000..7d760ab --- /dev/null +++ b/app/routes/contributions/new.js @@ -0,0 +1,9 @@ +import Route from '@ember/routing/route'; + +export default Route.extend({ + + model (params) { + return { params }; + } + +}); diff --git a/app/templates/contributions/new.hbs b/app/templates/contributions/new.hbs index c7b5ffb..5682115 100644 --- a/app/templates/contributions/new.hbs +++ b/app/templates/contributions/new.hbs @@ -6,7 +6,9 @@
- {{add-contribution contributors=sortedContributors save=(action "save")}} + {{add-contribution contributors=sortedContributors + attributes=model.params + save=(action "save")}}
From 0a6b6180b9d99f8e0d807deb866f267faa0ed40a Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 12 Dec 2019 17:33:08 +0100 Subject: [PATCH 5/6] Add "give kredits" button to contributor profiles closes #172 --- app/styles/components/_contributor-profile.scss | 4 ++++ app/templates/dashboard/contributors/show.hbs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/app/styles/components/_contributor-profile.scss b/app/styles/components/_contributor-profile.scss index b911efe..73ed08d 100644 --- a/app/styles/components/_contributor-profile.scss +++ b/app/styles/components/_contributor-profile.scss @@ -42,6 +42,10 @@ section#contributor-profile { } } } + + .actions { + margin-top: 2rem; + } } .actions { diff --git a/app/templates/dashboard/contributors/show.hbs b/app/templates/dashboard/contributors/show.hbs index 07fdad8..c629c52 100644 --- a/app/templates/dashboard/contributors/show.hbs +++ b/app/templates/dashboard/contributors/show.hbs @@ -22,6 +22,13 @@ {{/if}} +
+

+ {{link-to "♥ Give kredits" "contributions.new" + (query-params contributorId=model.id) + class="button green"}} +

+
From 3f4cc39067c52e914ecb15dd7b045f544b09bf89 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 13 Dec 2019 17:01:39 +0100 Subject: [PATCH 6/6] Refactor assignment Co-authored-by: Garret Alfert --- app/components/add-contribution/component.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/components/add-contribution/component.js b/app/components/add-contribution/component.js index b50b80f..19247a8 100644 --- a/app/components/add-contribution/component.js +++ b/app/components/add-contribution/component.js @@ -1,7 +1,7 @@ import Component from '@ember/component'; import { computed } from '@ember/object'; import { and, notEmpty } from '@ember/object/computed'; -import { isEmpty } from '@ember/utils'; +import { assign } from '@ember/polyfills'; import moment from 'moment'; export default Component.extend({ @@ -34,16 +34,7 @@ export default Component.extend({ details: null }); - // Default attributes used by reset - if (isEmpty(this.attributes)) { - this.set('attributes', this.defaultAttr); - } else { - Object.keys(this.defaultAttr).forEach(a => { - if (typeof this.attributes[a] === 'undefined') { - this.attributes[a] = this.defaultAttr[a]; - } - }) - } + this.set('attributes', assign({}, this.defaultAttr, this.attributes)); this.reset(); },