This commit is contained in:
Michele Artini 2022-12-16 15:31:49 +01:00
parent a5413b393a
commit ab1e85fa98
9 changed files with 141 additions and 177 deletions

View File

@ -13,13 +13,9 @@ app.controller('ctxListController', function($scope, $http) {
$scope.tmpCtx = {}; $scope.tmpCtx = {};
$scope.mode = ''; $scope.mode = '';
$scope.reload = function() { call_http_get($http, './ajax/contexts/?' + $.now(), function(res) {
$http.get('./ajax/contexts/?' + $.now()).then(function successCallback(res) {
$scope.contexts = res.data; $scope.contexts = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
};
$scope.prepareNewCtx = function() { $scope.prepareNewCtx = function() {
$scope.mode = 'new'; $scope.mode = 'new';
@ -50,27 +46,21 @@ app.controller('ctxListController', function($scope, $http) {
} }
} }
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; json_http_post($http,'./ajax/contexts/?' + $.now(), ctx, function(res) {
$http.post('./ajax/contexts/?' + $.now(), ctx).then(function successCallback(res) {
$scope.contexts = res.data; $scope.contexts = res.data;
alert("Context saved"); alert("Context saved");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}; };
$scope.deleteContext = function(id) { $scope.deleteContext = function(id) {
if (confirm("Are you sure ?")) { if (confirm("Are you sure ?")) {
$http.delete('./ajax/contexts/' + encodeURIComponent(id) + '?' + $.now()).then(function successCallback(res) { call_http_delete($http, './ajax/contexts/' + encodeURIComponent(id) + '?' + $.now(), function(res) {
$scope.contexts = res.data; $scope.contexts = res.data;
alert("Context deleted"); alert("Context deleted");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
}; };
$scope.reload();
}); });
app.controller('ctxEditorController', function($scope, $http, $location, $routeParams) { app.controller('ctxEditorController', function($scope, $http, $location, $routeParams) {
@ -81,24 +71,18 @@ app.controller('ctxEditorController', function($scope, $http, $location, $routeP
var url = './ajax/contexts/' + encodeURIComponent($scope.ctxId); var url = './ajax/contexts/' + encodeURIComponent($scope.ctxId);
$http.get(url + '?' + $.now()).then(function successCallback(res) { call_http_get($http, url + '?' + $.now(), function(res) {
$scope.ctxInfo = res.data; $scope.ctxInfo = res.data;
$http.get(url + '/categories?' + $.now()).then(function successCallback(res) { call_http_get($http, url + '/categories?' + $.now(), function(res) {
$scope.categories = res.data; $scope.categories = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
$scope.loadContextParameters = function() { $scope.loadContextParameters = function() {
$scope.parameters = []; $scope.parameters = [];
$http.get('./ajax/contexts/' + encodeURIComponent($scope.ctxId) + '?' + $.now()).then(function successCallback(res) { call_http_get($http, './ajax/contexts/' + encodeURIComponent($scope.ctxId) + '?' + $.now(), function(res) {
$scope.parameters = res.data.parameters; $scope.parameters = res.data.parameters;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
@ -111,10 +95,8 @@ app.controller('ctxEditorController', function($scope, $http, $location, $routeP
node.populated = true; node.populated = true;
$http.get($scope.url + '?' + $.now()).then(function successCallback(res) { call_http_get($http, $scope.url + '?' + $.now(), function(res) {
node.concepts = res.data; node.concepts = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }

View File

@ -7,10 +7,8 @@ app.controller('resourcesController', function($scope, $http) {
$scope.type = typeId(); $scope.type = typeId();
$scope.reload = function() { $scope.reload = function() {
$http.get('./ajax/resources/' + encodeURIComponent($scope.type) + '?' + $.now()).then(function successCallback(res) { call_http_get($http, './ajax/resources/' + encodeURIComponent($scope.type) + '?' + $.now(), function(res) {
$scope.resources = res.data; $scope.resources = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}; };
@ -29,62 +27,49 @@ app.controller('resourcesController', function($scope, $http) {
$scope.prepareEditContent = function(r) { $scope.prepareEditContent = function(r) {
$scope.tmpRes = angular.copy(r); $scope.tmpRes = angular.copy(r);
$scope.tmpContent = "loading..."; $scope.tmpContent = "loading...";
$http.get('./ajax/resources/' + encodeURIComponent(r.id) + '/content?' + $.now()).then(function successCallback(res) { call_http_get($http, './ajax/resources/' + encodeURIComponent(r.id) + '/content?' + $.now(), function(res) {
if (res.data instanceof Object) { if (res.data instanceof Object) {
$scope.tmpContent = JSON.stringify(res.data, null, "\t"); $scope.tmpContent = JSON.stringify(res.data, null, "\t");
} else { } else {
$scope.tmpContent = res.data; $scope.tmpContent = res.data;
} }
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
$scope.createNewResource = function(r) { $scope.createNewResource = function(r) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"; params_http_post($http, './ajax/resources/?' + $.now(), $.param({
$http.post('./ajax/resources/?' + $.now(), $.param({
'name' : r.name, 'name' : r.name,
'type' : $scope.type, 'type' : $scope.type,
'description' : r.description, 'description' : r.description,
'content' : r.content 'content' : r.content
})).then(function successCallback(res) { }), function(res) {
alert("Resource saved"); alert("Resource saved");
$('#newResourceModal').modal('hide'); $('#newResourceModal').modal('hide');
$scope.reload(); $scope.reload();
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
$scope.saveMetadata = function(id, md) { $scope.saveMetadata = function(id, md) {
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; json_http_post($http, './ajax/resources/' + encodeURIComponent(id) + '/metadata?' + $.now(), md, function(res) {
$http.post('./ajax/resources/' + encodeURIComponent(id) + '/metadata?' + $.now(), md).then(function successCallback(res) {
alert("Resource saved"); alert("Resource saved");
$scope.reload(); $scope.reload();
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}; };
$scope.saveContent = function(id, content) { $scope.saveContent = function(id, content) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"; params_http_post($http, './ajax/resources/' + encodeURIComponent(id) + '/content?' + $.now(), $.param({
$http.post('./ajax/resources/' + encodeURIComponent(id) + '/content?' + $.now(), $.param({
'content' : content 'content' : content
})).then(function successCallback(res) { }), function(res) {
alert("Resource saved"); alert("Resource saved");
$('#editContentModal').modal('hide'); $('#editContentModal').modal('hide');
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}; };
$scope.deleteResource = function(r) { $scope.deleteResource = function(r) {
if (confirm("Are you sure ?")) { if (confirm("Are you sure ?")) {
$http.delete('./ajax/resources/' + encodeURIComponent(r.id) + '?' + $.now()).then(function successCallback(res) { call_http_delete($http, './ajax/resources/' + encodeURIComponent(r.id) + '?' + $.now(), function(res) {
alert("Resource deleted"); alert("Resource deleted");
$scope.reload(); $scope.reload();
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
}; };

View File

@ -14,10 +14,8 @@ app.controller('vocListController', function($scope, $http, $location) {
$scope.tmpVoc = {}; $scope.tmpVoc = {};
$scope.mode = ''; $scope.mode = '';
$http.get('./ajax/vocs/?' + $.now()).then(function successCallback(res) { call_http_get($http, './ajax/vocs/?' + $.now(), function(res) {
$scope.vocabularies = res.data; $scope.vocabularies = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
$scope.prepareNewVoc = function() { $scope.prepareNewVoc = function() {
@ -48,22 +46,17 @@ app.controller('vocListController', function($scope, $http, $location) {
} }
} }
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; json_http_post($http, './ajax/vocs/?' + $.now(), voc, function(res) {
$http.post('./ajax/vocs/?' + $.now(), voc).then(function successCallback(res) {
$scope.vocabularies = res.data; $scope.vocabularies = res.data;
alert("Vocabulary saved"); alert("Vocabulary saved");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}; };
$scope.deleteVocabulary = function(id) { $scope.deleteVocabulary = function(id) {
if (confirm("Are you sure ?")) { if (confirm("Are you sure ?")) {
$http.delete('./ajax/vocs/' + encodeURIComponent(id) + '?' + $.now()).then(function successCallback(res) { call_http_delete($http, './ajax/vocs/' + encodeURIComponent(id) + '?' + $.now(), function(res) {
$scope.vocabularies = res.data; $scope.vocabularies = res.data;
alert("Vocabulary deleted"); alert("Vocabulary deleted");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
}; };
@ -80,16 +73,12 @@ app.controller('vocEditorController', function($scope, $http, $location, $routeP
$scope.baseUrl = './ajax/vocs/' + encodeURIComponent($scope.vocId); $scope.baseUrl = './ajax/vocs/' + encodeURIComponent($scope.vocId);
$http.get($scope.baseUrl + '?' + $.now()).then(function successCallback(res) { call_http_get($http, $scope.baseUrl + '?' + $.now(), function(res) {
$scope.vocInfo = res.data; $scope.vocInfo = res.data;
$http.get($scope.baseUrl + '/terms?' + $.now()).then(function successCallback(res) { call_http_get($http, $scope.baseUrl + '/terms?' + $.now(), function(res) {
$scope.terms = res.data; $scope.terms = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
$scope.setCurrTerm = function(term) { $scope.setCurrTerm = function(term) {
@ -115,38 +104,29 @@ app.controller('vocEditorController', function($scope, $http, $location, $routeP
$scope.saveTerm = function(term) { $scope.saveTerm = function(term) {
var url = $scope.baseUrl + '/terms?' + $.now(); var url = $scope.baseUrl + '/terms?' + $.now();
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; json_http_post($http, url, term, function(res) {
$http.post(url, term).then(function successCallback(res) {
if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) { if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) {
var deleteUrl = $scope.baseUrl + '/terms/' + encodeURIComponent($scope.editTermCode) + '?' + $.now(); var deleteUrl = $scope.baseUrl + '/terms/' + encodeURIComponent($scope.editTermCode) + '?' + $.now();
$http.delete(deleteUrl).then(function successCallback(res) { call_http_delete($http, deleteUrl, function(res) {
$scope.terms = res.data; $scope.terms = res.data;
alert("Term replaced"); alert("Term replaced");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} else { } else {
$scope.terms = res.data; $scope.terms = res.data;
alert("Term saved"); alert("Term saved");
} }
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}; };
$scope.deleteTerm = function(code) { $scope.deleteTerm = function(code) {
if (confirm("Are you sure ?")) { if (confirm("Are you sure ?")) {
var url = $scope.baseUrl + '/terms/' + encodeURIComponent(code) + '?' + $.now(); var url = $scope.baseUrl + '/terms/' + encodeURIComponent(code) + '?' + $.now();
$http.delete(url).then(function successCallback(res) { call_http_delete($http, url, function(res) {
$scope.terms = res.data; $scope.terms = res.data;
alert("Term deleted"); alert("Term deleted");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
}; };

View File

@ -1,81 +0,0 @@
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.baseUrl = './ajax/vocs/' + encodeURIComponent($scope.vocId) + '/terms';
$scope.reload = function() {
$http.get($scope.baseUrl + '?' + $.now()).then(function successCallback(res) {
$scope.terms = res.data;
}, function errorCallback(res) {
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' : '',
'name' : '',
'encoding' : 'OPENAIRE',
'synonyms' : []
};
}
$scope.prepareEditTerm = function(term) {
$scope.mode = 'edit';
$scope.editTermCode = term.code;
$scope.tmpTerm = angular.copy(term);
}
$scope.saveTerm = function(term) {
var url = $scope.baseUrl + '?' + $.now();
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
$http.post(url, term).then(function successCallback(res) {
if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) {
var deleteUrl = $scope.baseUrl + '/' + encodeURIComponent($scope.editTermCode) + '?' + $.now();
$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 ?")) {
var url = $scope.baseUrl + '/' + encodeURIComponent(code) + '?' + $.now();
$http.delete(url).then(function successCallback(res) {
$scope.terms = res.data;
alert("Term deleted");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});
}
};
$scope.reload();
});

View File

@ -18,10 +18,8 @@ app.controller('wfHistoryController', function($scope, $http) {
if ($scope.fromDate > 0) { url += "&from=" + $scope.fromDate; } if ($scope.fromDate > 0) { url += "&from=" + $scope.fromDate; }
if ($scope.toDate > 0) { url += "&to=" + $scope.toDate; } if ($scope.toDate > 0) { url += "&to=" + $scope.toDate; }
$http.get(url).then(function successCallback(res) { call_http_get($http, url, function(res) {
$scope.workflows = res.data; $scope.workflows = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}; };

View File

@ -3,12 +3,14 @@
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<p> <p>
<b>Vocabulary ID: </b><span th:text="${vocId}"></span><br /> <b>Vocabulary Name: </b><span th:text="${vocName}"></span><br /> <b>Description: </b><span th:text="${vocDesc}"></span> <b>Vocabulary ID: </b>{{vocId}}<br />
<b>Vocabulary Name: </b>{{vocInfo.name}}<br />
<b>Description: </b>{{vocInfo.description}}
</p> </p>
<p> <p>
<a class="btn btn-sm btn-info" href="#!/list">Return to vocabulary list</a> <a class="btn btn-sm btn-info" href="#!/list">Return to vocabulary list</a>
<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editVocabularyTermModal" ng-click="prepareNewTerm()">create a new term</button> <button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editVocabularyTermModal" ng-click="prepareNewTerm()">create a new term</button>
<a class="btn btn-sm btn-success" th:href="'/api/vocs/' + ${vocId} + '/terms'" target="_blank">Download</a> <a class="btn btn-sm btn-success" href="/api/vocs/{{vocId}}/terms" target="_blank">Download</a>
</p> </p>
<p ng-show="terms.length > 0"> <p ng-show="terms.length > 0">

View File

@ -44,10 +44,8 @@
$scope.browseFieldName = name; $scope.browseFieldName = name;
$scope.browseData = []; $scope.browseData = [];
$http.get('./ajax/dsm/browse/' + encodeURIComponent(id) + '?' + $.now()).then(function successCallback(res) { call_http_get($http, './ajax/dsm/browse/' + encodeURIComponent(id) + '?' + $.now(), function(res) {
$scope.browseData = res.data; $scope.browseData = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
} }
@ -79,13 +77,11 @@
url += '/' + $scope.currPage + '/' + $scope.pageSize; url += '/' + $scope.currPage + '/' + $scope.pageSize;
url += '?value=' + encodeURIComponent($scope.value) + '&' + $.now(); url += '?value=' + encodeURIComponent($scope.value) + '&' + $.now();
$http.get(url).then(function successCallback(res) { call_http_get($http, url, function(res) {
$scope.results = res.data.content; $scope.results = res.data.content;
$scope.nResults = res.data.totalElements; $scope.nResults = res.data.totalElements;
$scope.currPage = res.data.number; $scope.currPage = res.data.number;
$scope.nPages = res.data.totalPages; $scope.nPages = res.data.totalPages;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
$scope.gotoPage = function(page) { $scope.gotoPage = function(page) {

View File

@ -6,18 +6,44 @@
<link rel="stylesheet" href="common/css/bootstrap.cerulean.min.css" /> <link rel="stylesheet" href="common/css/bootstrap.cerulean.min.css" />
<link rel="stylesheet" href="common/css/fontawesome-all.min.css" /> <link rel="stylesheet" href="common/css/fontawesome-all.min.css" />
<style> <style type="text/css">
td,th { td,th {
vertical-align: middle !important; vertical-align: middle !important;
} }
label { label {
font-weight: bold; font-weight: bold;
} }
.overlaydiv {
position: fixed;
width: 100%;
height: 100%;
z-index: 10000;
visibility: hidden;
}
.grayRectangle {
position: absolute;
background-color: black;
opacity:0.6;
top: 30%;
left: 40%;
width: 20%;
height: 20%;
z-index: 100;
border-radius: 15px;
}
</style> </style>
</head> </head>
<body> <body>
<th:block th:fragment="mainMenu(pageTitle)"> <th:block th:fragment="mainMenu(pageTitle)">
<div id="spinnerdiv" class="overlaydiv">
<span class="grayRectangle"><!--The spinner is added on loading here--></span>
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/main">D-Net</a> <a class="navbar-brand" href="/main">D-Net</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown">
@ -80,11 +106,89 @@
</body> </body>
<th:block th:fragment="scripts"> <th:block th:fragment="scripts">
<script>
// Spinner show/hide methods ~ Andrea Mannocci
var spinnerOpts = {
lines: 15,
length: 16,
width: 5,
radius: 25,
color: '#eeeeee',
className: 'spinner',
top: '40%'
};
var spinnerTarget = document.getElementById('spinnerdiv');
var spinner;
function showSpinner() {
spinner = new Spinner(spinnerOpts).spin(spinnerTarget);
spinnerTarget.style.visibility = 'visible';
}
function hideSpinner() {
spinnerTarget.style.visibility = 'hidden';
spinner.stop();
}
function call_http_get($http, url, onSuccess) {
showSpinner();
$http.get(url).then(function successCallback(res) {
hideSpinner();
onSuccess(res);
}, function errorCallback(res) {
hideSpinner();
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
});
}
function call_http_delete($http, url, onSuccess) {
showSpinner();
$http.delete(url).then(function successCallback(res) {
hideSpinner();
onSuccess(res);
}, function errorCallback(res) {
hideSpinner();
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
});
}
function json_http_post($http, url, obj, onSuccess) {
showSpinner();
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
$http.post(url, obj).then(function successCallback(res) {
hideSpinner();
onSuccess(res);
}, function errorCallback(res) {
hideSpinner();
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
});
}
function params_http_post($http, url, params, onSuccess) {
showSpinner();
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
$http.post(url, params).then(function successCallback(res) {
hideSpinner();
onSuccess(res);
}, function errorCallback(res) {
hideSpinner();
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
});
}
</script>
<script src="common/js/jquery.min.js"></script> <script src="common/js/jquery.min.js"></script>
<script src="common/js/popper.min.js"></script> <script src="common/js/popper.min.js"></script>
<script src="common/js/bootstrap.min.js"></script> <script src="common/js/bootstrap.min.js"></script>
<script src="common/js/angular.min.js"></script> <script src="common/js/angular.min.js"></script>
<script src="common/js/angular-route.min.js"></script> <script src="common/js/angular-route.min.js"></script>
<script src="common/js/spin.js"></script>
</th:block> </th:block>
</html> </html>

View File

@ -58,7 +58,7 @@
app.controller('infoController', function($scope, $http) { app.controller('infoController', function($scope, $http) {
$scope.info = []; $scope.info = [];
$http.get('./ajax/info/?' + $.now()).then(function successCallback(res) { call_http_get($http, './ajax/info/?' + $.now(), function(res) {
angular.forEach(res.data, function(section) { angular.forEach(res.data, function(section) {
if (section.name != 'Modules') { if (section.name != 'Modules') {
angular.forEach(section.data, function(r) { angular.forEach(section.data, function(r) {
@ -69,8 +69,6 @@
} }
}); });
$scope.info = res.data; $scope.info = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
}); });
}); });
</script> </script>