Additional vote features

This commit is contained in:
Nico 2020-04-26 02:41:26 +02:00
parent fe7398faef
commit 7bb0aa7488
5 changed files with 62 additions and 32 deletions

View file

@ -212,6 +212,8 @@ template(name="cardDetails")
else
.card-label.card-label-green {{ voteCountPositive }}
.card-label.card-label-red {{ voteCountNegative }}
unless ($and currentBoard.isPublic voteAllowNonBoardMembers )
.card-label.card-label-gray {{ voteCount }} {{_ 'r-of' }} {{ currentBoard.activeMembers.length }}
+viewer
= getVoteQuestion
button.card-details-green.js-vote.js-vote-positive(class="{{#if voteState}}voted{{/if}}") {{_ 'vote-for-it'}}
@ -572,9 +574,17 @@ template(name="cardStartVotingPopup")
.fields
label(for="vote") {{_ 'vote-question'}}
input.js-vote-field#vote(type="text" name="vote" value="{{card.getVoteQuestion}}" autofocus)
label(for="vote-public") {{_ 'vote-public'}}
a.js-toggle-vote-public
.check-div
a.flex.js-toggle-vote-public
.materialCheckBox#vote-public(name="vote-public")
span {{_ 'vote-public'}}
.check-div
a.flex.js-toggle-vote-allow-non-members
.materialCheckBox#vote-allow-non-members(name="vote-allow-non-members")
span {{_ 'allowNonBoardMembers'}}
//- label(for="vote-public") {{_ 'vote-public'}}
//- a.js-toggle-vote-public
//- .materialCheckBox#vote-public(name="vote-public")
button.primary.confirm.js-submit {{_ 'save'}}
//- button.js-remove-color.negate.wide.right {{_ 'delete'}}

View file

@ -54,21 +54,7 @@ BlazeComponent.extendComponent({
}
return null;
},
votePublic() {
const card = this.currentData();
if (card.vote) return card.vote.public;
return null;
},
voteCountPositive() {
const card = this.currentData();
if (card.vote && card.vote.positive) return card.vote.positive.length;
return null;
},
voteCountNegative() {
const card = this.currentData();
if (card.vote && card.vote.negative) return card.vote.negative.length;
return null;
},
isWatching() {
const card = this.currentData();
return card.findWatcher(Meteor.userId());
@ -1001,13 +987,18 @@ BlazeComponent.extendComponent({
evt.preventDefault();
const voteQuestion = evt.target.vote.value;
const publicVote = $('#vote-public').hasClass('is-checked');
this.currentCard.setVoteQuestion(voteQuestion, publicVote);
const allowNonBoardMembers = $('#vote-allow-non-members').hasClass('is-checked');
this.currentCard.setVoteQuestion(voteQuestion, publicVote,allowNonBoardMembers);
Popup.close();
},
'click a.js-toggle-vote-public'(event) {
event.preventDefault();
$('#vote-public').toggleClass('is-checked');
},
'click a.js-toggle-vote-allow-non-members'(event) {
event.preventDefault();
$('#vote-allow-non-members').toggleClass('is-checked');
},
},
];
},

View file

@ -103,7 +103,9 @@ template(name="minicard")
if getVoteQuestion
.badge.badge-state-image-only(title=getVoteQuestion)
span.badge-icon.fa.fa-thumbs-up
span.badge-text {{ voteCountPositive }}
span.badge-icon.fa.fa-thumbs-down
span.badge-text {{ voteCountNegative }}
if attachments.count
.badge
span.badge-icon.fa.fa-paperclip

View file

@ -166,6 +166,7 @@
"cardStartVotingPopup-title": "Start a vote",
"positiveVoteMembersPopup-title": "Proponents",
"negativeVoteMembersPopup-title": "Opponents",
"allowNonBoardMembers": "Allow non board members",
"vote-question": "Voting question",
"vote-public": "Public vote",
"vote-for-it": "for it",
@ -675,6 +676,7 @@
"r-of-checklist": "of checklist",
"r-send-email": "Send an email",
"r-to": "to",
"r-of": "of",
"r-subject": "subject",
"r-rule-details": "Rule details",
"r-d-move-to-top-gen": "Move card to top of its list",

View file

@ -340,6 +340,10 @@ Cards.attachSchema(
type: Boolean,
defaultValue: false,
},
'vote.allowNonBoardMembers': {
type: Boolean,
defaultValue: false,
},
}),
);
@ -347,8 +351,8 @@ Cards.allow({
insert(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
},
update(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
update(userId, doc, fields) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId)) || _.isEqual(fields, ['vote', 'modifiedAt', 'dateLastActivity']);
},
remove(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
@ -1152,6 +1156,26 @@ Cards.helpers({
isTemplateCard() {
return this.type === 'template-card';
},
votePublic() {
if (this.vote) return this.vote.public;
return null;
},
voteAllowNonBoardMembers() {
if (this.vote) return this.vote.allowNonBoardMembers;
return null;
},
voteCountNegative() {
if (this.vote && this.vote.negative) return this.vote.negative.length;
return null;
},
voteCountPositive() {
if (this.vote && this.vote.positive) return this.vote.positive.length;
return null;
},
voteCount() {
return this.voteCountPositive() + this.voteCountNegative()
},
});
Cards.mutations({
@ -1475,12 +1499,13 @@ Cards.mutations({
},
};
},
setVoteQuestion(question, public) {
setVoteQuestion(question, public, allowNonBoardMembers) {
return {
$set: {
vote: {
question,
public,
allowNonBoardMembers,
positive: [],
negative: [],
},