Re-submit vetoed contributions
This commit is contained in:
@@ -1,6 +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 moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
@@ -25,14 +26,17 @@ export default Component.extend({
|
|||||||
this.set('defaultDate', moment().startOf('hour').toDate());
|
this.set('defaultDate', moment().startOf('hour').toDate());
|
||||||
|
|
||||||
// Default attributes used by reset
|
// Default attributes used by reset
|
||||||
this.set('attributes', {
|
if (isEmpty(this.attributes)) {
|
||||||
contributorId: null,
|
this.set('attributes', {
|
||||||
kind: null,
|
contributorId: null,
|
||||||
date: this.defaultDate,
|
kind: null,
|
||||||
amount: null,
|
date: this.defaultDate,
|
||||||
description: null,
|
amount: null,
|
||||||
url: null,
|
description: null,
|
||||||
});
|
url: null,
|
||||||
|
details: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
},
|
},
|
||||||
@@ -67,7 +71,6 @@ export default Component.extend({
|
|||||||
window.alert('Something went wrong. Check the browser console for details.');
|
window.alert('Something went wrong. Check the browser console for details.');
|
||||||
})
|
})
|
||||||
.finally(() => this.set('inProgress', false));
|
.finally(() => this.set('inProgress', false));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,17 @@
|
|||||||
</p>
|
</p>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
{{#if details}}
|
||||||
|
<label>
|
||||||
|
<p class="label">Details:</p>
|
||||||
|
<p>
|
||||||
|
<pre>
|
||||||
|
{{details}}
|
||||||
|
</pre>
|
||||||
|
</p>
|
||||||
|
</label>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<p class="actions">
|
<p class="actions">
|
||||||
{{input type="submit"
|
{{input type="submit"
|
||||||
disabled=inProgress
|
disabled=inProgress
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import ContributionsNewController from 'kredits-web/controllers/contributions/new';
|
||||||
|
|
||||||
|
export default ContributionsNewController.extend({
|
||||||
|
|
||||||
|
attributes: null,
|
||||||
|
|
||||||
|
});
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import EmberObject, { computed } from '@ember/object';
|
import EmberObject, { computed } from '@ember/object';
|
||||||
|
import { isEmpty } from '@ember/utils';
|
||||||
import bignumber from 'kredits-web/utils/cps/bignumber';
|
import bignumber from 'kredits-web/utils/cps/bignumber';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
export default EmberObject.extend({
|
export default EmberObject.extend({
|
||||||
|
|
||||||
@@ -24,11 +26,15 @@ export default EmberObject.extend({
|
|||||||
|
|
||||||
init () {
|
init () {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
this.set('details', {});
|
if (isEmpty(this.details)) this.set('details', {});
|
||||||
},
|
},
|
||||||
|
|
||||||
iso8601Date: computed('date', 'time', function() {
|
iso8601Date: computed('date', 'time', function() {
|
||||||
return this.time ? `${this.date}T${this.time}` : this.date;
|
return this.time ? `${this.date}T${this.time}` : this.date;
|
||||||
|
}),
|
||||||
|
|
||||||
|
jsDate: computed('iso8601Date', function() {
|
||||||
|
return moment(this.iso8601Date).toDate();
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Router.map(function() {
|
|||||||
});
|
});
|
||||||
this.route('contributions', function() {
|
this.route('contributions', function() {
|
||||||
this.route('new');
|
this.route('new');
|
||||||
|
this.route('resubmit', { path: ':id/resubmit' });
|
||||||
});
|
});
|
||||||
this.route('contributors', function() {
|
this.route('contributors', function() {
|
||||||
this.route('new');
|
this.route('new');
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import Route from '@ember/routing/route';
|
||||||
|
import { inject as service } from '@ember/service';
|
||||||
|
|
||||||
|
export default Route.extend({
|
||||||
|
|
||||||
|
kredits: service(),
|
||||||
|
|
||||||
|
model(params) {
|
||||||
|
const contribution = this.kredits.contributions.findBy('id', parseInt(params.id));
|
||||||
|
contribution.contributorId = contribution.contributorId.toString();
|
||||||
|
|
||||||
|
return contribution;
|
||||||
|
},
|
||||||
|
|
||||||
|
setupController (controller, model) {
|
||||||
|
this._super(controller, model);
|
||||||
|
|
||||||
|
controller.set('attributes', model.getProperties([
|
||||||
|
'kind', 'amount', 'description', 'url', 'details'
|
||||||
|
]));
|
||||||
|
controller.set('attributes.contributorId', model.contributorId.toString());
|
||||||
|
controller.set('attributes.date', model.jsDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
+22
-18
@@ -232,26 +232,30 @@ export default Service.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
addProposal (attributes) {
|
//
|
||||||
console.debug('[kredits] add proposal', attributes);
|
// TODO Implement proposals with voting
|
||||||
|
//
|
||||||
|
|
||||||
return this.kredits.Proposal.addProposal(attributes)
|
// addProposal (attributes) {
|
||||||
.then((data) => {
|
// console.debug('[kredits] add proposal', attributes);
|
||||||
console.debug('[kredits] add proposal response', data);
|
//
|
||||||
attributes.contributor = this.contributors.findBy('id', attributes.contributorId);
|
// return this.kredits.Proposal.addProposal(attributes)
|
||||||
return Proposal.create(attributes);
|
// .then((data) => {
|
||||||
});
|
// console.debug('[kredits] add proposal response', data);
|
||||||
},
|
// attributes.contributor = this.contributors.findBy('id', attributes.contributorId);
|
||||||
|
// return Proposal.create(attributes);
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
|
||||||
getProposals () {
|
// getProposals () {
|
||||||
return this.kredits.Proposal.all()
|
// return this.kredits.Proposal.all()
|
||||||
.then((proposals) => {
|
// .then(proposals => {
|
||||||
return proposals.map((proposal) => {
|
// return proposals.map(proposal => {
|
||||||
proposal.contributor = this.contributors.findBy('id', proposal.contributorId.toString());
|
// proposal.contributor = this.contributors.findBy('id', proposal.contributorId.toString());
|
||||||
return Proposal.create(proposal);
|
// return Proposal.create(proposal);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
|
|
||||||
getContributions () {
|
getContributions () {
|
||||||
return this.kredits.Contribution.all({page: {size: 200}})
|
return this.kredits.Contribution.all({page: {size: 200}})
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<main class="center-column">
|
||||||
|
|
||||||
|
<section id="add-contribution">
|
||||||
|
<header>
|
||||||
|
<h2>Re-submit contribution #{{model.id}}</h2>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
{{add-contribution attributes=attributes contributors=sortedContributors save=(action "save")}}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</main>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
kredits will be issued.
|
kredits will be issued.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
{{link-to "Re-submit contribution …" "signup" class="button small green"}}.
|
{{link-to "Re-submit contribution …" "contributions.resubmit" model class="button small green"}}.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
import Contribution from 'kredits-web/models/contribution';
|
||||||
|
|
||||||
|
module('Unit | Model | contribution', function(hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('iso8601Date', function(assert) {
|
||||||
|
const model = Contribution.create({
|
||||||
|
date: '2019-09-10'
|
||||||
|
});
|
||||||
|
assert.equal(model.iso8601Date, '2019-09-10');
|
||||||
|
|
||||||
|
model.set('time', '09:33:00.141Z');
|
||||||
|
assert.equal(model.iso8601Date, '2019-09-10T09:33:00.141Z');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('jsDate', function(assert) {
|
||||||
|
const model = Contribution.create({
|
||||||
|
date: '2019-09-10',
|
||||||
|
time: '09:33:00.141Z'
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.ok(model.jsDate instanceof Date);
|
||||||
|
assert.equal(model.jsDate.toISOString(), '2019-09-10T09:33:00.141Z');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
|
||||||
|
module('Unit | Route | contributions/resubmit', function(hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('it exists', function(assert) {
|
||||||
|
let route = this.owner.lookup('route:contributions/resubmit');
|
||||||
|
assert.ok(route);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user