Merge pull request #180 from 67P/feature/add_contribution_with_params
Add "give kredits" button to contributor profiles
This commit was merged in pull request #180.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import Component from '@ember/component';
|
import Component from '@ember/component';
|
||||||
import { computed } from '@ember/object';
|
import { computed } from '@ember/object';
|
||||||
import { and, notEmpty } from '@ember/object/computed';
|
import { and, notEmpty } from '@ember/object/computed';
|
||||||
import { isEmpty } from '@ember/utils';
|
import { assign } from '@ember/polyfills';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
@@ -24,19 +24,17 @@ export default Component.extend({
|
|||||||
init () {
|
init () {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
this.set('defaultDate', moment().startOf('hour').toDate());
|
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
|
this.set('attributes', assign({}, this.defaultAttr, this.attributes));
|
||||||
if (isEmpty(this.attributes)) {
|
|
||||||
this.set('attributes', {
|
|
||||||
contributorId: null,
|
|
||||||
kind: null,
|
|
||||||
date: this.defaultDate,
|
|
||||||
amount: null,
|
|
||||||
description: null,
|
|
||||||
url: null,
|
|
||||||
details: null
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export default Controller.extend({
|
|||||||
|
|
||||||
kredits: service(),
|
kredits: service(),
|
||||||
|
|
||||||
|
queryParams: ['contributorId', 'kind', 'amount'],
|
||||||
|
|
||||||
contributors: alias('kredits.contributors'),
|
contributors: alias('kredits.contributors'),
|
||||||
minedContributors: filterBy('contributors', 'id'),
|
minedContributors: filterBy('contributors', 'id'),
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ Router.map(function() {
|
|||||||
this.route('new');
|
this.route('new');
|
||||||
});
|
});
|
||||||
this.route('contributions', function() {
|
this.route('contributions', function() {
|
||||||
this.route('new');
|
this.route('new', { queryParams: ['contributorId', 'kind', 'amount'] });
|
||||||
this.route('resubmit', { path: ':id/resubmit' });
|
this.route('resubmit', { path: ':id/resubmit' });
|
||||||
});
|
});
|
||||||
this.route('contributors', function() {
|
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 {
|
.actions {
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{{add-contribution contributors=sortedContributors save=(action "save")}}
|
{{add-contribution contributors=sortedContributors
|
||||||
|
attributes=model.params
|
||||||
|
save=(action "save")}}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,13 @@
|
|||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
|
<div class="actions">
|
||||||
|
<p>
|
||||||
|
{{link-to "♥ Give kredits" "contributions.new"
|
||||||
|
(query-params contributorId=model.id)
|
||||||
|
class="button green"}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<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