From bbcd58a353f8b4b04baeeefd6d30f9fdeea11b2b Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Thu, 23 Jun 2022 12:04:38 +0200 Subject: [PATCH] ui --- .../vocabulary/VocabularyRestController.java | 5 +-- .../main/resources/static/js/vocabularies.js | 2 +- .../resources/static/js/vocabularyEditor.js | 44 ++++++++++++------- .../src/main/resources/sql/schema.sql | 2 +- 4 files changed, 32 insertions(+), 21 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 3c25f4d7..2e864885 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,7 +23,6 @@ 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; @@ -119,13 +118,13 @@ public class VocabularyRestController extends AbstractDnetController { } @PostMapping("/{vocabulary}/terms") - public Iterable saveTerm(@PathVariable final String vocabulary, @RequestParam final VocabularyTerm term) { + public Iterable saveTerm(@PathVariable final String vocabulary, @RequestBody final VocabularyTerm term) { term.setVocabulary(vocabulary); vocabularyTermRepository.save(term); return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary); } - @DeleteMapping("/{vocabulary}/terms/{termId}") + @DeleteMapping("/{vocabulary}/terms/{term}") public Iterable listTerms(@PathVariable final String vocabulary, @PathVariable final String term) { final VocabularyTermPK pk = new VocabularyTermPK(); pk.setCode(term); diff --git a/apps/dnet-is-application/src/main/resources/static/js/vocabularies.js b/apps/dnet-is-application/src/main/resources/static/js/vocabularies.js index 236b43fc..4a152abe 100644 --- a/apps/dnet-is-application/src/main/resources/static/js/vocabularies.js +++ b/apps/dnet-is-application/src/main/resources/static/js/vocabularies.js @@ -52,7 +52,7 @@ app.controller('vocabulariesController', function($scope, $http) { $scope.deleteVocabulary = function(id) { if (confirm("Are you sure ?")) { - $http.delete('./api/vocs/' + id).then(function successCallback(res) { + $http.delete('./api/vocs/' + encodeURIComponent(id)).then(function successCallback(res) { $scope.vocabularies = res.data; alert("Vocabulary deleted"); }, function errorCallback(res) { 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 7be7ae9b..7480ddc5 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 @@ -39,29 +39,41 @@ app.controller('vocabularyController', function($scope, $http, $location) { $scope.saveTerm = function(term) { + + var url = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms'; + $http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; - alert("TO SAVE HERE - " + term.code); - - //TODO - - if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) { - $scope.callDeleteTerm($scope.editTermCode); - } - + $http.post(url, term).then(function successCallback(res) { + if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) { + var deleteUrl = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms/' + encodeURIComponent($scope.editTermCode); + $http.delete(deleteUrl).then(function successCallback(res) { + $scope.terms = res.data; + alert("Term replaced"); + }, function errorCallback(res) { + alert('ERROR: ' + res.data.message); + }); + } else { + $scope.terms = res.data; + alert("Term saved"); + } + }, function errorCallback(res) { + alert('ERROR: ' + res.data.message); + }); + }; $scope.deleteTerm = function(code) { if (confirm("Are you sure ?")) { - $scope.callDeleteTerm(code); + var url = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms/' + encodeURIComponent(code); + + $http.delete(url).then(function successCallback(res) { + $scope.terms = res.data; + alert("Term deleted"); + }, function errorCallback(res) { + alert('ERROR: ' + res.data.message); + }); } }; - $scope.callDeleteTerm = function(code) { - alert("TO DELETE HERE - " + code); - // TODO - }; - - - $scope.reload(); }); diff --git a/libs/dnet-is-common/src/main/resources/sql/schema.sql b/libs/dnet-is-common/src/main/resources/sql/schema.sql index 214ac77e..9e95e5e8 100644 --- a/libs/dnet-is-common/src/main/resources/sql/schema.sql +++ b/libs/dnet-is-common/src/main/resources/sql/schema.sql @@ -5,7 +5,7 @@ CREATE TABLE vocabularies ( ); CREATE TABLE vocabulary_terms ( - vocabulary text NOT NULL REFERENCES vocabularies(id), + vocabulary text NOT NULL REFERENCES vocabularies(id) ON UPDATE CASCADE ON DELETE CASCADE, code text NOT NULL, name text NOT NULL, encoding text DEFAULT 'OPENAIRE',