in progress on timeline

This commit is contained in:
Francesco Mangiacrapa 2022-11-04 17:16:37 +01:00
parent a3b5045ef7
commit ed93c13434
9 changed files with 182 additions and 90 deletions

View File

@ -10,11 +10,11 @@ The GeoPortal Data Viewer App is an application to access, discovery and navigat
**Uses** **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 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) * 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 * 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 ## Documentation

View File

@ -253,18 +253,18 @@ public class GeoportalDataViewer implements EntryPoint {
RootPanel.get(APP_DIV).add(attributionDiv); RootPanel.get(APP_DIV).add(attributionDiv);
new Timer() { // new Timer() {
//
@Override // @Override
public void run() { // public void run() {
GWT.log("Instancing timeline"); // GWT.log("Instancing timeline");
ProjectDV project = new ProjectDV(); // ProjectDV project = new ProjectDV();
project.setId("fake"); // project.setId("fake");
project.setProfileID("fake"); // project.setProfileID("fake");
applicationBus.fireEvent(new TimelineProjectRelationsEvent(project, EVENT_TYPE.SHOW)); // applicationBus.fireEvent(new TimelineProjectRelationsEvent(project, EVENT_TYPE.SHOW));
//
} // }
}.schedule(1000); // }.schedule(1000);
// Modal modal = new Modal(true, true); // Modal modal = new Modal(true, true);
// modal.setWidth(400); // modal.setWidth(400);
@ -396,9 +396,10 @@ public class GeoportalDataViewer implements EntryPoint {
&& relationships!= null && relationships.size() > 0) { && relationships!= null && relationships.size() > 0) {
GWT.log("LoadTimelineRelationships is true and the project has Relationships"); GWT.log("LoadTimelineRelationships is true and the project has Relationships");
showTimelineProjectRelations(result.getTheProjectDV()); showTimelineProjectRelations(result.getTheProjectDV());
} else {
hideTimelineProjectRelations();
} }
// else {
// hideTimelineProjectRelations();
// }
} }
}); });

View File

@ -50,7 +50,7 @@ public interface GNAImages extends ClientBundle {
@Source("spinner_earth.gif") @Source("spinner_earth.gif")
ImageResource spinnerEarth(); ImageResource spinnerEarth();
@Source("spinner_clock2.gif") @Source("spinner_clock.gif")
ImageResource spinnerClock(); ImageResource spinnerClock();
} }

View File

@ -37,7 +37,8 @@ public class TimelineRelationPanel extends Composite {
@UiField @UiField
HTMLPanel timelineTitle; 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; private TimelineRelationPanel instance = this;
@ -57,15 +58,16 @@ public class TimelineRelationPanel extends Composite {
this.theProjectDV = theProjectDV; this.theProjectDV = theProjectDV;
this.applicationBus = applicationBus; this.applicationBus = applicationBus;
String html = ProjectUtil.toHMLCode(theProjectDV.getTheDocument(), theProjectDV.getId()); String html = ProjectUtil.toHMLCode(theProjectDV.getTheDocument());
HTML title = new HTML("Relationships of the Project: " + html); HTML title = new HTML("Relationships of the Project" + " <br>" + html);
timelineTitle.add(title); timelineTitle.add(title);
loaderData.getElement().getStyle().setTextAlign(TextAlign.CENTER); loaderData.getElement().getStyle().setTextAlign(TextAlign.CENTER);
timelineTitle.add(loaderData);
timelineContainer.getElement().setId("visualization"); timelineContainer.getElement().setId("visualization");
timelineContainer.add(loaderData);
Scheduler.get().scheduleDeferred(new ScheduledCommand() { Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() { public void execute() {
@ -75,6 +77,7 @@ public class TimelineRelationPanel extends Composite {
@Override @Override
public void onSuccess(List<String> result) { public void onSuccess(List<String> result) {
timelineContainer.remove(loaderData);
JSONArray toJsonArr = new JSONArray(); JSONArray toJsonArr = new JSONArray();
for (int i = 0; i < result.size(); i++) { for (int i = 0; i < result.size(); i++) {
@ -82,12 +85,12 @@ public class TimelineRelationPanel extends Composite {
} }
instanceTimeline(timelineContainer.getElement().getId(), toJsonArr, instance); instanceTimeline(timelineContainer.getElement().getId(), toJsonArr, instance);
timelineTitle.remove(loaderData);
} }
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
timelineTitle.remove(loaderData); timelineContainer.remove(loaderData);
Alert alert = new Alert(caught.getMessage()); Alert alert = new Alert(caught.getMessage());
alert.setType(AlertType.ERROR); alert.setType(AlertType.ERROR);
alert.setClose(false); alert.setClose(false);
@ -106,13 +109,11 @@ public class TimelineRelationPanel extends Composite {
String[] references = this.selectedProjectID.split(","); String[] references = this.selectedProjectID.split(",");
GeoportalItemReferences gir = new GeoportalItemReferences(references[1], GeoportalItemReferences gir = new GeoportalItemReferences(references[1], references[0]);
references[0]); ShowDetailsEvent showDetailsEvent = new ShowDetailsEvent(gir, null, null, false);
ShowDetailsEvent event = new ShowDetailsEvent(gir, null, null, false); GWT.log("fireEvetn: " + showDetailsEvent);
GWT.log("fireEvetn: "+event);
//applicationBus.fireEvent(new ShowDetailsEvent(gir, null, null, false));
applicationBus.fireEvent(showDetailsEvent);
} }
@ -145,11 +146,16 @@ public class TimelineRelationPanel extends Composite {
var timeline = new $wnd.vis.Timeline(container, items, var timeline = new $wnd.vis.Timeline(container, items,
$wnd.optionsTimeline); $wnd.optionsTimeline);
timeline.on('select',function(properties, items) { timeline
.on(
'select',
function(properties, items) {
//console.log('selected: ' + $wnd.JSON.stringify(properties)); //console.log('selected: ' + $wnd.JSON.stringify(properties));
console.log('selected items: ' + properties.items); console.log('selected items: ' + properties.items);
instance.@org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineRelationPanel::setSelectedProject(Ljava/lang/String;)(properties.items+'') instance.@org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineRelationPanel::setSelectedProject(Ljava/lang/String;)(properties.items+'')
}); });
//timeline.redraw();
}-*/; }-*/;
} }

View File

@ -967,7 +967,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
*/ */
@Override @Override
public ProjectView getProjectViewForId(String profileID, String projectID) throws Exception { 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) if (profileID == null || projectID == null)
throw new Exception("Invalid parameter. Either profileID or projectID is null"); throw new Exception("Invalid parameter. Either profileID or projectID is null");
@ -1265,49 +1265,78 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
List<String> listJSON = new ArrayList<String>(); List<String> listJSON = new ArrayList<String>();
try { try {
String template = "{\"content\": \"$._theDocument.nome\"," String template = "{\"content\": \"$.nome\"," + "\"title\": \"$.nome\","
+ "\"start\" : \"$._theDocument.dataInizioProgetto\"," + "\"start\" : \"$.dataInizioProgetto\"," + "\"end\" : \"$.dataFineProgetto\"}";
+ "\"end\" : \"$._theDocument.dataFineProgetto\"}";
JSONObject sourceJsonTemplate = new JSONObject(template); JSONObject sourceJsonTemplate = new JSONObject(template);
JSONObject targetJsonObject = new JSONObject();
com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration(); com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration();
com.jayway.jsonpath.Configuration conf2 = conf.addOptions(Option.ALWAYS_RETURN_LIST); com.jayway.jsonpath.Configuration conf2 = conf.addOptions(Option.ALWAYS_RETURN_LIST);
Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID);
List<Relationship> relationships = theProject.getRelationships(); List<Relationship> relationships = theProject.getRelationships();
for (Relationship relationship : relationships) { if(relationships==null || relationships.size()==0)
targetJsonObject.put("id", relationship.getTargetUCD()+","+relationship.getTargetID()); return new ArrayList<String>();
Project targetProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(),
relationship.getTargetID());
DocumentContext targetDoc = JsonPath.using(conf2).parse(targetProject.getTheDocument().toJson()); //Adding the input document
DocumentContext targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson());
for (Object key : sourceJsonTemplate.keySet()) { JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate,
String theKey = key + ""; profileID,projectID, null);
String jsonPath = sourceJsonTemplate.getString(theKey);
// Works fine
List<String> listValue = targetDoc.read(jsonPath); targetJsonObject.put("selected", "from here");
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<PayloadDV> 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(); String theJSONResult = targetJsonObject.toString();
LOG.debug("Built jsonObject " + theJSONResult); LOG.debug("Built jsonObject " + theJSONResult);
listJSON.add(theJSONResult); listJSON.add(theJSONResult);
for (Relationship relationship : relationships) {
Project targetProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(),
relationship.getTargetID());
targetDoc = JsonPath.using(conf2).parse(targetProject.getTheDocument().toJson());
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<String> 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<PayloadDV> 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) { } catch (Exception e) {
String erroMsg = "Error occurred on reading relatioships for id: " + projectID; 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 // TODO LOAD AND APPLT TEMPLATING OF KIND
//
for (int i = 0; i < 5; i++) { // for (int i = 0; i < 5; i++) {
//
JSONObject jsonObject = new JSONObject(); // JSONObject jsonObject = new JSONObject();
jsonObject.put("id", "UCD"+i+",ID"+i); // jsonObject.put("id", "UCD"+i+",ID"+i);
jsonObject.put("content", // jsonObject.put("content",
"title moooooooooooooolto lungoooooooooooooooooooooooooooooooooooooooooooooooooo" + i); // "title moooooooooooooolto lungoooooooooooooooooooooooooooooooooooooooooooooooooo" + i);
jsonObject.put("start", "201" + i + "-04-1"); // jsonObject.put("start", "201" + i + "-04-1");
jsonObject.put("end", "201" + i + "-09-1"); // jsonObject.put("end", "201" + i + "-09-1");
if (i < 3) // jsonObject.put("relationship_name", "follows");
jsonObject.put("image_url", // if (i < 3)
"https://data-pre.d4science.org/shub/E_ck5hN0hBcGljR3oySm5KOWJxOUMyRkRaWkZ4WnhmWXJjWVlLeWxGcW9FMWQraitOWStmQXREQklNUlMydzNFTw=="); // jsonObject.put("image_url",
// "https://data-pre.d4science.org/shub/E_ck5hN0hBcGljR3oySm5KOWJxOUMyRkRaWkZ4WnhmWXJjWVlLeWxGcW9FMWQraitOWStmQXREQklNUlMydzNFTw==");
listJSON.add(jsonObject.toString()); //
} // listJSON.add(jsonObject.toString());
// }
return listJSON; return listJSON;
} catch (Exception e) { } 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<String> 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<PayloadDV> 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;
}
} }

View File

@ -582,3 +582,10 @@ body {
left: 50%; left: 50%;
transform: translate(-50%); transform: translate(-50%);
} }
@media all and (max-width: 1024px) {
#timeline-data{
left: 730px;
width: 250px;
}
}

View File

@ -39,9 +39,14 @@
<script id="item-template" type="text/x-handlebars-template"> <script id="item-template" type="text/x-handlebars-template">
<table> <table>
{{#if relation}} {{#if selected}}
<tr><td> <tr><td>
<span id="relation-style">{{relation}}</span> <span id="relation-style">{{selected}}</span>
</tr></td>
{{/if}}
{{#if relationship_name}}
<tr><td>
<span id="relation-style">{{relationship_name}}</span>
</tr></td> </tr></td>
{{/if}} {{/if}}
{{#if image_url}} {{#if image_url}}

View File

@ -47,9 +47,9 @@
<script id="item-template" type="text/x-handlebars-template"> <script id="item-template" type="text/x-handlebars-template">
<table> <table>
{{#if relation}} {{#if relationship_name}}
<tr><td> <tr><td>
<span id="relation-style">{{relation}}</span> <span id="relation-style">{{relationship_name}}</span>
</tr></td> </tr></td>
{{/if}} {{/if}}
{{#if image_url}} {{#if image_url}}