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**
* 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

View File

@ -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();
// }
}
});

View File

@ -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();
}

View File

@ -18,7 +18,7 @@ public class ProjectUtil {
}
if (projectID != null) {
htmlCode += "(id: " + projectID + ")";
htmlCode += " (id: " + projectID + ")";
}
return htmlCode;

View File

@ -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" + " <br>" + 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<String> 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();
}-*/;
}

View File

@ -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<String> listJSON = new ArrayList<String>();
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<Relationship> relationships = theProject.getRelationships();
if(relationships==null || relationships.size()==0)
return new ArrayList<String>();
//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<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();
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) {
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<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

@ -581,4 +581,11 @@ body {
margin: 0;
left: 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">
<table>
{{#if relation}}
{{#if selected}}
<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>
{{/if}}
{{#if image_url}}

View File

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