Start managing the refresh of the iframe content only, without reload the whole page on redirect

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129323 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-22 16:40:38 +00:00
parent a5237b1c70
commit 835def2d71
4 changed files with 69 additions and 49 deletions

View File

@ -12,6 +12,7 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserDa
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserDatasetsEventHandler;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserOrganizationsEvent;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserOrganizationsEventHandler;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatasetForm;
import com.github.gwtbootstrap.client.ui.Modal;
@ -29,6 +30,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
public class CkanEventHandlerManager {
private HandlerManager eventBus = new HandlerManager(null);
private GCubeCkanDataCatalogPanel panel;
/**
*
@ -38,6 +40,15 @@ public class CkanEventHandlerManager {
}
/**
* @param panel the panel to set
*/
public void setPanel(GCubeCkanDataCatalogPanel panel) {
this.panel = panel;
}
private void bind() {
// bind on show home event
@ -46,28 +57,9 @@ public class CkanEventHandlerManager {
@Override
public void onShowHome(ShowHomeEvent showHomeEvent) {
// get the current path
String currentPath = Window.Location.getHref();
// check if the "path" parameter is already present
String currentParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
String finalPath;
if(currentParameter == null){
finalPath = currentPath;
}else{
// remove from the first "path" on
int index = currentPath.lastIndexOf("?"+GCubeCkanDataCatalog.GET_PATH_PARAMETER);
String firstPartOfThePath = currentPath.substring(0, index);
finalPath = firstPartOfThePath;
}
// redirect
Window.Location.assign(finalPath);
String baseUrlCkanConnector = panel.getBaseURLCKANConnector();
panel.instanceCkanFrame(baseUrlCkanConnector);
}
});
@ -124,31 +116,36 @@ public class CkanEventHandlerManager {
@Override
public void onShowDatasets(ShowUserDatasetsEvent showUserDatasetsEvent) {
// get the current path
String currentPath = Window.Location.getHref();
// check if the "path" parameter is already present
String currentParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
// the final path must be
String queryPar = "?" + GCubeCkanDataCatalog.GET_PATH_PARAMETER + "=" + "/dashboard/datasets";
String finalPath;
if(currentParameter == null){
finalPath = currentPath + queryPar;
}else{
// remove from the first "path" on
int index = currentPath.lastIndexOf("?"+GCubeCkanDataCatalog.GET_PATH_PARAMETER);
String firstPartOfThePath = currentPath.substring(0, index);
finalPath = firstPartOfThePath + queryPar;
}
// // get the current path
// String currentPath = Window.Location.getHref();
//
// // check if the "path" parameter is already present
// String currentParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
//
// // the final path must be
// String queryPar = "?" + GCubeCkanDataCatalog.GET_PATH_PARAMETER + "=" + "/dashboard/datasets";
//
// String finalPath;
//
// if(currentParameter == null){
// finalPath = currentPath + queryPar;
//
// }else{
//
// // remove from the first "path" on
// int index = currentPath.lastIndexOf("?"+GCubeCkanDataCatalog.GET_PATH_PARAMETER);
// String firstPartOfThePath = currentPath.substring(0, index);
// finalPath = firstPartOfThePath + queryPar;
//
// }
//
// // redirect
// Window.Location.assign(finalPath);
// redirect
Window.Location.assign(finalPath);
String baseUrlCkanConnector = panel.getBaseURLCKANConnector();
baseUrlCkanConnector += "/dashboard/datasets";
panel.instanceCkanFrame(baseUrlCkanConnector);
}
});

View File

@ -27,6 +27,7 @@ public class GCubeCkanDataCatalog implements EntryPoint {
* This is the entry point method.
*/
public void onModuleLoad() {
new GCubeCkanDataCatalogPanel(RootPanel.get(DIV_PORTLET_ID), eventManager.getEventBus());
GCubeCkanDataCatalogPanel panel = new GCubeCkanDataCatalogPanel(RootPanel.get(DIV_PORTLET_ID), eventManager.getEventBus());
eventManager.setPanel(panel);
}
}

View File

@ -3,6 +3,7 @@
*/
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
@ -27,6 +28,10 @@ public class CkanFramePanel extends FlowPanel{
}
private static native void print(String msg)/*-{
console.log(msg);
}-*/;
/**
* Instance frame.
*
@ -35,9 +40,16 @@ public class CkanFramePanel extends FlowPanel{
*/
public Frame instanceFrame(String ckanUrlConnector) {
try{
if(frame != null)
remove(frame);
}catch(Exception e){
print("Error " + e);
}
frame = new Frame(ckanUrlConnector);
frame.getElement().getStyle().setBorderWidth(0, Unit.PX);
// frame.getElement().setPropertyString("frameBorder", "0");
// frame.getElement().setPropertyString("frameBorder", "0");
frame.addLoadHandler(new LoadHandler() {
@Override

View File

@ -34,6 +34,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
private Image loading = new Image(CkanPortletResources.ICONS.loading());
private RootPanel rootPanel;
private HandlerManager eventBus;
private String baseURLCKANConnector;
/**
* Instantiates a new g cube ckan data catalog panel.
@ -54,7 +55,8 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
@Override
public void onSuccess(String ckanUrlConnector) {
GWT.log("Instancing CKAN iframe with url: "+ckanUrlConnector);
instanceCkanFrame(ckanUrlConnector);
baseURLCKANConnector = ckanUrlConnector;
instanceCkanFrame(baseURLCKANConnector);
GCubeCkanDataCatalogPanel.this.rootPanel.remove(loading);
updateSize();
}
@ -151,7 +153,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
* @param ckanUrlConnector the ckan url connector
* @return the frame
*/
private Frame instanceCkanFrame(String ckanUrlConnector){
public Frame instanceCkanFrame(String ckanUrlConnector){
return ckanFramePanel.instanceFrame(ckanUrlConnector);
@ -185,4 +187,12 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
if(ckanFramePanel.getFrame()!=null)
ckanFramePanel.getFrame().setSize(rootWidth+"px", height+"px");
}
/**
* @return the baseURLCKANConnector
*/
public String getBaseURLCKANConnector() {
return baseURLCKANConnector;
}
}