This commit is contained in:
Michele Artini 2022-11-21 14:26:22 +01:00
parent bf7962603f
commit 51a3eda4c2
7 changed files with 88 additions and 52 deletions

View File

@ -11,8 +11,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import eu.dnetlib.is.context.model.Context; import eu.dnetlib.is.context.model.Context;
import eu.dnetlib.is.context.model.repository.ContextRepository; import eu.dnetlib.is.context.model.repository.ContextRepository;
import eu.dnetlib.is.resource.model.SimpleResourceType; import eu.dnetlib.is.resource.model.ResourceType;
import eu.dnetlib.is.resource.repository.SimpleResourceTypeRepository; import eu.dnetlib.is.resource.repository.ResourceTypeRepository;
import eu.dnetlib.is.vocabulary.model.Vocabulary; import eu.dnetlib.is.vocabulary.model.Vocabulary;
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository; import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
import eu.dnetlib.is.wfs.WfHistoryRestController; import eu.dnetlib.is.wfs.WfHistoryRestController;
@ -27,11 +27,29 @@ public class MainController {
private VocabularyRepository vocabularyRepository; private VocabularyRepository vocabularyRepository;
@Autowired @Autowired
private SimpleResourceTypeRepository simpleResourceTypeRepository; private ResourceTypeRepository resourceTypeRepository;
@GetMapping("/main") @GetMapping("/main")
public void mainPage() {} 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") @GetMapping("/contextEditor")
public void contextEditor(@RequestParam final String id, final ModelMap map) { public void contextEditor(@RequestParam final String id, final ModelMap map) {
final Context ctx = contextRepository.getById(id); final Context ctx = contextRepository.getById(id);
@ -41,9 +59,6 @@ public class MainController {
map.put("ctxParams", ctx.getParameters()); map.put("ctxParams", ctx.getParameters());
} }
@GetMapping("/contexts")
public void contexts() {}
@GetMapping("/vocabularyEditor") @GetMapping("/vocabularyEditor")
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) { public void vocabularyEditor(@RequestParam final String id, final ModelMap map) {
final Vocabulary voc = vocabularyRepository.getById(id); final Vocabulary voc = vocabularyRepository.getById(id);
@ -52,22 +67,6 @@ public class MainController {
map.put("vocDesc", voc.getDescription()); 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") @GetMapping("/wf_history")
public void wfHistory(final ModelMap map, public void wfHistory(final ModelMap map,
@RequestParam(required = false, defaultValue = "-1") final Long from, @RequestParam(required = false, defaultValue = "-1") final Long from,
@ -78,7 +77,7 @@ public class MainController {
} }
@ModelAttribute("resTypes") @ModelAttribute("resTypes")
public Iterable<SimpleResourceType> resourceTypes() { public Iterable<ResourceType> resourceTypes() {
return simpleResourceTypeRepository.findAll(); return resourceTypeRepository.findAll();
} }
} }

View File

@ -31,12 +31,20 @@
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" data-toggle="dropdown">Resources</a> <a class="nav-link dropdown-toggle" href="javascript:void(0)" data-toggle="dropdown">Resources</a>
<div class="dropdown-menu"> <div class="dropdown-menu">
<a class="dropdown-item" href="./vocabularies">Vocabularies</a> <h6 class="dropdown-header">Simple resources</h6>
<a class="dropdown-item" href="./contexts">Contexts</a>
<div class="dropdown-divider"></div>
<a th:each="t: ${resTypes}" <a th:each="t: ${resTypes}"
th:if="${t.simple}"
class="dropdown-item" 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.name}"></span>
<span th:text="${t.count}" class="badge badge-primary"></span> <span th:text="${t.count}" class="badge badge-primary"></span>
</a> </a>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<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"> <script th:inline="javascript">
/*<![CDATA[*/ /*<![CDATA[*/
@ -11,7 +11,7 @@
<body ng-app="resourcesApp" ng-controller="resourcesController"> <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="container-fluid">
<div class="row"> <div class="row">

View File

@ -9,7 +9,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "resource_types_view") @Table(name = "resource_types_view")
public class SimpleResourceType implements Serializable { public class ResourceType implements Serializable {
private static final long serialVersionUID = -152368127918595773L; private static final long serialVersionUID = -152368127918595773L;
@ -23,12 +23,16 @@ public class SimpleResourceType implements Serializable {
@Column(name = "count") @Column(name = "count")
private long 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.id = id;
this.name = name; this.name = name;
this.count = count; this.count = count;
this.simple = true;
} }
public String getId() { public String getId() {
@ -55,4 +59,12 @@ public class SimpleResourceType implements Serializable {
this.count = count; this.count = count;
} }
public boolean isSimple() {
return simple;
}
public void setSimple(final boolean simple) {
this.simple = simple;
}
} }

View File

@ -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> {
}

View File

@ -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> {
}

View File

@ -97,11 +97,28 @@ CREATE TABLE resources (
modification_date timestamp NOT NULL DEFAULT now() 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.id AS id,
t.name AS name, t.name AS name,
count(r.id) AS count count(r.id) AS count,
FROM resource_types t true AS simple
LEFT OUTER JOIN resources r ON (r.type = t.id) FROM resource_types t
GROUP BY t.id, t.name LEFT OUTER JOIN resources r ON (r.type = t.id)
ORDER BY t.name; 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
);