This is an automated email from the git hooks/post-receive script. New commit to branch feature/multi-ui in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 95fc4105c29f32a86c1d787f25bdb92a36e83b86 Author: jcouteau <couteau@codelutin.com> Date: Thu Aug 22 17:03:27 2019 +0200 Multi-questions : results (working on single question vote, should work on multi too Todo : Vote ! --- .../tag/poll/{Results.tag.html => Result.tag.html} | 67 +++++++++++++--------- .../src/main/web/tag/poll/Results.tag.html | 48 +--------------- .../voteCountingType/BordaDetailResult.tag.html | 23 +++++--- .../CondorcetDetailResult.tag.html | 19 ++++-- .../voteCountingType/CoombsDetailResult.tag.html | 8 +-- .../InstantRunoffDetailResult.tag.html | 13 ++++- .../MajorityJudgmentDetailResult.tag.html | 21 ++++--- 7 files changed, 98 insertions(+), 101 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Results.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Result.tag.html similarity index 56% copy from pollen-ui-riot-js/src/main/web/tag/poll/Results.tag.html copy to pollen-ui-riot-js/src/main/web/tag/poll/Result.tag.html index 9badb03f..45b6ae43 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Results.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Result.tag.html @@ -24,51 +24,54 @@ import "../voteCountingType/BordaDetailResult.tag.html"; import "../voteCountingType/InstantRunoffDetailResult.tag.html"; import "../voteCountingType/CoombsDetailResult.tag.html"; import "../voteCountingType/MajorityJudgmentDetailResult.tag.html"; -<Results> +<Result> <div class="container" show="{loaded}"> - <div if="{poll.questions[0] && !poll.questions[0].resultIsVisible}" + <div if="{question && !question.resultIsVisible}" class="c-alert c-alert--warning"> {_t.noResult} </div> - <div if="{poll.questions[0] && poll.questions[0].resultIsVisible && poll.questions[0].results}" class="result-body" > + <div if="{question && question.resultIsVisible && question.results}" class="result-body" > + + <h2>{question.title}</h2> + <table class="table-results"> <thead> <tr> <th>{_t.rank}</th> - <th if={poll.questions[0] && (poll.questions[0].voteCountingType !== 5) && (poll.questions[0].voteCountingType !== 2) && (poll.questions[0].voteCountingType !== 4)}>{_t.results}</th> - <th if={poll.questions[0] && ((poll.questions[0].voteCountingType === 5) || (poll.questions[0].voteCountingType === 2))}>{_t.scores}</th> - <th if={poll.questions[0] && (poll.questions[0].voteCountingType === 4)}>{_t.totals}</th> + <th if={question && (question.voteCountingType !== 5) && (question.voteCountingType !== 2) && (question.voteCountingType !== 4)}>{_t.results}</th> + <th if={question && ((question.voteCountingType === 5) || (question.voteCountingType === 2))}>{_t.scores}</th> + <th if={question && (question.voteCountingType === 4)}>{_t.totals}</th> <th>{_t.choices}</th> </tr> </thead> <tbody> - <tr each="{result in poll.questions[0].results.scores}"> + <tr each="{result in question.results.scores}"> <td class="score separator-top">{result.scoreOrder + 1}</td> <td class="votes separator-top"> - <span if={parent.poll.questions[0].voteCountingType !== 8}> + <span if={question.voteCountingType !== 8}> <span if={result.scoreValue >= 0 || !pollTypeRound}> {result.scoreValue} - {parent._t["unit_" + poll.questions[0].voteCountingType + "_" + (result.scoreValue > 1 ? "many" : "one")]} + {parent._t["unit_" + question.voteCountingType + "_" + (result.scoreValue > 1 ? "many" : "one")]} </span> <span if={result.scoreValue < 0 && pollTypeRound}> - {parent._l("eliminated", parent.poll.questions[0].choiceCount + result.scoreValue + 1)} + {parent._l("eliminated", question.choiceCount + result.scoreValue + 1)} </span> </span> - <span if={parent.poll.voteCountingType === 8}> - {parent.poll.questions[0].voteCountingConfig.grades[result.scoreValue]} + <span if={question.voteCountingType === 8}> + {question.voteCountingConfig.grades[result.scoreValue]} </span> </td> <td class="choice separator-top"> - <ChoiceView choice={poll.getChoice(poll.questions[0].id, result.choiceId)} center="true" tooltip-placement="right"/> + <ChoiceView choice={poll.getChoice(question.id, result.choiceId)} center="true" tooltip-placement="right"/> </td> </tr> </tbody> </table> - <CondorcetDetailResult if={poll.questions[0].voteCountingType === 3}/> - <BordaDetailResult if={poll.questions[0].voteCountingType === 5}/> - <InstantRunoffDetailResult if={poll.questions[0].voteCountingType === 6}/> - <CoombsDetailResult if={poll.questions[0].voteCountingType === 7}/> - <MajorityJudgmentDetailResult if={poll.questions[0].voteCountingType === 8}/> + <CondorcetDetailResult if={question.voteCountingType === 3}/> + <BordaDetailResult if={question.voteCountingType === 5}/> + <InstantRunoffDetailResult if={question.voteCountingType === 6}/> + <CoombsDetailResult if={question.voteCountingType === 7}/> + <MajorityJudgmentDetailResult if={question.voteCountingType === 8}/> </div> </div> @@ -80,27 +83,37 @@ import "../voteCountingType/MajorityJudgmentDetailResult.tag.html"; this.installBundle(session, "poll_results"); this.poll = poll; - if (this.poll.questions[0]) { - this.poll.loadResults(this.poll.questions[0].id); + + this.question = opts.question; + if (this.question) { + this.poll.loadResults(this.question.id); } this.onPollChange = poll2 => { - this.loaded = !poll2.questions[0].resultIsVisible || poll2.questions[0].results !== undefined; - this.resultsLoaded = poll2.questions[0].results !== undefined; + //reload question + var _this = this; + poll2.questions.forEach(function(question) { + if (_this.question.id === question.id) { + _this.question = question; + } + }); + + this.loaded = !this.question.resultIsVisible || this.question.results !== undefined; + this.resultsLoaded = this.question.results !== undefined; this.poll = poll2; if (!this.resultsLoaded) { - this.poll.loadResults(poll2.questions[0].id).then(() => { + this.poll.loadResults(this.question.id).then(() => { }); } - this.poll.questions[0].pollTypeRound = poll2.questions[0].voteCountingType && (poll2.questions[0].voteCountingType === 7 || poll2.questions[0].voteCountingType === 6); + this.question.pollTypeRound = this.question.voteCountingType && (this.question.voteCountingType === 7 || this.question.voteCountingType === 6); this.update(); }; this.listen("poll", this.onPollChange); this.listen("user", (user, oldUser) => { - if (user !== oldUser && this.poll.questions[0]) { - this.poll.loadResults(this.poll.questions[0].id); + if (user !== oldUser && this.question) { + this.poll.loadResults(this.question.id); this.update(); } }); @@ -132,4 +145,4 @@ import "../voteCountingType/MajorityJudgmentDetailResult.tag.html"; } </style> -</Results> +</Result> diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Results.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Results.tag.html index 9badb03f..c346e808 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Results.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Results.tag.html @@ -19,58 +19,14 @@ #L% --> import "./ChoiceView.tag.html"; +import "./Result.tag.html"; import "../voteCountingType/CondorcetDetailResult.tag.html"; import "../voteCountingType/BordaDetailResult.tag.html"; import "../voteCountingType/InstantRunoffDetailResult.tag.html"; import "../voteCountingType/CoombsDetailResult.tag.html"; import "../voteCountingType/MajorityJudgmentDetailResult.tag.html"; <Results> - <div class="container" show="{loaded}"> - <div if="{poll.questions[0] && !poll.questions[0].resultIsVisible}" - class="c-alert c-alert--warning"> - {_t.noResult} - </div> - <div if="{poll.questions[0] && poll.questions[0].resultIsVisible && poll.questions[0].results}" class="result-body" > - <table class="table-results"> - <thead> - <tr> - <th>{_t.rank}</th> - <th if={poll.questions[0] && (poll.questions[0].voteCountingType !== 5) && (poll.questions[0].voteCountingType !== 2) && (poll.questions[0].voteCountingType !== 4)}>{_t.results}</th> - <th if={poll.questions[0] && ((poll.questions[0].voteCountingType === 5) || (poll.questions[0].voteCountingType === 2))}>{_t.scores}</th> - <th if={poll.questions[0] && (poll.questions[0].voteCountingType === 4)}>{_t.totals}</th> - <th>{_t.choices}</th> - </tr> - </thead> - <tbody> - <tr each="{result in poll.questions[0].results.scores}"> - <td class="score separator-top">{result.scoreOrder + 1}</td> - <td class="votes separator-top"> - <span if={parent.poll.questions[0].voteCountingType !== 8}> - <span if={result.scoreValue >= 0 || !pollTypeRound}> - {result.scoreValue} - {parent._t["unit_" + poll.questions[0].voteCountingType + "_" + (result.scoreValue > 1 ? "many" : "one")]} - </span> - <span if={result.scoreValue < 0 && pollTypeRound}> - {parent._l("eliminated", parent.poll.questions[0].choiceCount + result.scoreValue + 1)} - </span> - </span> - <span if={parent.poll.voteCountingType === 8}> - {parent.poll.questions[0].voteCountingConfig.grades[result.scoreValue]} - </span> - </td> - <td class="choice separator-top"> - <ChoiceView choice={poll.getChoice(poll.questions[0].id, result.choiceId)} center="true" tooltip-placement="right"/> - </td> - </tr> - </tbody> - </table> - <CondorcetDetailResult if={poll.questions[0].voteCountingType === 3}/> - <BordaDetailResult if={poll.questions[0].voteCountingType === 5}/> - <InstantRunoffDetailResult if={poll.questions[0].voteCountingType === 6}/> - <CoombsDetailResult if={poll.questions[0].voteCountingType === 7}/> - <MajorityJudgmentDetailResult if={poll.questions[0].voteCountingType === 8}/> - </div> - </div> + <Result each={question in poll.questions} /> <script type="es6"> import session from "../../js/Session"; diff --git a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/BordaDetailResult.tag.html b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/BordaDetailResult.tag.html index 55f272aa..f85bf786 100644 --- a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/BordaDetailResult.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/BordaDetailResult.tag.html @@ -25,23 +25,23 @@ import "../poll/ChoiceView.tag.html"; <table class="ranks"> <tr> <td class="cell">{_t.rank}</td> - <td class="cell rank" each={rank in Array.from(Array(poll.questions[0].voteCountingConfig.maxChoiceNumber || poll.questions[0].choices.length).keys())}> + <td class="cell rank" each={rank in Array.from(Array(question.voteCountingConfig.maxChoiceNumber || question.choices.length).keys())}> {rank + 1} </td> <td class="cell"></td> </tr> <tr> <td class="cell separator-top">{_t.points}</td> - <td class="cell separator-top" each={rank in Array.from(Array(poll.questions[0].voteCountingConfig.maxChoiceNumber || poll.questions[0].choices.length).keys())}> - {poll.questions[0].voteCountingConfig.pointsByRank ? poll.questions[0].voteCountingConfig.pointsByRank[rank] : (poll.questions[0].voteCountingConfig.maxChoiceNumber || poll.questions[0].choices.length) - rank} + <td class="cell separator-top" each={rank in Array.from(Array(question.voteCountingConfig.maxChoiceNumber || question.choices.length).keys())}> + {question.voteCountingConfig.pointsByRank ? question.voteCountingConfig.pointsByRank[rank] : (question.voteCountingConfig.maxChoiceNumber || question.choices.length) - rank} </td> <td class="cell score">{_t.total}</td> </tr> - <tr each={choice in poll.questions[0].choices}> + <tr each={choice in question.choices}> <td class="cell separator-top"> <ChoiceView choice={choice} center="true" tooltip-placement="left"/> </td> - <td class="cell separator-top" each={rank in Array.from(Array(poll.questions[0].voteCountingConfig.maxChoiceNumber || poll.questions[0].choices.length).keys())}> + <td class="cell separator-top" each={rank in Array.from(Array(question.voteCountingConfig.maxChoiceNumber || question.choices.length).keys())}> {getRankScore(choice, rank)} </td> <td class="cell separator-top score"> @@ -58,18 +58,25 @@ import "../poll/ChoiceView.tag.html"; this.poll = poll; this.onPollChange = poll2 => { + //reload question + _this=this; + poll2.questions.forEach(function(question) { + if (_this.question.id === question.id) { + _this.question = question; + } + }); this.poll = poll2; - this.pointsByRank = poll2.questions[0].choices ? (Array.from(Array(poll2.questions[0].choices.length).keys(), i => poll2.questions[0].choices.length - i)) : []; + this.pointsByRank = this.question.choices ? (Array.from(Array(this.question.choices.length).keys(), i => this.question.choices.length - i)) : []; this.update(); }; this.getRankScore = (choice, rank) => { - let rankScore = this.poll.questions[0].results.detail.choiceRanks.find(r => r.choiceId === choice.id && r.rank === rank); + let rankScore = this.question.results.detail.choiceRanks.find(r => r.choiceId === choice.id && r.rank === rank); return rankScore ? rankScore.score : 0; }; this.getScore = (choice) => { - let score = this.poll.questions[0].results.scores.find(s => s.choiceId === choice.id); + let score = this.question.results.scores.find(s => s.choiceId === choice.id); return score ? score.scoreValue : 0; }; diff --git a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CondorcetDetailResult.tag.html b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CondorcetDetailResult.tag.html index dea39c9f..8014ba5c 100644 --- a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CondorcetDetailResult.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CondorcetDetailResult.tag.html @@ -24,15 +24,15 @@ import "../poll/ChoiceView.tag.html"; <table class="battles"> <tr> <td class="cell runners"></td> - <td class="cell opponent" each={opponent in poll.questions[0].choices}> + <td class="cell opponent" each={opponent in question.choices}> <ChoiceView choice={opponent} center="true"/> </td> </tr> - <tr each={runner in poll.questions[0].choices}> + <tr each={runner in question.choices}> <td class="cell separator-top"> <ChoiceView choice={runner} center="true"/> </td> - <td each={opponent in poll.questions[0].choices} class="cell separator-top"> + <td each={opponent in question.choices} class="cell separator-top"> {getBattleScore(opponent, runner)} </td> </tr> @@ -40,7 +40,7 @@ import "../poll/ChoiceView.tag.html"; <td class="cell separator-top score"> {_t.total} </td> - <td each={opponent in poll.questions[0].choices} class="cell separator-top score"> + <td each={opponent in question.choices} class="cell separator-top score"> {getScore(opponent)} </td> </tr> @@ -54,6 +54,13 @@ import "../poll/ChoiceView.tag.html"; this.poll = poll; this.onPollChange = poll2 => { + //reload question + _this=this; + poll2.questions.forEach(function(question) { + if (_this.question.id === question.id) { + _this.question = question; + } + }); this.poll = poll2; this.update(); }; @@ -61,14 +68,14 @@ import "../poll/ChoiceView.tag.html"; this.getBattleScore = (opponent, runner) => { let result = ""; if (opponent !== runner) { - let battle = this.poll.questions[0].results.detail.battles.find(b => b.opponentId === opponent.id && b.runnerId === runner.id); + let battle = this.question.results.detail.battles.find(b => b.opponentId === opponent.id && b.runnerId === runner.id); result = battle ? battle.score : 0; } return result; }; this.getScore = (opponent) => { - let score = this.poll.questions[0].results.scores.find(s => s.choiceId === opponent.id); + let score = this.question.results.scores.find(s => s.choiceId === opponent.id); return score ? score.scoreValue : 0; }; diff --git a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CoombsDetailResult.tag.html b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CoombsDetailResult.tag.html index e7deb3cc..bd77832a 100644 --- a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CoombsDetailResult.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/CoombsDetailResult.tag.html @@ -24,13 +24,13 @@ import "../poll/ChoiceView.tag.html"; <table class="rounds"> <tr> <td class="cell">{_t.round}</td> - <td class="cell" each={round, index in (poll.questions[0].results && poll.questions[0].results.detail && poll.questions[0].results.detail.rounds || [])}> + <td class="cell" each={round, index in (question.results && question.results.detail && question.results.detail.rounds || [])}> {index + 1} </td> </tr> <tr> <td class="cell separator-top">{_t.ranks}</td> - <td class="separator-top" each={round in (poll.questions[0].results && poll.questions[0].results.detail && poll.questions[0].results.detail.rounds || [])}> + <td class="separator-top" each={round in (question.results && question.results.detail && question.results.detail.rounds || [])}> <div class="cell2"> <div class="cell"> {parent._t.firstRank} @@ -41,11 +41,11 @@ import "../poll/ChoiceView.tag.html"; </div> </td> </tr> - <tr each={choice in poll.questions[0].choices}> + <tr each={choice in question.choices}> <td class="cell separator-top"> <ChoiceView choice={choice} center="true" tooltip-placement="left"/> </td> - <td class="separator-top" each={round in (poll.questions[0].results && poll.questions[0].results.detail && poll.questions[0].results.detail.rounds || [])}> + <td class="separator-top" each={round in (question.results && question.results.detail && question.results.detail.rounds || [])}> <div class="cell2"> <div class="cell {eliminate: isExclude(choice, round)}"> {getRoundFirstScore(choice, round)} diff --git a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/InstantRunoffDetailResult.tag.html b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/InstantRunoffDetailResult.tag.html index 7454ac78..16705f86 100644 --- a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/InstantRunoffDetailResult.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/InstantRunoffDetailResult.tag.html @@ -24,15 +24,15 @@ import "../poll/ChoiceView.tag.html"; <table class="rounds"> <tr> <td class="cell">{_t.rounds}</td> - <td class="cell" each={round, index in poll.questions[0].results.detail.rounds}> + <td class="cell" each={round, index in question.results.detail.rounds}> {index + 1} </td> </tr> - <tr each={choice in poll.questions[0].choices}> + <tr each={choice in question.choices}> <td class="cell separator-top"> <ChoiceView choice={choice} center="true" tooltip-placement="left"/> </td> - <td class="cell separator-top {eliminate: isExclude(choice, round)}" each={round in poll.questions[0].results.detail.rounds}> + <td class="cell separator-top {eliminate: isExclude(choice, round)}" each={round in question.results.detail.rounds}> {getRoundScore(choice, round)} </td> </tr> @@ -46,6 +46,13 @@ import "../poll/ChoiceView.tag.html"; this.poll = poll; this.onPollChange = poll2 => { + //reload question + _this=this; + poll2.questions.forEach(function(question) { + if (_this.question.id === question.id) { + _this.question = question; + } + }); this.poll = poll2; this.update(); }; diff --git a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/MajorityJudgmentDetailResult.tag.html b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/MajorityJudgmentDetailResult.tag.html index 5f636cec..9c613bce 100644 --- a/pollen-ui-riot-js/src/main/web/tag/voteCountingType/MajorityJudgmentDetailResult.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/voteCountingType/MajorityJudgmentDetailResult.tag.html @@ -39,8 +39,8 @@ import "../poll/ChoiceView.tag.html"; <div class="scale"> <div class="yaxis separator-top"> <div class="yaxis-values"> - <div>{poll.questions[0].results.detail.sumWeight}</div> - <div>{poll.questions[0].results.detail.halfWeight}</div> + <div>{question.results.detail.sumWeight}</div> + <div>{question.results.detail.halfWeight}</div> <div>0</div> </div> <div class="yaxis-line separator-right"> @@ -49,7 +49,7 @@ import "../poll/ChoiceView.tag.html"; <div class="xaxis separator-top "> </div> </div> - <div each={choice in poll.questions[0].choices} class="choice"> + <div each={choice in question.choices} class="choice"> <div class="histogramme"> <div class="median separator-top"></div> <div class="bars"> @@ -75,17 +75,24 @@ import "../poll/ChoiceView.tag.html"; this.poll = poll; this.onPollChange = poll2 => { + //reload question + _this=this; + poll2.questions.forEach(function(question) { + if (_this.question.id === question.id) { + _this.question = question; + } + }); this.poll = poll2; this.update(); }; this.getColor = (index, s, l, a) => { - let hue = 0 + 120 * index / (this.poll.questions[0].voteCountingConfig.grades.length - 1); + let hue = 0 + 120 * index / (this.question.voteCountingConfig.grades.length - 1); return "hsla(" + hue + ", " + s + "%, " + l + "%, " + a + ")"; }; this.getGradLegend = () => { - return this.poll.questions[0].voteCountingConfig.grades.map((grad, index) => { + return this.question.voteCountingConfig.grades.map((grad, index) => { return { index: index, grad: grad, @@ -96,10 +103,10 @@ import "../poll/ChoiceView.tag.html"; }; this.getBars = choice => { - let choiceResult = this.poll.questions[0].results.detail.choiceResults + let choiceResult = this.question.results.detail.choiceResults .find(cr => cr.choiceId === choice.id); return choiceResult.voteByGrad.map((nbVotes, index) => { - let grad = this.poll.questions[0].voteCountingConfig.grades[index]; + let grad = this.question.voteCountingConfig.grades[index]; return { index: index, grad: grad, -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.