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 0bbe39e31305599358db8ee1cf8c0b07957d4d8d Author: Yannick Martel <martel@©odelutin.com> Date: Tue Dec 8 17:39:38 2015 +0100 fixes #7648 finish projects export --- .../coselmar/beans/QuestionExportModel.java | 30 ++++++++++----------- .../coselmar/services/v1/QuestionsWebService.java | 3 +++ .../i18n/coselmar-services_en_GB.properties | 11 +++++++- .../i18n/coselmar-services_fr_FR.properties | 11 +++++++- coselmar-ui/src/main/webapp/i18n/en.js | 1 + coselmar-ui/src/main/webapp/i18n/fr.js | 1 + .../src/main/webapp/js/coselmar-controllers.js | 17 ++++++++++++ .../main/webapp/js/coselmar-questions-services.js | 31 ++++++++++++++++++---- .../src/main/webapp/views/questions/questions.html | 4 +++ 9 files changed, 87 insertions(+), 22 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionExportModel.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionExportModel.java index 7b986e8..ac37bc0 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionExportModel.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionExportModel.java @@ -1,16 +1,12 @@ package fr.ifremer.coselmar.beans; import com.google.common.base.Joiner; -import fr.ifremer.coselmar.persistence.entity.Question; -import fr.ifremer.coselmar.persistence.entity.Status; import org.nuiton.csv.Common; -import org.nuiton.csv.ExportModel; -import org.nuiton.csv.ExportableColumn; import org.nuiton.csv.ValueFormatter; import org.nuiton.csv.ext.AbstractExportModel; import org.nuiton.util.DateUtil; -import java.util.List; +import java.util.Collection; import static org.nuiton.i18n.I18n.t; @@ -19,16 +15,20 @@ import static org.nuiton.i18n.I18n.t; */ public class QuestionExportModel extends AbstractExportModel<QuestionBean> { - protected static final ValueFormatter<List<String>> LIST_STRING_FORMATTER = new ValueFormatter<List<String>>() { + protected static final ValueFormatter<Collection<String>> COLLECTION_STRING_FORMATTER = new ValueFormatter<Collection<String>>() { @Override - public String format(List<String> value) { - return Joiner.on(",").join(value); + public String format(Collection<String> value) { + String result = ""; + if (value != null && !value.isEmpty()) { + result = Joiner.on(",").join(value); + } + return result; } }; - protected static final ValueFormatter<List<Object>> LIST_COUNTER_VALUE_FORMATTER = new ValueFormatter<List<Object>>() { + protected static final ValueFormatter<Collection<Object>> COLLECTION_COUNTER_VALUE_FORMATTER = new ValueFormatter<Collection<Object>>() { @Override - public String format(List<Object> value) { + public String format(Collection<Object> value) { String result = "0"; if (value != null) { result = String.valueOf(value.size()); @@ -44,12 +44,12 @@ public class QuestionExportModel extends AbstractExportModel<QuestionBean> { modelBuilder.newColumnForExport(t("question.metadata.title"), QuestionBean.PROPERTY_TITLE); modelBuilder.newColumnForExport(t("question.metadata.submissionDate"), QuestionBean.PROPERTY_SUBMISSION_DATE, dateFormatter); - modelBuilder.newColumnForExport(t("question.metadata.status"), QuestionBean.PROPERTY_STATUS, new Common.EnumByNameParserFormatter(Status.class)); - modelBuilder.newColumnForExport(t("question.metadata.themes"), QuestionBean.PROPERTY_THEMES, LIST_STRING_FORMATTER); + modelBuilder.newColumnForExport(t("question.metadata.status"), QuestionBean.PROPERTY_STATUS); + modelBuilder.newColumnForExport(t("question.metadata.themes"), QuestionBean.PROPERTY_THEMES, COLLECTION_STRING_FORMATTER); modelBuilder.newColumnForExport(t("question.metadata.deadline"), QuestionBean.PROPERTY_DEADLINE, dateFormatter); - modelBuilder.newColumnForExport(t("question.metadata.participants"), QuestionBean.PROPERTY_PARTICIPANTS, LIST_COUNTER_VALUE_FORMATTER); - modelBuilder.newColumnForExport(t("question.metadata.clients"), QuestionBean.PROPERTY_CLIENTS, LIST_COUNTER_VALUE_FORMATTER); - modelBuilder.newColumnForExport(t("question.metadata.relatedDocuments"), QuestionBean.PROPERTY_RELATED_DOCUMENTS, LIST_COUNTER_VALUE_FORMATTER); + modelBuilder.newColumnForExport(t("question.metadata.participants"), QuestionBean.PROPERTY_PARTICIPANTS, COLLECTION_COUNTER_VALUE_FORMATTER); + modelBuilder.newColumnForExport(t("question.metadata.clients"), QuestionBean.PROPERTY_CLIENTS, COLLECTION_COUNTER_VALUE_FORMATTER); + modelBuilder.newColumnForExport(t("question.metadata.relatedDocuments"), QuestionBean.PROPERTY_RELATED_DOCUMENTS, COLLECTION_COUNTER_VALUE_FORMATTER); } } 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 e5106aa..75ef937 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 @@ -837,6 +837,9 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { 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"); } diff --git a/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties b/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties index edf8993..01ee9f0 100644 --- a/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties +++ b/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties @@ -1,3 +1,12 @@ coselmar.service.mail.UserAccountCreatedMail.subject=[Coselmar] Account creation %s coselmar.service.mail.PasswordChangedMail.subject=[Coselmar] Password has been changed -coselmar.service.mail.LostPasswordMail.subject=[Coselmar] New password \ No newline at end of file +coselmar.service.mail.LostPasswordMail.subject=[Coselmar] New password + +question.metadata.title=Title +question.metadata.themes=Themes +question.metadata.submissionDate=Submission date +question.metadata.deadline=Deadline +question.metadata.status=Status +question.metadata.clients=Clients +question.metadata.relatedDocuments=Related documents +question.metadata.participants=Participants \ No newline at end of file diff --git a/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties b/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties index 04f2dbd..8b48da6 100644 --- a/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties +++ b/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties @@ -1,3 +1,12 @@ coselmar.service.mail.UserAccountCreatedMail.subject=[Coselmar] Création du compte %s coselmar.service.mail.PasswordChangedMail.subject=[Coselmar] Mot de passe modifié -coselmar.service.mail.LostPasswordMail.subject=[Coselmar] Nouveau mot de passe \ No newline at end of file +coselmar.service.mail.LostPasswordMail.subject=[Coselmar] Nouveau mot de passe + +question.metadata.title=Titre +question.metadata.themes=Thèmes +question.metadata.submissionDate=Date de soumission +question.metadata.deadline=Date limite +question.metadata.status=Status +question.metadata.clients=Clients +question.metadata.relatedDocuments=Documents associés +question.metadata.participants=Participants \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/i18n/en.js b/coselmar-ui/src/main/webapp/i18n/en.js index 3a61d04..7480e48 100644 --- a/coselmar-ui/src/main/webapp/i18n/en.js +++ b/coselmar-ui/src/main/webapp/i18n/en.js @@ -295,6 +295,7 @@ var translateEN = { "common.button.search" : "Search", "common.button.advanceSearch" : "Advance search", "common.button.simpleSearch" : "Simple search", +"common.button.csvExport" : "Export results as CSV", "common.message.missingMandatoryFields" : "Some mandatory field (*) have not been filled.", "common.message.notYetAvailable" : "Not yet available.", "common.message.mandatoryFieldsInfo" : "Field with <strong><big>*</big></strong> are mandatory.", diff --git a/coselmar-ui/src/main/webapp/i18n/fr.js b/coselmar-ui/src/main/webapp/i18n/fr.js index 0d6ede6..135a684 100644 --- a/coselmar-ui/src/main/webapp/i18n/fr.js +++ b/coselmar-ui/src/main/webapp/i18n/fr.js @@ -295,6 +295,7 @@ var translateFR = { "common.button.search" : "Rechercher", "common.button.advanceSearch" : "Recherche avancée", "common.button.simpleSearch" : "Recherche simple", +"common.button.csvExport" : "Exporter les résultats en CSV", "common.message.missingMandatoryFields" : "Certains champs obligatoires (*) n'ont pas été remplis.", "common.message.notYetAvailable" : "Pas encore disponible.", "common.message.mandatoryFieldsInfo" : "Les champs avec un <strong><big>*</big></strong> sont obligatoires.", diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 4af43f9..b690efe 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -851,6 +851,23 @@ 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) { 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 f8d64d6..a8957a5 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js @@ -22,15 +22,16 @@ * #L% */ -coselmarServices.factory('questionsService', ['$resource', 'coselmar-config', function($resource, coselmarConfig){ - return new Question($resource, coselmarConfig); +coselmarServices.factory('questionsService', ['$resource', '$http', 'coselmar-config', function($resource, $http, coselmarConfig){ + return new Question($resource, $http, coselmarConfig); }]); -function Question(resource, config){ +function Question(resource, http, config){ this.resource = resource; var baseURL = config.BASE_URL + "/questions"; + var exportURL = config.BASE_URL + "/export/questions"; var usersURL = config.BASE_URL + "/users"; this.saveQuestion = function(question, successFunction, failFunction){ @@ -61,8 +62,8 @@ function Question(resource, config){ this.getQuestions = function(searchOptions, successFunction, failFunction) { if (searchOptions.privacy - && searchOptions.privacy.toUpperCase() != "private" - && searchOptions.privacy.toUpperCase() != "public" ) { + && searchOptions.privacy.toUpperCase() != "PRIVATE" + && searchOptions.privacy.toUpperCase() != "PUBLIC" ) { searchOptions.privacy = undefined; } @@ -78,6 +79,26 @@ function Question(resource, config){ questionResource.query().$promise.then(successFunction, failFunction); }; + this.exportSearchResult = function(searchOptions, successFunction, failFunction) { + + 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; + } + + http.get(exportURL, {params: {'searchOption' : searchOptions}}).then(successFunction, failFunction); + + }; + this.getPublicQuestions = function(successFunction, failFunction) { var questionResource = resource(baseURL + "/public"); diff --git a/coselmar-ui/src/main/webapp/views/questions/questions.html b/coselmar-ui/src/main/webapp/views/questions/questions.html index 895198f..cf1fdea 100644 --- a/coselmar-ui/src/main/webapp/views/questions/questions.html +++ b/coselmar-ui/src/main/webapp/views/questions/questions.html @@ -106,5 +106,9 @@ </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> </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>.