This is an automated email from the git hooks/post-receive script. New commit to branch feature/pollen-riot-js in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 9ca567693008a1ab49c2e348aba93e4157782939 Author: Tony CHEMIT <dev@tchemit.fr> Date: Tue Jan 24 20:08:49 2017 +0100 Ajout des résultats + ... --- pollen-ui-riot-js/src/main/web/i18n.json | 18 ++++ pollen-ui-riot-js/src/main/web/js/ResultService.js | 36 ++++++++ pollen-ui-riot-js/src/main/web/tag/Pollen.tag | 6 ++ pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag | 56 +++++++++---- .../src/main/web/tag/poll/PollComments.tag | 10 ++- .../src/main/web/tag/poll/PollResults.tag | 95 ++++++++++++++++++++++ .../src/main/web/tag/poll/PollVotes.tag | 8 +- 7 files changed, 202 insertions(+), 27 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index 7cfb62e..48ce6f6 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -1,5 +1,14 @@ { "fr": { + "poll_votes":"Votes", + "poll_results":"Résultats", + "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_comments":"Commentaires", "poll_comments_noComment":"Pas de commentaire.", "poll_comments_title":"Commentaires", "poll_comments_addComment":"Ajouter un commentaire", @@ -150,6 +159,15 @@ "": "" }, "en": { + "poll_votes":"Votes", + "poll_results":"Results", + "poll_results_noResult":"Results are not yet available.", + "poll_results_title":"Results", + "poll_results_voter":"voter.", + "poll_results_voters":"voters.", + "poll_results_rank":"Rank:", + "poll_results_votesCount":"Votes count:", + "poll_comments":"Comments", "poll_comments_noComment":"No comment.", "poll_comments_title":"Comments", "poll_comments_addComment":"Add a comment", diff --git a/pollen-ui-riot-js/src/main/web/js/ResultService.js b/pollen-ui-riot-js/src/main/web/js/ResultService.js new file mode 100644 index 0000000..74b88b3 --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/js/ResultService.js @@ -0,0 +1,36 @@ +/*- + * #%L + * Pollen :: UI (Riot Js) + * %% + * Copyright (C) 2009 - 2017 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * 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% + */ +let singleton = require("./Singleton"); +let FetchService = require("./FetchService"); + +class ResultService extends FetchService { + + getResults(pollId, permission) { + let args = {}; + if (permission) { + args.permission = permission; + } + return this.getWithParams("/v1/polls/" + pollId + "/results", args); + } + +} + +module.exports = singleton(ResultService); diff --git a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag index b9fed83..ca631b2 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag +++ b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag @@ -70,6 +70,12 @@ require("./polls/CreatedPolls.tag"); route("/poll/*/comment/*", (pollId, permission) => { riot.mount(this.refs.content, "poll", {pollId: pollId, tabName: 'comments', permission: permission}); }); + route("/poll/*/result", (pollId) => { + riot.mount(this.refs.content, "poll", {pollId: pollId, tabName: 'results'}); + }); + route("/poll/*/result/*", (pollId, permission) => { + riot.mount(this.refs.content, "poll", {pollId: pollId, tabName: 'results', permission: permission}); + }); route("/user/profile", () => { riot.mount(this.refs.content, "userprofile"); diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag index 690326d..883f08f 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag @@ -1,5 +1,6 @@ require('./PollVotes.tag'); require('./PollComments.tag'); +require('./PollResults.tag'); <Poll> <div class="container"> @@ -11,12 +12,18 @@ require('./PollComments.tag'); <div class="tab-header"> <div class="{selectedTab=='votes'?'tab-selected':'tab-not-selected'}"> <a href="#poll/{pollId}/vote{permission?'/' + permission : ''}"> - <i class="fa fa-thumbs-o-up fa-flip-horizontal"></i>Votes + <i class="fa fa-thumbs-o-up fa-flip-horizontal"></i>{__.votes} ({votesCount}) </a> </div> <div class="{selectedTab=='comments'?'tab-selected':'tab-not-selected'}"> <a href="#poll/{pollId}/comment{permission?'/' + permission : ''}"> - <i class="fa fa-comments-o"></i>Comments + <i class="fa fa-comments-o"></i>{__.comments} ({commentsCount}) + </a> + </div> + <div class="{selectedTab=='results'?'tab-selected':'tab-not-selected'}"> + <a class="{withResults ? '' : 'block'}" + href="{withResults?'#poll/' + pollId + '/result' + (permission? '/' + permission : ''):''}"> + <i class="fa fa-bar-chart-o"></i><span>{__.results}</span> </a> </div> @@ -29,40 +36,53 @@ require('./PollComments.tag'); this.pollId = opts.pollId; this.selectedTab = opts.tabName; this.permission = opts.permission; + this.commentsCount = ' '; + this.votesCount = ' '; + this.withResults = true; let session = require("../../js/Session"); this.installBundle(session, "poll"); - this.on('mount', () => { let pollService = require('../../js/PollService'); pollService.getPoll(this.pollId).then(result => { this.poll = result; + this.withResults = this.poll.continiousResult || this.poll.isClosed; + this.commentsCount = this.poll.commentCount; + this.votesCount = this.poll.voteCount; console.info(this.poll); this.update(); - if (this.selectedTab == 'votes') { - riot.mount(this.refs.content, "pollvotes", { - pollId: this.pollId, - poll:this.poll, - session: session, - permission: this.permission + let tags = riot.mount(this.refs.content, "poll" + this.selectedTab, { + pollId: this.pollId, + poll: this.poll, + session: session, + permission: this.permission + }); + let countName = this.selectedTab == 'results' ? '' : (this.selectedTab + 'Count'); + if (countName) { + tags[0].on('count', count => { + this[countName] = count; + let args = {}; + args[countName] = count; + this.update(args); }); } - if (this.selectedTab == 'comments') { - riot.mount(this.refs.content, "pollcomments", { - pollId: this.pollId, - session: session, - permission: this.permission - }); - } - }); + }); }); - </script> <style> + .block { + cursor: not-allowed; + color: gray; + } + + .block > * { + color: gray; + } + .container { display: flex; justify-content: space-around; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollComments.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollComments.tag index 978d237..f0e70b4 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollComments.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollComments.tag @@ -3,10 +3,15 @@ require('./CommentPopup.tag'); <PollComments> <div class="comment-container"> + <div class="actions"> + <a class="button mainColorBackground" onclick="{openAddComment}"><i class="fa fa-plus"/> {__.addComment}</a> + </div> + <div class="legend"> {__.title} <a if="{comments.length > -1}" onclick="{toggleSort}"><i ref="sortOwner" class="fa fa-sort-amount-desc"></i></a> </div> + <div show="{loaded}" class="body"> <div show="{comments.length == 0}">{__.noComment}</div> @@ -47,10 +52,6 @@ require('./CommentPopup.tag'); </tr> </tfoot> </table> - - <div class="actions"> - <a class="button mainColorBackground" onclick="{openAddComment}">{__.addComment}</a> - </div> </div> </div> @@ -150,6 +151,7 @@ require('./CommentPopup.tag'); return commentService.getComments(this.pollId, pagination, this.permission).then((result) => { this.comments = result.elements; console.info(this.comments); + this.trigger('count', result.pagination.count); this.loaded = true; this.update(); return result; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollResults.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollResults.tag new file mode 100644 index 0000000..e3f6beb --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollResults.tag @@ -0,0 +1,95 @@ +<PollResults> + <div class="result-container"> + <div class="legend"> + {__.title} + </div> + <div> + <div if="{!poll.continiousResult && !poll.isClosed}"> + {__.noResult} + </div> + <div if="{poll.continiousResult || poll.isClosed}" class="result-body" > + <div if="{results.nbVotants==1}">1 {__.voter}</div> + <div if="{results.nbVotants>1}">{results.nbVotants} {__.voters}</div> + <br/> + <div class="result-content" each="{result in results.scores}"> + <div class='bold'>{result.choice}</div> + <div>{parent.__.rank} {result.scoreOrder + 1}</div> + <div>{parent.__.votesCount} {result.scoreValue}</div> + </div> + </div> + </div> + </div> + + <script> + this.loaded = false; + let session = require("../../js/Session"); + this.installBundle(session, "poll_results"); + let resultService = require("../../js/ResultService"); + let choiceService = require("../../js/ChoiceService"); + + this.pollId = opts.pollId; + this.poll = opts.poll; + this.permission = opts.permission; + console.info("permission:: " + this.permission); + + this.results = {nbVotants: 0, scores: []}; + this.choices = []; + this.scores = []; + this.on('mount', () => { + + + choiceService.getChoices(this.pollId, this.permission).then((result) => { + console.info("get choices"); + console.info(result); + this.choices = result; + + resultService.getResults(this.pollId, this.permission).then((result) => { + console.info("get results"); + console.info(result); + this.results = result; + this.results.scores.forEach(s => { + this.choices.forEach(c => { + if (c.id == s.choiceId) { + s.choice = c.choiceValue; + } + }); + }); + this.loaded = true; + + this.update(); + }); + }); + }); + + + </script> + <style> + + .bold { + font-weight: bold; + } + .result-container { + width: 800px; + } + + .result-body { + margin-top: 20px; + } + + .result-content { + display: flex; + flex-direction: row; + justify-content: space-between; + } + + .result-content > div:first-child { + width: 200px; + } + + .legend { + width: 800px; + margin-bottom: 20px; + } + + </style> +</PollResults> \ No newline at end of file diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag index 42abedf..5d31b40 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag @@ -54,8 +54,7 @@ <a onclick="{cancelEditVote}" class="small danger"> <i class="fa fa-remove fa-15x"/> </a> - <button class="icon" ref="vote_{vote.id}_vote" type="submit" - value="{__.vote}"> + <button class="icon" ref="vote_{vote.id}_vote" type="submit"> <i class="fa fa-check fa-15x"/> </button> </div> @@ -124,7 +123,6 @@ this.voteId = e.target.parentNode.parentNode.id; let tr = e.target.parentNode.parentNode.parentNode.parentNode; tr.classList.add("selected"); - this.refs['vote_' + this.voteId + "_vote"].value = this.__.vote; this.votes.forEach(v => { if (this.voteId == v.id) { this.refs['vote_' + this.voteId + "_voter"].value = v.voterName; @@ -149,12 +147,11 @@ vote.id = null; vote.voterName = this.refs.voterName.value; - let form = this.refs.form; this.choices.forEach(c => { vote.choice.push({ choiceId: c.id, - voteValue: form[c.id + '.voteValue'].checked ? 1 : 0 + voteValue: this.form[c.id + '.voteValue'].checked ? 1 : 0 }); }); @@ -232,6 +229,7 @@ this.votes = result; console.info("Reload votes"); console.info(this.votes); + this.trigger('count', result.length); this.loaded = true; this.update(); return result; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.