This is an automated email from the git hooks/post-receive script. New commit to branch feature/11_attach_not_connected_poll_to_pllen_account in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit ae5dd5e6d979c0964e35baf167a0f37c6cc87b55 Author: Kevin Morin <morin@codelutin.com> Date: Mon Apr 24 16:45:57 2017 +0200 refs #11 add form to link poll to user's account in the created poll page --- .../org/chorem/pollen/rest/api/PollApiTest.java | 15 +++ pollen-ui-riot-js/src/main/web/i18n.json | 8 ++ pollen-ui-riot-js/src/main/web/js/PollService.js | 8 ++ .../src/main/web/tag/poll/Polls.tag.html | 112 ++++++++++++++++++++- 4 files changed, 140 insertions(+), 3 deletions(-) diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java index e29032b..1d84aae 100644 --- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java +++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java @@ -237,4 +237,19 @@ public class PollApiTest extends AbstractPollenRestApiTest { showTestResult(content); assertNotNull(content); } + + @Test + @Ignore + public void assignPoll() throws URISyntaxException, IOException { + + Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID); + String pollId = encodeId(poll.getTopiaId()); + + Request request = createRequest(RestApiFixtures.polls(pollId, "assign")) + .addParameter(PollenRestApiRequestFilter.REQUEST_PERMISSION_PARAMETER, poll.getCreator().getPermission().getToken()) + .Put(); + String content = request.execute().returnContent().asString(); + showTestResult(content); + assertNotNull(content); + } } diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index 0c69fd3..e99ce24 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -88,6 +88,10 @@ "poll_votes_results_unit_7_many": "votes", "poll_votes_voteNotOpen": "Les votes ne sont pas encore ouverts.", "polls_createdPolls": "Mes sondages", + "polls_assignPollToMe": "Attacher le sondage", + "polls_assignPollToMe_title": "Attacher un sondage à mon compte", + "polls_assignPollToMe_desc": "Si vous avez créé un sondage sans être connecté, vous pouvez le rattacher à votre compte en remplissant ce formulaire avec l'url d'administration du sondage.", + "polls_assignSuccessMessage": "Le sondage suivant a bien été rattaché à votre compte :", "polls_invitedPolls": "Mes invitations", "polls_participatedPolls": "Mes participations", "polls_polls": "Tous les sondages", @@ -462,6 +466,10 @@ "poll_votes_results_unit_7_many": "votes", "poll_votes_voteNotOpen": "Votes are not open.", "polls_createdPolls": "My polls", + "polls_assignPollToMe": "Link a poll to my account", + "polls_assignPollToMe_title": "Link the poll", + "polls_assignPollToMe_desc": "If you created a poll without being connected, you can link it to your account by fillin the form below with the administration url of the poll.", + "polls_assignSuccessMessage": "The following poll has successfully been linked to your account:", "polls_invitedPolls": "My invitations", "polls_participatedPolls": "My participations", "polls_polls": "All polls", diff --git a/pollen-ui-riot-js/src/main/web/js/PollService.js b/pollen-ui-riot-js/src/main/web/js/PollService.js index 536a455..90e836d 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollService.js +++ b/pollen-ui-riot-js/src/main/web/js/PollService.js @@ -79,6 +79,14 @@ class PollService extends FetchService { } return this.put(url); } + + assignPoll(pollId, permission) { + let url = "/v1/polls/" + pollId + "/assign"; + if (permission) { + url += "?permission=" + permission; + } + return this.put(url); + } } module.exports = singleton(PollService); 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 f952e38..61392ca 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 @@ -23,22 +23,71 @@ require("./PollCard.tag.html"); </div> </div> - <Pagination pagination={pagination} onchange="{refresh}"/> + <Pagination pagination={pagination} onchange="{refresh}" /> - <PollCard each={poll in polls} poll={poll}/> + <PollCard each={poll in polls} poll={poll} /> - <Pagination pagination={pagination} onchange="{refresh}"/> + <Pagination pagination={pagination} onchange="{refresh}" /> </div> <div show={polls.length === 0} class="c-alert c-alert--info"> {__.noPoll} </div> + + + + <form if={opts.method === "createdPolls"} onsubmit="{assignPoll}" class="assign-form"> + <fieldset> + <legend>{__.assignPollToMe_title}</legend> + + <p><i class="fa fa-question-circle-o"></i> {__.assignPollToMe_desc}</p> + <div class="o-form-element"> + <div class="o-field o-field--icon-left"> + <i class="fa fa-fw fa-link c-icon"></i> + <input class="c-field" + type="text" + name="pollToAssign" + ref="pollToAssign" + placeholder={pollToAssignPlaceholder} + pattern={pollToAssignUrlPattern} + required> + </div> + </div> + + <div class="actions"> + <div class="actions-left"> + <div id="assign-poll-success-message" if={assignedPollTitle}> + <div class="close-message" onclick="{closeMessage}"><i class="fa fa-times" aria-hidden="true"></i></div> + <p> + {__.assignSuccessMessage} + </p> + <p> + <em>{assignedPollTitle}</em> + </p> + </div> + </div> + <div class="actions-right"> + <button type="submit" + class="c-button c-button--info pull-right"> + <i class="fa fa-link"/> + {__.assignPollToMe} + </button> + </div> + </div> + </fieldset> + </form> </div> </div> +</Polls> + +<style> <script type="es6"> this.loaded = false; let session = require("../../js/Session"); this.installBundle(session, "polls"); + this.pollToAssignPlaceholder = session.pollenUIContext.uiEndPoint + "/#poll/xxxx/vote/xxxx"; + this.pollToAssignUrlPattern = session.pollenUIContext.uiEndPoint + "/#poll/(.+)/vote/(.+)"; + this.assignedPollTitle = undefined; this.pagination = { order: "topiaCreateDate", @@ -51,6 +100,7 @@ require("./PollCard.tag.html"); let pollService = require("../../js/PollService"); this.refresh = () => { + this.assignedPollTitle = undefined; return pollService[this.opts.method](this.pagination).then((result) => { this.polls = result.elements; Object.assign(this.pagination, result.pagination); @@ -72,6 +122,31 @@ require("./PollCard.tag.html"); this.refresh(); }; + this.assignPoll = (e) => { + e.preventDefault(); + e.stopPropagation(); + var pollUrl = this.refs.pollToAssign.value; + var regex = new RegExp(this.pollToAssignUrlPattern); + var finds = regex.exec(pollUrl); + + return pollService.assignPoll(finds[1], finds[2]).then((result) => { + if (result) { + this.refresh(); + console.log(result); + this.assignedPollTitle = result.title; + this.update(); + } + }); + }; + + this.closeMessage = (e) => { + e.preventDefault(); + e.stopPropagation(); + var messageElement = document.getElementById("assign-poll-success-message"); + messageElement.parentNode.removeChild(messageElement); + this.assignedPollTitle = undefined; + }; + </script> <style> @@ -92,5 +167,36 @@ require("./PollCard.tag.html"); width: 200px; } + .assign-form { + margin: 20px 0; + } + + .assign-form legend { + font-weight: bold; + color: #2c3e50; + } + + .assign-form fieldset { + padding: 20px; + border: 1px solid #96a8b2; + border-radius: 5px; + } + + #assign-poll-success-message { + position: relative; + background: #aaffaa; + padding: 10px 30px 10px; + box-shadow: 5px 5px 5px 0px #9b9b9b; + border-radius: 5px; + } + + .close-message { + position: absolute; + top: 10px; + right: 10px; + color: #666; + cursor: pointer; + } + </style> </Polls> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.