From 5b681ed9e8351284ceb73e07d47f0e0fb80a2abf Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Thu, 12 Jan 2023 15:09:14 +0100 Subject: [PATCH] refactoring ui as single angularJs application --- .../eu/dnetlib/is/MainAjaxController.java | 30 + .../java/eu/dnetlib/is/MainController.java | 98 --- .../is/wfs/WfHistoryAjaxController.java | 8 +- .../openaire/dsm/DsmAjaxController.java | 25 + .../editor.html => html/context_viewer.html} | 4 +- .../list.html => html/contexts.html} | 3 +- .../addApi.html => html/dsm_add_api.html} | 2 + .../{dsm/api.html => html/dsm_api.html} | 2 + .../results.html => html/dsm_results.html} | 8 +- .../{dsm/search.html => html/dsm_search.html} | 2 + .../src/main/resources/static/html/info.html | 41 ++ .../main/resources/static/html/protocols.html | 34 + .../main/resources/static/html/resources.html | 124 ++++ .../editor.html => html/voc_editor.html} | 4 +- .../static/{vocs/list.html => html/vocs.html} | 4 +- .../resources/static/html/wf_history.html | 132 ++++ .../src/main/resources/static/index.html | 110 +++- .../src/main/resources/static/js/contexts.js | 107 ---- .../src/main/resources/static/js/is_main.js | 582 ++++++++++++++++++ .../src/main/resources/static/js/is_utils.js | 72 +++ .../resources/static/js/simpleResources.js | 78 --- .../main/resources/static/js/vocabularies.js | 134 ---- .../main/resources/static/js/wf_history.js | 93 --- .../main/resources/templates/contexts.html | 17 - .../src/main/resources/templates/dsm.html | 137 ----- .../templates/fragments/mainParts.html | 194 ------ .../src/main/resources/templates/info.html | 85 --- .../src/main/resources/templates/main.html | 14 - .../main/resources/templates/protocols.html | 62 -- .../resources/templates/simpleResources.html | 147 ----- .../src/main/resources/templates/vocs.html | 17 - .../main/resources/templates/wf_history.html | 153 ----- 32 files changed, 1174 insertions(+), 1349 deletions(-) create mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainAjaxController.java delete mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java rename apps/dnet-is-application/src/main/resources/static/{contexts/editor.html => html/context_viewer.html} (92%) rename apps/dnet-is-application/src/main/resources/static/{contexts/list.html => html/contexts.html} (97%) rename apps/dnet-is-application/src/main/resources/static/{dsm/addApi.html => html/dsm_add_api.html} (97%) rename apps/dnet-is-application/src/main/resources/static/{dsm/api.html => html/dsm_api.html} (66%) rename apps/dnet-is-application/src/main/resources/static/{dsm/results.html => html/dsm_results.html} (92%) rename apps/dnet-is-application/src/main/resources/static/{dsm/search.html => html/dsm_search.html} (97%) create mode 100644 apps/dnet-is-application/src/main/resources/static/html/info.html create mode 100644 apps/dnet-is-application/src/main/resources/static/html/protocols.html create mode 100644 apps/dnet-is-application/src/main/resources/static/html/resources.html rename apps/dnet-is-application/src/main/resources/static/{vocs/editor.html => html/voc_editor.html} (97%) rename apps/dnet-is-application/src/main/resources/static/{vocs/list.html => html/vocs.html} (95%) create mode 100644 apps/dnet-is-application/src/main/resources/static/html/wf_history.html delete mode 100644 apps/dnet-is-application/src/main/resources/static/js/contexts.js create mode 100644 apps/dnet-is-application/src/main/resources/static/js/is_main.js create mode 100644 apps/dnet-is-application/src/main/resources/static/js/is_utils.js delete mode 100644 apps/dnet-is-application/src/main/resources/static/js/simpleResources.js delete mode 100644 apps/dnet-is-application/src/main/resources/static/js/vocabularies.js delete mode 100644 apps/dnet-is-application/src/main/resources/static/js/wf_history.js delete mode 100644 apps/dnet-is-application/src/main/resources/templates/contexts.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/dsm.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/info.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/main.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/protocols.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/simpleResources.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/vocs.html delete mode 100644 apps/dnet-is-application/src/main/resources/templates/wf_history.html diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainAjaxController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainAjaxController.java new file mode 100644 index 00000000..aea360e2 --- /dev/null +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainAjaxController.java @@ -0,0 +1,30 @@ +package eu.dnetlib.is; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import eu.dnetlib.data.is.resource.model.ResourceType; +import eu.dnetlib.data.is.resource.repository.ResourceTypeRepository; + +@RestController +public class MainAjaxController { + + @Autowired + private ResourceTypeRepository resourceTypeRepository; + + @GetMapping("/ajax/resourceTypes") + public Iterable resourceTypes() { + return resourceTypeRepository.findAll(); + } + + @GetMapping("/ajax/resourceTypes/{id}") + public ResourceType resourceTypes(@PathVariable final String id) { + return resourceTypeRepository + .findById(id) + .orElse(new ResourceType("not_present", "???", MediaType.TEXT_PLAIN_VALUE, 0)); + } + +} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java deleted file mode 100644 index 92e4aebe..00000000 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java +++ /dev/null @@ -1,98 +0,0 @@ -package eu.dnetlib.is; - -import java.util.Arrays; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestParam; - -import eu.dnetlib.data.is.context.repository.ContextRepository; -import eu.dnetlib.data.is.resource.model.ResourceType; -import eu.dnetlib.data.is.resource.repository.ResourceTypeRepository; -import eu.dnetlib.data.is.vocabulary.repository.VocabularyRepository; -import eu.dnetlib.data.is.vocabulary.repository.VocabularyTermRepository; -import eu.dnetlib.is.info.KeyValue; -import eu.dnetlib.is.wfs.WfHistoryAjaxController; -import eu.dnetlib.openaire.dsm.utils.DsmBrowsableFields; - -@Controller -public class MainController { - - @Autowired - private ContextRepository contextRepository; - - @Autowired - private VocabularyRepository vocabularyRepository; - - @Autowired - private VocabularyTermRepository vocabularyTermRepository; - - @Autowired - private ResourceTypeRepository resourceTypeRepository; - - @GetMapping("/main") - public void mainPage() {} - - @GetMapping("/dsm") - public void searchDsApi(final ModelMap map) { - map.addAttribute("pageSize", 100); - map.addAttribute("browsableFields", Arrays.stream(DsmBrowsableFields.values()) - .map(f -> new KeyValue(f.name(), f.desc)) - .collect(Collectors.toList())); - map.addAttribute("protocols", vocabularyTermRepository.findTermsByVocabulary("dnet:protocols")); - map.addAttribute("compatibilityLevels", vocabularyTermRepository.findTermsByVocabulary("dnet:compatibilityLevel")); - map.addAttribute("contentDescTypes", vocabularyTermRepository.findTermsByVocabulary("dnet:content_description_typologies")); - } - - @GetMapping("/resources") - public String listResources(@RequestParam final String type, final ModelMap map) { - - if (type.equalsIgnoreCase("vocabulary")) { - return "redirect:vocs"; - } else if (type.equalsIgnoreCase("context")) { - return "redirect:contexts"; - } else if (type.equalsIgnoreCase("protocol")) { - return "redirect:protocols"; - } else { - final Optional restype = resourceTypeRepository.findById(type); - if (restype.isPresent() && restype.get().isSimple()) { - map.addAttribute("type", restype.get()); - } else { - map.addAttribute("type", new ResourceType("not_present", "???", MediaType.TEXT_PLAIN_VALUE, 0)); - } - return "simpleResources"; - } - } - - @GetMapping("/vocs") - public void vocabularies() {} - - @GetMapping("/contexts") - public void contexts() {} - - @GetMapping("/protocols") - public void protocols() {} - - @GetMapping("/wf_history") - public void wfHistory(final ModelMap map, - @RequestParam(required = false, defaultValue = "-1") final Long from, - @RequestParam(required = false, defaultValue = "-1") final Long to) { - map.put("maxNumberOfRecentWfs", WfHistoryAjaxController.MAX_NUMBER_OF_RECENT_WFS); - map.put("fromDate", from); - map.put("toDate", to); - } - - @GetMapping("/info") - public void wfHistory() throws Exception {} - - @ModelAttribute("resTypes") - public Iterable resourceTypes() { - return resourceTypeRepository.findAll(); - } -} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryAjaxController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryAjaxController.java index c42c12d2..2ff88462 100644 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryAjaxController.java +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryAjaxController.java @@ -22,12 +22,16 @@ public class WfHistoryAjaxController { @Autowired private WfProcessExecutionRepository wfProcessExecutionRepository; + @Deprecated public static final int MAX_NUMBER_OF_RECENT_WFS = 100; @GetMapping("/") - public List history(@RequestParam(required = false) final Long from, @RequestParam(required = false) final Long to) { + public List history( + @RequestParam(required = true) final int total, + @RequestParam(required = false) final Long from, + @RequestParam(required = false) final Long to) { if (from == null && to == null) { - return wfProcessExecutionRepository.findAll(PageRequest.of(0, MAX_NUMBER_OF_RECENT_WFS, Sort.by("endDate").descending())).toList(); + return wfProcessExecutionRepository.findAll(PageRequest.of(0, total, Sort.by("endDate").descending())).toList(); } else if (from == null) { return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(new Date(0), new Date(to)); } else if (to == null) { diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/openaire/dsm/DsmAjaxController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/openaire/dsm/DsmAjaxController.java index 444e5370..9e9cdcef 100644 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/openaire/dsm/DsmAjaxController.java +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/openaire/dsm/DsmAjaxController.java @@ -1,6 +1,10 @@ package eu.dnetlib.openaire.dsm; +import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -13,10 +17,12 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.common.controller.AbstractDnetController; +import eu.dnetlib.data.is.vocabulary.repository.VocabularyTermRepository; import eu.dnetlib.data.openaire.dsm.model.Api; import eu.dnetlib.data.openaire.dsm.model.BrowseTerm; import eu.dnetlib.data.openaire.dsm.model.view.SimpleDsWithApis; import eu.dnetlib.is.errors.DsmException; +import eu.dnetlib.is.info.KeyValue; import eu.dnetlib.openaire.dsm.utils.DsmBrowsableFields; @RestController @@ -26,6 +32,25 @@ public class DsmAjaxController extends AbstractDnetController { @Autowired private DsmService dsmService; + @Autowired + private VocabularyTermRepository vocabularyTermRepository; + + @GetMapping("/browsableFields") + public List browsableFields() { + return Arrays.stream(DsmBrowsableFields.values()) + .map(f -> new KeyValue(f.name(), f.desc)) + .collect(Collectors.toList()); + } + + @GetMapping("/validTerms") + public Map> validTerms() { + final Map> map = new LinkedHashMap<>(); + map.put("protocols", vocabularyTermRepository.findTermsByVocabulary("dnet:protocols")); + map.put("compatibilityLevels", vocabularyTermRepository.findTermsByVocabulary("dnet:compatibilityLevel")); + map.put("contentDescTypes", vocabularyTermRepository.findTermsByVocabulary("dnet:content_description_typologies")); + return map; + } + @GetMapping("/browse/{field}") public List browse(@PathVariable final String field) { return dsmService.browseTerm(DsmBrowsableFields.valueOf(field)); diff --git a/apps/dnet-is-application/src/main/resources/static/contexts/editor.html b/apps/dnet-is-application/src/main/resources/static/html/context_viewer.html similarity index 92% rename from apps/dnet-is-application/src/main/resources/static/contexts/editor.html rename to apps/dnet-is-application/src/main/resources/static/html/context_viewer.html index ac36dc61..a1c73d73 100644 --- a/apps/dnet-is-application/src/main/resources/static/contexts/editor.html +++ b/apps/dnet-is-application/src/main/resources/static/html/context_viewer.html @@ -1,3 +1,5 @@ +

Context Editor

+
@@ -6,7 +8,7 @@ data-target="#showParametersModal" ng-click="loadContextParameters()">[show]

- Return to contexts list Download + Return to contexts list Download

    diff --git a/apps/dnet-is-application/src/main/resources/static/contexts/list.html b/apps/dnet-is-application/src/main/resources/static/html/contexts.html similarity index 97% rename from apps/dnet-is-application/src/main/resources/static/contexts/list.html rename to apps/dnet-is-application/src/main/resources/static/html/contexts.html index 4dd1df6b..5a309327 100644 --- a/apps/dnet-is-application/src/main/resources/static/contexts/list.html +++ b/apps/dnet-is-application/src/main/resources/static/html/contexts.html @@ -1,3 +1,4 @@ +

    Contexts

    @@ -26,7 +27,7 @@ no contexts - {{ctx.id}} + {{ctx.id}} {{ctx.label}} {{ctx.type}} diff --git a/apps/dnet-is-application/src/main/resources/static/dsm/addApi.html b/apps/dnet-is-application/src/main/resources/static/html/dsm_add_api.html similarity index 97% rename from apps/dnet-is-application/src/main/resources/static/dsm/addApi.html rename to apps/dnet-is-application/src/main/resources/static/html/dsm_add_api.html index 0b4e0147..7e8af135 100644 --- a/apps/dnet-is-application/src/main/resources/static/dsm/addApi.html +++ b/apps/dnet-is-application/src/main/resources/static/html/dsm_add_api.html @@ -1,3 +1,5 @@ +

    Datasource Manager: Add API

    +
    diff --git a/apps/dnet-is-application/src/main/resources/static/dsm/api.html b/apps/dnet-is-application/src/main/resources/static/html/dsm_api.html similarity index 66% rename from apps/dnet-is-application/src/main/resources/static/dsm/api.html rename to apps/dnet-is-application/src/main/resources/static/html/dsm_api.html index 04185ca0..bef68f7c 100644 --- a/apps/dnet-is-application/src/main/resources/static/dsm/api.html +++ b/apps/dnet-is-application/src/main/resources/static/html/dsm_api.html @@ -1,3 +1,5 @@ +

    Datasource Manager: API

    +
    diff --git a/apps/dnet-is-application/src/main/resources/static/dsm/results.html b/apps/dnet-is-application/src/main/resources/static/html/dsm_results.html similarity index 92% rename from apps/dnet-is-application/src/main/resources/static/dsm/results.html rename to apps/dnet-is-application/src/main/resources/static/html/dsm_results.html index adf9fbf0..a0092ff4 100644 --- a/apps/dnet-is-application/src/main/resources/static/dsm/results.html +++ b/apps/dnet-is-application/src/main/resources/static/html/dsm_results.html @@ -1,3 +1,5 @@ +

    Datasource Manager: Results

    +
    @@ -5,7 +7,7 @@ Number of results: {{nResults}}
    Page: {{currPage + 1}} / {{nPages}}- / -

    - +