This commit is contained in:
parent
bf7962603f
commit
51a3eda4c2
|
@ -11,8 +11,8 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
|
||||
import eu.dnetlib.is.context.model.Context;
|
||||
import eu.dnetlib.is.context.model.repository.ContextRepository;
|
||||
import eu.dnetlib.is.resource.model.SimpleResourceType;
|
||||
import eu.dnetlib.is.resource.repository.SimpleResourceTypeRepository;
|
||||
import eu.dnetlib.is.resource.model.ResourceType;
|
||||
import eu.dnetlib.is.resource.repository.ResourceTypeRepository;
|
||||
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
||||
import eu.dnetlib.is.wfs.WfHistoryRestController;
|
||||
|
@ -27,11 +27,29 @@ public class MainController {
|
|||
private VocabularyRepository vocabularyRepository;
|
||||
|
||||
@Autowired
|
||||
private SimpleResourceTypeRepository simpleResourceTypeRepository;
|
||||
private ResourceTypeRepository resourceTypeRepository;
|
||||
|
||||
@GetMapping("/main")
|
||||
public void mainPage() {}
|
||||
|
||||
@GetMapping("/resources")
|
||||
public String listResources(@RequestParam final String type, final ModelMap map) {
|
||||
|
||||
if (type.equalsIgnoreCase("vocabulary")) {
|
||||
return "vocabularies";
|
||||
} else if (type.equalsIgnoreCase("context")) {
|
||||
return "contexts";
|
||||
} else {
|
||||
final Optional<ResourceType> restype = resourceTypeRepository.findById(type);
|
||||
if (restype.isPresent() && restype.get().isSimple()) {
|
||||
map.addAttribute("type", restype.get());
|
||||
} else {
|
||||
map.addAttribute("type", new ResourceType("not_present", "???", 0));
|
||||
}
|
||||
return "simpleResources";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/contextEditor")
|
||||
public void contextEditor(@RequestParam final String id, final ModelMap map) {
|
||||
final Context ctx = contextRepository.getById(id);
|
||||
|
@ -41,9 +59,6 @@ public class MainController {
|
|||
map.put("ctxParams", ctx.getParameters());
|
||||
}
|
||||
|
||||
@GetMapping("/contexts")
|
||||
public void contexts() {}
|
||||
|
||||
@GetMapping("/vocabularyEditor")
|
||||
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) {
|
||||
final Vocabulary voc = vocabularyRepository.getById(id);
|
||||
|
@ -52,22 +67,6 @@ public class MainController {
|
|||
map.put("vocDesc", voc.getDescription());
|
||||
}
|
||||
|
||||
@GetMapping("/vocabularies")
|
||||
public void vocabularies() {}
|
||||
|
||||
@GetMapping("/simpleResources")
|
||||
public void simpleResources(@RequestParam final String type, final ModelMap map) {
|
||||
|
||||
final Optional<SimpleResourceType> restype = simpleResourceTypeRepository.findById(type);
|
||||
|
||||
if (restype.isPresent()) {
|
||||
map.addAttribute("type", restype.get());
|
||||
} else {
|
||||
map.addAttribute("type", new SimpleResourceType("not_present", "???", 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/wf_history")
|
||||
public void wfHistory(final ModelMap map,
|
||||
@RequestParam(required = false, defaultValue = "-1") final Long from,
|
||||
|
@ -78,7 +77,7 @@ public class MainController {
|
|||
}
|
||||
|
||||
@ModelAttribute("resTypes")
|
||||
public Iterable<SimpleResourceType> resourceTypes() {
|
||||
return simpleResourceTypeRepository.findAll();
|
||||
public Iterable<ResourceType> resourceTypes() {
|
||||
return resourceTypeRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,12 +31,20 @@
|
|||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="javascript:void(0)" data-toggle="dropdown">Resources</a>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="./vocabularies">Vocabularies</a>
|
||||
<a class="dropdown-item" href="./contexts">Contexts</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<h6 class="dropdown-header">Simple resources</h6>
|
||||
<a th:each="t: ${resTypes}"
|
||||
th:if="${t.simple}"
|
||||
class="dropdown-item"
|
||||
th:href="@{'./simpleResources?type=' + ${t.id}}">
|
||||
th:href="@{'./resources?type=' + ${t.id}}">
|
||||
<span th:text="${t.name}"></span>
|
||||
<span th:text="${t.count}" class="badge badge-primary"></span>
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<h6 class="dropdown-header">Advanced resources</h6>
|
||||
<a th:each="t: ${resTypes}"
|
||||
th:unless="${t.simple}"
|
||||
class="dropdown-item"
|
||||
th:href="@{'./resources?type=' + ${t.id}}">
|
||||
<span th:text="${t.name}"></span>
|
||||
<span th:text="${t.count}" class="badge badge-primary"></span>
|
||||
</a>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('Resources: ' + ${type.name})"></head>
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader(${type.name})"></head>
|
||||
|
||||
<script th:inline="javascript">
|
||||
/*<![CDATA[*/
|
||||
|
@ -11,7 +11,7 @@
|
|||
|
||||
<body ng-app="resourcesApp" ng-controller="resourcesController">
|
||||
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('Resources: ' + ${type.name})"></nav>
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu(${type.name})"></nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
|
|
@ -9,7 +9,7 @@ import javax.persistence.Table;
|
|||
|
||||
@Entity
|
||||
@Table(name = "resource_types_view")
|
||||
public class SimpleResourceType implements Serializable {
|
||||
public class ResourceType implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -152368127918595773L;
|
||||
|
||||
|
@ -23,12 +23,16 @@ public class SimpleResourceType implements Serializable {
|
|||
@Column(name = "count")
|
||||
private long count;
|
||||
|
||||
public SimpleResourceType() {}
|
||||
@Column(name = "simple")
|
||||
private boolean simple = true;
|
||||
|
||||
public SimpleResourceType(final String id, final String name, final long count) {
|
||||
public ResourceType() {}
|
||||
|
||||
public ResourceType(final String id, final String name, final long count) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.count = count;
|
||||
this.simple = true;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -55,4 +59,12 @@ public class SimpleResourceType implements Serializable {
|
|||
this.count = count;
|
||||
}
|
||||
|
||||
public boolean isSimple() {
|
||||
return simple;
|
||||
}
|
||||
|
||||
public void setSimple(final boolean simple) {
|
||||
this.simple = simple;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package eu.dnetlib.is.resource.repository;
|
||||
|
||||
import eu.dnetlib.is.common.ReadOnlyRepository;
|
||||
import eu.dnetlib.is.resource.model.ResourceType;
|
||||
|
||||
public interface ResourceTypeRepository extends ReadOnlyRepository<ResourceType, String> {
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package eu.dnetlib.is.resource.repository;
|
||||
|
||||
import eu.dnetlib.is.common.ReadOnlyRepository;
|
||||
import eu.dnetlib.is.resource.model.SimpleResourceType;
|
||||
|
||||
public interface SimpleResourceTypeRepository extends ReadOnlyRepository<SimpleResourceType, String> {
|
||||
|
||||
}
|
|
@ -97,11 +97,28 @@ CREATE TABLE resources (
|
|||
modification_date timestamp NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE VIEW resource_types_view AS SELECT
|
||||
CREATE VIEW resource_types_view AS (
|
||||
SELECT
|
||||
t.id AS id,
|
||||
t.name AS name,
|
||||
count(r.id) AS count
|
||||
FROM resource_types t
|
||||
LEFT OUTER JOIN resources r ON (r.type = t.id)
|
||||
GROUP BY t.id, t.name
|
||||
ORDER BY t.name;
|
||||
count(r.id) AS count,
|
||||
true AS simple
|
||||
FROM resource_types t
|
||||
LEFT OUTER JOIN resources r ON (r.type = t.id)
|
||||
GROUP BY t.id, t.name
|
||||
ORDER BY t.name
|
||||
) UNION ALL (
|
||||
SELECT
|
||||
'vocabulary' AS id,
|
||||
'Vocabularies' AS name,
|
||||
count(*) AS count,
|
||||
false AS simple
|
||||
FROM vocabularies
|
||||
) UNION ALL (
|
||||
SELECT
|
||||
'context' AS id,
|
||||
'Contexts' AS name,
|
||||
count(*) AS count,
|
||||
false AS simple
|
||||
FROM contexts
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue