diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesRestController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesRestController.java new file mode 100644 index 00000000..fae5ebd2 --- /dev/null +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesRestController.java @@ -0,0 +1,6 @@ +package eu.dnetlib.is.resources; + + +public class ResourcesRestController { + +} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesUIController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesUIController.java new file mode 100644 index 00000000..bfd58609 --- /dev/null +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesUIController.java @@ -0,0 +1,29 @@ +package eu.dnetlib.is.resources; + +import java.util.stream.Collectors; + +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.resource.model.SimpleResourceType; +import eu.dnetlib.is.resource.repository.SimpleResourceTypeRepository; + +@Controller +public class ResourcesUIController { + + @Autowired + private SimpleResourceTypeRepository simpleResourceTypeRepository; + + @GetMapping("/simpleResources") + public void simpleResources(@RequestParam final String type, final ModelMap map) { + map.addAttribute("type", type); + map.addAttribute("types", simpleResourceTypeRepository.findAll() + .stream() + .map(SimpleResourceType::getType) + .sorted() + .collect(Collectors.toList())); + } +} diff --git a/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js b/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js new file mode 100644 index 00000000..f335efef --- /dev/null +++ b/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js @@ -0,0 +1,65 @@ +var app = angular.module('resourcesApp', []); + +app.controller('resourcesController', function($scope, $http) { + $scope.resources = []; + $scope.tmpRes = {}; + $scope.mode = ''; + + $scope.reload = function() { + $http.get('./api/resources/?' + $.now()).then(function successCallback(res) { + $scope.resources = res.data; + }, function errorCallback(res) { + alert('ERROR: ' + res.data.message); + }); + }; + + $scope.prepareNewRes = function() { + $scope.mode = 'new'; + $scope.tmpRes = { + 'id' : '', + 'name' : '', + 'description' : '' + }; + } + + $scope.prepareEditRes = function(res) { + $scope.mode = 'edit'; + $scope.tmpRes = angular.copy(res); + } + + $scope.saveResource = function(res) { + if ($scope.mode == 'new') { + var found = false; + + angular.forEach($scope.resources, function(r) { + if (res.id == r.id) { found = true; }; + }); + + if (found) { + alert("Insertion failed: resource already exists !"); + return; + } + } + + $http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; + $http.post('./api/resources/?' + $.now(), res).then(function successCallback(res) { + $scope.resources = res.data; + alert("Resource saved"); + }, function errorCallback(res) { + alert('ERROR: ' + res.data.message); + }); + }; + + $scope.deleteResource = function(id) { + if (confirm("Are you sure ?")) { + $http.delete('./api/resources/' + encodeURIComponent(id) + '?' + $.now()).then(function successCallback(res) { + $scope.resources = res.data; + alert("Resource deleted"); + }, function errorCallback(res) { + alert('ERROR: ' + res.data.message); + }); + } + }; + + $scope.reload(); +}); diff --git a/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html b/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html index b94c1d9b..d3952ae7 100644 --- a/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html +++ b/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html @@ -33,7 +33,8 @@