first version of vocabularies UI
This commit is contained in:
parent
0d722526c0
commit
6e42765602
|
@ -10,6 +10,8 @@ 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.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Node;
|
||||
|
@ -19,6 +21,7 @@ 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;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -27,7 +30,6 @@ import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
|||
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyTermRepository;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/vocs")
|
||||
|
@ -39,6 +41,8 @@ public class VocabularyRestController extends AbstractDnetController {
|
|||
@Autowired
|
||||
private VocabularyTermRepository vocabularyTermRepository;
|
||||
|
||||
private static final Log log = LogFactory.getLog(VocabularyRestController.class);
|
||||
|
||||
@GetMapping("/")
|
||||
public List<Vocabulary> listVocs() {
|
||||
return vocabularyRepository.findAll()
|
||||
|
@ -54,12 +58,14 @@ public class VocabularyRestController extends AbstractDnetController {
|
|||
|
||||
@DeleteMapping("/{vocabulary}")
|
||||
public List<Vocabulary> deleteVocs(@PathVariable final String vocabulary) {
|
||||
log.info("Deleting vocabulary: " + vocabulary);
|
||||
vocabularyRepository.deleteById(vocabulary);
|
||||
return listVocs();
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public List<Vocabulary> saveVoc(@RequestBody final Vocabulary voc) {
|
||||
log.info("Saving vocabulary: " + voc);
|
||||
vocabularyRepository.save(voc);
|
||||
return listVocs();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Information Service</title>
|
||||
<link rel="stylesheet" href="common/css/bootstrap.cerulean.min.css" />
|
||||
<link rel="stylesheet" href="common/css/fontawesome-all.min.css" />
|
||||
</head>
|
||||
|
||||
<style>
|
||||
td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Information Service</h1>
|
||||
<hr />
|
||||
<ul>
|
||||
<li>
|
||||
<a href="vocabularies.html">Vocabulary Editor</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<script src="common/js/jquery.min.js"></script>
|
||||
<script src="common/js/popper.min.js"></script>
|
||||
<script src="common/js/bootstrap.min.js"></script>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,40 @@
|
|||
var app = angular.module('vocabularyApp', []);
|
||||
|
||||
app.controller('vocabularyController', function($scope, $http) {
|
||||
$scope.vocabularies = [];
|
||||
|
||||
$scope.reload = function() {
|
||||
$http.get('./api/vocs/?' + $.now()).then(function successCallback(res) {
|
||||
$scope.vocabularies = res.data;
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.newVocabulary = function(id, name, desc) {
|
||||
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
||||
$http.post('./api/vocs/?' + $.now(), {
|
||||
'id' : id,
|
||||
'name' : name,
|
||||
'description' : desc
|
||||
}).then(function successCallback(res) {
|
||||
$scope.vocabularies = res.data;
|
||||
alert("New vocabulary created");
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteVocabulary = function(id) {
|
||||
if (confirm("Are you sure ?")) {
|
||||
$http.delete('./api/vocs/' + id).then(function successCallback(res) {
|
||||
$scope.vocabularies = res.data;
|
||||
alert("Vocabulary deleted");
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.reload();
|
||||
});
|
|
@ -0,0 +1,97 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Information Service - Vocabularies</title>
|
||||
<link rel="stylesheet" href="common/css/bootstrap.cerulean.min.css" />
|
||||
<link rel="stylesheet" href="common/css/fontawesome-all.min.css" />
|
||||
</head>
|
||||
|
||||
<style>
|
||||
td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body ng-app="vocabularyApp" ng-controller="vocabularyController">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Information Service - Vocabularies</h1>
|
||||
<hr />
|
||||
<p>
|
||||
<a href="javascript:void(0)" data-toggle="modal" data-target="#newVocabularyModal">create a new vocabulary</a>
|
||||
</p>
|
||||
<p ng-show="vocabularies.length > 0">
|
||||
<input type="text" class="form-control form-control-sm" ng-model="vocFilter" placeholder="Filter..."/>
|
||||
</p>
|
||||
<p>
|
||||
<span class="text-muted"><b>Number of vocabularies:</b> {{(vocabularies | filter:vocFilter).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="(vocabularies|filter:vocFilter).length == 0">
|
||||
<td colspan="4" class="text-muted">no vocabularies</td>
|
||||
</tr>
|
||||
<tr ng-repeat="v in vocabularies|filter:vocFilter">
|
||||
<th>{{v.id}}</th>
|
||||
<td>{{v.name}}</td>
|
||||
<td>{{v.description}}</td>
|
||||
<td align="right"><button type="button" class="btn btn-sm btn-danger" ng-click="deleteVocabulary(v.id)">delete</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modals -->
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="newVocabularyModal">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">New vocabulary</h4>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label>ID</label>
|
||||
<input type="text" class="form-control" ng-model="newVocId" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" ng-model="newVocName" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<textarea class="form-control" ng-model="newVocDesc"></textarea>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="newVocabulary(newVocId, newVocName, newVocDesc)">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<script src="common/js/jquery.min.js"></script>
|
||||
<script src="common/js/popper.min.js"></script>
|
||||
<script src="common/js/bootstrap.min.js"></script>
|
||||
<script src="common/js/angular.min.js"></script>
|
||||
|
||||
<script src="js/vocabulary.js"></script>
|
||||
</html>
|
|
@ -47,4 +47,9 @@ public class Vocabulary implements Serializable {
|
|||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Vocabulary [id=%s, name=%s, description=%s]", id, name, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue