This is an automated email from the git hooks/post-receive script. New commit to branch feature/6011-delete-document in repository coselmar. See http://git.codelutin.com/coselmar.git commit 25d72d37ceb301986eda59b3a22310aabb9efdec Author: Yannick Martel <martel@©odelutin.com> Date: Fri Nov 7 18:52:33 2014 +0100 add remove function for document --- .../coselmar/services/v1/DocumentsWebService.java | 2 ++ .../src/main/webapp/js/coselmar-controllers.js | 30 +++++++++++++++++++--- .../src/main/webapp/js/coselmar-services.js | 23 ++++++++++++----- coselmar-ui/src/main/webapp/views/document.html | 1 + coselmar-ui/src/main/webapp/views/documents.html | 6 +++++ 5 files changed, 52 insertions(+), 10 deletions(-) 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 91ca774..4489174 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 @@ -151,6 +151,8 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { Document document = getDocumentDao().forTopiaIdEquals(fullId).findUnique(); getDocumentDao().delete(document); + + commit(); } } diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index f6377a2..0fe4ced 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -4,16 +4,26 @@ var coselmarControllers = angular.module('coselmarControllers', []); coselmarControllers.controller("HomeCtrl", ['$scope', function($scope){ }]); // Controller for All Documents View -coselmarControllers.controller("DocumentsCtrl", ['$scope','documentService', function($scope, documentService){ +coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', 'documentService', function($scope, $route, documentService){ documentService.getDocuments($scope); + + $scope.deleteDocument = function(documentId){ + + // Call service to create a new document + documentService.deleteDocument(documentId, $scope, function() { + // Go back to documents list + $route.reload(); + }); + + // Reload the page +// $route.reload(); + }; }]); // Controller for new document View coselmarControllers.controller("NewDocumentCtrl", ['$scope', '$route', 'documentService', function($scope, $route, documentService){ - $scope.privacy="public"; - $scope.createNewDocument = function(){ var documentMetadata = {'privacy':$scope.privacy, 'keywords':$scope.keywords}; @@ -26,8 +36,20 @@ coselmarControllers.controller("NewDocumentCtrl", ['$scope', '$route', 'document }]); // Controller for single document View -coselmarControllers.controller("DocumentViewCtrl", [ '$scope','documentService', '$routeParams', function($scope, documentService, $routeParams) { +coselmarControllers.controller("DocumentViewCtrl", + ['$scope', '$route', '$location', 'documentService', '$routeParams', function($scope, $route, $location, documentService, $routeParams) { + documentService.getDocument($routeParams.documentId, $scope); + + $scope.deleteDocument = function(documentId){ + + // Call service to create a new document + var toto = documentService.deleteDocument(documentId, $scope, function() { + // Go back to documents list + $location.path("/documents"); + }); + + }; } ]); // Controller for document file download diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index d305d8d..3ff7fca 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -14,8 +14,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, @@ -31,14 +31,25 @@ 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; }); } + 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'}); +// docResource.delete({documentId:id}, function(){ +// route.reload(); +// }); + 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'}); @@ -51,8 +62,8 @@ function Document(resource){ this.getDocuments = function(scope){ // Load all documents console.log("loading all documents"); -// var docResource = resource('http://localhost:8081/services/v1/documents'); - var docResource = resource('v1/documents'); + var docResource = resource('http://localhost:8081/services/v1/documents'); +// var docResource = resource('v1/documents'); docResource.query(function(documents){ scope.documents = documents; }, function(errorResult) { diff --git a/coselmar-ui/src/main/webapp/views/document.html b/coselmar-ui/src/main/webapp/views/document.html index 7a80cc8..29f497d 100644 --- a/coselmar-ui/src/main/webapp/views/document.html +++ b/coselmar-ui/src/main/webapp/views/document.html @@ -34,6 +34,7 @@ </table> <div style="padding-left: 200px"> <a href="/v1/documents/{{document.id}}/file" class="btn btn-primary">Download</a> + <a class="btn btn-danger" ng-click="deleteDocument(document.id)">Delete</a> </div> </div> </div> \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/views/documents.html b/coselmar-ui/src/main/webapp/views/documents.html index 7157823..0c1426f 100644 --- a/coselmar-ui/src/main/webapp/views/documents.html +++ b/coselmar-ui/src/main/webapp/views/documents.html @@ -13,13 +13,19 @@ <table class="table"> <tr> <th>Name</th> + <th>Owner</th> <th>Privacy</th> <th>Keywords</th> + <th>Deposit Date</th> + <th></th> </tr> <tr ng-repeat="document in documents"> <td><a href="#/documents/{{document.id}}">{{document.name}}</a></td> + <td>{{document.ownerName}}</td> <td>{{document.privacy}}</td> <td>{{document.keywords}}</td> + <td>{{document.depositDate}}</td> + <td><a class="btn btn-danger" ng-click="deleteDocument(document.id)">Delete</a></td> </tr> </table> </div> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.