branch develop updated (9934395 -> 31be59f)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git from 9934395 Add pagniation on users list \o/ new 3fc3cfd Add pagination on projects list new 31be59f add pagination on documents The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 31be59ffe7182819601699339bd0ce73c12e52b0 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Feb 3 18:19:52 2016 +0100 add pagination on documents commit 3fc3cfd9b2d8647ef4caa1887d0412441e185bf6 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Feb 3 12:06:24 2016 +0100 Add pagination on projects list Summary of changes: .../persistence/entity/DocumentTopiaDao.java | 83 +++++++++++-------- .../persistence/entity/QuestionTopiaDao.java | 94 ++++++++++++--------- .../coselmar/services/v1/DocumentsWebService.java | 29 +++++-- .../coselmar/services/v1/QuestionsWebService.java | 96 ++++++++++++++++++---- coselmar-rest/src/main/resources/mapping | 2 + .../src/main/webapp/js/coselmar-controllers.js | 82 +++++++++++++----- .../main/webapp/js/coselmar-questions-services.js | 21 +++++ .../src/main/webapp/js/coselmar-services.js | 7 ++ coselmar-ui/src/main/webapp/js/paginationBinder.js | 3 +- .../src/main/webapp/views/documents/documents.html | 3 +- .../src/main/webapp/views/documents/toolsPart.html | 2 +- .../src/main/webapp/views/questions/questions.html | 7 +- 12 files changed, 306 insertions(+), 123 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 3fc3cfd9b2d8647ef4caa1887d0412441e185bf6 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Feb 3 12:06:24 2016 +0100 Add pagination on projects list --- .../persistence/entity/QuestionTopiaDao.java | 94 ++++++++++++--------- .../coselmar/services/v1/QuestionsWebService.java | 96 ++++++++++++++++++---- coselmar-rest/src/main/resources/mapping | 1 + .../src/main/webapp/js/coselmar-controllers.js | 30 +++++-- .../main/webapp/js/coselmar-questions-services.js | 21 +++++ .../src/main/webapp/views/questions/questions.html | 7 +- 6 files changed, 187 insertions(+), 62 deletions(-) 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 fec507d..0074d88 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 @@ -33,40 +33,45 @@ import fr.ifremer.coselmar.persistence.DaoUtils; import org.apache.commons.lang3.StringUtils; import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep; import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; public class QuestionTopiaDao extends AbstractQuestionTopiaDao<Question> { - public List<Question> findForExpert(CoselmarUser expert, QuestionSearchExample questionSearchExample, PaginationParameter page) { + public PaginationResult<Question> findForExpert(CoselmarUser expert, QuestionSearchExample questionSearchExample, PaginationParameter page) { - StringBuilder hqlBuilder = new StringBuilder("SELECT Q FROM " + Question.class.getName() + " Q " + StringBuilder hqlWithoutSelectBuilder = new StringBuilder(" FROM " + Question.class.getName() + " Q " + " INNER JOIN Q." + Question.PROPERTY_PARTICIPANTS + " CUG "); Map<String, Object> args = new HashMap<>(); String publicCondition = DaoUtils.getQueryForAttributeEquals("Q", Question.PROPERTY_PRIVACY, args, Privacy.PUBLIC, ""); - hqlBuilder.append(" WHERE ( (" + publicCondition + " ) "); + hqlWithoutSelectBuilder.append(" WHERE ( (" + publicCondition + " ) "); String privateCondition = DaoUtils.getQueryForAttributeEquals("Q", Question.PROPERTY_PRIVACY, args, Privacy.PRIVATE, ""); - hqlBuilder.append(" OR (" + privateCondition); + hqlWithoutSelectBuilder.append(" OR (" + privateCondition); String participantCondition = DaoUtils.andAttributeContains("CUG", CoselmarUserGroup.PROPERTY_MEMBERS, args, expert); - hqlBuilder.append(participantCondition); + hqlWithoutSelectBuilder.append(participantCondition); String clientCondition = DaoUtils.andAttributeContains("Q", Question.PROPERTY_CLIENTS, args, expert); - hqlBuilder.append(clientCondition + ") )"); + hqlWithoutSelectBuilder.append(clientCondition + ") )"); String finerHql = refineSearch(questionSearchExample, "Q", args); - hqlBuilder.append(" AND (" + finerHql + ")" ); + hqlWithoutSelectBuilder.append(" AND (" + finerHql + ")" ); + StringBuilder hqlBuilder = new StringBuilder("SELECT Q ").append(hqlWithoutSelectBuilder); - List<Question> questions; + PaginationResult<Question> questions; if (page != null) { - questions = forHql(hqlBuilder.toString(), args).find(page); + long count = findUnique("SELECT count(Q." + Question.PROPERTY_TOPIA_ID + " ) " + hqlWithoutSelectBuilder.toString(), args); + List<Question> questionList = forHql(hqlBuilder.toString(), args).find(page); + questions = PaginationResult.of(questionList, count, page); } else { - questions = forHql(hqlBuilder.toString(), args).findAll(); + List<Question> allQuestions = forHql(hqlBuilder.toString(), args).findAll(); + questions = PaginationResult.of(allQuestions, allQuestions.size(), PaginationParameter.of(0, -1)); } return questions; @@ -99,98 +104,113 @@ public class QuestionTopiaDao extends AbstractQuestionTopiaDao<Question> { return questions; } - public List<Question> findForExpert(CoselmarUser expert, List<String> topiaIds, PaginationParameter page) { + public PaginationResult<Question> findForExpert(CoselmarUser expert, List<String> topiaIds, PaginationParameter page) { - StringBuilder hqlBuilder = new StringBuilder("SELECT Q FROM " + Question.class.getName() + " Q " + StringBuilder hqlWithoutSelectBuilder = new StringBuilder(" FROM " + Question.class.getName() + " Q " + " INNER JOIN Q." + Question.PROPERTY_PARTICIPANTS + " CUG "); Map<String, Object> args = new HashMap<>(); String publicCondition = DaoUtils.getQueryForAttributeEquals("Q", Question.PROPERTY_PRIVACY, args, Privacy.PUBLIC, ""); - hqlBuilder.append(" WHERE ( (" + publicCondition + " ) "); + hqlWithoutSelectBuilder.append(" WHERE ( (" + publicCondition + " ) "); String privateCondition = DaoUtils.getQueryForAttributeEquals("Q", Question.PROPERTY_PRIVACY, args, Privacy.PRIVATE, ""); - hqlBuilder.append(" OR (" + privateCondition + " AND ( 0 = 1 "); + hqlWithoutSelectBuilder.append(" OR (" + privateCondition + " AND ( 0 = 1 "); String participantCondition = DaoUtils.orAttributeContains("CUG", CoselmarUserGroup.PROPERTY_MEMBERS, args, expert); - hqlBuilder.append(participantCondition); + hqlWithoutSelectBuilder.append(participantCondition); String clientCondition = DaoUtils.orAttributeContains("Q", Question.PROPERTY_CLIENTS, args, expert); - hqlBuilder.append(clientCondition + ") ) )"); + hqlWithoutSelectBuilder.append(clientCondition + ") ) )"); String topiaIdsCondition = DaoUtils.andAttributeIn("Q", Question.PROPERTY_TOPIA_ID, args, topiaIds); - hqlBuilder.append(topiaIdsCondition); + hqlWithoutSelectBuilder.append(topiaIdsCondition); + StringBuilder hqlBuilder = new StringBuilder("SELECT Q ").append(hqlWithoutSelectBuilder); - List<Question> questions; + PaginationResult<Question> questions; if (page != null) { - questions = forHql(hqlBuilder.toString(), args).find(page); + long count = findUnique("SELECT count(Q." + Question.PROPERTY_TOPIA_ID + " ) " + hqlWithoutSelectBuilder.toString(), args); + List<Question> questionList = forHql(hqlBuilder.toString(), args).find(page); + questions = PaginationResult.of(questionList, count, page); } else { - questions = forHql(hqlBuilder.toString(), args).findAll(); + List<Question> allQuestions = forHql(hqlBuilder.toString(), args).findAll(); + questions = PaginationResult.of(allQuestions, allQuestions.size(), PaginationParameter.of(0, -1)); } return questions; } - public List<Question> findForClient(CoselmarUser client, QuestionSearchExample searchExample, PaginationParameter page) { + public PaginationResult<Question> findForClient(CoselmarUser client, QuestionSearchExample searchExample, PaginationParameter page) { - StringBuilder hqlBuilder = new StringBuilder("SELECT Q FROM " + Question.class.getName() + " Q "); + StringBuilder hqlWithoutSelectBuilder = new StringBuilder(" FROM " + Question.class.getName() + " Q "); Map<String, Object> args = new HashMap<>(); String clientCondition = DaoUtils.andAttributeContains("Q", Question.PROPERTY_CLIENTS, args, client); - hqlBuilder.append(" WHERE 1=1 " + clientCondition + " "); + hqlWithoutSelectBuilder.append(" WHERE 1=1 " + clientCondition + " "); if (searchExample != null) { String finerHql = refineSearch(searchExample, "Q", args); - hqlBuilder.append(" AND (" + finerHql + ")" ); + hqlWithoutSelectBuilder.append(" AND (" + finerHql + ")" ); } - List<Question> questions; + StringBuilder hqlBuilder = new StringBuilder("SELECT Q ").append(hqlWithoutSelectBuilder); + + PaginationResult<Question> questions; if (page != null) { - questions = forHql(hqlBuilder.toString(), args).find(page); + long count = findUnique("SELECT count(Q." + Question.PROPERTY_TOPIA_ID + " ) " + hqlWithoutSelectBuilder.toString(), args); + List<Question> questionList = forHql(hqlBuilder.toString(), args).find(page); + questions = PaginationResult.of(questionList, count, page); } else { - questions = forHql(hqlBuilder.toString(), args).findAll(); + List<Question> allQuestions = forHql(hqlBuilder.toString(), args).findAll(); + questions = PaginationResult.of(allQuestions, allQuestions.size(), PaginationParameter.of(0, -1)); } return questions; } - public List<Question> findForClient(CoselmarUser client, List<String> topiaIds, PaginationParameter page) { + public PaginationResult<Question> findForClient(CoselmarUser client, List<String> topiaIds, PaginationParameter page) { TopiaQueryBuilderAddCriteriaOrRunQueryStep<Question> queryBuilder = forTopiaIdIn(topiaIds); queryBuilder.addContains(Question.PROPERTY_CLIENTS, client); - List<Question> questions; + PaginationResult<Question> questions; if (page != null) { - questions = queryBuilder.find(page); + questions = queryBuilder.findPage(page); } else { - questions = queryBuilder.findAll(); + List<Question> allQuestions = queryBuilder.findAll(); + questions = PaginationResult.of(allQuestions, allQuestions.size(), PaginationParameter.of(0, -1)); } return questions; } - public List<Question> findWithSearchExample(QuestionSearchExample searchExample, PaginationParameter page) { + public PaginationResult<Question> findWithSearchExample(QuestionSearchExample searchExample, PaginationParameter page) { - StringBuilder hqlBuilder = new StringBuilder("SELECT Q FROM " + Question.class.getName() + " Q "); + StringBuilder hqlWithoutSelectBuilder = new StringBuilder(" FROM " + Question.class.getName() + " Q "); Map<String, Object> args = new HashMap<>(); if (searchExample != null) { String finerHql = refineSearch(searchExample, "Q", args); - hqlBuilder.append(" WHERE (" + finerHql + ")" ); + hqlWithoutSelectBuilder.append(" WHERE (" + finerHql + ")" ); } - List<Question> questions; + StringBuilder hqlBuilder = new StringBuilder("SELECT Q ").append(hqlWithoutSelectBuilder); + + PaginationResult<Question> questions; if (page != null) { - questions = forHql(hqlBuilder.toString(), args).find(page); + long count = findUnique("SELECT count(Q." + Question.PROPERTY_TOPIA_ID + " ) " + hqlWithoutSelectBuilder.toString(), args); + List<Question> questionList = forHql(hqlBuilder.toString(), args).find(page); + questions = PaginationResult.of(questionList, count, page); } else { - questions = forHql(hqlBuilder.toString(), args).findAll(); + List<Question> allQuestions = forHql(hqlWithoutSelectBuilder.toString(), args).findAll(); + questions = PaginationResult.of(allQuestions, allQuestions.size(), PaginationParameter.of(0, -1)); } return questions; diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java index f5a7ca0..7a8eaab 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java @@ -75,6 +75,7 @@ import org.nuiton.topia.persistence.TopiaIdFactory; import org.nuiton.topia.persistence.TopiaNoResultException; import org.nuiton.util.DateUtil; import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; /** * @author ymartel <martel@codelutin.com> @@ -288,6 +289,27 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { return result; } + public PaginationResult<QuestionBean> getPaginatedQuestions(QuestionSearchBean searchOption) throws InvalidCredentialException, UnauthorizedException { + + // Check authentication + String authorization = getContext().getHeader("Authorization"); + CoselmarUser currentUser = checkUserAuthentication(authorization); + + PaginationResult<Question> paginatedQuestions; + + if (searchOption != null) { + paginatedQuestions = getPaginatedFilteredQuestions(currentUser, searchOption); + + } else { + List<Question> allQuestions = getAllQuestions(currentUser); + paginatedQuestions = PaginationResult.of(allQuestions, allQuestions.size(), PaginationParameter.of(0, -1)); + } + + PaginationResult<QuestionBean> result = convert(currentUser, paginatedQuestions); + + return result; + } + public List<QuestionBean> getPublicQuestions() throws InvalidCredentialException, UnauthorizedException { // No authentication needed, just filter to get last 5 public questions @@ -301,11 +323,11 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { PaginationParameter paginationParameter = PaginationParameter.of(0, 5, Question.PROPERTY_SUBMISSION_DATE, true); - List<Question> questionList = getQuestionDao().findWithSearchExample(searchOption, paginationParameter); + PaginationResult<Question> questionList = getQuestionDao().findWithSearchExample(searchOption, paginationParameter); - List<QuestionBean> result = new ArrayList<>(questionList.size()); + List<QuestionBean> result = new ArrayList<>(questionList.getElements().size()); - for (Question question : questionList) { + for (Question question : questionList.getElements()) { TopiaIdFactory topiaIdFactory = getPersistenceContext().getTopiaIdFactory(); QuestionBean questionBean = BeanEntityConverter.toLightBean(topiaIdFactory, question); @@ -1193,9 +1215,34 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { * * @return list of all question user is authorized to access. * @throws UnauthorizedException + * + * @deprecated use {@link #getPaginatedFilteredQuestions(CoselmarUser, QuestionSearchBean)} */ protected List<Question> getAllFilteredQuestions(CoselmarUser currentUser, QuestionSearchBean searchBean) throws UnauthorizedException { + PaginationResult<Question> paginatedFilteredQuestions = getPaginatedFilteredQuestions(currentUser, searchBean); + return paginatedFilteredQuestions.getElements(); + } + + /** + * Methods that retrieve questions matching search filter (based on an example + * or/and fullText search) also depending of current user role permission : + * <ul> + * <li>{@code ADMIN} and {@code SUPERVISOR} can access to all questions ;</li> + * <li>{@code MEMBER} can only access to all public questions (so, if filter is on private, it has no result) ;</li> + * <li>{@code EXPERT} can access to all private questions where he is participant or client and all public questions ;</li> + * <li>{@code CLIENT} can access to all questions where he is client.</li> + * </ul> + * The result is paginated, and only the elements of asking page are returned. + * + * @param currentUser : current user that make request + * @param searchBean : bean containing search param to filter result + * + * @return {@link PaginationResult} of questions user is authorized to access. + * @throws UnauthorizedException + */ + protected PaginationResult<Question> getPaginatedFilteredQuestions(CoselmarUser currentUser, QuestionSearchBean searchBean) throws UnauthorizedException { + QuestionsIndexationService questionsIndexationService = getServicesContext().newService(QuestionsIndexationService.class); //Try to retrieve corresponding questionIds from the index if searchBean given @@ -1216,7 +1263,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { } - List<Question> questionList; + PaginationResult<Question> paginatedQuestions; String currentUserRole = currentUser.getRole().name(); @@ -1288,11 +1335,11 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { || StringUtils.equalsIgnoreCase(CoselmarUserRole.SUPERVISOR.name(), currentUserRole)) { if (fromIndexQuestionIds != null && !fromIndexQuestionIds.isEmpty()) { - questionList = getQuestionDao().forTopiaIdIn(fromIndexQuestionIds).find(paginationParameter); + paginatedQuestions = getQuestionDao().forTopiaIdIn(fromIndexQuestionIds).findPage(paginationParameter); // classical search with DAO } else { - questionList = getQuestionDao().findWithSearchExample(searchExample, paginationParameter); + paginatedQuestions = getQuestionDao().findWithSearchExample(searchExample, paginationParameter); } @@ -1301,35 +1348,35 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { if (StringUtils.equals(searchBean.getPrivacy(), Privacy.PRIVATE.name())) { // Asking for private question ? directly no result ! - questionList = new ArrayList<>(0); + paginatedQuestions = PaginationResult.of(new ArrayList<Question>(0), 0, PaginationParameter.of(0, -1)); } else { if (fromIndexQuestionIds != null && !fromIndexQuestionIds.isEmpty()) { - questionList = getQuestionDao().forTopiaIdIn(fromIndexQuestionIds).find(paginationParameter); + paginatedQuestions = getQuestionDao().forTopiaIdIn(fromIndexQuestionIds).findPage(paginationParameter); // classical search with DAO } else { - questionList = getQuestionDao().findWithSearchExample(searchExample, paginationParameter); + paginatedQuestions = getQuestionDao().findWithSearchExample(searchExample, paginationParameter); } } // Expert : access to all public question and private question if he is participant or client } else if (StringUtils.equalsIgnoreCase(CoselmarUserRole.EXPERT.name(), currentUserRole)) { if (fromIndexQuestionIds != null && !fromIndexQuestionIds.isEmpty()) { - questionList = getQuestionDao().findForExpert(currentUser, fromIndexQuestionIds, paginationParameter); + paginatedQuestions = getQuestionDao().findForExpert(currentUser, fromIndexQuestionIds, paginationParameter); } else { - questionList = getQuestionDao().findForExpert(currentUser, searchExample, paginationParameter); + paginatedQuestions = getQuestionDao().findForExpert(currentUser, searchExample, paginationParameter); } // Client : access to question he is client } else if (StringUtils.equalsIgnoreCase(CoselmarUserRole.CLIENT.name(), currentUserRole)) { if (fromIndexQuestionIds != null && !fromIndexQuestionIds.isEmpty()) { - questionList = getQuestionDao().findForClient(currentUser, fromIndexQuestionIds, paginationParameter); + paginatedQuestions = getQuestionDao().findForClient(currentUser, fromIndexQuestionIds, paginationParameter); } else { - questionList = getQuestionDao().findForClient(currentUser, searchExample, paginationParameter); + paginatedQuestions = getQuestionDao().findForClient(currentUser, searchExample, paginationParameter); } } else { @@ -1339,7 +1386,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { } throw new UnauthorizedException(message); } - return questionList; + return paginatedQuestions; } protected List<String> getQuestionsFullId(List<String> questionShortIds) { @@ -1374,6 +1421,27 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { return questions; } + protected PaginationResult<QuestionBean> convert(CoselmarUser currentUser, PaginationResult<Question> paginatedQuestions) { + List<QuestionBean> questions = new ArrayList<>(paginatedQuestions.getElements().size()); + + for (Question question : paginatedQuestions.getElements()) { + TopiaIdFactory topiaIdFactory = getPersistenceContext().getTopiaIdFactory(); + + QuestionBean questionBean; + if (RESTRICTED_ACCESS_USERS.contains(currentUser.getRole().name())) { + questionBean = BeanEntityConverter.toLightBean(topiaIdFactory, question); + + } else { + questionBean = BeanEntityConverter.toBean(topiaIdFactory, question); + } + + questions.add(questionBean); + } + + PaginationResult paginatedQuestionBeans = PaginationResult.of(questions, paginatedQuestions.getCount(), paginatedQuestions.getCurrentPage()); + return paginatedQuestionBeans; + } + protected List<QuestionTreeNode> buildAncestorsTree(String questionId, int depth) { // Depth = 0 : it is the end of the tree ! if (depth == 0) { diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index f7d274b..5c97dc1 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -57,6 +57,7 @@ GET /v1/users/{userId}/projects QuestionsWebService.getUserQuest # Questions Api GET /v1/questions QuestionsWebService.getQuestions +GET /v2/questions QuestionsWebService.getPaginatedQuestions GET /v1/questions/public QuestionsWebService.getPublicQuestions GET /v1/questions/themes QuestionsWebService.getThemes GET /v1/questions/types QuestionsWebService.getTypes diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 39dd801..cd105f8 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -997,7 +997,7 @@ coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routePara function($scope, $route, $routeParams, $location, questionsService, notify, errorService){ $scope.$emit('dataLoading'); - $scope.searchOptions = { 'privacy' : '', 'status' : '', 'fullTextSearch' : []}; + $scope.searchOptions = { 'privacy' : '', 'status' : '', 'fullTextSearch' : [], page: 0, limit: 25}; var advancedSearch = $routeParams.advancedSearch; if (advancedSearch) { @@ -1006,18 +1006,19 @@ coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routePara $scope.advanced = false; } - questionsService.getQuestions($scope.searchOptions, function(questions) { + questionsService.getPaginatedQuestions($scope.searchOptions, function(paginatedQuestions) { // success : just get the questions - $scope.questions = questions; - + $scope.paginationData = paginatedQuestions; + $scope.$broadcast('pageLoaded', $scope.paginationData.currentPage, paginatedQuestions.count) }, errorService.defaultFailOnCall, function() { $scope.$emit('dataLoaded'); }); $scope.searchQuestions = function() { $scope.$emit('dataLoading'); - questionsService.getQuestions($scope.searchOptions, function(questions) { - $scope.questions = questions; + questionsService.getPaginatedQuestions($scope.searchOptions, function(paginatedQuestions) { + $scope.paginationData = paginatedQuestions; + $scope.$broadcast('pageLoaded', $scope.paginationData.currentPage, paginatedQuestions.count) }, errorService.defaultFailOnCall, function() { $scope.$emit('dataLoaded'); }); @@ -1054,8 +1055,9 @@ coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routePara $scope.searchOptions.deadlineBeforeDate = $scope.searchOptions.deadlineBeforeDate.getTime(); } - questionsService.getQuestions($scope.searchOptions, function(questions){ - $scope.questions = questions; + questionsService.getPaginatedQuestions($scope.searchOptions, function(paginatedQuestions) { + $scope.paginationData = paginatedQuestions; + $scope.$broadcast('pageLoaded', $scope.paginationData.currentPage, paginatedQuestions.count) }, errorService.defaultFailOnCall, function() { $scope.$emit('dataLoaded'); }); @@ -1112,6 +1114,18 @@ coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routePara return localStorage.getItem('coselmar-jwt'); }; + // Notification de changement dans le module de pagination + $scope.$on('loadPage', function(event, pageNumber, pageSize) { + $scope.searchOptions.page = pageNumber; + $scope.searchOptions.limit = pageSize; + questionsService.getPaginatedQuestions($scope.searchOptions, function(paginatedQuestions) { + $scope.paginationData = paginatedQuestions; + }, errorService.defaultFailOnCall, function() { + $scope.$broadcast('pageLoaded', $scope.paginationData.currentPage, $scope.paginationData.count); + $scope.$emit('dataLoaded'); + }); + }); + }]); // Controller for Question View diff --git a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js index 7c6701d..f0d0de1 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js @@ -31,6 +31,7 @@ function Question(resource, http, config){ this.resource = resource; var baseURL = config.BASE_URL + "v1/questions"; + var baseV2URL = config.BASE_URL + "v2/questions"; var exportURL = config.BASE_URL + "v1/export/questions"; var usersURL = config.BASE_URL + "v1/users"; @@ -79,6 +80,26 @@ function Question(resource, http, config){ questionResource.query().$promise.then(successFunction, failFunction).finally(finallyFunction); }; + this.getPaginatedQuestions = function(searchOptions, successFunction, failFunction, finallyFunction) { + + if (searchOptions.privacy + && searchOptions.privacy.toUpperCase() != "PRIVATE" + && searchOptions.privacy.toUpperCase() != "PUBLIC" ) { + + searchOptions.privacy = undefined; + } + + if (searchOptions.status && searchOptions.status.toUpperCase() != "IN_PROGRESS" + && searchOptions.status.toUpperCase() != "CLOSED" + && searchOptions.status.toUpperCase() != "ADJOURNED") { + + searchOptions.status = undefined; + } + + var questionResource = resource(baseV2URL, {'searchOption' : searchOptions}); + questionResource.get().$promise.then(successFunction, failFunction).finally(finallyFunction); + }; + this.exportSearchResult = function(searchOptions, successFunction, failFunction) { if (searchOptions.privacy diff --git a/coselmar-ui/src/main/webapp/views/questions/questions.html b/coselmar-ui/src/main/webapp/views/questions/questions.html index 70e7d43..71b4e9c 100644 --- a/coselmar-ui/src/main/webapp/views/questions/questions.html +++ b/coselmar-ui/src/main/webapp/views/questions/questions.html @@ -47,7 +47,7 @@ </tr> </thead> <tbody> - <tr ng-repeat="question in questions" > + <tr ng-repeat="question in paginationData.elements" > <td ng-if="context.currentUser.role != 'MEMBER'"> <span class="status-{{question.status|lowercase}}" title="{{question.status | translate}}"></span> <a href="#/questions/{{question.id}}" class="paddingLeft10" tooltip-placement="bottom" uib-tooltip="{{question.summary | limitTo: 250 }}">{{question.title}}</a> @@ -92,8 +92,9 @@ </tbody> </table> </div> - <p ng-if="questions && questions.length == 0" translate="common.search.noResult" class="info"/> - <div ng-if="questions && questions.length > 0" > + <pagination-tool></pagination-tool> + <p ng-if="!paginationData || !paginationData.elements || paginationData.elements.length == 0" translate="common.search.noResult" class="info"/> + <div ng-if="paginationData && paginationData.elements && paginationData.elements.length > 0" > <form action="{{getExportQuestionsUrl()}}" method="post" target="_blank"> <input type="hidden" name="searchOption" value="{{searchOptions}}" /> <input type="hidden" name="token" value="{{getToken()}}" /> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 31be59ffe7182819601699339bd0ce73c12e52b0 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Feb 3 18:19:52 2016 +0100 add pagination on documents --- .../persistence/entity/DocumentTopiaDao.java | 83 +++++++++++++--------- .../coselmar/services/v1/DocumentsWebService.java | 29 +++++--- coselmar-rest/src/main/resources/mapping | 1 + .../src/main/webapp/js/coselmar-controllers.js | 52 ++++++++++---- .../src/main/webapp/js/coselmar-services.js | 7 ++ coselmar-ui/src/main/webapp/js/paginationBinder.js | 3 +- .../src/main/webapp/views/documents/documents.html | 3 +- .../src/main/webapp/views/documents/toolsPart.html | 2 +- 8 files changed, 119 insertions(+), 61 deletions(-) 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 2e734cf..fcd7b0e 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 @@ -33,10 +33,11 @@ import fr.ifremer.coselmar.persistence.DaoUtils; import fr.ifremer.coselmar.persistence.SearchRequestBean; import org.apache.commons.lang3.StringUtils; import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { - public List<Document> findAllContainingAllKeywords(List<String> keywords) { + public PaginationResult<Document> findPaginatedContainingAllKeywords(List<String> keywords, PaginationParameter page) { StringBuilder hqlBuilder = new StringBuilder("FROM " + Document.class.getName() + " D"); Map<String, Object> args = new HashMap<>(); @@ -57,8 +58,12 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { hqlBuilder.append(" )"); } - List<Document> documents = forHql(hqlBuilder.toString(), args).findAll(); - return documents; + String hql = hqlBuilder.toString(); + Long count = forHql(hql).count(); + List<Document> documents = forHql(hql, args).find(page); + + PaginationResult paginationResult = PaginationResult.of(documents, count, page); + return paginationResult; } public List<Document> findAllFilterByUser(CoselmarUser currentUser, List<String> keywords) { @@ -104,12 +109,12 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { return documents; } - public List<Document> findAllByExample(CoselmarUser userFilter, DocumentSearchExample searchExample) { + public PaginationResult<Document> findAllByExample(CoselmarUser userFilter, DocumentSearchExample searchExample) { - StringBuilder hqlBuilder = new StringBuilder("SELECT DISTINCT(D) FROM " + Document.class.getName() + " D" + StringBuilder hqlWithoutSelectBuilder = new StringBuilder(" FROM " + Document.class.getName() + " D" + " LEFT OUTER JOIN D." + Document.PROPERTY_RESTRICTED_LIST + " CUG " + " LEFT OUTER JOIN D." + Document.PROPERTY_OWNER + " DO "); - hqlBuilder.append(" WHERE 1=1 "); // Just because next clause will begin with operator + hqlWithoutSelectBuilder.append(" WHERE 1=1 "); // Just because next clause will begin with operator Map<String, Object> args = new HashMap<>(); @@ -117,58 +122,58 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { if (userFilter != null) { // can list all public document String privacyPublicCondition = DaoUtils.getQueryForAttributeEquals("D", Document.PROPERTY_PRIVACY, args, Privacy.PUBLIC, ""); - hqlBuilder.append(" AND ( " + privacyPublicCondition); + hqlWithoutSelectBuilder.append(" AND ( " + privacyPublicCondition); // Can list his own document String ownerCondition = DaoUtils.orAttributeEquals("D", Document.PROPERTY_OWNER, args, userFilter); - hqlBuilder.append(ownerCondition); + hqlWithoutSelectBuilder.append(ownerCondition); // For limited access, check if user is in a restricted list String participantCondition = DaoUtils.orAttributeContains("CUG", CoselmarUserGroup.PROPERTY_MEMBERS, args, userFilter); - hqlBuilder.append(participantCondition + ")"); + hqlWithoutSelectBuilder.append(participantCondition + ")"); } // Manage example Document example = searchExample.getExample(); if (example != null) { - hqlBuilder.append(" AND ( 1 = 1 "); + hqlWithoutSelectBuilder.append(" AND ( 1 = 1 "); if (StringUtils.isNotBlank(example.getName())) { String nameCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_NAME, args, example.getName()); - hqlBuilder.append(nameCondition); + hqlWithoutSelectBuilder.append(nameCondition); } if (StringUtils.isNotBlank(example.getAuthors())) { String authorsCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_AUTHORS, args, example.getAuthors()); - hqlBuilder.append(authorsCondition); + hqlWithoutSelectBuilder.append(authorsCondition); } if (StringUtils.isNotBlank(example.getLicense())) { String licenseCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_LICENSE, args, example.getLicense()); - hqlBuilder.append(licenseCondition); + hqlWithoutSelectBuilder.append(licenseCondition); } if (StringUtils.isNotBlank(example.getType())) { String typeCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_TYPE, args, example.getType()); - hqlBuilder.append(typeCondition); + hqlWithoutSelectBuilder.append(typeCondition); } if (example.getPrivacy() != null ) { String privacyCondition = DaoUtils.andAttributeEquals("D", Document.PROPERTY_PRIVACY, args, example.getPrivacy()); - hqlBuilder.append(privacyCondition); + hqlWithoutSelectBuilder.append(privacyCondition); } if (example.getKeywords() != null && !example.getKeywords().isEmpty()) { for (String keyword : example.getKeywords()) { String keywordCondition = DaoUtils.andAttributeContains("D", Document.PROPERTY_KEYWORDS, args, keyword); - hqlBuilder.append(keywordCondition); + hqlWithoutSelectBuilder.append(keywordCondition); } } if (example.getOwner() != null) { String ownerCondition = DaoUtils.andAttributeEquals("D", Document.PROPERTY_OWNER, args, example.getOwner()); - hqlBuilder.append(ownerCondition); + hqlWithoutSelectBuilder.append(ownerCondition); } @@ -176,60 +181,60 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { if (StringUtils.isNotBlank(searchExample.getOwnerName())) { String activeCondition = DaoUtils.andAttributeEquals("DO", CoselmarUser.PROPERTY_ACTIVE, args, true); - hqlBuilder.append(activeCondition); + hqlWithoutSelectBuilder.append(activeCondition); // try to find name in user#firstName or user#name! - hqlBuilder.append(" AND ( 1=0 "); // Same as previously : need to have an insignificant clause to add all OR after + hqlWithoutSelectBuilder.append(" AND ( 1=0 "); // Same as previously : need to have an insignificant clause to add all OR after String orFirstname = DaoUtils.orAttributeLike("DO", CoselmarUser.PROPERTY_FIRSTNAME, args, searchExample.getOwnerName()); - hqlBuilder.append(orFirstname); + hqlWithoutSelectBuilder.append(orFirstname); // Name String orName = DaoUtils.orAttributeLike("DO", CoselmarUser.PROPERTY_NAME, args, searchExample.getOwnerName()); - hqlBuilder.append(orName); + hqlWithoutSelectBuilder.append(orName); - hqlBuilder.append(" ) "); // Close this keywords clause + hqlWithoutSelectBuilder.append(" ) "); // Close this keywords clause } // Manage date range if (searchExample.getPublicationBeforeDate() != null) { String publicationDateConditionBefore = DaoUtils.andAttributeLesserOrEquals("D", Document.PROPERTY_PUBLICATION_DATE, args, searchExample.getPublicationBeforeDate()); - hqlBuilder.append(publicationDateConditionBefore); + hqlWithoutSelectBuilder.append(publicationDateConditionBefore); } if (searchExample.getPublicationAfterDate() != null) { String publicationDateConditionAfter = DaoUtils.andAttributeGreaterOrEquals("D", Document.PROPERTY_PUBLICATION_DATE, args, searchExample.getPublicationAfterDate()); - hqlBuilder.append(publicationDateConditionAfter); + hqlWithoutSelectBuilder.append(publicationDateConditionAfter); } if (searchExample.getDepositBeforeDate() != null) { String depositDateConditionBefore = DaoUtils.andAttributeLesserOrEquals("D", Document.PROPERTY_DEPOSIT_DATE, args, searchExample.getDepositBeforeDate()); - hqlBuilder.append(depositDateConditionBefore); + hqlWithoutSelectBuilder.append(depositDateConditionBefore); } if (searchExample.getDepositAfterDate() != null) { String depositDateConditionAfter = DaoUtils.andAttributeGreaterOrEquals("D", Document.PROPERTY_DEPOSIT_DATE, args, searchExample.getDepositAfterDate()); - hqlBuilder.append(depositDateConditionAfter); + hqlWithoutSelectBuilder.append(depositDateConditionAfter); } - hqlBuilder.append(" ) "); + hqlWithoutSelectBuilder.append(" ) "); } // Manage keywords search in : title, summary, authors and keywords if (searchExample.getFullTextSearch() != null && !searchExample.getFullTextSearch().isEmpty()) { - hqlBuilder.append(" AND ( 1 = 0 "); + hqlWithoutSelectBuilder.append(" AND ( 1 = 0 "); for (String keyword : searchExample.getFullTextSearch()) { String nameClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_NAME, args, keyword); String summaryClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_SUMMARY, args, keyword); String authorsClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_AUTHORS, args, keyword); String containsKeyword = DaoUtils.orAttributeContains("D", Document.PROPERTY_KEYWORDS, args, keyword); - hqlBuilder.append(nameClause); - hqlBuilder.append(summaryClause); - hqlBuilder.append(authorsClause); - hqlBuilder.append(containsKeyword); + hqlWithoutSelectBuilder.append(nameClause); + hqlWithoutSelectBuilder.append(summaryClause); + hqlWithoutSelectBuilder.append(authorsClause); + hqlWithoutSelectBuilder.append(containsKeyword); } - hqlBuilder.append(" )"); + hqlWithoutSelectBuilder.append(" )"); } // Add the prefix for order clause @@ -237,9 +242,17 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { PaginationParameter paginationParameter = searchExample.getPaginationParameter(); - List<Document> documents = forHql(hqlBuilder.toString(), args).find(paginationParameter); + // Cannot use forHql().findPage due to topia bug with joins + // count total elements + StringBuilder hqlCountBuilder = new StringBuilder("SELECT count(D." + Document.PROPERTY_TOPIA_ID + ") ").append(hqlWithoutSelectBuilder); + Long count = findUnique(hqlCountBuilder.toString(), args); + // Get elements for wanted page + StringBuilder hqlSelectBuilder = new StringBuilder("SELECT DISTINCT(D) ").append(hqlWithoutSelectBuilder); + List<Document> documents = forHql(hqlSelectBuilder.toString(), args).find(paginationParameter); - return documents; + PaginationResult paginatedDocuments = PaginationResult.of(documents, count, paginationParameter); + + return paginatedDocuments; } public List<String> findAllKeywords() { diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index a0e6642..7f4c58a 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -56,6 +56,8 @@ import org.debux.webmotion.server.call.UploadFile; import org.debux.webmotion.server.render.Render; import org.nuiton.topia.persistence.TopiaNoResultException; import org.nuiton.util.DateUtil; +import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; import java.io.File; import java.io.FileInputStream; @@ -152,6 +154,13 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { public List<DocumentBean> getDocuments(DocumentSearchBean searchBean) throws InvalidCredentialException { + PaginationResult<DocumentBean> paginatedDocuments = getPaginatedDocuments(searchBean); + + return paginatedDocuments.getElements(); + } + + public PaginationResult<DocumentBean> getPaginatedDocuments(DocumentSearchBean searchBean) throws InvalidCredentialException { + // Check authentication String authorization = getContext().getHeader("Authorization"); CoselmarUser currentUser = checkUserAuthentication(authorization); @@ -195,7 +204,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } - List<Document> documentList; + PaginationResult<Document> paginatedDocuments; // Admin and Supervisor can see all documents (public, private and restricted) if (Lists.newArrayList(CoselmarUserRole.ADMIN, CoselmarUserRole.SUPERVISOR).contains(currentUserRole)) { @@ -207,27 +216,30 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { List<String> documentIds = documentsIndexationService.searchDocuments(searchKeywords); List<String> documentFullIds = getDocumentsFullId(documentIds); - documentList = getDocumentDao().forTopiaIdIn(documentFullIds).findAll(); + Long count = getDocumentDao().forTopiaIdIn(documentFullIds).count(); + List<Document> documentList = getDocumentDao().forTopiaIdIn(documentFullIds).find(searchExample.getPaginationParameter()); + + paginatedDocuments = PaginationResult.of(documentList, count, searchExample.getPaginationParameter()); } catch (IOException | ParseException e) { if (log.isErrorEnabled()) { log.error("Unable to search by lucene, make search directly in database", e); } - documentList = getDocumentDao().findAllContainingAllKeywords(searchKeywords); + paginatedDocuments = getDocumentDao().findPaginatedContainingAllKeywords(searchKeywords, searchExample.getPaginationParameter()); } } else { - documentList = getDocumentDao().findAllByExample(null, searchExample); + paginatedDocuments = getDocumentDao().findAllByExample(null, searchExample); } } else { //Other can only see public, his own private and restricted for which he is allowed - documentList = getDocumentDao().findAllByExample(currentUser, searchExample); + paginatedDocuments = getDocumentDao().findAllByExample(currentUser, searchExample); } - List<DocumentBean> result = new ArrayList<>(documentList.size()); + List<DocumentBean> documentBeans = new ArrayList<>(paginatedDocuments.getElements().size()); - for (Document document : documentList) { + for (Document document : paginatedDocuments.getElements()) { DocumentBean documentBean = BeanEntityConverter.toBean(getPersistenceContext().getTopiaIdFactory(), document); // Manage related Question @@ -237,9 +249,10 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { documentBean.setNbRelatedQuestions((int) (relatedQuestions + relatedQuestionsAsClosing)); - result.add(documentBean); + documentBeans.add(documentBean); } + PaginationResult result = PaginationResult.of(documentBeans, paginatedDocuments.getCount(), paginatedDocuments.getCurrentPage()); return result; } diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index 5c97dc1..156ce9b 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -32,6 +32,7 @@ GET /v1/doc DocApi.showMapping # Documents Api GET /v1/documents DocumentsWebService.getDocuments +GET /v2/documents DocumentsWebService.getPaginatedDocuments GET /v1/documents/keywords DocumentsWebService.getKeywords GET /v1/documents/types DocumentsWebService.getTypes GET /v1/documents/{documentId} DocumentsWebService.getDocument diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index cd105f8..6f32f3b 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -180,14 +180,13 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara $scope.$emit('dataLoading'); //manage keywords if given - $scope.search = { searchKeywords : []}; - $scope.example = { keywords: []}; + $scope.example = { fullTextSearch : [], keywords: [], page: 0, limit: 25}; var keywords = $routeParams.keywords; if (Array.isArray(keywords)) { - $scope.search.searchKeywords = keywords; + $scope.example.fullTextSearch = keywords; } else if (keywords) { - $scope.search.searchKeywords.push(keywords); + $scope.example.fullTextSearch.push(keywords); } var advancedSearch = $routeParams.advancedSearch; @@ -197,10 +196,21 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara $scope.advanced = false; } - documentService.getDocuments($scope.search.searchKeywords, function(documents) { - $scope.documents = documents; - }, errorService.defaultFailOnCall, function() { - $scope.$emit('dataLoaded'); + var page = $routeParams.page; + if (limit) { + $scope.example.page = page; + } + + var limit = $routeParams.limit; + if (limit) { + $scope.example.limit = limit; + } + + documentService.getPaginatedDocuments($scope.example, function(paginatedDocuments) { + $scope.paginationData = paginatedDocuments; + }, errorService.defaultFailOnCall, function() { + $scope.$broadcast('pageLoaded', $scope.paginationData.currentPage, $scope.paginationData.count) + $scope.$emit('dataLoaded'); }); $scope.deleteDocument = function(documentId){ @@ -220,7 +230,9 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara }; $scope.searchDocuments = function(){ - $location.search('keywords', $scope.search.searchKeywords); + $location.search('keywords', $scope.example.fullTextSearch); + $location.search('page', $scope.example.page); + $location.search('limit', $scope.example.limit); }; $scope.advancedSearchDocuments = function() { @@ -242,11 +254,12 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara } $scope.$emit('dataLoading'); - documentService.getAdvancedDocuments($scope.example, function(documents){ - $scope.documents = documents; - }, errorService.defaultFailOnCall, function() { - $scope.$emit('dataLoaded'); - }); + documentService.getPaginatedDocuments($scope.example, function(paginatedDocuments) { + $scope.paginationData = paginatedDocuments; + }, errorService.defaultFailOnCall, function() { + $scope.$broadcast('pageLoaded', $scope.paginationData.currentPage, $scope.paginationData.count) + $scope.$emit('dataLoaded'); + }); }; $scope.searchMode = function(type) { @@ -259,6 +272,17 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara } }; + $scope.$on('loadPage', function(event, pageNumber, pageSize) { + $scope.example.page = pageNumber; + $scope.example.limit = pageSize; + documentService.getPaginatedDocuments($scope.example, function(paginatedDocuments) { + $scope.paginationData = paginatedDocuments; + }, errorService.defaultFailOnCall, function() { + $scope.$broadcast('pageLoaded', $scope.paginationData.currentPage, $scope.paginationData.count); + $scope.$emit('dataLoaded'); + }); + }); + }]); // Controller for new document View diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index 2129d30..64f4706 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -32,6 +32,7 @@ function Document(resource, config){ this.resource = resource; var baseURL = config.BASE_URL + "v1/documents"; + var baseV2URL = config.BASE_URL + "v2/documents"; var usersURL = config.BASE_URL + "v1/users"; this.saveDocument = function(document, successFunction, failFunction, finallyFunction) { @@ -141,4 +142,10 @@ function Document(resource, config){ docResource.query(successFunction, failFunction).$promise.finally(finallyFunction); }; + this.getPaginatedDocuments = function(searchExample, successFunction, failFunction, finallyFunction){ + // Load documents with search example + var docResource = resource(baseV2URL, {'searchBean' : searchExample}); + docResource.get(successFunction, failFunction).$promise.finally(finallyFunction); + }; + }; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/js/paginationBinder.js b/coselmar-ui/src/main/webapp/js/paginationBinder.js index a9b8fab..fc6606d 100644 --- a/coselmar-ui/src/main/webapp/js/paginationBinder.js +++ b/coselmar-ui/src/main/webapp/js/paginationBinder.js @@ -46,9 +46,8 @@ paginationBinder.controller('paginationController', function($scope) { if (paginationParameter.pageSize <= 0) { $scope.pageContext.nbPages = 0; } else { - $scope.pageContext.nbPages = Math.ceil(nbElements / paginationParameter.pageSize) - 1; + $scope.pageContext.nbPages = Math.max(0 ,Math.ceil(nbElements / paginationParameter.pageSize) - 1); } - $scope.pageContext.firstPage = $scope.pageContext.pageNumber == 0; $scope.pageContext.lastPage = $scope.pageContext.pageNumber == $scope.pageContext.nbPages; diff --git a/coselmar-ui/src/main/webapp/views/documents/documents.html b/coselmar-ui/src/main/webapp/views/documents/documents.html index 1580631..61b3c1b 100644 --- a/coselmar-ui/src/main/webapp/views/documents/documents.html +++ b/coselmar-ui/src/main/webapp/views/documents/documents.html @@ -45,7 +45,7 @@ </tr> </thead> <tbody> - <tr ng-repeat="document in documents"> + <tr ng-repeat="document in paginationData.elements"> <td><a href="#/documents/{{document.id}}">{{document.name}}</a></td> <td>{{document.authors}}</td> <td>{{document.privacy}}</td> @@ -61,6 +61,7 @@ </tr> </tbody> </table> + <pagination-tool></pagination-tool> <p ng-if="documents && documents.length == 0" translate="common.search.noResult" class="info"/> </div> </div> \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html index cfac4a9..bf1b457 100644 --- a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html +++ b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html @@ -37,7 +37,7 @@ <span class="fa fa-info-circle" tooltip-placement="bottom" uib-tooltip="{{ 'common.message.info.searchKeywords' | translate }}"></span> <div class="input-group"> - <input type="text" class="form-control" placeholder="keyword1,keyword2,..." ng-model="search.searchKeywords" ng-list /> + <input type="text" class="form-control" placeholder="keyword1,keyword2,..." ng-model="example.fullTextSearch" ng-list /> <span class="input-group-btn"> <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button> </span> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm