prelimanary code from simple resources
This commit is contained in:
parent
97eafc7ff0
commit
a4a2489643
|
@ -0,0 +1,6 @@
|
|||
package eu.dnetlib.is.resources;
|
||||
|
||||
|
||||
public class ResourcesRestController {
|
||||
|
||||
}
|
|
@ -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()));
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
});
|
|
@ -33,7 +33,8 @@
|
|||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="./vocabularies">Vocabularies</a>
|
||||
<a class="dropdown-item" href="./contexts">Contexts</a>
|
||||
<a class="dropdown-item" href="./transformationRules">Transformation rules</a>
|
||||
<a class="dropdown-item" href="./simpleResources?type=transformation_rules">Transformation rules</a>
|
||||
<a class="dropdown-item" href="./simpleResources?type=cleaning_rules">Cleaning rules</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('Resources: ' + ${type})"></head>
|
||||
|
||||
<body ng-app="resourcesApp" ng-controller="resourcesController">
|
||||
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('Resources: ' + ${type})"></nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<p ng-show="resources.length > 0">
|
||||
<input type="text" class="form-control form-control-sm" ng-model="resFilter" placeholder="Filter..."/>
|
||||
</p>
|
||||
<p>
|
||||
<span class="text-muted"><b>Number of resources:</b> {{(resources | filter:resFilter).length}}</span>
|
||||
</p>
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 25%">ID</th>
|
||||
<th style="width: 25%">Name</th>
|
||||
<th>Description</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-show="(resources|filter:resFilter).length == 0">
|
||||
<td colspan="4" class="text-muted">no resources</td>
|
||||
</tr>
|
||||
<tr ng-repeat="r in resources|filter:resFilter">
|
||||
<th>{{r.id}}</th>
|
||||
<td>{{r.name}}</td>
|
||||
<td>{{r.description}}</td>
|
||||
<td align="right">
|
||||
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editResourceModal" ng-click="prepareEditRes(r)" >edit</button>
|
||||
<button type="button" class="btn btn-sm btn-danger" ng-click="deleteResource(r.id)">delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modals -->
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="editResourceModal">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" ng-if="mode == 'new'">New resource</h4>
|
||||
<h4 class="modal-title" ng-if="mode == 'edit'">Edit resource</h4>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label>ID</label>
|
||||
<input ng-show="mode == 'new'" type="text" class="form-control" ng-model="tmpRes.id" />
|
||||
<input ng-show="mode == 'edit'" type="text" readonly class="form-control-plaintext" ng-model="tmpRes.id" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Type</label>
|
||||
<input type="text" readonly class="form-control-plaintext" th-value="${type}" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" ng-model="tmpRes.name" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<textarea class="form-control" ng-model="tmpRes.description"></textarea>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="saveResource(tmpRes)" ng-disabled="!tmpRes.id || !tmpRes.name">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<th:block th:replace="fragments/mainParts.html :: scripts"></th:block>
|
||||
|
||||
<script src="js/simpleResources.js"></script>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package eu.dnetlib.is.resource.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
@Entity
|
||||
@Table(name = "resources")
|
||||
public class SimpleResource implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5339095932018797315L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "creation_date")
|
||||
private Date creationDate;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "modification_date")
|
||||
private Date modificationDate;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(final Date creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public Date getModificationDate() {
|
||||
return modificationDate;
|
||||
}
|
||||
|
||||
public void setModificationDate(final Date modificationDate) {
|
||||
this.modificationDate = modificationDate;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package eu.dnetlib.is.resource.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "resource_types")
|
||||
public class SimpleResourceType implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -152368127918595773L;
|
||||
|
||||
@Id
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package eu.dnetlib.is.resource.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import eu.dnetlib.is.resource.model.SimpleResource;
|
||||
|
||||
public interface SimpleResourceRepository extends JpaRepository<SimpleResource, String> {
|
||||
|
||||
@Query(value = "select content from resources where id = :id", nativeQuery = true)
|
||||
String getContentById(String id);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update resources set content = :content where id = :id", nativeQuery = true)
|
||||
String setContentById(String id, String content);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.dnetlib.is.resource.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.resource.model.SimpleResourceType;
|
||||
|
||||
public interface SimpleResourceTypeRepository extends JpaRepository<SimpleResourceType, String> {
|
||||
|
||||
}
|
|
@ -76,4 +76,19 @@ CREATE TABLE wf_history (
|
|||
ds_name text,
|
||||
ds_api text,
|
||||
details jsonb
|
||||
);
|
||||
);
|
||||
|
||||
-- Other Resources
|
||||
|
||||
CREATE TABLE resource_types(type text PRIMARY KEY);
|
||||
INSERT INTO resource_types(type) VALUES ('transformation_rule'), ('cleaning_rule');
|
||||
|
||||
CREATE TABLE resources (
|
||||
id text PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
description text,
|
||||
content text NOT NULL,
|
||||
type text NOT NULL REFERENCES resource_types(type),
|
||||
creation_date timestamp NOT NULL DEFAULT now(),
|
||||
modification_date timestamp NOT NULL DEFAULT now()
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue