From ed93c13434bc4859d401df4bf52e8bc592c843e6 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 4 Nov 2022 17:16:37 +0100 Subject: [PATCH] in progress on timeline --- README.md | 6 +- .../client/GeoportalDataViewer.java | 31 ++-- .../client/resources/GNAImages.java | 2 +- .../client/ui/cms/project/ProjectUtil.java | 2 +- .../relation/TimelineRelationPanel.java | 50 +++--- .../GeoportalDataViewerServiceImpl.java | 161 +++++++++++++----- src/main/webapp/GeoportalDataViewer.css | 7 + src/main/webapp/GeoportalDataViewer.html | 9 +- .../GeoPortalDataViewerAppPortlet_view.jsp | 4 +- 9 files changed, 182 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index ba1be3a..7e3fcd9 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ The GeoPortal Data Viewer App is an application to access, discovery and navigat **Uses** * GWT v.2.9.0. [GWT](http://www.gwtproject.org) is licensed under [Apache License 2.0](http://www.gwtproject.org/terms.html) -* GWT-Bootstrap v.2.3.2.0. [GWT-Bootstrap](https://github.com/gwtbootstrap) is licensed under [[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) +* GWT-Bootstrap v.2.3.2.0. [GWT-Bootstrap](https://github.com/gwtbootstrap) is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) * GWT-OpenLayers 3+ v.8.1.0-gwt2_9. [GWT-OL3](https://github.com/TDesjardins/gwt-ol) -* OpenLayers v.6.X. [OpenLayers](https://openlayers.org/) is licensed under [BSD 2-Clause "Simplified"](https://github.com/openlayers/openlayers/blob/main/LICENSE.md) +* OpenLayers v.6.x [OpenLayers](https://openlayers.org/) is licensed under [BSD 2-Clause "Simplified"](https://github.com/openlayers/openlayers/blob/main/LICENSE.md) * Vis-Timeline v7.x [VisTimeline](https://github.com/visjs/vis-timeline) is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) and MIT -* Handlebarsjs v4.X [Handlebarsjs](https://handlebarsjs.com/) is licensed under MIT +* Handlebarsjs v4.x [Handlebarsjs](https://handlebarsjs.com/) is licensed under MIT ## Documentation diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java index 94831c1..fd61a90 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java @@ -253,18 +253,18 @@ public class GeoportalDataViewer implements EntryPoint { RootPanel.get(APP_DIV).add(attributionDiv); - new Timer() { - - @Override - public void run() { - GWT.log("Instancing timeline"); - ProjectDV project = new ProjectDV(); - project.setId("fake"); - project.setProfileID("fake"); - applicationBus.fireEvent(new TimelineProjectRelationsEvent(project, EVENT_TYPE.SHOW)); - - } - }.schedule(1000); +// new Timer() { +// +// @Override +// public void run() { +// GWT.log("Instancing timeline"); +// ProjectDV project = new ProjectDV(); +// project.setId("fake"); +// project.setProfileID("fake"); +// applicationBus.fireEvent(new TimelineProjectRelationsEvent(project, EVENT_TYPE.SHOW)); +// +// } +// }.schedule(1000); // Modal modal = new Modal(true, true); // modal.setWidth(400); @@ -396,9 +396,10 @@ public class GeoportalDataViewer implements EntryPoint { && relationships!= null && relationships.size() > 0) { GWT.log("LoadTimelineRelationships is true and the project has Relationships"); showTimelineProjectRelations(result.getTheProjectDV()); - } else { - hideTimelineProjectRelations(); - } + } +// else { +// hideTimelineProjectRelations(); +// } } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java index ae1ee6e..30bbdaa 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java @@ -50,7 +50,7 @@ public interface GNAImages extends ClientBundle { @Source("spinner_earth.gif") ImageResource spinnerEarth(); - @Source("spinner_clock2.gif") + @Source("spinner_clock.gif") ImageResource spinnerClock(); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectUtil.java index 0e70df2..6453f5b 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectUtil.java @@ -18,7 +18,7 @@ public class ProjectUtil { } if (projectID != null) { - htmlCode += "(id: " + projectID + ")"; + htmlCode += " (id: " + projectID + ")"; } return htmlCode; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/TimelineRelationPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/TimelineRelationPanel.java index 2c4ce9c..052d758 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/TimelineRelationPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/TimelineRelationPanel.java @@ -36,8 +36,9 @@ public class TimelineRelationPanel extends Composite { @UiField HTMLPanel timelineTitle; - - private LoaderIcon loaderData = new LoaderIcon("Loading data... please wait", new Image(GNAImages.ICONS.spinnerClock())); + + private LoaderIcon loaderData = new LoaderIcon("Loading data... please wait", + new Image(GNAImages.ICONS.spinnerClock())); private TimelineRelationPanel instance = this; @@ -57,15 +58,16 @@ public class TimelineRelationPanel extends Composite { this.theProjectDV = theProjectDV; this.applicationBus = applicationBus; - String html = ProjectUtil.toHMLCode(theProjectDV.getTheDocument(), theProjectDV.getId()); - HTML title = new HTML("Relationships of the Project: " + html); + String html = ProjectUtil.toHMLCode(theProjectDV.getTheDocument()); + HTML title = new HTML("Relationships of the Project" + "
" + html); timelineTitle.add(title); - + loaderData.getElement().getStyle().setTextAlign(TextAlign.CENTER); - timelineTitle.add(loaderData); timelineContainer.getElement().setId("visualization"); + timelineContainer.add(loaderData); + Scheduler.get().scheduleDeferred(new ScheduledCommand() { public void execute() { @@ -75,6 +77,7 @@ public class TimelineRelationPanel extends Composite { @Override public void onSuccess(List result) { + timelineContainer.remove(loaderData); JSONArray toJsonArr = new JSONArray(); for (int i = 0; i < result.size(); i++) { @@ -82,12 +85,12 @@ public class TimelineRelationPanel extends Composite { } instanceTimeline(timelineContainer.getElement().getId(), toJsonArr, instance); - timelineTitle.remove(loaderData); + } @Override public void onFailure(Throwable caught) { - timelineTitle.remove(loaderData); + timelineContainer.remove(loaderData); Alert alert = new Alert(caught.getMessage()); alert.setType(AlertType.ERROR); alert.setClose(false); @@ -103,17 +106,15 @@ public class TimelineRelationPanel extends Composite { private void setSelectedProject(String projectID) { this.selectedProjectID = projectID; GWT.log("selectedProjectID: " + selectedProjectID); - + String[] references = this.selectedProjectID.split(","); - GeoportalItemReferences gir = new GeoportalItemReferences(references[1], - references[0]); - ShowDetailsEvent event = new ShowDetailsEvent(gir, null, null, false); - GWT.log("fireEvetn: "+event); - - //applicationBus.fireEvent(new ShowDetailsEvent(gir, null, null, false)); - - + GeoportalItemReferences gir = new GeoportalItemReferences(references[1], references[0]); + ShowDetailsEvent showDetailsEvent = new ShowDetailsEvent(gir, null, null, false); + GWT.log("fireEvetn: " + showDetailsEvent); + + applicationBus.fireEvent(showDetailsEvent); + } public String getSelectedProjectID() { @@ -145,11 +146,16 @@ public class TimelineRelationPanel extends Composite { var timeline = new $wnd.vis.Timeline(container, items, $wnd.optionsTimeline); - timeline.on('select',function(properties, items) { - //console.log('selected: ' + $wnd.JSON.stringify(properties)); - console.log('selected items: ' + properties.items); - instance.@org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineRelationPanel::setSelectedProject(Ljava/lang/String;)(properties.items+'') - }); + timeline + .on( + 'select', + function(properties, items) { + //console.log('selected: ' + $wnd.JSON.stringify(properties)); + console.log('selected items: ' + properties.items); + instance.@org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineRelationPanel::setSelectedProject(Ljava/lang/String;)(properties.items+'') + }); + + //timeline.redraw(); }-*/; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java index 558267d..28572c3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java @@ -967,7 +967,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme */ @Override public ProjectView getProjectViewForId(String profileID, String projectID) throws Exception { - LOG.info("getProjectForId profileID: " + profileID + ", projectID: " + projectID + "called"); + LOG.info("getProjectViewForId profileID: " + profileID + ", projectID: " + projectID + ", called"); if (profileID == null || projectID == null) throw new Exception("Invalid parameter. Either profileID or projectID is null"); @@ -1265,49 +1265,78 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme List listJSON = new ArrayList(); try { - String template = "{\"content\": \"$._theDocument.nome\"," - + "\"start\" : \"$._theDocument.dataInizioProgetto\"," - + "\"end\" : \"$._theDocument.dataFineProgetto\"}"; + String template = "{\"content\": \"$.nome\"," + "\"title\": \"$.nome\"," + + "\"start\" : \"$.dataInizioProgetto\"," + "\"end\" : \"$.dataFineProgetto\"}"; JSONObject sourceJsonTemplate = new JSONObject(template); - JSONObject targetJsonObject = new JSONObject(); com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration(); com.jayway.jsonpath.Configuration conf2 = conf.addOptions(Option.ALWAYS_RETURN_LIST); Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); List relationships = theProject.getRelationships(); + + if(relationships==null || relationships.size()==0) + return new ArrayList(); + + //Adding the input document + DocumentContext targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson()); - for (Relationship relationship : relationships) { - targetJsonObject.put("id", relationship.getTargetUCD()+","+relationship.getTargetID()); + JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, + profileID,projectID, null); + + targetJsonObject.put("selected", "from here"); + String theJSONResult = targetJsonObject.toString(); + LOG.debug("Built jsonObject " + theJSONResult); + listJSON.add(theJSONResult); + + for (Relationship relationship : relationships) { Project targetProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(), relationship.getTargetID()); - DocumentContext targetDoc = JsonPath.using(conf2).parse(targetProject.getTheDocument().toJson()); + targetDoc = JsonPath.using(conf2).parse(targetProject.getTheDocument().toJson()); - for (Object key : sourceJsonTemplate.keySet()) { - String theKey = key + ""; - String jsonPath = sourceJsonTemplate.getString(theKey); - // Works fine - - List listValue = targetDoc.read(jsonPath); - String result = ""; - for (int i = 0; i < listValue.size() - 1; i++) { - result += listValue.get(i) + ", "; - } - result += listValue.get(listValue.size() - 1); - targetJsonObject.put(theKey, result); - } - - List images = getImagesForId(relationship.getTargetUCD(), relationship.getTargetID(), - true); - if (images.size() > 0) { - images.get(0).getLink(); - targetJsonObject.put("image_url", images.get(0).getLink()); - } - String theJSONResult = targetJsonObject.toString(); + targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, + relationship.getTargetUCD(), relationship.getTargetID(), null); + theJSONResult = targetJsonObject.toString(); LOG.debug("Built jsonObject " + theJSONResult); listJSON.add(theJSONResult); +// GeoportalClientCaller.projects().getRelationshipChain(profileID, projectID, relationship.getRelationshipName()); +// relationship.getRelationshipName(); + +// targetJsonObject.put("id", relationship.getTargetUCD() + "," + relationship.getTargetID()); +// targetJsonObject.put("relationship_name", relationship.getRelationshipName()); +// +// LOG.debug("targetDoc is: " + targetDoc.jsonString()); +// LOG.debug("sourceJsonTemplate is: " + sourceJsonTemplate.toString()); +// +// for (Object key : sourceJsonTemplate.keySet()) { +// String theKey = key + ""; +// LOG.debug("Searching key: " + theKey); +// String jsonPath = sourceJsonTemplate.getString(theKey); +// LOG.debug("with key: " + theKey + " read JSON path: " + jsonPath); +// +// // Works fine +// +// List listValue = targetDoc.read(jsonPath); +// String result = ""; +// for (int i = 0; i < listValue.size() - 1; i++) { +// result += listValue.get(i) + ", "; +// } +// result += listValue.get(listValue.size() - 1); +// targetJsonObject.put(theKey, result); +// } +// +// List images = getImagesForId(relationship.getTargetUCD(), relationship.getTargetID(), +// true); +// if (images.size() > 0) { +// images.get(0).getLink(); +// targetJsonObject.put("image_url", images.get(0).getLink()); +// } +// String theJSONResult = targetJsonObject.toString(); +// LOG.debug("Built jsonObject " + theJSONResult); +// listJSON.add(theJSONResult); + } } catch (Exception e) { String erroMsg = "Error occurred on reading relatioships for id: " + projectID; @@ -1315,21 +1344,22 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } // TODO LOAD AND APPLT TEMPLATING OF KIND - - for (int i = 0; i < 5; i++) { - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "UCD"+i+",ID"+i); - jsonObject.put("content", - "title moooooooooooooolto lungoooooooooooooooooooooooooooooooooooooooooooooooooo" + i); - jsonObject.put("start", "201" + i + "-04-1"); - jsonObject.put("end", "201" + i + "-09-1"); - if (i < 3) - jsonObject.put("image_url", - "https://data-pre.d4science.org/shub/E_ck5hN0hBcGljR3oySm5KOWJxOUMyRkRaWkZ4WnhmWXJjWVlLeWxGcW9FMWQraitOWStmQXREQklNUlMydzNFTw=="); - - listJSON.add(jsonObject.toString()); - } +// +// for (int i = 0; i < 5; i++) { +// +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("id", "UCD"+i+",ID"+i); +// jsonObject.put("content", +// "title moooooooooooooolto lungoooooooooooooooooooooooooooooooooooooooooooooooooo" + i); +// jsonObject.put("start", "201" + i + "-04-1"); +// jsonObject.put("end", "201" + i + "-09-1"); +// jsonObject.put("relationship_name", "follows"); +// if (i < 3) +// jsonObject.put("image_url", +// "https://data-pre.d4science.org/shub/E_ck5hN0hBcGljR3oySm5KOWJxOUMyRkRaWkZ4WnhmWXJjWVlLeWxGcW9FMWQraitOWStmQXREQklNUlMydzNFTw=="); +// +// listJSON.add(jsonObject.toString()); +// } return listJSON; } catch (Exception e) { @@ -1339,4 +1369,47 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } } + private JSONObject toTimelineJSONModel(DocumentContext targetDoc, JSONObject sourceJsonTemplate, String targetUCD, + String targetProjectID, String relationName) { + JSONObject targetJsonObject = new JSONObject(); + + targetJsonObject.put("id", targetUCD + "," + targetProjectID); + + if (relationName != null) + targetJsonObject.put("relationship_name", relationName); + + for (Object key : sourceJsonTemplate.keySet()) { + String jsonPath = null; + String theKey = null; + try { + theKey = key + ""; + LOG.debug("Searching key: " + theKey); + jsonPath = sourceJsonTemplate.getString(theKey); + LOG.debug("with key: " + theKey + " read JSON path: " + jsonPath); + List listValue = targetDoc.read(jsonPath); + String result = ""; + for (int i = 0; i < listValue.size() - 1; i++) { + result += listValue.get(i) + ", "; + } + result += listValue.get(listValue.size() - 1); + targetJsonObject.put(theKey, result); + } catch (Exception e) { + LOG.trace("Error on setting key: {}, path: {}", theKey, jsonPath); + } + } + List images = null; + try { + images = getImagesForId(targetUCD, targetProjectID, true); + } catch (Exception e) { + + } + if (images != null && images.size() > 0) { + images.get(0).getLink(); + targetJsonObject.put("image_url", images.get(0).getLink()); + } + + return targetJsonObject; + + } + } diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index 8384359..e361c5c 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -581,4 +581,11 @@ body { margin: 0; left: 50%; transform: translate(-50%); +} + +@media all and (max-width: 1024px) { + #timeline-data{ + left: 730px; + width: 250px; + } } \ No newline at end of file diff --git a/src/main/webapp/GeoportalDataViewer.html b/src/main/webapp/GeoportalDataViewer.html index 0b8edc6..4b5f062 100644 --- a/src/main/webapp/GeoportalDataViewer.html +++ b/src/main/webapp/GeoportalDataViewer.html @@ -39,9 +39,14 @@