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 7909c489..1b95a307 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 @@ -49,7 +49,7 @@ public class VocabularyRestController extends AbstractDnetController { public List listVocs() { return vocabularyRepository.findAll() .stream() - .sorted((v1, v2) -> StringUtils.compare(v1.getName(), v2.getName())) + .sorted((v1, v2) -> StringUtils.compareIgnoreCase(v1.getId(), v2.getId())) .collect(Collectors.toList()); } 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 13d1f8b0..236b43fc 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 @@ -24,14 +24,23 @@ app.controller('vocabulariesController', function($scope, $http) { $scope.prepareEditVoc = function(voc) { $scope.mode = 'edit'; - $scope.tmpVoc = { - 'id' : voc.id, - 'name' : voc.name, - 'description' : voc.description - }; + $scope.tmpVoc = angular.copy(voc); } - $scope.saveVocabulary = function(voc) { + $scope.saveVocabulary = function(voc) { + if ($scope.mode == 'new') { + var found = false; + + angular.forEach($scope.vocabularies, function(v) { + if (voc.id == v.id) { found = true; }; + }); + + if (found) { + alert("Insertion failed: vocabulary already exists !"); + return; + } + } + $http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; $http.post('./api/vocs/?' + $.now(), voc).then(function successCallback(res) { $scope.vocabularies = res.data; 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 9959c3e7..2ca6f0ea 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 @@ -3,6 +3,10 @@ var app = angular.module('vocabularyApp', []); app.controller('vocabularyController', function($scope, $http, $location) { $scope.terms = []; $scope.vocId = vocId(); + $scope.editTermCode = ''; + $scope.tmpTerm = {}; + $scope.mode = ''; + $scope.currTerm = []; $scope.reload = function() { $http.get('./api/vocs/'+ encodeURIComponent($scope.vocId) + '/terms?' + $.now()).then(function successCallback(res) { @@ -11,17 +15,53 @@ app.controller('vocabularyController', function($scope, $http, $location) { alert('ERROR: ' + res.data.message); }); }; + + $scope.setCurrTerm = function(term) { + $scope.currTerm = angular.copy(term); + } + + $scope.prepareNewTerm = function() { + $scope.mode = 'new'; + $scope.editTermCode = ''; + $scope.tmpTerm = { + 'code' : '', + 'englishName' : '', + 'nativeName' : '', + 'synonyms' : [] + }; + } + + $scope.prepareEditTerm = function(term) { + $scope.mode = 'edit'; + $scope.editTermCode = term.code; + $scope.tmpTerm = angular.copy(term); + } + - $scope.newTerm = function(code, englishName, nativeName) { + $scope.saveTerm = function(term) { $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); + } + }; - + $scope.deleteTerm = function(code) { if (confirm("Are you sure ?")) { - //TODO + $scope.callDeleteTerm(code); } }; + $scope.callDeleteTerm = function(code) { + alert("TO DELETE HERE - " + code); + // TODO + }; + + + $scope.reload(); }); diff --git a/apps/dnet-is-application/src/main/resources/static/vocabularies.html b/apps/dnet-is-application/src/main/resources/static/vocabularies.html index ce5af69d..90919e9b 100644 --- a/apps/dnet-is-application/src/main/resources/static/vocabularies.html +++ b/apps/dnet-is-application/src/main/resources/static/vocabularies.html @@ -11,6 +11,10 @@ td { vertical-align: middle !important; } + label { + font-weight: bold; + } + 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 8d7ce53a..5a09d2de 100644 --- a/apps/dnet-is-application/src/main/resources/templates/vocabularyEditor.html +++ b/apps/dnet-is-application/src/main/resources/templates/vocabularyEditor.html @@ -11,6 +11,9 @@ td { vertical-align: middle !important; } + label { + font-weight: bold; + }