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 f11feebeda5326cce83a6e4e71dd3dcb3eda8519 Author: Yannick Martel <martel@©odelutin.com> Date: Tue Dec 22 17:09:46 2015 +0100 fixes #7774 revue de la gestion de l'export --- .../src/main/webapp/js/coselmar-constants.js | 2 +- .../coselmar/services/v1/QuestionsWebService.java | 66 +++++++++++++++++----- coselmar-rest/src/main/resources/mapping | 2 +- .../src/main/webapp/js/coselmar-constants.js | 13 ++++- .../src/main/webapp/js/coselmar-controllers.js | 30 ++++------ .../main/webapp/js/coselmar-general-services.js | 2 +- .../main/webapp/js/coselmar-questions-services.js | 6 +- .../src/main/webapp/js/coselmar-services.js | 2 +- .../src/main/webapp/js/coselmar-user-services.js | 2 +- .../src/main/webapp/views/questions/questions.html | 10 +++- 10 files changed, 90 insertions(+), 45 deletions(-) diff --git a/coselmar-bundle/src/main/webapp/js/coselmar-constants.js b/coselmar-bundle/src/main/webapp/js/coselmar-constants.js index c13b440..97b7520 100644 --- a/coselmar-bundle/src/main/webapp/js/coselmar-constants.js +++ b/coselmar-bundle/src/main/webapp/js/coselmar-constants.js @@ -21,7 +21,7 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -coselmarApp.constant('coselmar-config', { +coselmarApp.constant('coselmarConfig', { BASE_URL : "v1", SUPPORTED_LOCALE : ["en", "fr"] }); \ No newline at end of file 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 75ef937..457cac9 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 @@ -254,21 +254,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { questionList = getAllQuestions(currentUser); } - List<QuestionBean> result = new ArrayList<>(questionList.size()); - - for (Question question : questionList) { - 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); - } - - result.add(questionBean); - } + List<QuestionBean> result = convert(currentUser, questionList); return result; } @@ -847,6 +833,37 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { } + public Render exportSearchedQuestions(String token, QuestionSearchBean searchOption) throws InvalidCredentialException, UnauthorizedException { + + CoselmarUser currentUser = checkUserAuthentication(token); + + List<Question> questionList; + + if (searchOption != null) { + questionList = getAllFilteredQuestions(currentUser, searchOption); + + } else { + questionList = getAllQuestions(currentUser); + } + + List<QuestionBean> questions = convert(currentUser, questionList); + + QuestionExportModel exportModel = new QuestionExportModel(); + + String exportData; + try { + exportData = Export.exportToString(exportModel, questions); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Error during export", e); + } + throw new CoselmarTechnicalException("Unable to export datas"); + } + + return renderDownload(IOUtils.toInputStream(exportData), "export-projects-result.csv", "text/csv"); + + } + //////////////////////////////////////////////////////////////////////////// /////////////////////// Internal Parts ///////////////////////////// @@ -1093,4 +1110,23 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { return fullIds; } + protected List<QuestionBean> convert(CoselmarUser currentUser, List<Question> questionList) { + List<QuestionBean> questions = new ArrayList<>(questionList.size()); + + for (Question question : questionList) { + 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); + } + return questions; + } + } diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index 3a50f5e..9a5eb16 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -73,7 +73,7 @@ POST /v1/admin/lucene/index AdminWebService.refreshLuceneInd # Export -GET /v1/export/questions QuestionsWebService.exportQuestions +POST /v1/export/questions QuestionsWebService.exportSearchedQuestions # Health diff --git a/coselmar-ui/src/main/webapp/js/coselmar-constants.js b/coselmar-ui/src/main/webapp/js/coselmar-constants.js index 566831a..b3894d6 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-constants.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-constants.js @@ -23,7 +23,18 @@ */ // DON'T FORGET TO EDIT ONE IN BUNDLE MODULE \\ -coselmarApp.constant('coselmar-config', { +coselmarApp.constant('coselmarConfig', { BASE_URL : "http://localhost:8081/services/v1", SUPPORTED_LOCALE : ["en", "fr"] +}); + +coselmarApp.config(function($sceDelegateProvider, coselmarConfig) { + $sceDelegateProvider.resourceUrlWhitelist([ + // Allow same origin resource loads. + 'self', + // Allow loading from our assets domain. Notice the difference between * and **. + coselmarConfig.BASE_URL+'/**' + ]); + console.log(coselmarConfig.BASE_URL+'/**'); + }); \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index fe038a7..d432d51 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -24,7 +24,7 @@ var coselmarControllers = angular.module('coselmarControllers', ['ui.bootstrap', 'ui.select', 'ui.bootstrap.tooltip', 'pascalprecht.translate', 'tmh.dynamicLocale']); // Controller when the main page/view loads -coselmarControllers.controller("HomeCtrl", ['$scope', '$http', '$location', '$route', '$routeParams', '$locale', '$translate', 'tmhDynamicLocale', 'userService', 'jwtHelper', 'coselmar-config', 'notify', +coselmarControllers.controller("HomeCtrl", ['$scope', '$http', '$location', '$route', '$routeParams', '$locale', '$translate', 'tmhDynamicLocale', 'userService', 'jwtHelper', 'coselmarConfig', 'notify', function ($scope, $http, $location, $route, $routeParams, $locale, $translate, tmhDynamicLocale, userService, jwtHelper, coselmarConfig, notify) { var jwtToken = localStorage.getItem('coselmar-jwt'); @@ -341,7 +341,7 @@ coselmarControllers.controller("NewDocumentCtrl", ['$scope', '$location', 'notif // Controller for single document View coselmarControllers.controller("DocumentViewCtrl", - ['$scope', '$route', '$location', '$routeParams', 'coselmar-config', 'notify', 'documentService', 'errorService', + ['$scope', '$route', '$location', '$routeParams', 'coselmarConfig', 'notify', 'documentService', 'errorService', function($scope, $route, $location, $routeParams, coselmarConfig, notify, documentService, errorService) { $scope.container = {baseUrl : coselmarConfig.BASE_URL}; @@ -905,24 +905,6 @@ coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routePara }; - $scope.downloadSearchResult = function() { - questionsService.exportSearchResult($scope.searchOptions, function(result) { - - var data = result.data; - - var hiddenElement = document.createElement('a'); - - var file = new Blob([data], {type: 'application/csv'}); - var fileURL = URL.createObjectURL(file); - - hiddenElement.href = fileURL; - hiddenElement.target = '_blank'; - hiddenElement.download = 'export-projects.csv'; - hiddenElement.click(); - }, errorService.defaultFailOnCall); - - }; - $scope.deleteQuestion = function(questionId) { questionsService.deleteQuestion(questionId, function(questions) { @@ -960,6 +942,14 @@ coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routePara return titles; }; + $scope.getExportQuestionsUrl = function() { + return questionsService.getExportQuestionsUrl(); + }; + + $scope.getToken = function() { + return localStorage.getItem('coselmar-jwt'); + } + }]); // Controller for Question View diff --git a/coselmar-ui/src/main/webapp/js/coselmar-general-services.js b/coselmar-ui/src/main/webapp/js/coselmar-general-services.js index def2091..c8b0f64 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-general-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-general-services.js @@ -22,7 +22,7 @@ * #L% */ -coselmarServices.factory('generalService', ['$http', 'coselmar-config', function($http, coselmarConfig){ +coselmarServices.factory('generalService', ['$http', 'coselmarConfig', function($http, coselmarConfig){ return new GeneralService($http, coselmarConfig); }]); 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 a8957a5..a466fe7 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js @@ -22,7 +22,7 @@ * #L% */ -coselmarServices.factory('questionsService', ['$resource', '$http', 'coselmar-config', function($resource, $http, coselmarConfig){ +coselmarServices.factory('questionsService', ['$resource', '$http', 'coselmarConfig', function($resource, $http, coselmarConfig){ return new Question($resource, $http, coselmarConfig); }]); @@ -139,4 +139,8 @@ function Question(resource, http, config){ questionResource.query(successFunction); }; + this.getExportQuestionsUrl = function() { + return exportURL; + }; + }; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index cd741f5..38e90a8 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -23,7 +23,7 @@ */ var coselmarServices = angular.module('coselmarServices', ['ngResource']); -coselmarServices.factory('documentService', ['$resource', 'coselmar-config', function($resource, coselmarConfig){ +coselmarServices.factory('documentService', ['$resource', 'coselmarConfig', function($resource, coselmarConfig){ return new Document($resource, coselmarConfig); }]); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-user-services.js b/coselmar-ui/src/main/webapp/js/coselmar-user-services.js index 1f18b3c..81415fb 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-user-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-user-services.js @@ -21,7 +21,7 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -coselmarServices.factory('userService', ['$resource', 'coselmar-config', function($resource, coselmarConfig){ +coselmarServices.factory('userService', ['$resource', 'coselmarConfig', function($resource, coselmarConfig){ return new User($resource, coselmarConfig); }]); diff --git a/coselmar-ui/src/main/webapp/views/questions/questions.html b/coselmar-ui/src/main/webapp/views/questions/questions.html index 3f580d9..9d0da29 100644 --- a/coselmar-ui/src/main/webapp/views/questions/questions.html +++ b/coselmar-ui/src/main/webapp/views/questions/questions.html @@ -106,9 +106,13 @@ </table> </div> <p ng-if="questions && questions.length == 0" translate="common.search.noResult" class="info"/> - <div ng-if="questions && questions.length > 0 && questions.length <= 20"> - <button type="button" class="btn btn-primary" ng-click="downloadSearchResult()"> - <span class="fa fa-download" aria-hidden="true"></span>{{ 'common.button.csvExport' | translate }}</button> + <div ng-if="questions && questions.length > 0" > + <form action="{{getExportQuestionsUrl()}}" method="post" target="_blank"> + <input type="hidden" name="searchOption" value="{{searchOptions}}" /> + <input type="hidden" name="token" value="{{getToken()}}" /> + <button type="submit" class="btn btn-primary"> + <span class="fa fa-download" aria-hidden="true"></span>{{ 'common.button.csvExport' | translate }}</button> + </form> </div> </div> </div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.