This is an automated email from the git hooks/post-receive script. New commit to branch feature/149-jugement-majoritaire in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit dd36bebb5ae59580ddb4b69821563c6be627bde7 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Oct 9 14:33:10 2017 +0200 modification de l'écran de vote pour la jugement majoritaire ref #149 --- .../pollen/services/bean/VoteCountingTypeBean.java | 4 +++ pollen-ui-riot-js/src/main/web/js/Poll.js | 6 +++- .../src/main/web/tag/poll/Votes.tag.html | 40 +++++++++++++++++++--- .../votecounting/model/ChoiceToVoteRenderType.java | 5 ++- .../votecounting/MajorityJudgmentVoteCounting.java | 6 ++-- .../MajorityJudgmentVoteCountingStrategy.java | 5 +-- 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java index b5ee6b98..32e0ed17 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java @@ -97,6 +97,10 @@ public class VoteCountingTypeBean { case TEXTFIELD: this.renderType = "text"; break; + + case SELECT: + this.renderType = "select"; + break; } } diff --git a/pollen-ui-riot-js/src/main/web/js/Poll.js b/pollen-ui-riot-js/src/main/web/js/Poll.js index 25518a5c..3dc4f817 100644 --- a/pollen-ui-riot-js/src/main/web/js/Poll.js +++ b/pollen-ui-riot-js/src/main/web/js/Poll.js @@ -208,7 +208,11 @@ class Poll { getVoteValue(vote, choice) { let voteChoice = this.getVoteChoice(vote, choice); - return voteChoice && voteChoice.voteValue; + let value = voteChoice && voteChoice.voteValue; + if (this.voteCountingType === 8) { + value = this.voteCountingConfig.grades[value]; + } + return value; } loadResults() { diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html index 9e88a4a4..195c0f10 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html @@ -68,7 +68,7 @@ require("../components/Avatar.tag.html"); onchange="{onVoteChanged}" ref="{choice.id}_voteValue" tabindex="{10 * (index + 1)}"> - <input if={!pollTypeCheckbox} + <input if={!pollTypeCheckbox && !pollTypeSelect} class="text c-field {c-field--error: !voteInEdition && error && (error['vote.voteValue#' + choice.id] || error['vote.totalVoteValue'])}" type="number" required={!poll.voteCountingConfig.maxChoiceNumber} @@ -77,14 +77,31 @@ require("../components/Avatar.tag.html"); onchange="{onVoteChanged}" ref="{choice.id}_voteValue" tabindex="{10 * (index + 1)}"> + <select if={pollTypeSelect} + class="c-field {c-field--error: !voteInEdition && error && error['vote.voteValue#' + choice.id]}" + required + onchange={onVoteChanged} + tabindex="{10 * (index + 1)}"> + <option value=""></option> + <option each={grad, index in poll.voteCountingConfig.grades} + value={index} + ref="{choice.id}_voteValue"> + {grad} + </option> + </select> </div> </div> <div if={poll.resultIsVisible} class="score-choice"> <span if={!choice.score}>{parent.__.noVote}</span> <span if={choice.score}> <i if="{choice.score.scoreOrder === 0}" class="fa fa-trophy fa-15x winner"></i> - {choice.score.scoreValue} - {parent.__["results_unit_" + poll.voteCountingType + "_" + (choice.score.scoreValue > 1 ? "many" : "one")]} + <span if={!pollTypeSelect}> + {choice.score.scoreValue} + {parent.__["results_unit_" + poll.voteCountingType + "_" + (choice.score.scoreValue > 1 ? "many" : "one")]} + </span> + <span if={pollTypeSelect}> + {poll.voteCountingConfig.grades[choice.score.scoreValue]} + </span> </span> </div> </div> @@ -284,6 +301,7 @@ require("../components/Avatar.tag.html"); this.loaded = poll.choices !== undefined; this.poll = poll; this.pollTypeCheckbox = poll.voteCountingTypeValue && poll.voteCountingTypeValue.renderType === "checkbox"; + this.pollTypeSelect = poll.voteCountingTypeValue && poll.voteCountingTypeValue.renderType === "select"; this.choiceToAdd = this.poll.initChoice(this.choiceToAdd); this.onVoteChanged(); this.refresh(); @@ -316,11 +334,18 @@ require("../components/Avatar.tag.html"); if (input) { if (this.poll.voteCountingTypeValue.renderType === "text") { input.value = choice.voteValue; + } else if (this.poll.voteCountingTypeValue.renderType === "select") { + input.forEach(option => {option.selected = option.value === choice.voteValue + "";}); + } else { + input.checked = choice.voteValue === 1; } - input.checked = choice.voteValue === 1; } }); - this.refs[this.poll.choices[0].id + "_voteValue"].focus(); + if (this.poll.voteCountingTypeValue.renderType === "select") { + this.refs[this.poll.choices[0].id + "_voteValue"][0].parentNode.focus(); + } else { + this.refs[this.poll.choices[0].id + "_voteValue"].focus(); + } }; this.getChoiceVoteValue = ref => { @@ -331,6 +356,9 @@ require("../components/Avatar.tag.html"); if (this.poll.voteCountingTypeValue.renderType === "text") { return input.value; } + if (this.poll.voteCountingTypeValue.renderType === "select") { + return input.find(option => option.selected).value; + } return input.checked ? 1 : 0; }; @@ -356,6 +384,8 @@ require("../components/Avatar.tag.html"); let input = this.refs[choice.id + "_voteValue"]; if (this.poll.voteCountingTypeValue.renderType === "text") { input.value = ""; + } else if (this.poll.voteCountingTypeValue.renderType === "select") { + input.forEach(option => {option.selected = false;}); } else { input.checked = ""; } diff --git a/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceToVoteRenderType.java b/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceToVoteRenderType.java index 2f3207c3..519f2d81 100644 --- a/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceToVoteRenderType.java +++ b/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceToVoteRenderType.java @@ -36,5 +36,8 @@ public enum ChoiceToVoteRenderType { */ CHECKBOX, /** To render as a text field. */ - TEXTFIELD + TEXTFIELD, + + /** To render as a select. */ + SELECT } diff --git a/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCounting.java b/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCounting.java index 09dc8d4d..f06c5363 100644 --- a/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCounting.java +++ b/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCounting.java @@ -67,7 +67,7 @@ public class MajorityJudgmentVoteCounting extends AbstractVoteCounting<MajorityJ @Override public ChoiceToVoteRenderType getVoteValueEditorType() { - return ChoiceToVoteRenderType.TEXTFIELD; + return ChoiceToVoteRenderType.SELECT; } @Override @@ -87,7 +87,7 @@ public class MajorityJudgmentVoteCounting extends AbstractVoteCounting<MajorityJ @Override public boolean isChoiceInVote(Double voteValue) { - return voteValue != null && voteValue > 0; + return voteValue != null && voteValue >= 0; } @Override @@ -97,7 +97,7 @@ public class MajorityJudgmentVoteCounting extends AbstractVoteCounting<MajorityJ @Override public boolean isVoteValueValid(Double voteValue) { - return voteValue != null && voteValue > 0; + return voteValue != null && voteValue >= 0; } @Override diff --git a/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCountingStrategy.java b/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCountingStrategy.java index 698f8a8e..adc0796f 100644 --- a/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCountingStrategy.java +++ b/pollen-votecounting-majority-judgment/src/main/java/org/chorem/pollen/votecounting/MajorityJudgmentVoteCountingStrategy.java @@ -104,10 +104,11 @@ public class MajorityJudgmentVoteCountingStrategy extends AbstractVoteCountingSt .stream() .filter(choiceResult -> voteForChoice.getChoiceId().equals(choiceResult.getChoiceId())) .findFirst() - .ifPresent(choiceResult -> addGrad(choiceResult, voteForChoice.getVoteValue().intValue(), weight)); + .ifPresent(choiceResult -> addGrad(choiceResult, voteForChoice.getVoteValue(), weight)); } - protected void addGrad(MajorityJudgmentChoiceResult choiceResult, int grade, BigDecimal weight) { + protected void addGrad(MajorityJudgmentChoiceResult choiceResult, Double voteValue, BigDecimal weight) { + int grade = voteValue == null ? 0 : voteValue.intValue(); List<BigDecimal> voteByGrad = choiceResult.getVoteByGrad(); BigDecimal vote = voteByGrad.get(grade).add(weight); voteByGrad.set(grade, vote); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.