This is an automated email from the git hooks/post-receive script. New commit to branch devel in repository Pollen. See http://git.None/Pollen.git commit 93c91efcb981f481ed34c4a3d2a7274b373a5664 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue May 27 17:06:53 2014 +0200 Add Comment --- pollen-rest-api/src/main/resources/mapping | 2 +- pollen-ui-angular/src/main/webapp/css/style.css | 24 ++++++- pollen-ui-angular/src/main/webapp/js/app.js | 1 + .../src/main/webapp/js/controllers/pollCtrl.js | 78 +++++++++++++++------- pollen-ui-angular/src/main/webapp/js/services.js | 24 +++++++ .../src/main/webapp/partials/poll-comment.html | 46 +++++++++++++ .../src/main/webapp/partials/poll.html | 6 +- 7 files changed, 153 insertions(+), 28 deletions(-) diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index c60deeb..b782d82 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -72,7 +72,7 @@ DELETE /v1/polls/{pollId}/choices/{choiceId} ChoiceApi.deleteChoice GET /v1/polls/{pollId}/comments CommentApi.getComments POST /v1/polls/{pollId}/comments CommentApi.addComment GET /v1/polls/{pollId}/comments/{commentId} CommentApi.getComment -PUT /v1/polls/{pollId}/comments/{commentId} CommentApi.editComment +POST /v1/polls/{pollId}/comments/{commentId} CommentApi.editComment DELETE /v1/polls/{pollId}/comments/{commentId} CommentApi.deleteComment # FavoriteListApi diff --git a/pollen-ui-angular/src/main/webapp/css/style.css b/pollen-ui-angular/src/main/webapp/css/style.css index d6ef705..66fad89 100644 --- a/pollen-ui-angular/src/main/webapp/css/style.css +++ b/pollen-ui-angular/src/main/webapp/css/style.css @@ -104,11 +104,11 @@ i.icon-collapse { width:99%; } -.pollAnim { +.pollAnim, #comments tr { background-color:inherit; transition-duration:0.8s; } -.pollAnim:hover { +.pollAnim:hover, #comments tr:hover { background:#DDDDDD; transition-duration: 0.8s; } @@ -209,3 +209,23 @@ i.icon-collapse { .danger { color: #a94442; } + +#comments { + margin-top:30px; + width:100%; + border-collapse:collapse; +} + +#comments tr td{ + border-bottom:1px solid #DDD; + padding-top:5px; + padding-bottom:15px; + padding-left:5px; + padding-right:5px; + vertical-align:top; +} + +#comments tr>td:first-child { + width:200px; + border-right:1px solid #DDD; +} diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index a7b5d62..ee998d0 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -64,6 +64,7 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC .when('/poll/edit/:pollId', {templateUrl: './partials/poll.html', controller:"PollEditCtrl"}) .when('/poll/vote/:pollId', {templateUrl: './partials/poll.html', controller :"PollVoteCtrl"}) .when('/poll/result/:pollId', {templateUrl: './partials/poll.html', controller :"PollResultCtrl"}) + .when('/poll/comment/:pollId', {templateUrl: './partials/poll.html', controller :"PollCommentCtrl"}) .when('/poll/list', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) .when('/poll/list/:cmd', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) .when('/user/register', {templateUrl: './partials/user-register.html', controller:"UserRegisterCtrl"}) diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js index bc74f2b..1f24c1f 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -23,6 +23,14 @@ angular.module('pollControllers', []) }]) .controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', function ($scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage) { + $scope.setTab = function (defaultValue) { + if (angular.isDefined($routeParams.tab)) { + return $routeParams.tab; + } + else { + return defaultValue; + } + }; $scope.url = window.location.origin+window.location.pathname+'#'+$location.path(); if ($location.search().length != 0) { @@ -74,12 +82,14 @@ angular.module('pollControllers', []) if (angular.isDefined($routeParams.pollId)) { var baseUrl = window.location.origin+window.location.pathname; - $scope.globalVariables.linkVote = baseUrl; - $scope.globalVariables.linkEdit = baseUrl; - $scope.globalVariables.linkResult = baseUrl; - $scope.globalVariables.linkVote += '#/poll/vote/'+$routeParams.pollId; - $scope.globalVariables.linkEdit += '#/poll/edit/'+$routeParams.pollId; - $scope.globalVariables.linkResult += '#/poll/result/'+$routeParams.pollId; + $scope.globalVariables.linkVote = baseUrl; + $scope.globalVariables.linkComment = baseUrl; + $scope.globalVariables.linkEdit = baseUrl; + $scope.globalVariables.linkResult = baseUrl; + $scope.globalVariables.linkVote += '#/poll/vote/'+$routeParams.pollId; + $scope.globalVariables.linkComment += '#/poll/comment/'+$routeParams.pollId; + $scope.globalVariables.linkEdit += '#/poll/edit/'+$routeParams.pollId; + $scope.globalVariables.linkResult += '#/poll/result/'+$routeParams.pollId; if (angular.isDefined($scope.globalVariables.permission)) { $scope.globalVariables.linkEdit += '?token='+$scope.globalVariables.permission; @@ -122,12 +132,7 @@ angular.module('pollControllers', []) .controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$timeout', '$routeParams', function ($scope, $controller, $modal, $timeout, $routeParams) { $controller('PollCtrl', {$scope:$scope}); - if (angular.isDefined($routeParams.tab)) { - $scope.tab = $routeParams.tab; - } - else { - $scope.tab = 'edit'; - } + $scope.tab = $scope.setTab('edit'); var initChoice = function () { return { @@ -372,12 +377,7 @@ angular.module('pollControllers', []) .controller('PollVoteCtrl', ['$scope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $controller, $routeParams, Poll, PollChoice, PollVote) { $controller('PollCtrl', {$scope:$scope}); - if (angular.isDefined($routeParams.tab)) { - $scope.tab = $routeParams.tab; - } - else { - $scope.tab = 'vote'; - } + $scope.tab = $scope.setTab('vote'); var initPoll = function () { var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { @@ -422,6 +422,7 @@ angular.module('pollControllers', []) initPoll(); $scope.globalVariables.editMode = false; + $scope.globalVariables.voteMode = true; var initVote = function () { $scope.data.vote = {}; @@ -452,16 +453,45 @@ angular.module('pollControllers', []) } }]) -.controller('PollResultCtrl', ['$scope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $controller, $routeParams, Poll, PollChoice, PollVote) { +.controller('PollCommentCtrl', ['$scope', '$controller', '$routeParams', 'PollComment', function ($scope, $controller, $routeParams, PollComment) { $controller('PollCtrl', {$scope:$scope}); - if (angular.isDefined($routeParams.tab)) { - $scope.tab = $routeParams.tab; - } - else { - $scope.tab = 'result'; + $scope.globalVariables.commentMode = true; + + if (angular.isUndefined($scope.data.poll.id)) { + $scope.data.poll.id = $routeParams.pollId; } + $scope.tab = $scope.setTab('comment'); + $scope.comment = {text:''}; + + PollComment.query({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (data) { + $scope.data.comments = data; + }); + + $scope.postComment = function () { + PollComment.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, $scope.comment, function (data) { + $scope.globalVariables.saved = true; + + // add ID and Permission and push in list of comments + $scope.comment.id = data.id; + $scope.comment.permission = data.permission; + $scope.comment.postDate = new Date(); + $scope.data.comments.push(angular.copy($scope.comment)); + + //clean form + $scope.comment = {text:''}; + }, function (error) { + $scope.restError = error.data; + }); + }; +}]) + +.controller('PollResultCtrl', ['$scope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $controller, $routeParams, Poll, PollChoice, PollVote) { + $controller('PollCtrl', {$scope:$scope}); + + $scope.tab = $scope.setTab('result'); + var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { $scope.data.poll = poll; }).$promise; diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index 1c5fe2d..785de6f 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -88,6 +88,30 @@ angular.module('pollenServices', ['ngResource']) ); }]) +.factory('PollComment', ['$resource', function ($resource) { + var transformParam = function (data) { + return 'comment='+encodeURIComponent(JSON.stringify(data)); + }; + + return $resource(conf.restURL+'/polls/:pollId/comments/:commentId', {commentId : '@id'}, + { + 'add' : { + method:'POST', + transformRequest : function (data, headersGetter) { + return transformParam(data); + } + }, + 'update' : + { + method:'POST', + transformRequest : function (data, headersGetter) { + return transformParam(data); + } + } + } + ); +}]) + .factory('User', ['$resource', function ($resource) { var transformParam = function (data) { return 'user='+encodeURIComponent(JSON.stringify(data))+'&generatePassword=false'; diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-comment.html b/pollen-ui-angular/src/main/webapp/partials/poll-comment.html new file mode 100644 index 0000000..d35a4b1 --- /dev/null +++ b/pollen-ui-angular/src/main/webapp/partials/poll-comment.html @@ -0,0 +1,46 @@ +<!-- + #%L + Pollen :: UI (Angular) + %% + Copyright (C) 2009 - 2014 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% + --> +<div ng-controller="PollCommentCtrl"> + <h2>Commentaire:</h2> + + <!-- begin for add comment --> + <form ng-submit="postComment()"> + name : <input type="text" ng-model="comment.authorName" /> <info-error error="restError['author.name'][0]" data="comment.authorName"></info-error><br/> + text : <info-error error="restError.text[0]" data="comment.text"></info-error> <br/> + <textarea data-ck-editor ng-model="comment.text"></textarea> + <button type="submit" class="btn btn-primary" ng-click="postComment()">Commenter</button> + </form> + <!-- end form comment --> + + <!-- begin print comments --> + <table id="comments"> + <tr ng-repeat="comment in data.comments"> + <td> + <i class="glyphicon glyphicon-user"></i>{{comment.authorName}}<br/> + <i class="glyphicon glyphicon-calendar"></i>{{comment.postDate | date:'dd/MM/yyyy HH:mm'}} + </td> + <td> + <div ng-bind-html="toHTML(comment.text)"></div> + </td> + </tr> + </table> + <!-- end print comments --> +</div> \ No newline at end of file diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html index eb56255..6d35af1 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll.html @@ -21,11 +21,13 @@ <form class="form-horizontal" novalidate> <alert type="danger" class="alert-float" ng-if="restError.choice" close="restError.choice = false"> Vous devez avoir au moins 1 choix </alert> <alert type="success" class="alert-float" ng-if="globalVariables.editMode && globalVariables.saved" close="globalVariables.saved = false"> Sondage sauvegardé..</alert> - <alert type="success" class="alert-float" ng-if="!globalVariables.editMode && globalVariables.saved" close="globalVariables.saved = false"> Vote effectué..</alert> + <alert type="success" class="alert-float" ng-if="globalVariables.voteMode && globalVariables.saved" close="globalVariables.saved = false"> Vote effectué..</alert> + <alert type="success" class="alert-float" ng-if="globalVariables.commentMode && globalVariables.saved" close="globalVariables.saved = false"> Commentaire effectué..</alert> <ul class="nav nav-tabs"> <li ng-class="{active: tab == 'home'}"><a href="{{url}}tab=home"> <span class="glyphicon glyphicon-home"></span> </a></li> <li ng-class="{active: tab == 'vote'}" ng-show="data.poll.id"><a href="{{globalVariables.linkVote}}">Voter</a></li> + <li ng-class="{active: tab == 'comment'}" ng-show="data.poll.id"><a href="{{globalVariables.linkComment}}">Commenter</a></li> <li ng-class="{active: tab == 'result'}" ng-show="!globalVariables.create"><a href="{{globalVariables.linkResult}}">Résultat</a></li> <li ng-class="{active: tab == 'edit'}" ng-show="globalVariables.create"><a href="#/poll/create">Créer</a></li> <li ng-class="{active: tab == 'edit'}" ng-show="data.poll.permission"><a href="{{globalVariables.linkEdit}}">Editer</a></li> @@ -78,6 +80,8 @@ <div ng-include="'partials/poll-settings.html'" ng-if="tab == 'conf'"></div> + <div ng-include="'partials/poll-comment.html'" ng-if="tab == 'comment'"></div> + <div ng-include="'./partials/poll-result.html'" ng-if="tab == 'result'"></div> </form> \ No newline at end of file -- To stop receiving notification emails like this one, please contact Chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
Chorem.org scm