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 6802c82a567771fcefc256384311697e185f55ff Author: jcouteau <couteau@codelutin.com> Date: Tue Oct 29 11:14:09 2019 +0100 Fix VotesTable loading (still some hickups in some configurations) --- pollen-ui-riot-js/src/main/web/js/Poll.js | 56 +++++++++++----------- .../src/main/web/tag/poll/EditVote.tag.html | 27 ++++++++++- .../src/main/web/tag/poll/VotesTable.tag.html | 22 ++++++++- 3 files changed, 74 insertions(+), 31 deletions(-) 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 6d82ac6c..1c6b6abf 100644 --- a/pollen-ui-riot-js/src/main/web/js/Poll.js +++ b/pollen-ui-riot-js/src/main/web/js/Poll.js @@ -167,27 +167,34 @@ class Poll { promises.push(voteService.getNewVote(this.id, questionId, this.getPermission())); } return Promise.all(promises).then(resultsArray => { - let indexResult = 0; - this.choices = resultsArray[indexResult++]; - this.choiceCount = this.choices.length; - this.voteCountingTypeValue = resultsArray[indexResult++]; + this.questions.forEach(function(question) { + if (questionId === question.id) { + let indexResult = 0; + question.choices = resultsArray[indexResult++]; + question.choiceCount = this.choices.length; - if (this.resultIsVisible) { - this.results = resultsArray[indexResult++]; - this.choices.forEach(choice => { - choice.score = this.results.scores.find(score => score.choiceId === choice.id); - }); - } + question.voteCountingTypeValue = resultsArray[indexResult++]; - if (this.canVote) { - this.voterName = resultsArray[indexResult++].voterName; - } + if (this.resultIsVisible) { + question.results = resultsArray[indexResult++]; + question.choices.forEach(choice => { + choice.score = question.results.scores.find(score => score.choiceId === choice.id); + }); + } - pageTracker.trackPoll(); + if (this.canVote) { + this.voterName = resultsArray[indexResult++].voterName; + } + + pageTracker.trackPoll(); + + bus.trigger("question", question); + return Promise.resolve(this); + } + }); - bus.trigger("poll", this); - return Promise.resolve(this); + return Promise.reject(); }); } return Promise.reject("Init poll after load questions"); @@ -214,6 +221,7 @@ class Poll { let voteChoice = this.getVoteChoice(vote, choice); let value = voteChoice && voteChoice.voteValue; if (this.voteCountingType === 8) { + //TODO voteCountingConfig et voteCountingType sont sur la question et pas le poll value = this.voteCountingConfig.grades[value]; } return value; @@ -227,23 +235,20 @@ class Poll { choiceService.getChoices(this.id, questionId, this.getPermission()), resultService.getResults(this.id, questionId, this.getPermission())]) .then(resultsArray => { - this.choices = resultsArray[0]; - this.choiceCount = this.choices.length; - var _this = this; this.questions.forEach(function(question) { if (questionId === question.id) { + question.choices = resultsArray[0]; + question.choiceCount = question.choices.length; question.results = resultsArray[1]; question.choices.forEach(choice => { choice.score = question.results.scores.find(score => score.choiceId === choice.id); }); - - _this.question = question; + bus.trigger("question", question); } }); pageTracker.trackResults(); - bus.trigger("question", this.question); return Promise.resolve(this); }); } @@ -422,13 +427,6 @@ class Poll { return Promise.reject("Init poll after ignore report"); } - loadVoteCountingType() { - voteCountingTypeService.getVoteCountingType(this.questions[0].voteCountingType).then((voteCountingTypeValue) => { - this.questions[0].voteCountingTypeValue = voteCountingTypeValue; - bus.trigger("poll", this); - }); - } - getInvalidEmails() { if (this.id) { return pollService.getInvalidEmails(this.id, this.permission); diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html index fd033f8b..9a973a9e 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html @@ -229,6 +229,32 @@ this.multi = multi2; }; + this.onPollChange = poll2 => { + this.poll = poll2; + this.question = this.poll.questions[0]; + if (this.question) { + if (!this.question.voteCountingTypeValue) { + this.poll.reloadVoteCountingTypeValue(this.question).then(() => { + this.pollTypeCheckbox = this.question.voteCountingTypeValue && this.question.voteCountingTypeValue.renderType === "checkbox"; + this.pollTypeSelect = this.question.voteCountingTypeValue && this.question.voteCountingTypeValue.renderType === "select"; + this.pollTypeCoombs = this.question.voteCountingType && this.question.voteCountingType === 7; + }); + } else { + this.pollTypeCheckbox = this.question.voteCountingTypeValue && this.question.voteCountingTypeValue.renderType === "checkbox"; + this.pollTypeSelect = this.question.voteCountingTypeValue && this.question.voteCountingTypeValue.renderType === "select"; + this.pollTypeCoombs = this.question.voteCountingType && this.question.voteCountingType === 7; + } + this.resultsLoaded = this.question.results !== undefined; + if (!this.resultsLoaded) { + this.poll.loadResults(this.question.id).then(() => { + }); + } + this.onVoteChanged(); + } + this.update(); + }; + + this.listen("poll", this.onPollChange); this.listen("question", this.onQuestionChange); this.listen("multi", this.onMultiChange); this.listen("user", (user, oldUser) => { @@ -400,7 +426,6 @@ this.voteInEdition = null; this.resetVoteForm(); if (this.multi) { - this.update(); this.parent.parent.nextQuestion(); } else { this.update(); diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/VotesTable.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/VotesTable.tag.html index d09bdbb1..8367e683 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/VotesTable.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/VotesTable.tag.html @@ -110,6 +110,18 @@ this.question = this.opts.question; + this.loadVoteCountingTypeValue = () => { + if (!this.question.voteCountingTypeValue) { + this.poll.reloadVoteCountingTypeValue(this.question).then(() => { + this.pollTypeCheckbox = this.question.voteCountingTypeValue && this.question.voteCountingTypeValue.renderType === "checkbox"; + this.update(); + }); + } else { + this.pollTypeCheckbox = this.question.voteCountingTypeValue && this.question.voteCountingTypeValue.renderType === "checkbox"; + } + }; + + this.pagination = { order: "topiaCreateDate", desc: true @@ -137,7 +149,8 @@ this.onQuestionChange = question2 => { this.question = question2; - this.pollTypeCheckbox = question2.voteCountingTypeValue && question2.voteCountingTypeValue.renderType === "checkbox"; + this.loadVoteCountingTypeValue(); + this.lazyLoad(this.pagination); this.refresh(); this.update(); }; @@ -228,6 +241,13 @@ } }; + this.on('mount', function() { + //first load + //FIXME JC191023 Ça semble pas être la bonne façon de faire :( mais ça marche ! + this.loadVoteCountingTypeValue(); + this.refresh(); + }) + </script> <style> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.