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 8575bb0b19cb411f8776f117bd57184a99dc2c64 Author: Yannick Martel <martel@©odelutin.com> Date: Mon Nov 17 20:20:02 2014 +0100 prepare users javascript services --- coselmar-bundle/pom.xml | 2 +- coselmar-persistence/pom.xml | 2 +- coselmar-rest/pom.xml | 2 +- .../{UserWebService.java => UsersWebService.java} | 4 +- coselmar-rest/src/main/resources/mapping | 7 ++ coselmar-ui/pom.xml | 2 +- coselmar-ui/src/main/webapp/index.html | 1 + .../src/main/webapp/js/coselmar-controllers.js | 67 +++++++++++++++++- .../src/main/webapp/js/coselmar-services.js | 20 +++--- .../src/main/webapp/js/coselmar-user-services.js | 82 ++++++++++++++++++++++ coselmar-ui/src/main/webapp/js/coselmar.js | 23 ++++-- .../webapp/views/{ => documents}/document.html | 0 .../webapp/views/{ => documents}/documents.html | 0 .../webapp/views/{ => documents}/newdocument.html | 0 .../src/main/webapp/views/users/newuser.html | 2 +- pom.xml | 4 +- 16 files changed, 194 insertions(+), 24 deletions(-) diff --git a/coselmar-bundle/pom.xml b/coselmar-bundle/pom.xml index 7955ac8..70fdc2b 100644 --- a/coselmar-bundle/pom.xml +++ b/coselmar-bundle/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>coselmar</artifactId> - <version>0.1</version> + <version>0.2-SNAPSHOT</version> </parent> <groupId>fr.ifremer.coselmar</groupId> diff --git a/coselmar-persistence/pom.xml b/coselmar-persistence/pom.xml index fd8a8aa..21faa60 100644 --- a/coselmar-persistence/pom.xml +++ b/coselmar-persistence/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>coselmar</artifactId> - <version>0.1</version> + <version>0.2-SNAPSHOT</version> </parent> <groupId>fr.ifremer.coselmar</groupId> diff --git a/coselmar-rest/pom.xml b/coselmar-rest/pom.xml index 402db18..b58962c 100644 --- a/coselmar-rest/pom.xml +++ b/coselmar-rest/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>coselmar</artifactId> - <version>0.1</version> + <version>0.2-SNAPSHOT</version> </parent> <groupId>fr.ifremer.coselmar</groupId> diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UserWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java similarity index 94% rename from coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UserWebService.java rename to coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java index 0005b1f..3add9f3 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UserWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java @@ -17,9 +17,9 @@ import static org.apache.commons.logging.LogFactory.getLog; /** * @author ymartel <martel@codelutin.com> */ -public class UserWebService extends CoselmarWebServiceSupport { +public class UsersWebService extends CoselmarWebServiceSupport { - private static final Log log = getLog(UserWebService.class); + private static final Log log = getLog(UsersWebService.class); public UserBean getUser(String userId) { diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index 603b956..d18f439 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -33,3 +33,10 @@ POST /v1/documents DocumentsWebService.addDocument PUT /v1/documents/{documentId} DocumentsWebService.saveDocument DELETE /v1/documents/{documentId} DocumentsWebService.deleteDocument +# Users Api + +GET /v1/users UsersWebService.getUsers +GET /v1/users/{userId} UsersWebService.getUser +POST /v1/users UsersWebService.addUser +DELETE /v1/users/{userId} UsersWebService.deleteUser + diff --git a/coselmar-ui/pom.xml b/coselmar-ui/pom.xml index 1c4f01f..f6a7134 100644 --- a/coselmar-ui/pom.xml +++ b/coselmar-ui/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>coselmar</artifactId> - <version>0.1</version> + <version>0.2-SNAPSHOT</version> </parent> <groupId>fr.ifremer.coselmar</groupId> diff --git a/coselmar-ui/src/main/webapp/index.html b/coselmar-ui/src/main/webapp/index.html index e0c9e5c..f7f222d 100644 --- a/coselmar-ui/src/main/webapp/index.html +++ b/coselmar-ui/src/main/webapp/index.html @@ -34,6 +34,7 @@ <script src="nuiton-js/bootstrap.js"></script> <script src="js/coselmar-controllers.js"></script> <script src="js/coselmar-services.js"></script> + <script src="js/coselmar-user-services.js"></script> <script src="js/coselmar.js"></script> </head> diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 02a3206..5e5a756 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -107,4 +107,69 @@ coselmarControllers.directive('ngFileModel', ['$parse', function ($parse) { }); } }; -}]); \ No newline at end of file +}]); + + +///////////////////////////////////////////////// +////////////// Users Part ///////////////////// +///////////////////////////////////////////////// + +// Controller for All User View +coselmarControllers.controller("UsersCtrl", ['$scope', '$route', '$routeParams', '$location', 'userService', function($scope, $route, $routeParams, $location, userService){ + + //manage keywords if given + $scope.searchKeywords = []; + var keywords = $routeParams.keywords; + if (Array.isArray(keywords)) { + $scope.searchKeywords = keywords; + } else if (keywords) { + $scope.searchKeywords.push(keywords); + } + + userService.getUsers($scope); + + $scope.deleteUser = function(userId){ + + userService.deleteUser(userId, $scope, function() { + // Go back to documents list + $route.reload(); + }); + }; + + $scope.searchUsers = function(){ + $location.search('keywords', $scope.searchKeywords); + } +}]); + + +// Controller for new user View +coselmarControllers.controller("NewUserCtrl", ['$scope', '$route', 'userService', function($scope, $route, userService){ + + $scope.createNewUser = function(){ +// var user = {'privacy':$scope.privacy, 'role':'expert'}; + + // Call service to create a new user + userService.createUser($scope.user, $scope, function() { + $location.path("/users"); + }); + + // Reload the page + $route.reload(); + }; +}]); + +// Controller for single document View +coselmarControllers.controller("UserViewCtrl", + ['$scope', '$route', '$location', 'userService', '$routeParams', function($scope, $route, $location, userService, $routeParams) { + + userService.getUser($routeParams.userId, $scope); + + $scope.deleteUser = function(userId){ + + documentService.deleteUser(documentId, $scope, function() { + // Go back to users list + $location.path("/users"); + }); + + }; +} ]); \ 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 e4c462b..ce2b0da 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -37,8 +37,8 @@ function Document(resource){ formData.append("uploadFile", file); formData.append("document", JSON.stringify(metadata)); // Save the document -// var docResource = resource('http://localhost:8081/services/v1/documents', null, { - var docResource = resource('v1/documents', null, { + var docResource = resource('http://localhost:8081/services/v1/documents', null, { +// var docResource = resource('v1/documents', null, { 'upload': { method:'POST', transformRequest: angular.identity, @@ -54,8 +54,8 @@ function Document(resource){ this.getDocument = function(id, scope){ // Load the document -// var docResource = resource('http://localhost:8081/services/v1/documents/:documentId', {documentId:'@documentId'}); - var docResource = resource('v1/documents/:documentId', {documentId:'@documentId'}); + var docResource = resource('http://localhost:8081/services/v1/documents/:documentId', {documentId:'@documentId'}); +// var docResource = resource('v1/documents/:documentId', {documentId:'@documentId'}); docResource.get({documentId:id}, function(document){ console.log(document); scope.document = document; @@ -65,15 +65,15 @@ function Document(resource){ this.deleteDocument = function(id, scope, successFunction){ // Load the document -// var docResource = resource('http://localhost:8081/services/v1/documents/:documentId', {documentId:'@id'}); - var docResource = resource('v1/documents/:documentId', {documentId:'@documentId'}); + var docResource = resource('http://localhost:8081/services/v1/documents/:documentId', {documentId:'@id'}); +// var docResource = resource('v1/documents/:documentId', {documentId:'@documentId'}); docResource.delete({documentId:id}, successFunction); } this.getDocumentFile = function(id, scope){ // Load the document - var docResource = resource('http://localhost:8081/services/v1/documents/:documentId/file', {documentId:'@documentId'}); -// var docResource = resource('v1/documents/:documentId/file', {documentId:'@documentId'}); +// var docResource = resource('http://localhost:8081/services/v1/documents/:documentId/file', {documentId:'@documentId'}); + var docResource = resource('v1/documents/:documentId/file', {documentId:'@documentId'}); docResource.get({documentId:id}, function(file){ // redirect to document page ? }); @@ -83,8 +83,8 @@ function Document(resource){ // Load all documents console.log("loading all documents"); -// var docResource = resource('http://localhost:8081/services/v1/documents', {searchKeywords : scope.searchKeywords}); - var docResource = resource('v1/documents', {searchKeywords : scope.searchKeywords}); + var docResource = resource('http://localhost:8081/services/v1/documents', {searchKeywords : scope.searchKeywords}); +// var docResource = resource('v1/documents', {searchKeywords : scope.searchKeywords}); docResource.query(function(documents){ scope.documents = documents; }, function(errorResult) { diff --git a/coselmar-ui/src/main/webapp/js/coselmar-user-services.js b/coselmar-ui/src/main/webapp/js/coselmar-user-services.js new file mode 100644 index 0000000..5ff11d0 --- /dev/null +++ b/coselmar-ui/src/main/webapp/js/coselmar-user-services.js @@ -0,0 +1,82 @@ +/* + * #%L + * Coselmar :: UI + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2014 Ifremer, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +coselmarServices.factory('userService', ['$resource', function($resource){ + return new User($resource); +}]); + +function User(resource){ + + var baseURL = "http://localhost:8081/services/v1/users"; + + this.resource = resource; +// this.baseURL = "v1/users"; + + this.createUser = function(user, scope, successFunction){ + +// var formData = new FormData(); +// formData.append("user", JSON.stringify(user)); + // Save the User + var userResource = resource(baseURL, {user:user}); +// var userResource = resource(baseURL, null, { +// 'save': { +// method:'POST', +// transformRequest: angular.identity, +// headers:{ +// 'Content-Type':undefined +// } +// } +// }); + userResource.save({user:user}, successFunction); + } + + this.getUser = function(id, scope){ + // Load the User + var userResource = resource(baseURL + '/:userId', {userId:'@userId'}); + userResource.get({userId:id}, function(user){ + scope.user = user; + }); + } + + this.deleteUser = function(id, scope, successFunction){ + + var userResource = resource(baseURL + '/:userId', {userId:'@id'}); + userResource.delete({userId:id}, successFunction); + } + + this.getUsers = function(scope){ + // Load all users + + var userResource = resource(baseURL, {searchKeywords : scope.searchKeywords}); + userResource.query(function(users){ + scope.users = users; + }, function(errorResult) { + // let's log errors + if(errorResult.status === 404) { + console.log("Service unreachable, deal it boy!"); + } else { + console.log("WTF ?!?"); + } + }); + } +}; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/js/coselmar.js b/coselmar-ui/src/main/webapp/js/coselmar.js index 70d0ad2..1a342e2 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar.js +++ b/coselmar-ui/src/main/webapp/js/coselmar.js @@ -24,17 +24,32 @@ var coselmarApp = angular.module("coselmarApp", ['ngRoute', 'ngResource', 'coselmarControllers', 'coselmarServices']); coselmarApp.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/documents', { + $routeProvider + //documents + .when('/documents', { controller : 'DocumentsCtrl', - templateUrl : 'views/documents.html' + templateUrl : 'views/documents/documents.html' }).when('/documents/new', { controller : 'NewDocumentCtrl', - templateUrl : 'views/newdocument.html' + templateUrl : 'views/documents/newdocument.html' }).when('/documents/:documentId', { controller : 'DocumentViewCtrl', - templateUrl : 'views/document.html' + templateUrl : 'views/documents/document.html' + + //users + }).when('/users', { + controller : 'UsersCtrl', + templateUrl : 'views/users/users.html' + + }).when('/users/new', { + controller : 'NewUserCtrl', + templateUrl : 'views/users/newuser.html' + + }).when('/users/:userId', { + controller : 'UserViewCtrl', + templateUrl : 'views/users/users.html' }).otherwise({ redirectTo: '/', diff --git a/coselmar-ui/src/main/webapp/views/document.html b/coselmar-ui/src/main/webapp/views/documents/document.html similarity index 100% rename from coselmar-ui/src/main/webapp/views/document.html rename to coselmar-ui/src/main/webapp/views/documents/document.html diff --git a/coselmar-ui/src/main/webapp/views/documents.html b/coselmar-ui/src/main/webapp/views/documents/documents.html similarity index 100% rename from coselmar-ui/src/main/webapp/views/documents.html rename to coselmar-ui/src/main/webapp/views/documents/documents.html diff --git a/coselmar-ui/src/main/webapp/views/newdocument.html b/coselmar-ui/src/main/webapp/views/documents/newdocument.html similarity index 100% rename from coselmar-ui/src/main/webapp/views/newdocument.html rename to coselmar-ui/src/main/webapp/views/documents/newdocument.html diff --git a/coselmar-ui/src/main/webapp/views/users/newuser.html b/coselmar-ui/src/main/webapp/views/users/newuser.html index 6a75c85..3fa8e87 100644 --- a/coselmar-ui/src/main/webapp/views/users/newuser.html +++ b/coselmar-ui/src/main/webapp/views/users/newuser.html @@ -22,7 +22,7 @@ <label class="col-md-4 control-label">FirstName</label> <div class="col-md-5"> - <input type="file" class="form-control" name="firstName" ng-model="user.firstName" required/> + <input type="text" class="form-control" name="firstName" ng-model="user.firstName" required/> </div> </div> diff --git a/pom.xml b/pom.xml index d74e758..a11ecaa 100644 --- a/pom.xml +++ b/pom.xml @@ -27,12 +27,12 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>codelutinpom</artifactId> - <version>1.5</version> + <version>1.6</version> </parent> <groupId>fr.ifremer</groupId> <artifactId>coselmar</artifactId> - <version>0.1</version> + <version>0.2-SNAPSHOT</version> <packaging>pom</packaging> <name>Coselmar</name> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.