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 c64514a5471fcb8d2d2b0c7151c69dd12abf2e6f Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Fri May 23 17:13:01 2014 +0200 set home page for poll --- .../src/main/webapp/js/controllers/pollCtrl.js | 77 ++++++++++++++++------ .../src/main/webapp/partials/poll-link.html | 24 +++++++ .../src/main/webapp/partials/poll.html | 26 ++++---- 3 files changed, 96 insertions(+), 31 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 19526d4..202b551 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -22,11 +22,29 @@ angular.module('pollControllers', []) .controller('HomeCtrl', ['$scope', function ($scope) { }]) -.controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$cookies', function ($scope, $controller, $sce, $timeout, $cookies) { +.controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', function ($scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage) { + if (angular.isDefined($routeParams.tab)) { + $scope.tab = $routeParams.tab; + } + else { + $scope.tab = 'poll'; + } + + $scope.url = $location.protocol()+'://'+$location.host()+'/#'+$location.path(); + if ($location.search().length != 0) { + $scope.url += '?'; + angular.forEach($location.search(), function(value, key) { + if (key != 'tab') + $scope.url += key+'='+value+'&'; + }) + } + else { + $scope.url += '?'; + } - if (!angular.isDefined($scope.globalVariables)) { - $scope.globalVariables = {saved : $cookies.saved}; - delete $cookies.saved + if (angular.isUndefined($scope.globalVariables)) { + $scope.globalVariables = {saved : SessionStorage.get().saved}; + SessionStorage.remove('saved'); $scope.$watch('globalVariables.saved', function() { $timeout(function () { @@ -37,6 +55,15 @@ angular.module('pollControllers', []) $scope.data = {}; $scope.data.poll = {}; + if (angular.isDefined($routeParams.pollId)) { + $scope.globalVariables.linkVote = $location.protocol()+'://'+$location.host()+'/#/poll/vote/'+$routeParams.pollId; + $scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId; + + if (angular.isDefined($routeParams.token)) { + $scope.globalVariables.linkEdit += '?token='+$routeParams.token; + } + } + $scope.toHTML = function (data) { return $sce.trustAsHtml(data); } @@ -165,7 +192,7 @@ angular.module('pollControllers', []) } }]) -.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', '$cookies', function ($scope, $controller, $location, Poll, $cookies) { +.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', 'SessionStorage', function ($scope, $controller, $location, Poll, SessionStorage) { $controller('PollAdminCtrl', {$scope:$scope}); $scope.globalVariables.create = true; @@ -185,7 +212,7 @@ angular.module('pollControllers', []) var poll = angular.copy($scope.data.poll); poll.choice = angular.copy($scope.data.choices); Poll.add(poll, function (data) { - $cookies.saved = true; + SessionStorage.save({saved: true}); $location.url('/poll/edit/'+data.id+'?token='+data.permission); }, function (error) { $scope.globalVariables.restError = true; @@ -204,16 +231,10 @@ angular.module('pollControllers', []) }]) -.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', '$location', '$timeout', 'Poll', 'PollChoice', 'PollVote', function ($scope, $controller, $routeParams, $location, $timeout, Poll, PollChoice, PollVote) { +.controller('PollEditCtrl', ['$scope', '$q', '$controller', '$routeParams', '$location', '$timeout', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $controller, $routeParams, $location, $timeout, Poll, PollChoice, PollVote) { $controller('PollAdminCtrl', {$scope:$scope}); $scope.globalVariables.edit = true; - $scope.globalVariables.hostName = $location.protocol()+'://'+$location.host(); - - $scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId - if (angular.isDefined($routeParams.token)) { - $scope.globalVariables.linkEdit += '?token='+$routeParams.token; - } $scope.callBackAddChoice = function (choice) { PollChoice.add({pollId:$routeParams.pollId, permission:$routeParams.token}, choice, function (data) { @@ -247,18 +268,20 @@ angular.module('pollControllers', []) } var initPoll = function () { - Poll.get({pollId:$routeParams.pollId, permission:$routeParams.token}, function (poll) { + var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$routeParams.token}, function (poll) { if (angular.isUndefined(poll.permission)) { $location.path('/'); } $scope.data.poll = poll; - }); - PollChoice.query({pollId:$routeParams.pollId, permission:$routeParams.token}).$promise.then(function (choices) { + }).$promise; + + var choicesPromise = PollChoice.query({pollId:$routeParams.pollId, permission:$routeParams.token}).$promise.then(function (choices) { $scope.data.choices = choices; $scope.data.vote = {}; $scope.data.vote.choice = $scope.data.choices; - }); - PollVote.query({pollId:$routeParams.pollId}, function (votes) { + }).$promise; + + var votesPromise = PollVote.query({pollId:$routeParams.pollId}, function (votes) { $scope.data.votants = votes; angular.forEach($scope.data.votants, function (vote) { angular.forEach(vote.choice, function (choice) { @@ -270,7 +293,23 @@ angular.module('pollControllers', []) } }) }) - }) + }).$promise; + + $q.all([choicesPromise, votesPromise]).then(function () { + Poll.get({pollId:$routeParams.pollId, cmd:'results'}, function (result) { + $scope.data.result = result; + angular.forEach(result.scores, function(value, key) { + for (var i = 0; i < $scope.data.choices.length; i++) { + if ($scope.data.choices[i].id == value.choiceId) { + value.choice = $scope.data.choices[i]; + i = $scope.data.choices.length; + } + } + }) + $scope.data.result.nbVotant = $scope.data.votants.length; + }); + }); + } initPoll(); diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-link.html b/pollen-ui-angular/src/main/webapp/partials/poll-link.html new file mode 100644 index 0000000..0e00f8b --- /dev/null +++ b/pollen-ui-angular/src/main/webapp/partials/poll-link.html @@ -0,0 +1,24 @@ +<!-- + #%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> + <alert type="warning" ng-if="globalVariables.linkEdit && data.poll.permission"> Lien d'édition : <a href="{{globalVariables.linkEdit}}">{{globalVariables.linkEdit}}</a> </alert> + <alert type="success" ng-if="globalVariables.linkVote"> Lien de vote : <a href="{{globalVariables.linkVote}}"> {{globalVariables.linkVote}}</a> </alert> +</div> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html index d8529fb..e20217c 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll.html @@ -23,11 +23,16 @@ <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="warning" ng-if="globalVariables.linkEdit"> Lien d'édition : <a href="{{globalVariables.linkEdit}}">{{globalVariables.linkEdit}}</a> </alert> - <alert type="success" ng-if="globalVariables.edit"> Lien de vote : <a href="#/poll/vote/{{data.poll.id}}"> {{globalVariables.hostName}}/#/poll/vote/{{data.poll.id}}</a> </alert> -<tabset> -<tab heading="Sondage"> + <ul class="nav nav-tabs"> + <li ng-class="{active: tab == 'home'}" ng-click="tab = 'home'"><a href="{{url}}tab=home"> <span class="glyphicon glyphicon-home"></span> </a></li> + <li ng-class="{active: tab == 'poll'}" ng-click="tab = 'poll'"><a href="{{url}}tab=poll">Sondage</a></li> + <li ng-class="{active: tab == 'result'}" ng-click="tab = 'result'" ng-show="!globalVariables.create"><a href="{{url}}tab=result">Result</a></li> + <li ng-class="{active: tab == 'conf'}" ng-click="tab = 'conf'" ng-show="globalVariables.editMode"><a href="{{url}}tab=conf">Configuration</a></li> + </ul> +<div ng-include="'partials/poll-link.html'" ng-if="tab == 'home'"></div> + +<div ng-if="tab == 'poll'"> <div class="pollTitle" edit-me="showEditTitle"> <h1 ng-hide="showEditTitle"> {{data.poll.title || 'Click pour éditer'}} @@ -56,14 +61,6 @@ </div> -</tab> -<tab heading="Configuration" ng-show="globalVariables.editMode" > - <div ng-include="'partials/poll-settings.html'"></div> -</tab> -</tabset> - - <div ng-include="'./partials/poll-result.html'" ng-if="globalVariables.results"></div> - <div ng-if="globalVariables.create"> <hr/> <button type="button" class="btn btn-default" ng-model="globalVariables.editMode" btn-checkbox>Mode Edition</button> @@ -75,5 +72,10 @@ <button type="button" class="btn btn-default" ng-model="globalVariables.editMode" btn-checkbox>Mode Edition</button> <button class="btn btn-danger" ng-click="deletePoll();">Supprimer</button> </div> +</div> + + <div ng-include="'partials/poll-settings.html'" ng-if="tab == 'conf'"></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