This commit is contained in:
parent
3905cf3c3f
commit
45673b832c
|
@ -23,11 +23,13 @@ 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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
||||
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
||||
import eu.dnetlib.is.vocabulary.model.VocabularyTermPK;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyTermRepository;
|
||||
|
||||
|
@ -52,8 +54,8 @@ public class VocabularyRestController extends AbstractDnetController {
|
|||
}
|
||||
|
||||
@GetMapping("/{vocabulary}")
|
||||
public Iterable<VocabularyTerm> listVocs(@PathVariable final String vocabulary) {
|
||||
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
|
||||
public Vocabulary getVoc(@PathVariable final String vocabulary) {
|
||||
return vocabularyRepository.getById(vocabulary);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{vocabulary}")
|
||||
|
@ -110,4 +112,25 @@ public class VocabularyRestController extends AbstractDnetController {
|
|||
return voc;
|
||||
}
|
||||
|
||||
@GetMapping("/{vocabulary}/terms")
|
||||
public Iterable<VocabularyTerm> listTerms(@PathVariable final String vocabulary) {
|
||||
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
|
||||
}
|
||||
|
||||
@PostMapping("/{vocabulary}/terms")
|
||||
public Iterable<VocabularyTerm> saveTerm(@PathVariable final String vocabulary, @RequestParam final VocabularyTerm term) {
|
||||
term.setVocabulary(vocabulary);
|
||||
vocabularyTermRepository.save(term);
|
||||
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{vocabulary}/terms/{termId}")
|
||||
public Iterable<VocabularyTerm> listTerms(@PathVariable final String vocabulary, @PathVariable final String term) {
|
||||
final VocabularyTermPK pk = new VocabularyTermPK();
|
||||
pk.setCode(term);
|
||||
pk.setVocabulary(vocabulary);
|
||||
vocabularyTermRepository.deleteById(pk);
|
||||
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,28 @@
|
|||
package eu.dnetlib.is.vocabulary;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
||||
|
||||
@Controller
|
||||
public class VocabularyUIController {
|
||||
|
||||
@Autowired
|
||||
private VocabularyRepository vocabularyRepository;
|
||||
|
||||
@GetMapping("/vocabularyEditor")
|
||||
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) {
|
||||
map.put("vocId", id);
|
||||
|
||||
final Vocabulary voc = vocabularyRepository.getById(id);
|
||||
|
||||
map.put("vocId", voc.getId());
|
||||
map.put("vocName", voc.getName());
|
||||
map.put("vocDesc", voc.getDescription());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ app.controller('vocabularyController', function($scope, $http, $location) {
|
|||
$scope.vocId = vocId();
|
||||
|
||||
$scope.reload = function() {
|
||||
$http.get('./api/vocs/'+ encodeURIComponent($scope.vocId) + '?' + $.now()).then(function successCallback(res) {
|
||||
$http.get('./api/vocs/'+ encodeURIComponent($scope.vocId) + '/terms?' + $.now()).then(function successCallback(res) {
|
||||
$scope.terms = res.data;
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
|
|
|
@ -24,8 +24,13 @@
|
|||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Information Service - Vocabulary {{vocId}}</h1>
|
||||
<hr />
|
||||
<h1>Information Service - Vocabulary Editor</h1>
|
||||
|
||||
<p>
|
||||
<b>ID: </b><span th:text="${vocId}"></span><br />
|
||||
<b>Name: </b><span th:text="${vocName}"></span><br />
|
||||
<b>Description: </b><span th:text="${vocDesc}"></span>
|
||||
</p>
|
||||
|
||||
<p ng-show="terms.length > 0">
|
||||
<input type="text" class="form-control form-control-sm" ng-model="termFilter" placeholder="Filter..."/>
|
||||
|
@ -33,23 +38,26 @@
|
|||
<p>
|
||||
<span class="text-muted"><b>Number of terms:</b> {{(terms | filter:termFilter).length}}</span>
|
||||
</p>
|
||||
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 25%">Code</th>
|
||||
<th style="width: 25%">English Name</th>
|
||||
<th style="width: 25%">Native Name</th>
|
||||
<th style="width: 20%">English Name</th>
|
||||
<th style="width: 20%">Native Name</th>
|
||||
<th style="width: 10%">Synonyms</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-show="(terms|filter:termFilter).length == 0">
|
||||
<td colspan="4" class="text-muted">no terms</td>
|
||||
<td colspan="5" class="text-muted">no terms</td>
|
||||
</tr>
|
||||
<tr ng-repeat="t in terms|filter:termFilter">
|
||||
<th>{{t.code}}</th>
|
||||
<td>{{t.englishName}}</td>
|
||||
<td>{{t.nativeName}}</td>
|
||||
<td>{{t.synonyms.length}} synonym(s)</td>
|
||||
<td align="right"><button type="button" class="btn btn-sm btn-danger" ng-click="deleteTerm(t.id)">delete</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in New Issue