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 ac074ae84f52a3edfa2039c60d8e261a0ff63a68 Author: Kevin Morin <morin@codelutin.com> Date: Tue Apr 18 17:31:13 2017 +0200 Ajout d'un panel pour afficher des erreurs --- pollen-ui-riot-js/src/main/web/conf.js | 1 + pollen-ui-riot-js/src/main/web/i18n.json | 9 ++- pollen-ui-riot-js/src/main/web/js/Error.js | 37 +++++++++++ pollen-ui-riot-js/src/main/web/js/FetchService.js | 11 +--- pollen-ui-riot-js/src/main/web/js/I18nHelper.js | 2 +- pollen-ui-riot-js/src/main/web/js/Poll.js | 4 ++ pollen-ui-riot-js/src/main/web/js/PollForm.js | 5 +- pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html | 10 ++- .../src/main/web/tag/PollenErrorManager.tag.html | 75 ++++++++++++++++++++++ 9 files changed, 138 insertions(+), 16 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/conf.js b/pollen-ui-riot-js/src/main/web/conf.js index 702b5f7..d88f88b 100644 --- a/pollen-ui-riot-js/src/main/web/conf.js +++ b/pollen-ui-riot-js/src/main/web/conf.js @@ -12,6 +12,7 @@ window.pollenConf = { defaultTimeFormat: "shortTime", defaultDateTimeFormat: "short", debugI18n: false, + defaultErrorTimeout: 15, infoMessages: { fr: [], en: [] diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index 548834c..34e36ce 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -354,7 +354,10 @@ "favoriteList_member_email_placeholder": "Le courriel du membre", "favoriteList_member_weight": "Poids", "favoriteList_member_ldap_placeholder": "L'adresse de l'annuaire LDAP", - "favoriteList_member_add": "Ajouter" + "favoriteList_member_add": "Ajouter", + "error_manager_403": "Erreur : Accès refusé", + "error_manager_poll_403": "Erreur : le sondage n'est pas accessible", + "error_manager_500": "Erreur : Service indisponible" }, "en": { "pagination_all": "All", @@ -701,6 +704,8 @@ "favoriteList_member_email_placeholder": "Member email", "favoriteList_member_weight": "Weight", "favoriteList_member_ldap_placeholder": "LDAP repository address", - "favoriteList_member_add": "Add" + "favoriteList_member_add": "Add", + "error_manager_403": "Error: Forbidden access", + "error_manager_500": "Error: Service unavailable" } } diff --git a/pollen-ui-riot-js/src/main/web/js/Error.js b/pollen-ui-riot-js/src/main/web/js/Error.js new file mode 100644 index 0000000..bbe7513 --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/js/Error.js @@ -0,0 +1,37 @@ +/*- + * #%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% + */ +class Error { + + constructor(e, timeout) { + if (e instanceof Error) { + this.message = e.message; + this.timeout = e.timeout; + } else { + this.message = e; + } + if (!this.timeout) { + this.timeout = timeout; + } + } +} + +module.exports = Error; + 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 01604ca..9aeec9a 100644 --- a/pollen-ui-riot-js/src/main/web/js/FetchService.js +++ b/pollen-ui-riot-js/src/main/web/js/FetchService.js @@ -61,17 +61,12 @@ class FetchService { bus.trigger("unauthorize"); return Promise.reject(); } - - return response.text() - .then((code) => { - return Promise.reject(code); - }, () => { - return Promise.reject(); - }); + return Promise.reject(response); }, (error) => { bus.trigger("loaded", loadEvent); - console.error(error); + + return Promise.reject(error); }); } 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 5293d1a..e12c445 100644 --- a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js @@ -60,7 +60,7 @@ module.exports = { }, _l(key, ...params) { - return this.i18nformat(this.__[key], ...params); + return this.i18nformat(this.__[key], ...params) || key; }, i18nformat(value, params) { 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 8c22af8..0524bc6 100644 --- a/pollen-ui-riot-js/src/main/web/js/Poll.js +++ b/pollen-ui-riot-js/src/main/web/js/Poll.js @@ -9,6 +9,7 @@ let commentService = require("./CommentService"); let Pagination = require("./Pagination"); let resourceService = require("./ResourceService"); let bus = require("./PollenBus.js"); +let Error = require("./Error"); class Poll { @@ -35,6 +36,9 @@ class Poll { this.results = undefined; bus.trigger("poll", this); return Promise.resolve(this); + }, + (error) => { + bus.trigger("error", new Error("poll_" + error.status)); }); return this._initPromise; diff --git a/pollen-ui-riot-js/src/main/web/js/PollForm.js b/pollen-ui-riot-js/src/main/web/js/PollForm.js index 2d6332e..dd00cd6 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollForm.js +++ b/pollen-ui-riot-js/src/main/web/js/PollForm.js @@ -25,7 +25,7 @@ let voteCountingTypeService = require("./VoteCountingTypeService"); let choiceService = require("./ChoiceService"); let resourceService = require("./ResourceService"); let pollService = require("./PollService"); - +let bus = require("./PollenBus"); class PollForm { @@ -81,15 +81,12 @@ class PollForm { this.showOptions = false; this.hasVotes = false; this.creation = true; - console.info("init form"); return Promise.all([ pollService.empty(this.choiceType), this._loadVoteCountingTypes() ]).then((results) => { this.model = results[0]; - console.info("empty poll"); - console.info(this.model); if (user) { this.model.creatorName = user.name; 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 1438b6f..404d33e 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 @@ -21,6 +21,7 @@ require("./PollenWaiter.tag.html"); require("./PollenHeader.tag.html"); require("./PollenFooter.tag.html"); +require("./PollenErrorManager.tag.html"); require("./SignIn.tag.html"); require("./SignUp.tag.html"); require("./SignCheck.tag.html"); @@ -43,6 +44,8 @@ require("./favoriteList/FavoriteList.tag.html"); <PollenFooter/> + <PollenErrorManager/> + <script type="es6"> let session = require("../js/Session"); session.start(); @@ -68,7 +71,6 @@ require("./favoriteList/FavoriteList.tag.html"); }); this.on("before-unmount", () => { - console.log("um"); this.bus.off("locale", this.showInfoMessages); }); @@ -218,5 +220,11 @@ require("./favoriteList/FavoriteList.tag.html"); padding: 10px; } + pollenerrormanager { + position: absolute; + bottom: 20px; + right: 0px; + } + </style> </Pollen> diff --git a/pollen-ui-riot-js/src/main/web/tag/PollenErrorManager.tag.html b/pollen-ui-riot-js/src/main/web/tag/PollenErrorManager.tag.html new file mode 100644 index 0000000..be3e39a --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/tag/PollenErrorManager.tag.html @@ -0,0 +1,75 @@ +<PollenErrorManager> + + <div each={error in errors} class="pollen-error" id="{error.id}"> + <div class="close-error" onclick="{closeError(error.id)}"><i class="fa fa-times" aria-hidden="true"></i></div> + {_l(error.message)} + </div> + + <style> + <script type="es6"> + let Error = require('../js/Error'); + let session = require("../js/Session"); + this.installBundle(session, "error_manager"); + + this.errorIndex = 0; + this.errors = []; + + this.handleErrors = (e) => { + var error = new Error(e); + if (!error.timeout) { + error.timeout = session.configuration.defaultErrorTimeout + } + error.id = "error-" + this.errorIndex++; + + this.errors.push(error); + this.update(); + + setTimeout(() => { + this.closeError(error.id).apply(); + }, error.timeout * 1000); + }; + + this.on("mount", () => { + this.bus.on("error", this.handleErrors); + }); + + this.on("before-unmount", () => { + this.bus.off("error", this.handleErrors); + }); + + this.closeError = (errorId) => (e) => { + if (e) { + e.preventDefault(); + e.stopPropagation(); + } + console.log(errorId); + var errorElement = document.getElementById(errorId); + errorElement.addEventListener("transitionend", () => { + errorElement.parentNode.removeChild(errorElement); + }); + errorElement.style.transform = "scaleY(0)"; + }; + + </script> + .pollen-error { + width: 300px; + background: #ffcccc; + padding: 10px 30px 10px; + box-shadow: 5px 5px 5px 0px #9b9b9b; + border-radius: 5px; + margin: 10px; + transform: scaleY(1); + transform-origin: 50% 100%; + transition: transform 0.5s; + } + + .close-error { + position: absolute; + top: 10px; + right: 10px; + color: #666; + cursor: pointer; + } + </style> + +</PollenErrorManager> \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.