diff --git a/app/components/proposal-list/component.js b/app/components/proposal-list/component.js index 272e28e..1ce555d 100644 --- a/app/components/proposal-list/component.js +++ b/app/components/proposal-list/component.js @@ -1,20 +1,30 @@ import Component from '@ember/component'; +import { inject } from '@ember/service'; +import { empty } from '@ember/object/computed'; export default Component.extend({ + kredits: inject(), tagName: 'ul', classNames: ['proposal-list'], + selectedProposals: [], + submitButtonDisabled: empty('selectedProposals'), + actions: { + confirm() { + this.confirmProposals(this.selectedProposals) + .then(() => { + this.selectedProposals = []; + }); + }, - confirm(proposalId) { - if (this.contractInteractionEnabled) { - this.confirmProposal(proposalId); + toggleSelect(proposalId, selected) { + if (selected) { + this.selectedProposals.removeObject(proposalId); } else { - window.alert('Only members can vote on proposals. Please ask someone to set you up.'); + this.selectedProposals.addObject(proposalId); } - } - + }, } - }); diff --git a/app/components/proposal-list/item/component.js b/app/components/proposal-list/item/component.js new file mode 100644 index 0000000..66c000e --- /dev/null +++ b/app/components/proposal-list/item/component.js @@ -0,0 +1,29 @@ +import Component from '@ember/component'; +import tag from 'ember-awesome-macros/tag'; +import { computed } from '@ember/object'; +import { reads } from '@ember/object/computed'; +import { inject } from '@ember/service'; + +export default Component.extend({ + kredits: inject(), + + tagName: 'li', + classNames: ['proposal-list-item'], + + attributeBindings: ['data-proposal-id', 'title'], + + title: tag`(${'proposal.kind'}) ${'proposal.description'}`, + 'data-proposal-id': reads('proposal.id'), + + canBeVoted: computed('voterIds.[]', 'kredits.currentUser', function() { + let { isExecuted, voterIds } = this.proposal; + let { currentUser } = this.kredits; + voterIds = voterIds.map((id) => id.toString()); + + return currentUser.isCore && !isExecuted && !voterIds.includes(currentUser.id); + }), + + selected: computed('selectedProposals.[]', function() { + return this.selectedProposals.includes(this.proposal.id); + }) +}); diff --git a/app/components/proposal-list/item/template.hbs b/app/components/proposal-list/item/template.hbs new file mode 100644 index 0000000..75ab52e --- /dev/null +++ b/app/components/proposal-list/item/template.hbs @@ -0,0 +1,8 @@ +♥ +{{proposal.amount}}₭S +for {{proposal.contributor.name}} +({{proposal.votesCount}}/{{proposal.votesNeeded}} votes) + +{{#if canBeVoted}} + +{{/if}} diff --git a/app/components/proposal-list/template.hbs b/app/components/proposal-list/template.hbs index 87bdbae..e12313a 100644 --- a/app/components/proposal-list/template.hbs +++ b/app/components/proposal-list/template.hbs @@ -1,12 +1,15 @@ {{#each proposals as |proposal|}} -