01/01: add choice type Image
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 d73a42e650cbc181eb22bf3b361e2c1216f452d5 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Mon Jul 7 17:25:58 2014 +0200 add choice type Image --- pollen-persistence/src/main/xmi/pollen.properties | 1 + .../chorem/pollen/services/bean/ChoiceBean.java | 11 ++-- .../pollen/services/service/ChoiceService.java | 14 ++--- .../src/main/webapp/js/controllers/pollCtrl.js | 59 ++++++++++++++++------ pollen-ui-angular/src/main/webapp/js/directives.js | 28 +++++++++- pollen-ui-angular/src/main/webapp/less/style.less | 5 ++ .../src/main/webapp/partials/inline-poll.html | 16 +++++- .../src/main/webapp/partials/poll-popupChoice.html | 20 ++++++-- .../src/main/webapp/partials/poll-result.html | 2 +- 9 files changed, 121 insertions(+), 35 deletions(-) diff --git a/pollen-persistence/src/main/xmi/pollen.properties b/pollen-persistence/src/main/xmi/pollen.properties index 0b26c1f..8a4f95e 100644 --- a/pollen-persistence/src/main/xmi/pollen.properties +++ b/pollen-persistence/src/main/xmi/pollen.properties @@ -30,6 +30,7 @@ model.tagValue.hibernateAttributeType.String=string # Text org.chorem.pollen.persistence.entity.Poll.attribute.description.tagValue.hibernateAttributeType=text org.chorem.pollen.persistence.entity.Choice.attribute.description.tagValue.hibernateAttributeType=text +org.chorem.pollen.persistence.entity.Choice.attribute.name.tagValue.hibernateAttributeType=text org.chorem.pollen.persistence.entity.Comment.attribute.text.tagValue.hibernateAttributeType=text # clef naturelle non modifiable sur PollenToken.token diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java index 99c7fb6..fa0b5fa 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java @@ -75,8 +75,8 @@ public class ChoiceBean extends PollenBean<Choice> { case IMAGE: - throw new IllegalStateException("Not implemented"); - //break; + setValue(entity.getName()); + break; } setDescription(entity.getDescription()); @@ -109,8 +109,11 @@ public class ChoiceBean extends PollenBean<Choice> { case IMAGE: - throw new IllegalStateException("Not implemented"); - //break; + if ( getValue() != null ) { + entity.setName(getValue()); + } + + break; } } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java index f47aa77..ae476f4 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java @@ -237,24 +237,24 @@ public class ChoiceService extends PollenServiceSupport { case TEXT: toSave.setName(choice.getValue()); - toSave.setDescription(choice.getDescription()); - toSave.setCreator(poll.getCreator()); break; case DATE: toSave.setName(choice.getValue()); - toSave.setDescription(choice.getDescription()); - toSave.setCreator(poll.getCreator()); break; case IMAGE: - throw new IllegalStateException("Not implemented"); + toSave.setName(choice.getValue()); + } + toSave.setDescription(choice.getDescription()); + toSave.setCreator(poll.getCreator()); + return toSave; } @@ -328,8 +328,8 @@ public class ChoiceService extends PollenServiceSupport { break; case IMAGE: - - throw new IllegalStateException("Not implemented"); + // TODO : verify picture + break; } } 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 8395de8..9bb3187 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -200,6 +200,31 @@ angular.module('pollControllers', []) } } + $scope.preSendChoice = function (choice) { + if (choice.choiceType == 'DATE') { + choice.value = choice.value.getTime(); + } + else if (choice.choiceType == 'IMAGE') { + + choice.value = choice.value.meta.name+"####"+choice.value.data; + } + + return choice; + } + + $scope.postReceiveChoice = function (choice) { + if (choice.choiceType == 'DATE') { + choice.value = new Date(Number(choice.value)); + } + else if (choice.choiceType == 'IMAGE') { + var tmp = choice.value.split("####"); + + choice.value = {meta:{name:tmp[0]}, data : tmp[1]}; + } + + return choice; + } + $timeout(function () { $scope.$watch('data.poll.voteCountingType', function (newVal, oldVal) { if (newVal != oldVal && oldVal !== undefined) { @@ -386,6 +411,9 @@ angular.module('pollControllers', []) else if (choice.choiceType == 'DATE') { choice.valueDate = choice.value; } + else if (choice.choiceType == 'IMAGE') { + choice.valueImage = choice.value; + } // set default date if (angular.isUndefined(choice.valueDate)) { @@ -410,8 +438,12 @@ angular.module('pollControllers', []) choice.value = choice.valueDate; $scope.globalVariables.lastDate = angular.copy(choice.valueDate); } + else if (choice.choiceType == 'IMAGE') { + choice.value = choice.valueImage; + } delete choice.valueText; delete choice.valueDate; + delete choice.valueImage if (!angular.equals(choiceEdit, choice)) { choiceEdit.value = choice.value; @@ -510,9 +542,7 @@ angular.module('pollControllers', []) poll.choice = angular.copy($scope.data.choices); angular.forEach(poll.choice, function(choice) { - if (choice.choiceType == 'DATE') { - choice.value = choice.value.getTime(); - } + choice = $scope.preSendChoice(choice); }); if (angular.isDate(poll.beginDate)) { @@ -571,9 +601,7 @@ angular.module('pollControllers', []) $scope.callBackAddChoice = function (choice) { saveChoice = angular.copy(choice); - if (saveChoice.choiceType == 'DATE') { - saveChoice.value = saveChoice.value.getTime(); - } + saveChoice = $scope.preSendChoice(saveChoice); PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, saveChoice, function (data) { delete choice.restError; @@ -587,9 +615,7 @@ angular.module('pollControllers', []) $scope.callBackEditChoice = function (choice) { saveChoice = angular.copy(choice); - if (saveChoice.choiceType == 'DATE') { - saveChoice.value = saveChoice.value.getTime(); - } + saveChoice = $scope.preSendChoice(saveChoice); PollChoice.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, saveChoice, function() { delete choice.restError; @@ -860,9 +886,7 @@ angular.module('pollControllers', []) PollChoice.query({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}).$promise.then(function (choices) { $scope.data.choices = choices; angular.forEach(choices, function (ch) { - if (ch.choiceType == 'DATE') { - ch.value = new Date(Number(ch.value)); - } + ch = $scope.postReceiveChoice(ch); }) $scope.data.vote = {}; $scope.data.vote.choice = $scope.data.choices; @@ -932,9 +956,7 @@ angular.module('pollControllers', []) var pollChoicePromise = PollChoice.query({pollId:$routeParams.pollId}, function (choices) { angular.forEach(choices, function (ch) { - if (ch.choiceType == 'DATE') { - ch.value = new Date(Number(ch.value)); - } + ch = $scope.postReceiveChoice(ch); }); $scope.data.choices = choices; @@ -1230,6 +1252,9 @@ angular.module('pollControllers', []) var choicesDeferred = $q.defer(); PollChoice.query({pollId:$routeParams.pollId}, function (choices) { $scope.data.choices = choices; + angular.forEach(choices, function (choice) { + choice = $scope.postReceiveChoice(choice); + }); choicesDeferred.resolve('choices load'); }); @@ -1264,6 +1289,10 @@ angular.module('pollControllers', []) scores.push([$filter('date')(value.choice.value, $scope.globalVariables.dateFormat), value.scoreValue]); break; + case 'IMAGE': + scores.push([value.choice.value.meta.name, value.scoreValue]); + break; + default: scores.push([key, value.scoreValue]); } diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index f3ef921..a006325 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -144,7 +144,7 @@ angular.module('pollenDirective', []) } }); - element.bind('blur', function () { + element.bind('blur change', function () { $timeout (function () { scope.$apply(attrs.ngExit); }, 150); @@ -431,4 +431,28 @@ angular.module('pollenDirective', []) }) } } -}]) \ No newline at end of file +}]) + + +.directive("uploadFile", function () { + return { + restrict : "E", + scope: { + ngModel: "=" + }, + template:'<input type="file" />', + link: function (scope, element, attrs) { + element.bind("change", function (changeEvent) { + var reader = new FileReader(); + reader.onload = function (loadEvent) { + scope.$apply(function () { +// scope.ngModel.data = loadEvent.target.result; + scope.ngModel = { meta: changeEvent.target.files[0], data: loadEvent.target.result}; + }); + } + reader.readAsDataURL( changeEvent.target.files[0] ); + }); + + } + } +}) \ No newline at end of file diff --git a/pollen-ui-angular/src/main/webapp/less/style.less b/pollen-ui-angular/src/main/webapp/less/style.less index 8f39e9b..5e6e25b 100644 --- a/pollen-ui-angular/src/main/webapp/less/style.less +++ b/pollen-ui-angular/src/main/webapp/less/style.less @@ -211,6 +211,11 @@ height:60px; width:80px; } + + img { + max-width:200px; + max-height:200px; + } } } diff --git a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html index abaf068..4801314 100644 --- a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html @@ -24,7 +24,9 @@ <table id="poll-inline"> <!-- begin print choices --> <tr> - <td><button ng-click="bigVersion()" class="btn btn-default" >Big version</button></td> + <td> + <!--<button ng-click="bigVersion()" class="btn btn-default" >Big version</button>--> + </td> <td ng-repeat="choice in data.choices" class="pollChoice pollAnim" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> <div ng-if="choice.choiceType == 'TEXT'" edit-me="showEdit" > <div ng-hide="showEdit && !globalVariables.voted" class="fixe-input" title="{{choice.description}}"> @@ -48,6 +50,18 @@ <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> </div> </div> + <div ng-if="choice.choiceType == 'IMAGE'"> + <div class="fixe-input" title="{{choice.description}}"> + {{choice.value.meta.name}} + <info-error error="choice.restError.value[0]" data="choice.value"></info-error> + <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/> + <br/> + <img ng-attr-src="{{choice.value.data}}" /> + + </div> + + + </div> </td> <td ng-if="!globalVariables.voted && globalVariables.editMode"><button class="btn btn-default btn-large" ng-click="addChoice()"> <span class="glyphicon glyphicon-plus"></span> </button></td> </tr> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html index b81131d..bb2bf39 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html @@ -31,28 +31,38 @@ <div class="col-sm-8 btn-group"> <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'TEXT'">Text</button> <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'DATE'">Date</button> - <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'IMAGE'" disabled>Image</button> + <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'IMAGE'">Image</button> </div> </div> <div class="form-group" ng-if="choice.choiceType == 'TEXT'"> - <label for="popNameChoiceCheck" class="col-sm-4 control-label">Nom du Choix : </label> + <label for="popChoiceText" class="col-sm-4 control-label">Nom du Choix : </label> <div class="col-sm-6"> - <input id="popNameChoiceCheck" type="text" ng-model="choice.valueText" class="form-control" focus-me="choice.choiceType == 'TEXT'"/> + <input id="popChoiceText" type="text" ng-model="choice.valueText" class="form-control" focus-me="choice.choiceType == 'TEXT'"/> </div> </div> <div class="form-group" ng-if="choice.choiceType == 'DATE'"> - <label for="popNameChoiceDate" class="col-sm-4 control-label">Date : </label> + <label for="popChoiceDate" class="col-sm-4 control-label">Date : </label> <div class="col-sm-6"> <div class="right-inner-addon "> <i class="glyphicon glyphicon-calendar glyphicon-input"></i> - <input id="popNameChoiceDate" class="form-control" datepicker-popup="{{dateFormat}}" type="text" ng-model="choice.valueDate" is-open="opened" ng-click="opened = true" focus-me="choice.choiceType == 'DATE'"/> + <input id="popChoiceDate" class="form-control" datepicker-popup="{{dateFormat}}" type="text" ng-model="choice.valueDate" is-open="opened" ng-click="opened = true" focus-me="choice.choiceType == 'DATE'"/> </div> </div> </div> + + <div class="form-group" ng-if="choice.choiceType == 'IMAGE'"> + <label for="popChoiceImage" class="col-sm-4 control-label">Image : </label> + + <div class="col-sm-6"> + <upload-file id="popChoiceImage" ng-model="choice.valueImage" focus-me="choice.choiceType == 'IMAGE'" ></upload-file> + {{choice.valueImage.meta.name}} + </div> + </div> + <div class="form-group"> <label for="popDescChoice" class="col-sm-4 control-label">Description : </label> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-result.html b/pollen-ui-angular/src/main/webapp/partials/poll-result.html index dd918ea..6965664 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-result.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-result.html @@ -24,7 +24,7 @@ <th>{{ 'poll.result.score' | translate }}</th> </tr> <tr ng-repeat="score in data.result.scores"> - <th> {{ score.choice.name || (score.choice.date | date:globalVariables.dateFormat) }} </th> + <th> {{ score.choice.value.meta.name || (score.choice.value | date:globalVariables.dateFormat) || score.choice.value }} </th> <td> {{score.scoreValue}} </td> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm