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 0d96c20ab2d8651cc834859b6bcd5a98552d9a28 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Mar 23 17:13:59 2017 +0100 utilisation du bus d'événement pour les modification de connection et de locale --- pollen-ui-riot-js/src/main/web/i18n.json | 2 + pollen-ui-riot-js/src/main/web/js/FetchService.js | 7 ++- pollen-ui-riot-js/src/main/web/js/I18nHelper.js | 8 ++- pollen-ui-riot-js/src/main/web/js/Session.js | 62 +++++++--------------- .../src/main/web/tag/HeaderI18n.tag.html | 16 ++++-- pollen-ui-riot-js/src/main/web/tag/Home.tag.html | 13 +---- pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html | 5 +- .../src/main/web/tag/PollenHeader.tag.html | 29 ++++------ pollen-ui-riot-js/src/main/web/tag/Users.tag.html | 4 +- .../src/main/web/tag/poll/Comments.tag.html | 5 +- .../src/main/web/tag/poll/EditPoll.tag.html | 8 ++- .../src/main/web/tag/poll/Polls.tag.html | 2 +- .../src/main/web/tag/poll/Votes.tag.html | 14 ++--- 13 files changed, 70 insertions(+), 105 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index 325bbc5..c14f4a8 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -48,6 +48,7 @@ "poll_votes_authorPlaceHolder": "Renseignez votre nom", "poll_votes_vote": "Voter", "poll_votes_addChoice": "Ajouter un choix", + "poll_votes_choices": "Choix", "poll_votes_delete": "Supprimer le vote ?", "poll_votes_results": "Resultats", "poll_votes_noVote": "Aucun vote", @@ -307,6 +308,7 @@ "poll_votes_authorPlaceHolder": "Fill your name", "poll_votes_vote": "Vote", "poll_votes_addChoice": "Add choice", + "poll_votes_choices": "Choices", "poll_votes_delete": "Delete vote?", "poll_votes_results": "Results", "poll_votes_noVote": "No vote", diff --git a/pollen-ui-riot-js/src/main/web/js/FetchService.js b/pollen-ui-riot-js/src/main/web/js/FetchService.js index 4bf7221..e33d46b 100644 --- a/pollen-ui-riot-js/src/main/web/js/FetchService.js +++ b/pollen-ui-riot-js/src/main/web/js/FetchService.js @@ -18,6 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ + +let bus = require("./PollenBus.js"); + class FetchService { constructor() { @@ -48,11 +51,11 @@ class FetchService { return response.json().then(json => Promise.reject(json)); } if (response.status === 401) { - require("./Session").emitUnauthorize(); + bus.trigger("unauthorize"); return Promise.reject(); } if (response.status === 503) { - require("./Session").emitUnauthorize(); + bus.trigger("unauthorize"); return Promise.reject(); } diff --git a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js index f0eab00..5293d1a 100644 --- a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js @@ -18,13 +18,15 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ +let bus = require("./PollenBus.js"); + module.exports = { installBundle(session, value, callback) { this.bundle = session.i18n; this.debug = session.configuration.debugI18n; this.generateBundle(session.locale, value); - session.onLocaleChanged((locale) => { + let onLocalChange = (locale) => { this.generateBundle(locale, value); if (callback) { callback(locale); @@ -34,6 +36,10 @@ module.exports = { } catch (e) { console.error("Error in generateBundle for " + value, e); } + }; + bus.on("locale", onLocalChange); + this.on("before-unmount", () => { + bus.off("locale", onLocalChange); }); }, diff --git a/pollen-ui-riot-js/src/main/web/js/Session.js b/pollen-ui-riot-js/src/main/web/js/Session.js index 6306730..afcb67c 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -21,6 +21,7 @@ */ let singleton = require("./Singleton"); let authService = require("./AuthService"); +let bus = require("./PollenBus.js"); class Session { @@ -67,63 +68,32 @@ class Session { input.setAttribute("value", notADateValue); this.datetimeInputSupported = (input.value !== notADateValue); - this.onUnauthorize(() => { + bus.on("unauthorize", () => { this.user = null; + bus.trigger("user", this.user); }); } start() { if (this.isConnected()) { - this.user = this.connect(); - } else { - this.user = Promise.resolve(); + this.connect().then(user => { + this.user = user; + bus.trigger("user", user); + }); } - return this.user; } getUser() { return this.user; } - emitUnauthorize() { - this.trigger("unauthorized"); - } - - onUnauthorize(fn) { - this.on("unauthorized", fn); - } - - emitConnected(user) { - this.trigger("connected", user); - } - - onConnected(fn) { - this.on("connected", fn); - } - - emitDisconnected(user) { - this.trigger("disconnected", user); - } - - onDisconnected(fn) { - this.on("disconnected", fn); - } - - emitError() { - this.trigger("error"); - } - - onError(fn) { - this.on("error", fn); - } - onLocaleChanged(fn) { this.on("localeChanged", fn); } changeLocale(locale) { this.locale = locale; - this.trigger("localeChanged", locale); + bus.trigger("locale", this.locale); } isConnected() { @@ -139,8 +109,10 @@ class Session { } console.info("Connect user::"); console.info(user); - this.emitConnected(user); return Promise.resolve(user); + }, () => { + console.info("Connect error"); + return Promise.reject(); }); } @@ -151,13 +123,14 @@ class Session { return authService.userPromise(auth).then((user) => { if (!user) { console.info("SignIn error"); - this.user = Promise.reject(); - return this.user; + this.user = null; + bus.trigger("user", this.user); + return Promise.reject(); } console.info("SignIn user::"); console.info(user); - this.user = Promise.resolve(user); - this.emitConnected(user); + this.user = user; + bus.trigger("user", this.user); return this.user; }); @@ -167,7 +140,8 @@ class Session { signOut() { return authService.signOut().then(() => { - delete this.user; + this.user = null; + bus.trigger("user", this.user); }); } diff --git a/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag.html b/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag.html index 515f3ae..2ac5668 100644 --- a/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag.html @@ -35,17 +35,25 @@ this.toEnglish = () => { if ("en" !== session.locale) { session.changeLocale("en"); - this.locale = session.locale; - this.update(); } }; this.toFrench = () => { if ("fr" !== session.locale) { session.changeLocale("fr"); - this.locale = session.locale; - this.update(); } }; + + this.onLocalChange = locale => { + this.locale = locale; + this.update(); + }; + + this.bus.off("locale", this.onLocaleChange); + + this.on("before-unmount", () => { + this.bus.off("locale", this.onLocaleChange); + }); + </script> <style> diff --git a/pollen-ui-riot-js/src/main/web/tag/Home.tag.html b/pollen-ui-riot-js/src/main/web/tag/Home.tag.html index 4630d39..19e5998 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Home.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/Home.tag.html @@ -38,19 +38,10 @@ this.installBundle(session, "home"); this.createOther = () => { - session.getUser().then(user => { - form.init("TEXT", user).then(() => { - route("/poll/new/text"); - }); - }); - + route("/poll/new/text"); }; this.createDate = () => { - session.getUser().then(user => { - form.init("DATE", user).then(() => { - route("/poll/new/date"); - }); - }); + route("/poll/new/date"); }; </script> diff --git a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html index 6c864b6..d296472 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html @@ -35,10 +35,7 @@ require("./Users.tag.html"); <script type="es6"> let session = require("../js/Session"); - session.start().then(() => { - // console.info("session started"); - }); - + session.start(); this.installBundle(session, "main"); let route = require("riot-route"); diff --git a/pollen-ui-riot-js/src/main/web/tag/PollenHeader.tag.html b/pollen-ui-riot-js/src/main/web/tag/PollenHeader.tag.html index 7794bac..9d1f942 100644 --- a/pollen-ui-riot-js/src/main/web/tag/PollenHeader.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/PollenHeader.tag.html @@ -73,37 +73,26 @@ require("./HeaderI18n.tag.html"); this.signOut = () => { let callback = () => { - this.user = null; - this.admin = false; - this.update({user: this.user, admin: this.admin}); route("home"); }; - session.signOut().then(callback, callback); }; - this.user = null; - - if (session.isConnected()) { - - session.getUser().then(user => { - this.user = user; - this.admin = user.administrator; - this.update({user: this.user, admin: this.admin}); - }); - } + this.user = session.getUser(); + this.admin = this.usser && this.user.administrator; - session.onConnected((user) => { + this.onUserChange = user => { this.user = user; - this.admin = user.administrator; + this.admin = user && user.administrator; this.update(); - }); + }; - session.onUnauthorize(() => { - this.user = null; - this.update(); + this.bus.on("user", this.onUserChange); + + this.on("before-unmount", () => { + this.bus.off("user", this.onUserChange); }); </script> diff --git a/pollen-ui-riot-js/src/main/web/tag/Users.tag.html b/pollen-ui-riot-js/src/main/web/tag/Users.tag.html index cf9ed9d..5196209 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Users.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/Users.tag.html @@ -79,9 +79,7 @@ require("./Pagination.tag.html"); this.moment = require("moment"); this.moment.locale(this.session.locale); - this.session.getUser().then(user=> { - this.connectedUser = user; - }); + this.connectedUser = this.session.getUser(); this.sortName = "name"; this.sortValue = false; // means asc 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 877092c..d0ac15d 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 @@ -145,9 +145,8 @@ require("./CommentPopup.tag.html"); this.installBundle(session, "poll_comments"); let moment = require("moment"); - session.getUser().then(user => { - this.userName = user && user.name; - }); + let user = session.getUser(); + this.userName = user && user.name; this.poll = require("../../js/Poll.js"); this.poll.loadComments(); diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html index 4169dc4..e6c8b9e 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html @@ -91,11 +91,9 @@ require("./Created.tag.html"); this.update(); }); } else { - this.session.getUser().then(user => { - this.form.init(this.opts.choiceType, user).then(() => { - this.loaded = true; - this.update(); - }); + this.form.init(this.opts.choiceType, this.session.getUser()).then(() => { + this.loaded = true; + this.update(); }); } diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html index b4178f8..f952e38 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html @@ -41,7 +41,7 @@ require("./PollCard.tag.html"); this.installBundle(session, "polls"); this.pagination = { - order: "title", + order: "topiaCreateDate", desc: true, pageSize: 5, pageNumber: 0 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 e87133a..6d75067 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 @@ -5,11 +5,9 @@ require("./Podium.tag.html"); <div class="container"> <div show="{loaded}"> - <div if="{!voting}">{__.voteNotOpen}</div> - <Podium if={poll.resultIsVisible}/> - <div if="{voting}" class="voters"> + <div class="voters"> <form ref="formAddVote" onsubmit="{addVote}" class="fix"> <div class="current-voter"> @@ -29,6 +27,10 @@ require("./Podium.tag.html"); if={!voteId && error['voter.name']}> {error['voter.name']} </div> + <div if={!poll.canVote} + class="choices-label"> + {__.choices} + </div> </div> <div each={choice in poll.choices} class="choice"> <div class="choice-value"> @@ -194,9 +196,8 @@ require("./Podium.tag.html"); let session = require("../../js/Session"); let Choice = require("../../js/Choice"); this.installBundle(session, "poll_votes"); - session.getUser().then(user => { - this.userName = user && user.name; - }); + let user = session.getUser(); + this.userName = user && user.name; this.poll = require("../../js/Poll.js"); this.poll.loadVotes(); @@ -205,7 +206,6 @@ require("./Podium.tag.html"); this.onPollChange = poll => { this.loaded = poll.choices !== undefined; this.poll = poll; - this.voting = poll.canVote || poll.status === "VOTING" || poll.status === "CLOSED"; this.choiceToAdd = this.poll.initChoice(this.choiceToAdd); this.update(); }; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.