Add "give kredits" button to contributor profiles #180
@@ -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({
|
||||
@@ -24,19 +24,17 @@ 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', assign({}, this.defaultAttr, this.attributes));
|
||||
|
||||
this.reset();
|
||||
},
|
||||
|
||||
@@ -6,6 +6,8 @@ export default Controller.extend({
|
||||
|
||||
kredits: service(),
|
||||
|
||||
queryParams: ['contributorId', 'kind', 'amount'],
|
||||
|
||||
contributors: alias('kredits.contributors'),
|
||||
minedContributors: filterBy('contributors', 'id'),
|
||||
|
||||
|
||||
+1
-1
@@ -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() {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default Route.extend({
|
||||
|
||||
model (params) {
|
||||
return { params };
|
||||
}
|
||||
|
||||
});
|
||||
@@ -42,6 +42,10 @@ section#contributor-profile {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
{{add-contribution contributors=sortedContributors save=(action "save")}}
|
||||
{{add-contribution contributors=sortedContributors
|
||||
attributes=model.params
|
||||
save=(action "save")}}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -22,6 +22,13 @@
|
||||
</li>
|
||||
{{/if}}
|
||||
</ul>
|
||||
<div class="actions">
|
||||
<p>
|
||||
{{link-to "♥ Give kredits" "contributions.new"
|
||||
(query-params contributorId=model.id)
|
||||
class="button green"}}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user
Instead of merging attributes manually, you can use Ember's
assignmethod to replace the wholeif-elseblock.