This commit is contained in:
Michele Artini 2022-06-21 09:55:39 +02:00
parent 3905cf3c3f
commit 45673b832c
4 changed files with 54 additions and 10 deletions

View File

@ -23,11 +23,13 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.common.controller.AbstractDnetController; import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.is.vocabulary.model.Vocabulary; import eu.dnetlib.is.vocabulary.model.Vocabulary;
import eu.dnetlib.is.vocabulary.model.VocabularyTerm; 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.VocabularyRepository;
import eu.dnetlib.is.vocabulary.repository.VocabularyTermRepository; import eu.dnetlib.is.vocabulary.repository.VocabularyTermRepository;
@ -52,8 +54,8 @@ public class VocabularyRestController extends AbstractDnetController {
} }
@GetMapping("/{vocabulary}") @GetMapping("/{vocabulary}")
public Iterable<VocabularyTerm> listVocs(@PathVariable final String vocabulary) { public Vocabulary getVoc(@PathVariable final String vocabulary) {
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary); return vocabularyRepository.getById(vocabulary);
} }
@DeleteMapping("/{vocabulary}") @DeleteMapping("/{vocabulary}")
@ -110,4 +112,25 @@ public class VocabularyRestController extends AbstractDnetController {
return voc; 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);
}
} }

View File

@ -1,15 +1,28 @@
package eu.dnetlib.is.vocabulary; package eu.dnetlib.is.vocabulary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import eu.dnetlib.is.vocabulary.model.Vocabulary;
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
@Controller @Controller
public class VocabularyUIController { public class VocabularyUIController {
@Autowired
private VocabularyRepository vocabularyRepository;
@GetMapping("/vocabularyEditor") @GetMapping("/vocabularyEditor")
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) { 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());
} }
} }

View File

@ -5,7 +5,7 @@ app.controller('vocabularyController', function($scope, $http, $location) {
$scope.vocId = vocId(); $scope.vocId = vocId();
$scope.reload = function() { $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; $scope.terms = res.data;
}, function errorCallback(res) { }, function errorCallback(res) {
alert('ERROR: ' + res.data.message); alert('ERROR: ' + res.data.message);

View File

@ -24,8 +24,13 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1>Information Service - Vocabulary {{vocId}}</h1> <h1>Information Service - Vocabulary Editor</h1>
<hr />
<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"> <p ng-show="terms.length > 0">
<input type="text" class="form-control form-control-sm" ng-model="termFilter" placeholder="Filter..."/> <input type="text" class="form-control form-control-sm" ng-model="termFilter" placeholder="Filter..."/>
@ -33,23 +38,26 @@
<p> <p>
<span class="text-muted"><b>Number of terms:</b> {{(terms | filter:termFilter).length}}</span> <span class="text-muted"><b>Number of terms:</b> {{(terms | filter:termFilter).length}}</span>
</p> </p>
<table class="table table-sm table-striped"> <table class="table table-sm table-striped">
<thead> <thead>
<tr> <tr>
<th style="width: 25%">Code</th> <th style="width: 25%">Code</th>
<th style="width: 25%">English Name</th> <th style="width: 20%">English Name</th>
<th style="width: 25%">Native Name</th> <th style="width: 20%">Native Name</th>
<th style="width: 10%">Synonyms</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-show="(terms|filter:termFilter).length == 0"> <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>
<tr ng-repeat="t in terms|filter:termFilter"> <tr ng-repeat="t in terms|filter:termFilter">
<th>{{t.code}}</th> <th>{{t.code}}</th>
<td>{{t.englishName}}</td> <td>{{t.englishName}}</td>
<td>{{t.nativeName}}</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> <td align="right"><button type="button" class="btn btn-sm btn-danger" ng-click="deleteTerm(t.id)">delete</button></td>
</tr> </tr>
</tbody> </tbody>