This is an automated email from the git hooks/post-receive script. New commit to branch feature/importFavoriteList in repository pollen. See http://git.chorem.org/pollen.git commit 95ccc6238dae90d8ccf736b9d98cdac0ac9113f0 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Aug 20 12:33:00 2014 +0200 add import favorite list from 'csv' file --- .../chorem/pollen/rest/api/v1/FavoriteListApi.java | 5 ++-- .../pollen/rest/api/v1/PollenResourceApi.java | 1 + pollen-rest-api/src/main/resources/mapping | 1 + pollen-ui-angular/src/main/webapp/js/directives.js | 33 ++++++++++++++++++++++ pollen-ui-angular/src/main/webapp/js/services.js | 8 ++++++ pollen-ui-angular/src/main/webapp/less/style.less | 4 +++ .../main/webapp/partials/favoriteList-edit.html | 6 ++++ 7 files changed, 56 insertions(+), 2 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java index 8adb776..23e415d 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java @@ -35,6 +35,7 @@ import org.chorem.pollen.services.service.FavoriteListImportException; import org.chorem.pollen.services.service.FavoriteListService; import org.chorem.pollen.services.service.InvalidFormException; import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.call.UploadFile; import java.io.File; @@ -80,9 +81,9 @@ public class FavoriteListApi extends WebMotionController { } - public void importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, File csvFile) throws FavoriteListImportException { + public void importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, UploadFile csvFile) throws FavoriteListImportException { - favoriteListService.importFavoriteListMembersFromCsv(favoriteListId.getEntityId(), csvFile); + favoriteListService.importFavoriteListMembersFromCsv(favoriteListId.getEntityId(), csvFile.getFile()); } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java index db7dc0e..734b8de 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java @@ -19,6 +19,7 @@ import java.io.IOException; * Created on 10/07/14. * * @author dralagen + * @since 2.0 */ public class PollenResourceApi extends WebMotionController { diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index d0dbfd1..c17b4c7 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -42,6 +42,7 @@ org.chorem.pollen.services.service.security.PollenInvalidPermissionException org.chorem.pollen.services.service.security.PollenInvalidEmailActivationTokenException ErrorAction.on403 org.chorem.pollen.services.service.security.PollenInvalidPasswordException ErrorAction.on400Form org.chorem.pollen.services.service.InvalidFormException ErrorAction.on400Form +org.chorem.pollen.services.service.FavoriteListImportException ErrorAction.on400Form org.nuiton.topia.persistence.TopiaNoResultException ErrorAction.on404 org.chorem.pollen.services.service.InvalidEntityLinkException ErrorAction.on404 diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index 1e7bfe1..2c14179 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -453,6 +453,7 @@ angular.module('pollenDirective', []) scope.ngModel.data = conf.restURL+'/resources/'+response.id; }); }; + console.log(changeEvent.target.files[0]); reader.readAsDataURL( changeEvent.target.files[0] ); }); @@ -461,6 +462,38 @@ angular.module('pollenDirective', []) }]) ////////////////////////////////////// +///// IMPORT CSV ///// +////////////////////////////////////// + + .directive("importCsv", ['FavoriteList', '$route', function (FavoriteList, $route) { + return { + restrict : "E", + scope: { + fvId: "=" + }, + template: + '<form>' + + '<input type="file" name="csvFile"/>' + + '<button class="btn btn-primary" type="submit"><span class="fa fa-download"></span> {{ \'action.favoriteList.importCSV\' | translate }}</button>' + + '</form>', + link: function (scope, element) { + element.find('button').bind("click", function (event) { + var reader = new FileReader(); + reader.onload = function () { + var formData = new FormData(element[0].firstChild); + FavoriteList.importcsv({favoriteListId: scope.fvId}, formData, function (data) { + $route.reload(); + }, function (error) { + console.log(error); + }); + }; + reader.readAsText(element.find('input[type=file]')[0].files[0]); + }); + } + } + }]) + +////////////////////////////////////// ///// PRINT RESOURCE ///// ////////////////////////////////////// diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index de2714b..51d46ff 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -313,6 +313,14 @@ angular.module('pollenServices', ['ngResource']) transformRequest: function (data) { return transformParam(data); } + }, + 'importcsv': { + method:'POST', + url: conf.restURL + '/favoriteLists/:favoriteListId/importCsv', + transformRequest: angular.identity, + headers:{ + 'Content-Type':undefined + } } }) }]) diff --git a/pollen-ui-angular/src/main/webapp/less/style.less b/pollen-ui-angular/src/main/webapp/less/style.less index 666903c..bb8f3eb 100644 --- a/pollen-ui-angular/src/main/webapp/less/style.less +++ b/pollen-ui-angular/src/main/webapp/less/style.less @@ -485,6 +485,10 @@ a { &.action { width:@width-action; } + + input[type=file] { + display: inline-block; + } } } diff --git a/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html b/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html index d1b4d54..59b1b8b 100644 --- a/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html +++ b/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html @@ -70,6 +70,12 @@ <button class="btn btn-danger" ng-click="deleteFavoriteList();"><span class="fa fa-trash-o"></span> {{ 'action.favoriteList.delete' | translate }} </button> </th> </tr> + + <tr ng-if="data.favoriteList.id"> + <th colspan="3"> + <import-csv fv-id="data.favoriteList.id"></import-csv> + </th> + </tr> </table> <div class="text-right"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.