From 45673b832c01d68bca15181ddb0be46c412f2796 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Tue, 21 Jun 2022 09:55:39 +0200 Subject: [PATCH] ui --- .../vocabulary/VocabularyRestController.java | 27 +++++++++++++++++-- .../is/vocabulary/VocabularyUIController.java | 15 ++++++++++- .../resources/static/js/vocabularyEditor.js | 2 +- .../resources/templates/vocabularyEditor.html | 20 +++++++++----- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyRestController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyRestController.java index 6d353fdb..7909c489 100644 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyRestController.java +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyRestController.java @@ -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 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 listTerms(@PathVariable final String vocabulary) { + return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary); + } + + @PostMapping("/{vocabulary}/terms") + public Iterable 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 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); + } + } diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java index a95e2d1f..d724c6d8 100644 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java @@ -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()); + } } diff --git a/apps/dnet-is-application/src/main/resources/static/js/vocabularyEditor.js b/apps/dnet-is-application/src/main/resources/static/js/vocabularyEditor.js index 0f72fdb2..9959c3e7 100644 --- a/apps/dnet-is-application/src/main/resources/static/js/vocabularyEditor.js +++ b/apps/dnet-is-application/src/main/resources/static/js/vocabularyEditor.js @@ -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); diff --git a/apps/dnet-is-application/src/main/resources/templates/vocabularyEditor.html b/apps/dnet-is-application/src/main/resources/templates/vocabularyEditor.html index ec9ae6c1..8d7ce53a 100644 --- a/apps/dnet-is-application/src/main/resources/templates/vocabularyEditor.html +++ b/apps/dnet-is-application/src/main/resources/templates/vocabularyEditor.html @@ -24,32 +24,40 @@
-

Information Service - Vocabulary {{vocId}}

-
+

Information Service - Vocabulary Editor

+ +

+ ID:
+ Name:
+ Description: +

Number of terms: {{(terms | filter:termFilter).length}} -

+

+ - - + + + - + +
CodeEnglish NameNative NameEnglish NameNative NameSynonyms
no termsno terms
{{t.code}} {{t.englishName}} {{t.nativeName}}{{t.synonyms.length}} synonym(s)