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.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@ -29,6 +32,15 @@ public class ResourcesRestController {
@Autowired
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}")
public List<SimpleResource> listResources(@PathVariable final String 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 ?")) {
$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;
alert("Resource deleted");
}, function errorCallback(res) {

View File

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