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 b1712689c5a72c0b8e8308fc0ff04e14d228fe51 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 23 13:51:31 2017 +0200 création d'un utilitaire de log pour le JS --- pollen-ui-riot-js/src/main/web/index.js | 1 + pollen-ui-riot-js/src/main/web/js/FormHelper.js | 4 +++- pollen-ui-riot-js/src/main/web/js/I18nHelper.js | 4 ++-- pollen-ui-riot-js/src/main/web/js/Logger.js | 18 +++++++++++++++++ pollen-ui-riot-js/src/main/web/js/PollForm.js | 23 +++++++++++----------- .../src/main/web/js/ResourceService.js | 3 ++- pollen-ui-riot-js/src/main/web/js/Session.js | 21 ++++++++++---------- pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html | 2 +- .../src/main/web/tag/poll/ChoiceDate.tag.html | 8 ++++---- .../src/main/web/tag/poll/Created.tag.html | 4 ++-- .../src/main/web/tag/poll/Polls.tag.html | 2 +- 11 files changed, 57 insertions(+), 33 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/index.js b/pollen-ui-riot-js/src/main/web/index.js index 08e2a76..1a76a90 100644 --- a/pollen-ui-riot-js/src/main/web/index.js +++ b/pollen-ui-riot-js/src/main/web/index.js @@ -20,6 +20,7 @@ // */ riot.mixin(require("./js/I18nHelper")); riot.mixin(require("./js/UIHelper")); +riot.mixin({logger: require("./js/Logger")}); require("./tag/Pollen.tag.html"); riot.mount("*"); diff --git a/pollen-ui-riot-js/src/main/web/js/FormHelper.js b/pollen-ui-riot-js/src/main/web/js/FormHelper.js index 6d9b024..25b3347 100644 --- a/pollen-ui-riot-js/src/main/web/js/FormHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/FormHelper.js @@ -18,6 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ +let logger = require("./Logger"); + class FormHelper { static formToMap(form) { @@ -32,7 +34,7 @@ class FormHelper { } else if (e.type === "datetime-local") { if (e.value !== "") { result[e.name] = moment(e.value).format("YYYY-MM-DDTHH:mm"); - console.info("date::: " + e.value + " -- " + result[e.name]); + logger.info("date::: " + e.value + " -- " + result[e.name]); } } else if (e.type === "radio") { Array.prototype.forEach.call(form.elements[e.name], function(r) { 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 d062aa2..1b75ff5 100644 --- a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js @@ -32,7 +32,7 @@ module.exports = { try { this.update(); } catch (e) { - console.error("Error in generateBundle for " + value, e); + this.logger.error("Error in generateBundle for " + value, e); } }; this.listen("locale", onLocalChange); @@ -48,7 +48,7 @@ module.exports = { let realKey = key.substring(value.length + 1); this.__[realKey] = bundle[key]; if (this.debug) { - console.debug(realKey + " -> " + this.__[realKey]); + this.logger.debug(realKey + " -> " + this.__[realKey]); } } }); diff --git a/pollen-ui-riot-js/src/main/web/js/Logger.js b/pollen-ui-riot-js/src/main/web/js/Logger.js new file mode 100644 index 0000000..3ce2f68 --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/js/Logger.js @@ -0,0 +1,18 @@ + +module.exports = { + log(message) { + console.log(message); + }, + + info(message) { + console.info(message); + }, + + warn(message) { + console.warn(message); + }, + + error(message) { + console.error(message); + } +}; 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 72d2201..155ee84 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollForm.js +++ b/pollen-ui-riot-js/src/main/web/js/PollForm.js @@ -27,6 +27,7 @@ let resourceService = require("./ResourceService"); let pollService = require("./PollService"); let voterListService = require("./VoterListService"); let bus = require("./PollenBus"); +let logger = require("./Logger"); class PollForm { @@ -90,10 +91,10 @@ class PollForm { this.choices = results[1]; if (clone) { - for (var i in this.choices) { - this.choices[i].id = undefined; - this.choices[i].permission = undefined; - } + this.choices.forEach(choice => { + choice.id = undefined; + choice.permission = undefined; + }); } voterListService.init(this).then(voterList => { @@ -135,8 +136,8 @@ class PollForm { } create() { - console.info("form before create"); - console.info(this.form); + logger.info("form before create"); + logger.info(this.form); // if the choice is of type resource, then upload the file and set its id as choice value let fileUploadPromises = []; @@ -153,15 +154,15 @@ class PollForm { }); return Promise.all(fileUploadPromises).then(() => { return pollService.create(this.model, this.choices, voterListService.getVoterLists(), voterListService.getVoterListMembers()).then((result) => { - console.info("Poll created"); - console.info(result); + logger.info("Poll created"); + logger.info(result); this.model.id = result.id; this.model.permission = result.permission; return Promise.resolve(); }, (error) => { - console.error("Could not create poll"); - console.error(error); + logger.error("Could not create poll"); + logger.error(error); return Promise.reject(error); }); }); @@ -237,7 +238,7 @@ class PollForm { } setStep(step) { - console.info("setStep:: " + step); + logger.info("setStep:: " + step); this.step = Math.min(this.steps.length, Math.max(0, step)); } diff --git a/pollen-ui-riot-js/src/main/web/js/ResourceService.js b/pollen-ui-riot-js/src/main/web/js/ResourceService.js index 7d3ce2e..35cfa19 100644 --- a/pollen-ui-riot-js/src/main/web/js/ResourceService.js +++ b/pollen-ui-riot-js/src/main/web/js/ResourceService.js @@ -20,11 +20,12 @@ */ let singleton = require("./Singleton"); let FetchService = require("./FetchService"); +let logger = require("./Logger"); class ResourceService extends FetchService { create(resource) { - console.log(resource); + logger.log(resource); return this.form("/v1/resources", {resource: resource}, true); } 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 851e415..4b32882 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -22,6 +22,7 @@ let singleton = require("./Singleton"); let authService = require("./AuthService"); let bus = require("./PollenBus.js"); +let logger = require("./Logger"); class Session { @@ -105,34 +106,34 @@ class Session { } connect() { - console.info("Connect::"); + logger.info("Connect::"); return authService.connectedUserPromise().then((user) => { if (!user) { - console.info("Connect error"); + logger.info("Connect error"); return Promise.reject(); } - console.info("Connect user::"); - console.info(user); + logger.info("Connect user::"); + logger.info(user); return Promise.resolve(user); }, () => { - console.info("Connect error"); + logger.info("Connect error"); return Promise.reject(); }); } signIn(login, password) { return authService.signIn(login, password).then(auth => { - console.info("SignIn::"); - console.info(auth); + logger.info("SignIn::"); + logger.info(auth); return authService.userPromise(auth).then((user) => { if (!user) { - console.info("SignIn error"); + logger.info("SignIn error"); this.user = null; bus.trigger("user", this.user); return Promise.reject(); } - console.info("SignIn user::"); - console.info(user); + logger.info("SignIn user::"); + logger.info(user); this.user = user; bus.trigger("user", this.user); return this.user; diff --git a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html index 1b58988..569579c 100644 --- a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html @@ -83,7 +83,7 @@ require("./SignUp.tag.html"); }; this.close = () => { - console.log("close !"); + this.logger.log("close !"); this.openSignIn = false; this.update(); }; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/ChoiceDate.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/ChoiceDate.tag.html index c0ad88c..f962a20 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/ChoiceDate.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/ChoiceDate.tag.html @@ -93,8 +93,8 @@ this.choice.time = choiceValue.substring(index + 1); this.timed = true; } - // console.info("init choice: (" + this.timed + ")"); - // console.info(this.choice); + this.logger.info("init choice: (" + this.timed + ")"); + this.logger.info(this.choice); } this.on("mount", () => { @@ -132,7 +132,7 @@ ref.classList.remove("choice-view"); this.trigger("editChoice", this.number); Object.assign(this.$choice = {}, this.choice); - // console.info(this.$choice); + this.logger.info(this.$choice); }; this.cancelEditChoice = () => { @@ -141,7 +141,7 @@ ref.classList.remove("choice-edit"); ref.classList.add("choice-view"); Object.assign(this.choice, this.$choice); - // console.info(this.choice); + this.logger.info(this.choice); this.refs.choice.value = this.choice.date; this.refs.time.value = this.choice.time; this.timed = !!this.choice.time; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Created.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Created.tag.html index a79081b..e861920 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Created.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Created.tag.html @@ -40,8 +40,8 @@ <script type="es6"> this.installBundle(this.opts.session, "poll_created"); this.form = this.opts.form; - // console.info("Created poll"); - // console.info(this.form); + this.logger.info("Created poll"); + this.logger.info(this.form); </script> <style> 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 61392ca..243d00e 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 @@ -132,7 +132,7 @@ require("./PollCard.tag.html"); return pollService.assignPoll(finds[1], finds[2]).then((result) => { if (result) { this.refresh(); - console.log(result); + this.logger.log(result); this.assignedPollTitle = result.title; this.update(); } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.