This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 90e32a4833280849c018f0028e6b3ffaf1fbc800 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Jan 20 17:37:41 2016 +0100 fixes #7914 filtered already added documents and parents in project modification --- .../fr/ifremer/coselmar/persistence/DaoUtils.java | 17 ++++++ .../persistence/entity/DocumentTopiaDao.java | 7 ++- .../persistence/entity/QuestionTopiaDao.java | 3 ++ .../src/main/webapp/js/coselmar-controllers.js | 63 +++++++++++++++++----- .../views/questions/modalQuestionSearch.html | 2 +- 5 files changed, 78 insertions(+), 14 deletions(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java index cbe02ab..0c61205 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java @@ -91,6 +91,18 @@ public class DaoUtils { return result; } + public static String getQueryForAttributeNotEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value, String operator) { + String result = ""; + + if (value != null) { + String alias = StringUtils.isBlank(entityAlias) ? "" : entityAlias + "."; + String queryAttributeName = addQueryAttribute(args, entityAttributeName, value); + result += String.format(" %s %s != :%s", operator, alias + entityAttributeName, queryAttributeName); + } + + return result; + } + public static String getQueryForAttributeGreaterOrEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value, String operator) { String result = ""; @@ -120,6 +132,11 @@ public class DaoUtils { return result; } + public static String andAttributeNotEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value) { + String result = getQueryForAttributeNotEquals(entityAlias, entityAttributeName, args, value, "AND"); + return result; + } + public static String andAttributeGreaterOrEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value) { String result = getQueryForAttributeGreaterOrEquals(entityAlias, entityAttributeName, args, value, "AND"); return result; diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java index ad68043..2e734cf 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java @@ -32,6 +32,7 @@ import fr.ifremer.coselmar.beans.DocumentSearchExample; import fr.ifremer.coselmar.persistence.DaoUtils; import fr.ifremer.coselmar.persistence.SearchRequestBean; import org.apache.commons.lang3.StringUtils; +import org.nuiton.util.pagination.PaginationParameter; public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { @@ -231,8 +232,12 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { hqlBuilder.append(" )"); } + // Add the prefix for order clause + searchExample.setOrderClause("D." + searchExample.getOrderClause()); - List<Document> documents = forHql(hqlBuilder.toString(), args).findAll(); + PaginationParameter paginationParameter = searchExample.getPaginationParameter(); + + List<Document> documents = forHql(hqlBuilder.toString(), args).find(paginationParameter); return documents; } diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java index 6973305..fec507d 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java @@ -237,6 +237,9 @@ public class QuestionTopiaDao extends AbstractQuestionTopiaDao<Question> { if (status != null) { String statusHql = DaoUtils.andAttributeEquals(alias, Question.PROPERTY_STATUS, args, status); finerHqlBuilder.append(statusHql); + } else { + String statusHql = DaoUtils.andAttributeNotEquals(alias, Question.PROPERTY_STATUS, args, Status.DELETED); + finerHqlBuilder.append(statusHql); } String type = example.getType(); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 778da6a..92f6139 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -1424,7 +1424,18 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam var modalInstance = $uibModal.open({ templateUrl: 'views/documents/modalDocumentSearch.html', controller: 'ModalSearchDocumentsCtrl', - size: 'lg' + size: 'lg', + resolve : { + presentDocumentIds : function() { + if (angular.isDefined($scope.question.relatedDocuments)) { + return $scope.question.relatedDocuments.map(function(document) { + return document.id; + }); + } else { + return []; + } + } + } }); modalInstance.result.then(function (selectedDocument) { @@ -1476,9 +1487,16 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam controller: 'ModalSearchQuestionsCtrl', size: 'lg', resolve : { - currentQuestionId : function() { - return $scope.question.id; - } + presentQuestionIds : function() { + var presentQuestionIds = []; + if (angular.isDefined($scope.question.parents)) { + presentQuestionIds = $scope.question.parents.map(function(question) { + return question.id; + }); + } + presentQuestionIds.push($scope.question.id); + return presentQuestionIds; + } } }); @@ -1572,17 +1590,27 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam }]); -coselmarControllers.controller('ModalSearchDocumentsCtrl', function ($scope, $uibModalInstance, documentService, errorService) { +coselmarControllers.controller('ModalSearchDocumentsCtrl', function ($scope, $uibModalInstance, presentDocumentIds, documentService, errorService) { + $scope.searchKeywords = []; + $scope._isNotPresent = function(document) { + return presentDocumentIds.indexOf(document.id) == -1; + } + + $scope._filterDocuments = function(documents) { + var filtered = documents.filter($scope._isNotPresent); + return filtered; + }; + documentService.getDocuments($scope.searchKeywords, function(documents) { - $scope.documents = documents; + $scope.documents = $scope._filterDocuments(documents); }, errorService.defaultFailOnCall); $scope.searchDocuments = function(searchKeywords) { documentService.getDocuments(searchKeywords, function(documents) { - $scope.documents = documents; + $scope.documents = $scope._filterDocuments(documents); }, errorService.defaultFailOnCall); }; @@ -1596,20 +1624,31 @@ coselmarControllers.controller('ModalSearchDocumentsCtrl', function ($scope, $ui }); -coselmarControllers.controller('ModalSearchQuestionsCtrl', function ($scope, $uibModalInstance, currentQuestionId, questionsService, errorService) { +coselmarControllers.controller('ModalSearchQuestionsCtrl', function ($scope, $uibModalInstance, presentQuestionIds, questionsService, errorService) { $scope.searchKeywords = []; - $scope.searchOptions = { 'type' : 'PERIODICAL_PUBLICATION', 'privacy' : '', 'status' : '', 'fullTextSearch' : []}; - $scope.currentQuestionId = currentQuestionId; + $scope.searchOptions = { 'type' : '', 'privacy' : '', 'status' : '', 'fullTextSearch' : []}; + + $scope._isNotPresent = function(question) { + return presentQuestionIds.indexOf(question.id) == -1; + } + + $scope._filterQuestions = function(questions) { + var filtered = questions.filter($scope._isNotPresent); + return filtered; + }; questionsService.getQuestions($scope.searchOptions, function(questions) { - $scope.questions = questions; + console.log("search !"); + $scope.questions = $scope._filterQuestions(questions); + console.log("find !"); + console.log($scope.questions); }, errorService.defaultFailOnCall); $scope.searchQuestions = function(searchKeywords) { $scope.searchOptions = { 'privacy' : '', 'status' : '', 'fullTextSearch' : searchKeywords}; questionsService.getQuestions($scope.searchOptions, function(questions) { - $scope.questions = questions; + $scope.questions = $scope._filterQuestions(questions); }, errorService.defaultFailOnCall); }; diff --git a/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html b/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html index ef8a554..6dd62f2 100644 --- a/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html +++ b/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html @@ -62,7 +62,7 @@ <td><span class="status-{{question.status|lowercase}}"></span>{{question.status | translate}}</td> <td> <a class="btn fa fa-plus" title="Add question as parent" - ng-click="select(question)" ng-if="currentQuestionId != question.id"/></td> + ng-click="select(question)"/></td> </tr> </table> <p ng-if="questions && questions.length == 0" translate="common.search.noResult" class="info"/> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.