This is an automated email from the git hooks/post-receive script. New commit to branch feature/58-limitation-des-votants in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 9703cece80388014678074d1eb9c5f52870b39b7 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Sep 28 08:43:02 2017 +0200 ne pas afficher les votes ignorés (ref #58) --- .../pollen/persistence/entity/VoteTopiaDao.java | 11 ++++++++ .../org/chorem/pollen/services/bean/VoteBean.java | 8 ++++++ .../pollen/services/service/VoteService.java | 27 +++++++++----------- pollen-ui-riot-js/src/main/web/css/custom.css | 6 +++-- pollen-ui-riot-js/src/main/web/i18n/en.json | 1 + pollen-ui-riot-js/src/main/web/i18n/fr.json | 1 + .../src/main/web/tag/poll/Votes.tag.html | 29 ++++++++++++++++++---- 7 files changed, 61 insertions(+), 22 deletions(-) diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java index a8ada816..6af63b31 100644 --- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java @@ -21,6 +21,8 @@ package org.chorem.pollen.persistence.entity; * #L% */ +import org.nuiton.topia.persistence.HqlAndParametersBuilder; + import java.util.Date; import java.util.List; @@ -33,6 +35,15 @@ public class VoteTopiaDao extends AbstractVoteTopiaDao<Vote> { .findAll(); } + public long getVoteIndex(Vote vote) { + + HqlAndParametersBuilder<Vote> builder = newHqlAndParametersBuilder(); + builder.addEquals(Vote.PROPERTY_POLL, vote.getPoll()); + builder.addLowerOrEquals(Vote.PROPERTY_TOPIA_CREATE_DATE, vote.getTopiaCreateDate()); + builder.setSelectClause("select count(" + Vote.PROPERTY_TOPIA_ID + ")"); + return count(builder.getHql(), builder.getHqlParameters()); + } + public List<Vote> findAllSince(Poll poll, Date since) { if (since == null) { return findAll(poll); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java index cf2ead11..7b79f09a 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java @@ -138,4 +138,12 @@ public class VoteBean extends PollenBean<Vote> { public ReportResumeBean getReport() { return report; } + + public boolean isIgnored() { + return ignored; + } + + public void setIgnored(boolean ignored) { + this.ignored = ignored; + } } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java index fc907339..724178f8 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java @@ -45,12 +45,12 @@ import org.chorem.pollen.votecounting.VoteCounting; import org.nuiton.util.pagination.PaginationParameter; import org.nuiton.util.pagination.PaginationResult; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.l; @@ -100,12 +100,19 @@ public class VoteService extends PollenServiceSupport { if (entity.isAnonymous()) { bean.setVoterName(null); } + + int maxVoters = getPollService().getMaxVoters(entity.getPoll()); + if (maxVoters > 0 && getVoteDao().getVoteIndex(entity) >= maxVoters) { + bean.setIgnored(true); + bean.getChoice().forEach(vc -> vc.setVoteValue(null)); + } + } else { ReportResumeBean report = getReportService().getReport(entity.getTopiaId()); bean.setReport(report); } return bean; - }; + } public VoteToChoiceBean toVoteToChoiceBean(VoteToChoice entity) { @@ -155,19 +162,9 @@ public class VoteService extends PollenServiceSupport { checkNotNull(pollId); Poll poll = getPollService().getPoll0(pollId); - List<Vote> allVotes = getVotes0(poll); - int maxVoters = getPollService().getMaxVoters(poll); - - List<Vote> votes = new ArrayList<>(); - - int indexVote = 0; - for (Vote vote : allVotes) { - if (isPermitted(PermissionVerb.editVote, vote.getTopiaId()) - || (isPermitted(PermissionVerb.readVote, vote.getTopiaId()) && (maxVoters == 0 || indexVote < maxVoters))) { - votes.add(vote); - } - indexVote++; - } + List<Vote> votes = getVotes0(poll).stream() + .filter(vote -> isPermitted(PermissionVerb.readVote, vote.getTopiaId())) + .collect(Collectors.toList()); PaginationResult<Vote> votePaginationResult = PaginationResult.fromFullList(votes, getPaginationParameter(paginationParameter)); diff --git a/pollen-ui-riot-js/src/main/web/css/custom.css b/pollen-ui-riot-js/src/main/web/css/custom.css index 6545f121..ecd2d8a5 100644 --- a/pollen-ui-riot-js/src/main/web/css/custom.css +++ b/pollen-ui-riot-js/src/main/web/css/custom.css @@ -8,12 +8,12 @@ * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% @@ -116,4 +116,6 @@ --report-hover: #04c4bb; --list-alternate-row: #f3f3f3; + + --hatching: #f3f3f3; } diff --git a/pollen-ui-riot-js/src/main/web/i18n/en.json b/pollen-ui-riot-js/src/main/web/i18n/en.json index 4f49b4e4..39b46372 100644 --- a/pollen-ui-riot-js/src/main/web/i18n/en.json +++ b/pollen-ui-riot-js/src/main/web/i18n/en.json @@ -154,6 +154,7 @@ "poll_votes_results_unit_7_many": "votes", "poll_votes_voteNotOpen": "Votes are not open.", "poll_votes_voteClosed": "Votes are closed", + "poll_votes_ignored": "Ignored", "polls_createdPolls": "My polls", "polls_assignPollToMe": "Link a poll to my account", "polls_assignPollToMe_title": "Link the poll", diff --git a/pollen-ui-riot-js/src/main/web/i18n/fr.json b/pollen-ui-riot-js/src/main/web/i18n/fr.json index 585cc2b5..5d451158 100644 --- a/pollen-ui-riot-js/src/main/web/i18n/fr.json +++ b/pollen-ui-riot-js/src/main/web/i18n/fr.json @@ -154,6 +154,7 @@ "poll_votes_results_unit_7_many": "votes", "poll_votes_voteNotOpen": "Les votes ne sont pas encore ouverts.", "poll_votes_voteClosed": "Les votes sont clos.", + "poll_votes_ignored": "Ignoré", "polls_createdPolls": "Mes sondages", "polls_assignPollToMe": "Attacher le sondage", "polls_assignPollToMe_title": "Attacher un sondage à mon compte", 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 fec772d8..182bc16b 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 @@ -8,12 +8,12 @@ it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. #L% @@ -194,7 +194,7 @@ require("../components/LazyLoad.tag.html"); <i class="fa fa-trash"></i> </button> </div> - <div class="results separator-left" ref="results{index}"> + <div class="results separator-left {'ignored': element.ignored}" ref="results{index}"> <div each="{choice in parent.parent.poll.choices}" class="result separator-right {'checkbox' : parent.parent.pollTypeCheckbox} {'selected' : parent.parent.pollTypeCheckbox && parent.parent.poll.getVoteValue(element, choice) == 1}" onmouseenter="{parent.parent.parent.showTooltip(element, choice)}" onclick="{parent.parent.parent.showTooltip(element, choice)}" onmouseleave="{parent.parent.parent.hideTooltip}"> @@ -223,7 +223,8 @@ require("../components/LazyLoad.tag.html"); <div class="vote-tooltip" ref="voteTooltip" show="{voteTooltip.show}"> <ChoiceView if="{voteTooltip.choice}" choice="{voteTooltip.choice}" center="true" hideReport="true"></ChoiceView> - <div class="vote-value" if="{!pollTypeCheckbox && voteTooltip.vote && voteTooltip.choice}">{poll.getVoteValue(voteTooltip.vote, voteTooltip.choice)}</div> + <div class="vote-value" if="{!pollTypeCheckbox && voteTooltip.vote && voteTooltip.choice}"> + {voteTooltip.vote.ignored ? __.ignored :poll.getVoteValue(voteTooltip.vote, voteTooltip.choice)}</div> <div if="{voteTooltip.vote && !voteTooltip.choice}">{voteTooltip.vote.voterName}</div> </div> </div> @@ -723,10 +724,28 @@ require("../components/LazyLoad.tag.html"); text-overflow:ellipsis; } - .voters .row:hover .result { + .voters .row .ignored { + background: repeating-linear-gradient( + 45deg, + transparent, + transparent 10px, + var(--hatching) 10px, + var(--hatching) 20px); + } + + .voters .row:hover { background-color: var(--vote-hover); } + .voters .row:hover .ignored { + background: repeating-linear-gradient( + 45deg, + var(--vote-hover), + var(--vote-hover) 10px, + var(--hatching) 10px, + var(--hatching) 20px); + } + .voters .result.checkbox { background-color: var(--vote-not-selected); } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.