This commit is contained in:
Michele Artini 2022-11-17 15:21:40 +01:00
parent 582c198cc0
commit bf7962603f
3 changed files with 31 additions and 27 deletions

View File

@ -8,7 +8,10 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -29,6 +32,15 @@ public class ResourcesRestController {
@Autowired @Autowired
private SimpleResourceRepository simpleResourceRepository; private SimpleResourceRepository simpleResourceRepository;
private static final Log log = LogFactory.getLog(ResourcesRestController.class);
@DeleteMapping("/{type}/{id}")
public List<SimpleResource> deleteResources(@PathVariable final String type, @PathVariable final String id) {
log.info("Deleting rewsource: " + id);
simpleResourceRepository.deleteById(id);
return listResources(type);
}
@GetMapping("/{type}") @GetMapping("/{type}")
public List<SimpleResource> listResources(@PathVariable final String type) { public List<SimpleResource> listResources(@PathVariable final String type) {
return simpleResourceRepository.findByType(type) return simpleResourceRepository.findByType(type)

View File

@ -51,9 +51,9 @@ app.controller('resourcesController', function($scope, $http) {
}); });
}; };
$scope.deleteResource = function(id) { $scope.deleteResource = function(r) {
if (confirm("Are you sure ?")) { if (confirm("Are you sure ?")) {
$http.delete('./api/resources/' + encodeURIComponent(id) + '?' + $.now()).then(function successCallback(res) { $http.delete('./api/resources/' + encodeURIComponent(r.type) + '/' + encodeURIComponent(r.id) + '?' + $.now()).then(function successCallback(res) {
$scope.resources = res.data; $scope.resources = res.data;
alert("Resource deleted"); alert("Resource deleted");
}, function errorCallback(res) { }, function errorCallback(res) {

View File

@ -22,30 +22,22 @@
<p> <p>
<span class="text-muted"><b>Number of resources:</b> {{(resources | filter:resFilter).length}}</span> <span class="text-muted"><b>Number of resources:</b> {{(resources | filter:resFilter).length}}</span>
</p> </p>
<table class="table table-sm table-striped">
<thead> <div class="card mb-4" ng-repeat="r in resources|filter:resFilter">
<tr> <div class="card-body small">
<th style="width: 25%">ID</th> <span class="badge badge-primary float-right">{{r.contentType}}</span>
<th style="width: 25%">Name</th> <h5 class="card-title" title="{{r.id}}">{{r.name}}</h5>
<th>Description</th> <p class="card-text">{{r.description}}</p>
<th></th> <p class="text-muted small">
</tr> <b>Id:</b> {{r.id}}<br />
</thead> <b>Creation date:</b> {{r.creationDate}}<br />
<tbody> <b>Modification date:</b> {{r.modificationDate}}
<tr ng-show="(resources|filter:resFilter).length == 0"> </p>
<td colspan="4" class="text-muted">no resources</td> <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editResourceModal" ng-click="prepareEditRes(r)" >edit</button>
</tr> <button type="button" class="btn btn-sm btn-danger" ng-click="deleteResource(r)">delete</button>
<tr ng-repeat="r in resources|filter:resFilter"> </div>
<th>{{r.id}}</th> </div>
<td>{{r.name}}</td>
<td>{{r.description}}</td>
<td align="right">
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editResourceModal" ng-click="prepareEditRes(r)" >edit</button>
<button type="button" class="btn btn-sm btn-danger" ng-click="deleteResource(r.id)">delete</button>
</td>
</tr>
</tbody>
</table>
</div> </div>
</div> </div>
</div> </div>
@ -69,7 +61,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Type</label> <label>Type</label>
<input type="text" readonly class="form-control-plaintext" th-value="${type.id}" /> <input type="text" readonly class="form-control-plaintext" ng-model="tmpRes.type" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Name</label> <label>Name</label>