This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 5893c91a4ee417c9c7918e8aa678406de99963a5 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Mar 22 15:00:55 2017 +0100 information du sondage sur les écrans de votes, résultat, et commentaire et mise en place du bus d'événements pour le modification du sondage --- pollen-ui-riot-js/src/main/web/i18n.json | 82 ++++++++------- pollen-ui-riot-js/src/main/web/js/Poll.js | 113 +++++++++++++-------- pollen-ui-riot-js/src/main/web/js/PollenBus.js | 11 ++ pollen-ui-riot-js/src/main/web/js/UIHelper.js | 4 +- .../src/main/web/tag/poll/Comments.tag.html | 29 +++--- .../src/main/web/tag/poll/Poll.tag.html | 80 +++++++++++---- .../src/main/web/tag/poll/PollCard.tag.html | 2 +- .../src/main/web/tag/poll/Results.tag.html | 57 ++++------- .../src/main/web/tag/poll/Votes.tag.html | 91 ++++++++--------- 9 files changed, 263 insertions(+), 206 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index c30d817..c915254 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -10,12 +10,29 @@ "poll_settings": "Configuration", "poll_choices": "Choix", "poll_results": "Résultats", + "poll_CLOSED": "Fermé", + "poll_ADDING_CHOICES": "Ajout de choix", + "poll_VOTING": "Ouvert", + "poll_CREATED": "Créé", + "poll_createdBy": "Créé par", + "poll_createdIn": "le", + "poll_beginChoiceFrom": "ajout de choix à partir du", + "poll_votingFrom": "ouverture à partir du", + "poll_votingFromTo": "jusqu'au", + "poll_beginChoiceTo": "ajout de choix jusqu'au", + "poll_noChoice": "aucun choix", + "poll_choice": "choix", + "poll_choices": "choix", + "poll_votingTo": "ouvert jusqu'au", + "poll_noVote": "aucun vote", + "poll_vote": "vote", + "poll_votes": "votes", + "poll_closedFrom": "Fermé depuis le", "poll_results_title": "Résultats", "poll_results_noResult": "Les résultats ne sont pas encore disponibles.", - "poll_results_voter": "votant.", - "poll_results_voters": "votants.", "poll_results_rank": "Rang :", - "poll_results_votesCount": "Nombre de votes :", + "poll_results_vote": "vote", + "poll_results_votes": "votes", "poll_comments": "Commentaires", "poll_comments_noComment": "Pas de commentaire.", "poll_comments_title": "Commentaires", @@ -45,24 +62,6 @@ "polls_sort": "Trier par", "polls_createDate": "Date de création", "polls_noPoll": "Aucun sondage", - "pollCard_CLOSED": "Fermé", - "pollCard_ADDING_CHOICES": "Ajout de choix", - "pollCard_VOTING": "Ouvert", - "pollCard_CREATED": "Créé", - "pollCard_createdBy": "Créé par", - "pollCard_createdIn": "le", - "pollCard_beginChoiceFrom": "ajout de choix à partir du", - "pollCard_votingFrom": "ouverture à partir du", - "pollCard_votingFromTo": "jusqu'au", - "pollCard_beginChoiceTo": "ajout de choix jusqu'au", - "pollCard_noChoice": "aucun choix", - "pollCard_choice": "choix", - "pollCard_choices": "choix", - "pollCard_votingTo": "ouvert jusqu'au", - "pollCard_noVote": "aucun vote", - "pollCard_vote": "vote", - "pollCard_votes": "votes", - "pollCard_closedFrom": "Fermé depuis le", "signup_title": "Créer un compte", "signup_email": "Email", "signup_email_placeholder": "Entrez votre adresse email", @@ -268,12 +267,29 @@ "poll_deletePoll": "Delete poll", "poll_editPoll": "Edit poll", "poll_results": "Results", + "poll_CLOSED": "Closed", + "poll_ADDING_CHOICES": "Adding choices", + "poll_VOTING": "Voting", + "poll_CREATED": "Created", + "poll_createdBy": "Create by", + "poll_createdIn": "in", + "poll_beginChoiceFrom": "add choice from", + "poll_votingFrom": "voting from", + "poll_votingFromTo": "to", + "poll_beginChoiceTo": "add choice to", + "poll_noChoice": "no choice", + "poll_choice": "choice", + "poll_choices": "choices", + "poll_votingTo": "voting to", + "poll_noVote": "no vote", + "poll_vote": "vote", + "poll_votes": "votes", + "poll_closedFrom": "Closing from", "poll_results_noResult": "Results are not yet available.", "poll_results_title": "Results", - "poll_results_voter": "voter.", - "poll_results_voters": "voters.", + "poll_results_vote": "vote", + "poll_results_votes": "votes", "poll_results_rank": "Rank:", - "poll_results_votesCount": "Votes count:", "poll_comments": "Comments", "poll_comments_noComment": "No comment.", "poll_comments_title": "Comments", @@ -303,24 +319,6 @@ "polls_name": "Name", "polls_sort": "Sort by", "polls_noPoll": "No poll", - "pollCard_CLOSED": "Closed", - "pollCard_ADDING_CHOICES": "Adding choices", - "pollCard_VOTING": "Voting", - "pollCard_CREATED": "Created", - "pollCard_createdBy": "Create by", - "pollCard_createdIn": "in", - "pollCard_beginChoiceFrom": "add choice from", - "pollCard_votingFrom": "voting from", - "pollCard_votingFromTo": "to", - "pollCard_beginChoiceTo": "add choice to", - "pollCard_noChoice": "no choice", - "pollCard_choice": "choice", - "pollCard_choices": "choices", - "pollCard_votingTo": "voting to", - "pollCard_noVote": "no vote", - "pollCard_vote": "vote", - "pollCard_votes": "votes", - "pollCard_closedFrom": "Closing from", "signup_title": "Create an account", "signup_email": "Email", "signup_email_placeholder": "Enter your email", 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 83cedfe..dc91f8c 100644 --- a/pollen-ui-riot-js/src/main/web/js/Poll.js +++ b/pollen-ui-riot-js/src/main/web/js/Poll.js @@ -8,6 +8,7 @@ let resultService = require("./ResultService"); let commentService = require("./CommentService"); let Pagination = require("./Pagination"); let resourceService = require("./ResourceService"); +let bus = require("./PollenBus.js"); class Poll { @@ -18,13 +19,17 @@ class Poll { } init(pollId, permission) { - return pollService.getPoll(pollId, permission).then(result => { + this._initPromise = pollService.getPoll(pollId, permission).then(result => { Object.assign(this, result); this.choices = undefined; this.votes = undefined; this.comments = undefined; + this.results = undefined; + bus.trigger("poll", this); return Promise.resolve(this); }); + + return this._initPromise; } delete() { @@ -32,9 +37,11 @@ class Poll { return pollService.deletePoll(this.id, this.permission).then(() => { delete this.id; delete this.permission; + delete this._initPromise; this.choices = []; this.votes = []; this.comments = []; + bus.trigger("poll", this); }); } return Promise.reject("Init poll after delete poll"); @@ -45,7 +52,7 @@ class Poll { return choiceService.getChoices(this.id, this.permission) .then(result => { this.choices = result; - this.choiceCount = this.choices.length; + bus.trigger("poll", this); return Promise.resolve(this); } ); @@ -56,7 +63,7 @@ class Poll { initChoice(choice) { choice = choice || new Choice(); choice.id = undefined; - if (this.choices.length > 0) { + if (this.choices && this.choices.length > 0) { let lastChoice = this.choices[this.choices.length - 1]; choice.choiceType = lastChoice.choiceType; if (lastChoice.choiceType.startsWith("DATE")) { @@ -94,14 +101,35 @@ class Poll { } loadVotes() { - if (this.id) { - return voteService.getVotes(this.id, this.permission) - .then(result => { - this.votes = result; + if (this._initPromise) { + return this._initPromise.then(() => { + var promises = [ + choiceService.getChoices(this.id, this.permission), + voteService.getVotes(this.id, this.permission), + voteCountingTypeService.getVoteCountingType(this.voteCountingType) + ]; + if (this.resultIsVisible) { + promises.push(resultService.getResults(this.id, this.permission)); + } + return Promise.all(promises).then(resultsArray => { + this.choices = resultsArray[0]; + this.choiceCount = this.choices.length; + + this.votes = resultsArray[1]; this.voteCount = this.votes.length; + + this.voteCountingTypeValue = resultsArray[2]; + + if (this.resultIsVisible) { + this.results = resultsArray[3]; + this.choices.forEach(choice => { + choice.score = this.results.scores.find(score => score.choiceId === choice.id); + }); + } + bus.trigger("poll", this); return Promise.resolve(this); - } - ); + }); + }); } return Promise.reject("Init poll after load votes"); } @@ -115,45 +143,42 @@ class Poll { return voteChoice && voteChoice.voteValue; } - loadVoteCountingType() { - if (this.id) { - return voteCountingTypeService.getVoteCountingType(this.voteCountingType) - .then(result => { - this.voteCountingTypeValue = result; - return Promise.resolve(this); - } - ); - } - return Promise.reject("Init poll after load vote counting type"); - } - loadResults() { - if (this.id) { - return resultService.getResults(this.id, this.permission) - .then(results => { - this.results = results; - this.results.winners = results.scores.filter(score => score.scoreOrder === 0); - this.choices.forEach(choice => { - choice.score = this.results.scores.find(score => score.choiceId === choice.id); - }); - return Promise.resolve(this); - } - ); + if (this._initPromise) { + return this._initPromise.then(() => { + return Promise.all([ + choiceService.getChoices(this.id, this.permission), + resultService.getResults(this.id, this.permission)]).then(resultsArray => { + this.choices = resultsArray[0]; + this.choiceCount = this.choices.length; + this.results = resultsArray[1]; + this.choices.forEach(choice => { + choice.score = this.results.scores.find(score => score.choiceId === choice.id); + }); + bus.trigger("poll", this); + return Promise.resolve(this); + } + ); + }); } return Promise.reject("Init poll after load results"); } loadComments() { - if (this.id) { - let paginationParameter = new Pagination(); - paginationParameter.pageSize = -1; - paginationParameter.order = "postDate"; - return commentService.getComments(this.id, paginationParameter, this.permission) - .then((result) => { - this.comments = result.elements; - return Promise.resolve(this); - } - ); + if (this._initPromise) { + return this._initPromise.then(() => { + let paginationParameter = new Pagination(); + paginationParameter.pageSize = -1; + paginationParameter.order = "postDate"; + return commentService.getComments(this.id, paginationParameter, this.permission) + .then((result) => { + this.comments = result.elements; + this.commentCount = result.elements.length; + bus.trigger("poll", this); + return Promise.resolve(this); + } + ); + }); } return Promise.reject("Init poll after load comments"); } @@ -163,6 +188,7 @@ class Poll { return pollService.closePoll(this.id, this.permission).then(() => { this.isClosed = true; this.canVote = false; + bus.trigger("poll", this); return Promise.resolve(this); }); } @@ -174,6 +200,7 @@ class Poll { return pollService.reopenPoll(this.id, this.permission).then(() => { this.isClosed = false; this.canVote = true; + bus.trigger("poll", this); return Promise.resolve(this); }); } @@ -208,7 +235,7 @@ class Poll { } getChoice(choiceId) { - return this.choices.find(choice => choice.id === choiceId); + return this.choices && this.choices.find(choice => choice.id === choiceId); } addComment(authorName, text) { diff --git a/pollen-ui-riot-js/src/main/web/js/PollenBus.js b/pollen-ui-riot-js/src/main/web/js/PollenBus.js new file mode 100644 index 0000000..5afa2c3 --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/js/PollenBus.js @@ -0,0 +1,11 @@ +let singleton = require("./Singleton"); + +class PollenBus { + + constructor() { + riot.observable(this); + } + +} + +module.exports = singleton(PollenBus); diff --git a/pollen-ui-riot-js/src/main/web/js/UIHelper.js b/pollen-ui-riot-js/src/main/web/js/UIHelper.js index 743cd31..c220b9e 100644 --- a/pollen-ui-riot-js/src/main/web/js/UIHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/UIHelper.js @@ -45,5 +45,7 @@ module.exports = { return moment(date).format(format || "LLLL"); } return ""; - } + }, + + bus: require("./PollenBus.js") }; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Comments.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Comments.tag.html index f7fa007..877092c 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Comments.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Comments.tag.html @@ -2,7 +2,7 @@ require("../Pagination.tag.html"); require("./CommentPopup.tag.html"); <Comments> - <div class="actions-header"> + <div show="{loaded}" class="actions-header"> <button type="button" class="c-button c-button--info" onclick="{toggleSort}"> @@ -145,19 +145,22 @@ require("./CommentPopup.tag.html"); this.installBundle(session, "poll_comments"); let moment = require("moment"); - this.poll = {}; session.getUser().then(user => { this.userName = user && user.name; }); - this.opts.pollPromise.then(poll => { + + this.poll = require("../../js/Poll.js"); + this.poll.loadComments(); + + this.onPollChange = poll => { + this.loaded = poll.comments !== undefined; this.poll = poll; - return poll.loadComments(); - }).then(() => { - this.loaded = true; this.update(); - }); + }; - this.orderDesc = true; // means desc + this.bus.on("poll", this.onPollChange); + + this.orderDesc = true; this.toggleSort = () => { this.orderDesc = !this.orderDesc; @@ -169,7 +172,6 @@ require("./CommentPopup.tag.html"); this.poll.addComment(this.refs.author.value, this.refs.text.value) .then(() => { this.refs.text.value = ""; - this.update(); }); }; @@ -185,7 +187,6 @@ require("./CommentPopup.tag.html"); this.commentEditing.text = this.refs.editText.value; this.poll.updateComment(this.commentEditing).then(() => { this.cancelEditComment(); - this.update(); }); }; @@ -196,12 +197,14 @@ require("./CommentPopup.tag.html"); this.deleteComment = (comment) => () => { let response = confirm(this.__.deleteComment); if (response) { - this.poll.deleteComment(comment).then(() => { - this.update(); - }); + this.poll.deleteComment(comment); } }; + this.on("before-unmount", () => { + this.bus.off("poll", this.onPollChange); + }); + </script> <style> diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html index c676cd7..fbc3646 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html @@ -13,8 +13,7 @@ require("./Settings.tag.html"); </a> </div> <div class={tab : true, selected : selectedTab === "results"}> - <a class="{withResults ? '' : 'block'}" - href="{withResults?'#poll/' + poll.id + '/result' + (poll.permission? '/' + poll.permission : ''):''}"> + <a href="#poll/{poll.id}/result{poll.permission?'/' + poll.permission : ''}"> <i class="fa fa-trophy fa-15x"></i> {__.results} </a> </div> @@ -47,34 +46,69 @@ require("./Settings.tag.html"); </div> <div class="container"> - <h1 class="center">{poll.title}<h1> + <div class="poll-info"> + <h1>{poll.title}<h1> - <h3 class="center">{poll.description}</h3> + <h3>{poll.description}</h3> - <Votes if={selectedTab === "votes"} - poll-promise={pollPromise}/> + <div class="poll-creation"> + {__.createdBy} {poll.creatorName} {__.createdIn} {formatDate(poll.createDate)} + </div> + + <div class="beginChoiceDate" + if={poll.status === "CREATED" && poll.choiceAddAllowed}> + {__.beginChoiceFrom} {formatDate(poll.beginChoiceDate)} + </div> + <div class="poll-created" + if={poll.status === "CREATED"}> + {__.votingFrom} {formatDate(poll.beginDate)} + <span if={poll.endDate}> {__votingFromTo} {formatDate(poll.endDate)}</span> + </div> + + <div class="poll-adding-choices" + if={poll.status === "ADDING_CHOICES"}> + {__.beginChoiceTo} {formatDate(poll.endChoiceDate)} + </div> + + <div class="poll-voting" + if={poll.status === "VOTING"}> + <span if={poll.voteCount === 0}>{__.noVote}</span> + <span if={poll.voteCount === 1}>1 {__.vote}</span> + <span if={poll.voteCount > 1}>{poll.voteCount} {__.votes}</span> + <span if={poll.endDate}> {__.votingTo} {formatDate(poll.endDate)}</span> + </div> + + <div class="poll-voting" + if={poll.status === "CLOSED"}> + <span if={poll.voteCount === 0}>{__.noVote}</span> + <span if={poll.voteCount === 1}>1 {__.vote}</span> + <span if={poll.voteCount > 1}>{poll.voteCount} {__.votes}</span> + <span if={poll.endDate}> {__.closedFrom} {formatDate(poll.endDate)}</span> + </div> + </div> - <Results if={selectedTab === "results"} - poll-promise={pollPromise}/> + <Votes if={selectedTab === "votes"}/> - <Comments if={selectedTab === "comments"} - poll-promise={pollPromise}/> + <Results if={selectedTab === "results"}/> + + <Comments if={selectedTab === "comments"}/> </div> <script type="es6"> - this.poll = {}; - this.pollPromise = require("../../js/Poll").init(this.opts.pollId, this.opts.permission) - .then(poll => { - this.poll = poll; - this.update(); - return Promise.resolve(poll); - } - ); - this.selectedTab = this.opts.tabName; - this.withResults = true; this.session = require("../../js/Session"); this.installBundle(this.session, "poll"); + this.selectedTab = this.opts.tabName; + + this.poll = require("../../js/Poll"); + this.onPollChange = poll => { + this.poll = poll; + this.update(); + }; + + this.bus.on("poll", this.onPollChange); + this.poll.init(this.opts.pollId, this.opts.permission); + this.closePoll = (e) => { e.preventDefault(); e.stopPropagation(); @@ -103,10 +137,14 @@ require("./Settings.tag.html"); } }; + this.on("before-unmount", () => { + this.bus.off("poll", this.onPollChange); + }); + </script> <style> - .center { + .poll-info { text-align: center; } diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollCard.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/PollCard.tag.html index d9fec89..8d63d1e 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollCard.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollCard.tag.html @@ -51,7 +51,7 @@ <script type="es6"> let session = require("../../js/Session"); - this.installBundle(session, "pollCard"); + this.installBundle(session, "poll"); </script> <style> 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 4056598..cda48a7 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 @@ -1,18 +1,16 @@ require("./ChoiceView.tag.html"); <Results> - <div class="container"> - <div if="{!poll.continuousResults && !poll.isClosed}"> + <div class="container" show="{loaded}"> + <div if="{!poll.resultIsVisible}"> {__.noResult} </div> - <div if="{poll.continuousResults || poll.isClosed}" class="result-body" > + <div if="{poll.resultIsVisible && poll.results}" class="result-body" > <div class="result-content" each="{result in poll.results.scores}"> - <div class="result {winner : result.scoreOrder === 0, second : result.scoreOrder === 1, third : result.scoreOrder === 2}"> - {result.scoreOrder + 1} : + <div class="result"> + {result.scoreOrder + 1} ({result.scoreValue} {result.scoreValue > 1 ? parent.__.votes : parent.__.vote}) : <ChoiceView choice={poll.getChoice(result.choiceId)}/> </div> - <div class="votes">{parent.__.votesCount} {result.scoreValue}</div> </div> - <div class="voters-count">{poll.results.nbVotants} {poll.results.nbVotants==1 ? __.voter : __.voters}</div> </div> </div> @@ -20,17 +18,20 @@ require("./ChoiceView.tag.html"); this.loaded = false; let session = require("../../js/Session"); this.installBundle(session, "poll_results"); - let moment = require("moment"); - this.poll = {}; - this.opts.pollPromise.then(poll => { + this.poll = require("../../js/Poll.js"); + this.poll.loadResults(); + + this.onPollChange = poll => { + this.loaded = poll.results !== undefined; this.poll = poll; - return poll.loadChoices().then(() =>{ - return poll.loadResults(); - }); - }).then(() => { - this.loaded = true; this.update(); + }; + + this.bus.on("poll", this.onPollChange); + + this.on("before-unmount", () => { + this.bus.off("poll", this.onPollChange); }); </script> @@ -38,29 +39,15 @@ require("./ChoiceView.tag.html"); .result-content { display: flex; - justify-content: space-between; - align-items: baseline; - flex-wrap: wrap; - } - .result { - + flex-direction: column; + align-items : center; } - .winner { - font-size: 3em; - } - - .second { - font-size: 2.2em; - } - - .third { - font-size: 1.5em; - } + .result { + display: flex; + justify-content: space-between; + align-items: baseline; - .voters-count { - margin: 10px 0; - text-align: right; } </style> 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 dcefdfd..c8e07e4 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 @@ -55,20 +55,6 @@ require("./ChoiceView.tag.html"); disabled={voteId}> {__.vote} </button> - <button type="button" - if={!poll.resultIsVisible && poll.voteIsVisible && !showVotes} - class="c-button c-button--info" - onclick="{onShowVotes}"> - <i class="fa fa-caret-left"/> - <i class="fa fa-caret-right"/> - </button> - <button type="button" - if={!poll.resultIsVisible && poll.voteIsVisible && showVotes} - class="c-button c-button--info" - onclick="{onHideVotes}"> - <i class="fa fa-caret-right"/> - <i class="fa fa-caret-left"/> - </button> </div> </form> <div class="window"> @@ -86,22 +72,21 @@ require("./ChoiceView.tag.html"); </span> </div> <div class="results-actions"> - <button type="button" - if={poll.voteIsVisible && !showVotes} - class="c-button c-button--info" - onclick="{onShowVotes}"> - <i class="fa fa-caret-left"/> - <i class="fa fa-caret-right"/> - </button> - <button type="button" - if={poll.voteIsVisible && showVotes} - class="c-button c-button--info" - onclick="{onHideVotes}"> - <i class="fa fa-caret-right"/> - <i class="fa fa-caret-left"/> - </button> + </div> </div> + <button type="button" + if={poll.voteIsVisible && poll.voteCount > 0 && !showVotes} + class="expand c-button c-button--info" + onclick="{onShowVotes}"> + <i class="fa fa-caret-right"/> + </button> + <button type="button" + if={poll.voteIsVisible && poll.voteCount > 0 && showVotes} + class="collapse c-button c-button--info" + onclick="{onHideVotes}"> + <i class="fa fa-caret-left"/> + </button> <form if={showVotes} each={vote in poll.votes} class="vote" onsubmit="{updateVote(vote)}"> <div class="voter"> <span class="voter-name" @@ -209,27 +194,20 @@ require("./ChoiceView.tag.html"); session.getUser().then(user => { this.userName = user && user.name; }); - this.poll = {}; - this.showVotes = false; - this.opts.pollPromise.then(poll => { + + this.poll = require("../../js/Poll.js"); + this.poll.loadVotes(); + + this.onPollChange = poll => { + this.loaded = poll.choices !== undefined; this.poll = poll; this.voting = poll.canVote || poll.status === "VOTING" || poll.status === "CLOSED"; - let promises = [ - poll.loadChoices(), - poll.loadVotes(), - poll.loadVoteCountingType() - ]; - return Promise.all(promises).then(() =>{ - if (this.poll.resultIsVisible) { - return poll.loadResults(); - } - return Promise.resolve(); - }); - }).then(() => { - this.choiceToAdd = this.poll.initChoice(); - this.loaded = true; + this.choiceToAdd = this.poll.initChoice(this.choiceToAdd); this.update(); - }); + }; + + this.bus.on("poll", this.onPollChange); + this.showVotes = false; this.voteId = null; this.error = {}; @@ -363,6 +341,10 @@ require("./ChoiceView.tag.html"); this.showVotes = false; }; + this.on("before-unmount", () => { + this.bus.off("poll", this.onPollChange); + }); + </script> <style> @@ -413,15 +395,24 @@ require("./ChoiceView.tag.html"); align-items: stretch; } - .voters .window .frame .vote, .voters .window .frame .results { min-width: 100px; border-left: 1px solid #b2c7d3; } - .voters .window .frame .vote:first-child, - .voters .window .frame .results:first-child { - border-left: none; + .voters .window .frame .vote { + min-width: 100px; + border-right: 1px solid #b2c7d3; + } + + .voters .window .frame .vote:last-child { + border-right: none; + } + + .voters .window .frame .expand, + .voters .window .frame .collapse { + padding: 0; + min-width: 6px; } .current-voter, -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.