This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit 914b05a691a008381d9e9220c6483df3333a19ee Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jun 18 12:01:27 2014 +0200 improve load poll --- pollen-ui-angular/src/main/webapp/js/app.js | 4 +- .../src/main/webapp/js/controllers/pollCtrl.js | 137 +++++++++++---------- 2 files changed, 76 insertions(+), 65 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index 1d31b79..aea01ff 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -128,9 +128,9 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }); }); - ngModel.$render = function (value) { + ck.on('instanceReady', function() { ck.setData(ngModel.$modelValue); - }; + }); } }; }) 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 0f20f1c..9eecc06 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -24,8 +24,8 @@ angular.module('pollControllers', []) }]) .controller('PollCtrl', - ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', '$translate', '$route', - function ( $scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage, $translate, $route) { + ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', '$translate', '$route', '$q', 'Poll', + function ( $scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage, $translate, $route, $q, Poll) { $scope.setTab = function (defaultValue) { if (angular.isDefined($routeParams.tab)) { return $routeParams.tab; @@ -94,26 +94,47 @@ angular.module('pollControllers', []) $scope.data.poll = {}; if (angular.isDefined($routeParams.pollId)) { - var baseUrl = window.location.origin+window.location.pathname; - $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; - $scope.globalVariables.linkResult += '?token='+$scope.globalVariables.permission; - $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'&tab=conf'; - $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'&tab=participant'; - } - else { - $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'?tab=conf'; - $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'?tab=participant'; - } + var pollDeferred = $q.defer(); + $scope.pollDeferred = pollDeferred; + Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { + $scope.data.poll = poll; + $scope.globalVariables.permission = poll.permission; + pollDeferred.resolve('read-write poll'); + }, function (error) { + Poll.get({pollId:$routeParams.pollId}, function (poll) { + $scope.data.poll = poll; + // clean permission + SessionStorage.remove('permission'); + delete $scope.globalVariables.permission; + + pollDeferred.resolve('read-only poll') + }, function (error) { + pollDeferred.reject(error); + }); + }); + + pollDeferred.promise.then(function () { + var baseUrl = window.location.origin+window.location.pathname; + $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; + $scope.globalVariables.linkResult += '?token='+$scope.globalVariables.permission; + $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'&tab=conf'; + $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'&tab=participant'; + } + else { + $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'?tab=conf'; + $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'?tab=participant'; + } + }); } $scope.toHTML = function (data) { @@ -142,8 +163,7 @@ angular.module('pollControllers', []) else { $scope.inlineVersion(); } - } - initTemplateURL(); + }; initTemplateURL(); var lastRoute = $route.current; $scope.$on('$locationChangeSuccess', function(event) { @@ -567,13 +587,7 @@ angular.module('pollControllers', []) //////////////////////////////// var initPoll = function () { - Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { - if (angular.isUndefined(poll.permission)) { - $location.path('/'); - } - $scope.data.poll = poll; - initVoterList(); - }); + initVoterList(); PollChoice.query({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}).$promise.then(function (choices) { $scope.data.choices = choices; @@ -594,8 +608,19 @@ angular.module('pollControllers', []) }) }) }); - } - initPoll(); + }; + $scope.pollDeferred.promise.then(function () { + if (angular.isDefined($scope.data.poll.permission)) { + initPoll(); + delete $scope.pollDeferred; + } else { + $location.path('/'); + } + }, function (error) { + $location.path('/'); + }); + + $scope.autoSavePoll = function () { $scope.savePoll(); @@ -638,10 +663,6 @@ angular.module('pollControllers', []) $scope.tab = $scope.setTab('vote'); var initPoll = function () { - Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { - $scope.data.poll = poll; - }); - PollChoice.query({pollId:$routeParams.pollId}, function (choices) { $scope.data.choices = choices; initVote(); @@ -754,10 +775,6 @@ angular.module('pollControllers', []) $scope.globalVariables.commentMode = true; - Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (data) { - $scope.data.poll = data; - }) - $scope.comment = {text:''}; var initAuthor = function () { if (angular.isDefined($scope.session.user)) { @@ -889,25 +906,26 @@ angular.module('pollControllers', []) $scope.tab = $scope.setTab('result'); - var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { - $scope.data.poll = poll; - }).$promise; - - var choicesPromise = PollChoice.query({pollId:$routeParams.pollId}, function (choices) { + var choicesDeferred = $q.defer(); + PollChoice.query({pollId:$routeParams.pollId}, function (choices) { $scope.data.choices = choices; - }).$promise; + choicesDeferred.resolve('choices load'); + }); - var votesPromise = PollVote.query({pollId:$routeParams.pollId}, function (votes) { + var votesDeferred = $q.defer(); + PollVote.query({pollId:$routeParams.pollId}, function (votes) { $scope.data.votants = votes; - resultPromise.then(function () { + resultDeferred.promise.then(function () { $scope.data.result.nbVotant = $scope.data.votants.length; + votesDeferred.resolve('votes load'); }); - }).$promise; + }); - var resultPromise = Poll.result({pollId:$routeParams.pollId}, function (result) { + var resultDeferred = $q.defer(); + Poll.result({pollId:$routeParams.pollId}, function (result) { $scope.data.result = result; - choicesPromise.then(function () { + choicesDeferred.promise.then(function () { var scoresSorted = []; $scope.data.result.scoreTotal = 0; angular.forEach(result.scores, function(value, key) { @@ -924,10 +942,11 @@ angular.module('pollControllers', []) } }) $scope.data.result.scoresChart = scoresSorted; + resultDeferred.resolve('result load'); }); - }).$promise; + }); - votesPromise.then(function () { + votesDeferred.promise.then(function () { angular.forEach($scope.data.result.scoresChart, function (value, key) { value.push( Math.floor(value[1] * 100 / $scope.data.result.scoreTotal) + '% - '+value[1]+' Vote(s)'); }); @@ -954,15 +973,7 @@ angular.module('pollControllers', []) } var initPolls = function () { - var pollPromise; - if (angular.isDefined($routeParams.cmd)) { - pollPromise = Poll.get({cmd:$routeParams.cmd, paginationParameter:paginationParameter}).$promise; - } - else { - pollPromise = Poll.get({paginationParameter:paginationParameter}).$promise; - } - - pollPromise.then(function (data) { + Poll.get({paginationParameter:paginationParameter}, function (data) { $scope.data.polls = data.elements $scope.data.pollsPagination = data.pagination; }, function (error) { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm