01/01: get poll with pagination
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 e022b11a34860aea3db0dfc25bb770e68deb50e4 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed May 28 10:38:39 2014 +0200 get poll with pagination --- .../src/main/webapp/js/controllers/pollCtrl.js | 99 +++++++++++++++------- .../src/main/webapp/partials/poll-list.html | 14 ++- 2 files changed, 80 insertions(+), 33 deletions(-) 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 683986e..ee5b00f 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -22,7 +22,9 @@ angular.module('pollControllers', []) .controller('HomeCtrl', ['$scope', function ($scope) { }]) -.controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', function ($scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage) { +.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; @@ -32,17 +34,23 @@ angular.module('pollControllers', []) } }; - $scope.url = window.location.origin+window.location.pathname+'#'+$location.path(); - if ($location.search().length != 0) { - $scope.url += '?'; + $scope.setUrl = function (exclude) { + var url = window.location.origin+window.location.pathname+'#'+$location.path(); + if ($location.search().length != 0) { + url += '?'; angular.forEach($location.search(), function(value, key) { - if (key != 'tab') - $scope.url += key+'='+value+'&'; + if (exclude.indexOf(key) == -1) + url += key+'='+value+'&'; }) - } - else { - $scope.url += '?'; - } + } + else { + url += '?'; + } + return url; + }; + + $scope.urlTab = $scope.setUrl(['tab']); + if (angular.isUndefined($scope.globalVariables)) { $scope.globalVariables = {saved : SessionStorage.get().saved}; @@ -57,17 +65,17 @@ angular.module('pollControllers', []) /** * Sauvegarde du token si non connecté */ - var session = SessionStorage.get(); - if (angular.isUndefined($routeParams.token) && angular.isUndefined(session.id)) { // pas de paramètre url et non connecté - if (angular.isDefined(session.permission) && session.permission != '') { // existe une permission - $scope.globalVariables.permission = session.permission; + $scope.session = SessionStorage.get(); + if (angular.isUndefined($routeParams.token) && angular.isUndefined($scope.session.id)) { // pas de paramètre url et non connecté + if (angular.isDefined($scope.session.permission) && $scope.session.permission != '') { // existe une permission + $scope.globalVariables.permission = $scope.session.permission; } - else if (session.permission == '') { + else if ($scope.session.permission == '') { SessionStorage.remove('permission'); } } - else if (angular.isDefined(session.id)) { // connecté - if (angular.isDefined(session.permission)) { // connecté => pas besoin de permission + else if (angular.isDefined($scope.session.id)) { // connecté + if (angular.isDefined($scope.session.permission)) { // connecté => pas besoin de permission SessionStorage.remove('permission'); } } @@ -453,7 +461,9 @@ angular.module('pollControllers', []) } }]) -.controller('PollCommentCtrl', ['$scope', '$controller', '$routeParams', 'Poll', 'PollComment', function ($scope, $controller, $routeParams, Poll, PollComment) { +.controller('PollCommentCtrl', + ['$scope', '$controller', '$routeParams', 'Poll', 'PollComment', + function ( $scope, $controller, $routeParams, Poll, PollComment ) { $controller('PollCtrl', {$scope:$scope}); $scope.globalVariables.commentMode = true; @@ -465,8 +475,17 @@ angular.module('pollControllers', []) $scope.tab = $scope.setTab('comment'); $scope.comment = {text:''}; - PollComment.query({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (data) { - $scope.data.comments = data; + if (angular.isDefined($scope.session.user)) { + if (angular.isDefined($scope.session.user.name)) { + $scope.comment.authorName = $scope.session.user.name; + } + else { + $scope.comment.authorName = $scope.session.user.login; + } + } + + PollComment.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (data) { + $scope.data.comments = data.elements; }); $scope.postComment = function () { @@ -480,7 +499,7 @@ angular.module('pollControllers', []) $scope.data.comments.push(angular.copy($scope.comment)); //clean form - $scope.comment = {text:''}; + $scope.comment.text = ''; }, function (error) { $scope.restError = error.data; }); @@ -532,24 +551,40 @@ angular.module('pollControllers', []) }]) -.controller('PollListCtrl', ['$scope', '$controller', '$routeParams', 'Poll', function ($scope, $controller, $routeParams, Poll) { +.controller('PollListCtrl', + ['$scope', '$controller', '$routeParams', 'Poll', + function ($scope, $controller, $routeParams, Poll) { $controller('PollCtrl', {$scope:$scope}); + var pollPromise; + var paginationParameter = {pageSize:5}; + if (angular.isDefined($routeParams.pageSize)) { + paginationParameter.pageSize= $routeParams.pageSize; + } + if (angular.isDefined($routeParams.page)) { + paginationParameter.pageNumber = $routeParams.page; + } + if (angular.isDefined($routeParams.cmd)) { - Poll.query({cmd:$routeParams.cmd}, function (data) { - $scope.data.polls = data; - }, function (error) { - $scope.restError = {forbidden:true}; - }); + pollPromise = Poll.get({cmd:$routeParams.cmd, paginationParameter:paginationParameter}).$promise; } else { - Poll.query(function (data) { - $scope.data.polls = data; - }, function (error) { - $scope.restError = {forbidden:true}; - }); + pollPromise = Poll.get({paginationParameter:paginationParameter}).$promise; } + pollPromise.then(function (data) { + $scope.data.polls = data.elements + $scope.data.pollsPagination = data.pagination; + $scope.pageList = []; + for (var i = 0; i <= $scope.data.pollsPagination.lastPage; i++) { + $scope.pageList.push(i); + } + }, function (error) { + $scope.restError = {forbidden:true}; + }); + + $scope.urlPagination = $scope.setUrl(['page', 'pageSize']); + }]) ; \ No newline at end of file diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-list.html b/pollen-ui-angular/src/main/webapp/partials/poll-list.html index 1648b0b..75c7b87 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-list.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-list.html @@ -5,4 +5,16 @@ <h2><a href="#/poll/vote/{{poll.id}}">{{poll.title}}</a> <a href="#/poll/edit/{{poll.id}}"><i class="glyphicon glyphicon-pencil"></i></a></h2> <p ng-bind-html="toHTML(poll.description)"></p> <hr/> -</div> \ No newline at end of file +</div> + +<ul class="pagination" ng-show="pageList.length > 1"> + <li ng-class="{disabled:data.pollsPagination.currentPage == 0}"> + <a ng-if="data.pollsPagination.currentPage != 0" href="{{urlPagination}}page={{data.pollsPagination.currentPage-1}}&pageSize={{data.pollsPagination.pageSize}}">«</a> + <a ng-if="data.pollsPagination.currentPage == 0">«</a> + </li> + <li ng-repeat="page in pageList" ng-class="{active:data.pollsPagination.currentPage == page}"><a href="{{urlPagination}}page={{page}}&pageSize={{data.pollsPagination.pageSize}}">{{page+1}}</a></li> + <li ng-class="{disabled:data.pollsPagination.currentPage == data.pollsPagination.lastPage}"> + <a ng-if="data.pollsPagination.currentPage != data.pollsPagination.lastPage" href="{{urlPagination}}page={{data.pollsPagination.currentPage+1}}&pageSize={{data.pollsPagination.pageSize}}">»</a> + <a ng-if="data.pollsPagination.currentPage == data.pollsPagination.lastPage">»</a> + </li> +</ul> \ 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