portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msnickl...@apache.org
Subject [4/8] portals-pluto git commit: Completed session history prototype. Adapted portlets to store control stats as parameters so that they are propery set when navigating through the history.
Date Fri, 12 Dec 2014 05:41:10 GMT
Completed session history prototype. Adapted portlets to store control
stats as parameters so that they are propery set when navigating through
the history.


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/04cd7efa
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/04cd7efa
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/04cd7efa

Branch: refs/heads/PortletHub
Commit: 04cd7efae1fbaba34508f6613829d5bf9792fde8
Parents: eadf854
Author: Scott Nicklous <msnicklous@apache.org>
Authored: Sun Dec 7 18:35:34 2014 +0100
Committer: Scott Nicklous <msnicklous@apache.org>
Committed: Sun Dec 7 18:35:34 2014 +0100

----------------------------------------------------------------------
 .../java/basic/portlet/ColorSelPortlet.java     | 29 ++++++------
 .../src/main/java/basic/portlet/Constants.java  |  5 ++
 .../src/main/webapp/WEB-INF/jsp/view-csp.jsp    | 49 ++++++++++++++++----
 .../src/main/webapp/WEB-INF/jsp/view-isp.jsp    | 43 ++++++++++++-----
 .../src/main/webapp/WEB-INF/jsp/view-ivp.jsp    | 45 +++++++++++++++---
 .../src/main/webapp/WEB-INF/jsp/view-pap.jsp    |  5 +-
 pluto-portal/src/main/webapp/portletHubImpl.js  | 46 ++++++++++++++----
 7 files changed, 168 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/04cd7efa/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java b/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
index fed79e6..326191c 100644
--- a/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
+++ b/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
@@ -37,7 +37,7 @@ import javax.xml.namespace.QName;
 
 
 /**
- * A management portlet that displays the current deep link configuraion
+ * A management portlet that displays the current deep link configuration
  */
 public class ColorSelPortlet extends GenericPortlet {
 
@@ -67,20 +67,7 @@ public class ColorSelPortlet extends GenericPortlet {
 
    public void processAction(ActionRequest req, ActionResponse resp)
          throws PortletException, IOException {
-      
-      // pass the action params from the form submission as render parameters
-      resp.setRenderParameter(PARAM_ERRMSG, " "); // hack as Pluto does not support deleting
parameters
-      String val = req.getParameter(PARAM_COLOR);
-      if (val != null) {
-         if (val.matches("^#(?:[A-Fa-f0-9]{3}){1,2}$")) {
-            resp.setRenderParameter(PARAM_COLOR, val);
-         } else {
-            resp.setRenderParameter(PARAM_ERRMSG, "bad color. try again.");
-         }
-      } else {
-         resp.setRenderParameter(PARAM_ERRMSG, "enter color #xxxxxx or #xxx.");
-      }
-      
+            
       String[] vals = req.getParameterValues(PARAM_FG_COLOR);
       String r = "0";
       String g = "0";
@@ -92,13 +79,23 @@ public class ColorSelPortlet extends GenericPortlet {
             if (v.equals(PARAM_FG_BLUE)) b = "F";
          }
       }
+      String clr = "#" + r + g + b;
       
+      // make sure the private parameter are all on the URL for 
+      // potential back button support
       if (vals != null) {
          resp.setRenderParameter(PARAM_FG_COLOR, vals);
       }
       
-      String clr = "#" + r + g + b;
+      String val = req.getParameter(PARAM_SUBTYPE);
+      if (val != null) {
+         resp.setRenderParameter(PARAM_SUBTYPE, val);
+      }
+      
       val = req.getParameter(PARAM_MSG_INPUT);
+      if (val != null) {
+         resp.setRenderParameter(PARAM_MSG_INPUT, val);
+      }
       
       String msg = val + DELIM + clr;
       QName qn = new QName(EVENT_NAMESPACE, EVENT_NAME);

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/04cd7efa/PortletHubDemo/src/main/java/basic/portlet/Constants.java
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/java/basic/portlet/Constants.java b/PortletHubDemo/src/main/java/basic/portlet/Constants.java
index a001d89..fad97d7 100644
--- a/PortletHubDemo/src/main/java/basic/portlet/Constants.java
+++ b/PortletHubDemo/src/main/java/basic/portlet/Constants.java
@@ -20,6 +20,11 @@ public class Constants {
    public final static String PARAM_SELTYPE_RADIO = "radio";
    public final static String PARAM_SELTYPE_DROPDOWN = "dropdown";
    
+   // privae parameter for color selection portlet
+   public final static String PARAM_SUBTYPE = "subType";
+   public final static String PARAM_SUBTYPE_URL = "URL";
+   public final static String PARAM_SUBTYPE_FORM = "form";
+   
    public final static String PARAM_IMGNAME = "imgName";
    public final static String PARAM_COLOR = "color";
    public final static String PARAM_ERRMSG = "errmsg";

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/04cd7efa/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
index 6bb6a19..f3ffe52 100644
--- a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
@@ -74,9 +74,9 @@ limitations under the License.
    </td></tr><tr><td>
    Form submission:
    </td><td>
-   <input id='<portlet:namespace/>sType-url' type='radio' name='sType' value='url'
checked>URL
+   <input id='<portlet:namespace/>sType-url' type='radio' name='<%=PARAM_SUBTYPE%>'
value='<%=PARAM_SUBTYPE_URL%>' checked>URL
    </td><td>
-   <input id='<portlet:namespace/>sType-form' type='radio' name='sType' value='form'>Form
+   <input id='<portlet:namespace/>sType-form' type='radio' name='<%=PARAM_SUBTYPE%>'
value='<%=PARAM_SUBTYPE_FORM%>'>Form
    </td><td>
    <INPUT id ='<portlet:namespace/>-send' VALUE='send' TYPE='submit'>
    </td></tr></table>
@@ -90,12 +90,12 @@ limitations under the License.
    var pid = '<portlet:namespace/>',
        colorEntry = '<portlet:namespace/>-color',
        msgdiv = '<portlet:namespace/>-putMsgHere',
-       sendbtn = '<portlet:namespace/>-send',
        rid = '<portlet:namespace/>-red',
        gid = '<portlet:namespace/>-green',
        bid = '<portlet:namespace/>-blue',
        mid = '<portlet:namespace/>-msg',
        formid = '<portlet:namespace/>-setParams',
+       sidurl = '<portlet:namespace/>sType-url',
        sidform = '<portlet:namespace/>sType-form',
        currState,
        hub,
@@ -103,13 +103,42 @@ limitations under the License.
        
    // Handler for onStateChange event
    update = function (type, state) {
-      var oldColor = currState.p.getValue('color'),
-          newColor = state.p.getValue('color', '#FFFFFF');
+      var oldColor = currState.p.getValue('<%=PARAM_COLOR%>'),
+      
+          // use getValue with default value that is used if the parameter is not set
+          newColor = state.p.getValue('<%=PARAM_COLOR%>', '#FFFFFF'),
+          subtype = state.p.getValue('<%=PARAM_SUBTYPE%>', '<%=PARAM_SUBTYPE_URL%>'),
+          msg = state.p.getValue('<%=PARAM_MSG_INPUT%>', ''),
+          
+          fgcolor = state.p.getValues('<%=PARAM_FG_COLOR%>'),
+          clr = {red: false, green: false, blue: false}, ii;
+      
       console.log("CSP: state updated. Type=" + type + ", color=" + newColor);
+      
       if (newColor !== oldColor) {
          document.getElementById(msgdiv).innerHTML = '';
          document.getElementById(colorEntry).value = newColor;
       }
+      
+      // make sure controls are set according to parameters
+      
+      if (subtype === '<%=PARAM_SUBTYPE_URL%>') {
+         document.getElementById(sidurl).checked = true;
+      } else {
+         document.getElementById(sidform).checked = true;
+      }
+       
+      if (fgcolor) {
+         for (ii = 0; ii < fgcolor.length; ii++) {
+            clr[fgcolor[ii]] = true;
+         }
+      } 
+      document.getElementById(rid).checked = clr.red;
+      document.getElementById(gid).checked = clr.green;
+      document.getElementById(bid).checked = clr.blue;
+
+      document.getElementById(mid).value = msg;
+
       currState = state;
    };
    
@@ -151,18 +180,18 @@ limitations under the License.
          parms = hub.newParameters();
          parms.setValue('action', 'send');
          if (document.getElementById(rid).checked) {
-            clrs.push("red");
+            clrs.push("<%=PARAM_FG_RED%>");
          } 
          if (document.getElementById(gid).checked) {
-            clrs.push("green");
+            clrs.push("<%=PARAM_FG_GREEN%>");
          } 
          if (document.getElementById(bid).checked) {
-            clrs.push("blue");
+            clrs.push("<%=PARAM_FG_BLUE%>");
          } 
          if (clrs.length > 0) {
-            parms.setValue('fgcolor', clrs);
+            parms.setValue('<%=PARAM_FG_COLOR%>', clrs);
          }
-         parms.setValue('imsg', document.getElementById(mid).value);
+         parms.setValue('<%=PARAM_MSG_INPUT%>', document.getElementById(mid).value);
          hub.action(parms);
       }
       event.preventDefault();

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/04cd7efa/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
index 74cf0d9..2efd1f2 100644
--- a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
@@ -76,10 +76,38 @@ limitations under the License.
       }
    },
    
+   // function to select the proper image depending on radio button or dropdown display
+   selectImage = function (seltype, imgName) {
+      var ii, f = document.getElementById(fid);
+      
+      if (!imgName) {
+         imgName = 'default';
+      }
+      
+      if (seltype === 'radio') {
+         for (ii=0; ii < f.imgName.length; ii++) {
+            if (f.imgName[ii].value === imgName) {
+               console.log("ISP: image clicked: " + imgName);
+               f.imgName[ii].checked = true;
+            } else {
+               f.imgName[ii].checked = false;
+            }
+         }
+      } else {
+         for (ii=0; ii < f.imgName.length; ii++) {
+            if (f.imgName[ii].value === imgName) {
+               console.log("ISP: image selected: " + imgName);
+               f.imgName[ii].selected = true;
+            }
+         }
+      }
+   },
+   
    // Handler for onStateChange event
    update = function (type, state) {
       var oldST = currState.p.getValue('selType'),
           newST = state.p.getValue('selType', 'radio'),
+          oldImg = currState.p.getValue('imgName'),
           newImg = state.p.getValue('imgName');
           
       console.log("ISP: state updated. type=" + type + ", selType=" + newST + ", imgName="
+ newImg);
@@ -98,27 +126,20 @@ limitations under the License.
                      for (ii=0; ii < f.imgName.length; ii++) {
                         console.log("ISP: adding selection handler for: " + f.imgName[ii].value);
                         f.imgName[ii].onclick = handleImgRadio;
-                        if (f.imgName[ii].value === newImg) {
-                           console.log("ISP: image clicked: " + newImg);
-                           f.imgName[ii].clicked = true;
-                        }
                      }
                   } else if (newST === 'dropdown') {
                      console.log("ISP: adding selection handler to dropdown list element:
" + selBox);
                      document.getElementById(selBox).onchange = handleImgDropdown;
-                     for (ii=0; ii < f.imgName.length; ii++) {
-                        if (f.imgName[ii].value === newImg) {
-                           console.log("ISP: image selected: " + newImg);
-                           f.imgName[ii].selected = true;
-                        }
-                     }
                   }
-
+				  selectImage(newST, newImg);
                }
             };
             xhr.open("GET",url,true);
             xhr.send();
          });
+      } else {
+         // make sure image is selected according to parameter setting. 
+         selectImage(newST, newImg);
       }
 
       if (newST === 'dropdown') {

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/04cd7efa/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-ivp.jsp
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-ivp.jsp b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-ivp.jsp
index e61b91c..68aa575 100644
--- a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-ivp.jsp
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-ivp.jsp
@@ -59,12 +59,43 @@ limitations under the License.
        
        resparms = {},
        cacheability,
+       currState,
        hub,
    
    // Update function called by the Portlet Hub when an onStatechange event occurs. 
    update = function (type, state) {
+      var bo = state.p.getValue('bo'),
+          ca = state.p.getValue('ca', hub.constants.PAGE);
+      
+      currState = state;
+      
       console.log("IVP: state updated. event type=" + type);
       
+      // set cacheability & border color according to parameters. Set controls
+      // according to parameers to enable back button support.
+      
+      resparms = hub.newParameters();
+      if (bo) {
+         resparms.setValue('border', bo);
+         document.getElementById(border).checked = true;
+      } else {
+         document.getElementById(border).checked = false;
+      }
+      
+      cacheability = ca;
+      switch (ca) {
+      case hub.constants.PAGE:
+         document.getElementById(ca_page).checked = true;
+         break;
+      case hub.constants.PORTLET:
+         document.getElementById(ca_portlet).checked = true;
+         break;
+      case hub.constants.FULL:
+         document.getElementById(ca_full).checked = true;
+         break;
+      }
+      
+      
       hub.createResourceUrl(resparms, cacheability).then(function (url) {
          var brdr = (resparms.border === undefined) ? undefined : resparms.border[0],
              xhr = new XMLHttpRequest();
@@ -81,11 +112,13 @@ limitations under the License.
    
    // Handler for cacheability radio buttons
    handleCA = function () {
-      var c = hub.constants[this.value];
+      var c = hub.constants[this.value], nstate;
       console.log("IVP: cacheability button clicked: " + this.value + ", corresponding to
constant value " + c);
       if (cacheability !== c) {
          cacheability = c;
-         update();
+         nstate = currState.clone();
+         nstate.p.setValue('ca', c);
+         hub.setPortletState(nstate);
       }
    };
    
@@ -97,13 +130,14 @@ limitations under the License.
    // Handler for 'border' checkbox 
    document.getElementById(border).checked = false;
    document.getElementById(border).onclick = function () {
+      var nstate = currState.clone();
       console.log("IVP: border checked: " + this.checked);
       if (this.checked) {
-         resparms.setValue('border', '#00F');;
+         nstate.p.setValue('bo', '#00F');;
       } else {
-         resparms.remove('border');
+         nstate.p.remove('bo');
       }
-      update();
+      hub.setPortletState(nstate);
    };
    
    // Register this portlet with the Portlet Hub and add event listener for 
@@ -111,7 +145,6 @@ limitations under the License.
    portlet.register(pid).then(function (pi) {
       console.log("IVP: registered: " + pid);
       hub = pi;
-      resparms = hub.newParameters();
       cacheability = hub.constants.PAGE;
       hub.addEventListener("portlet.onStateChange", update);
    });

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/04cd7efa/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-pap.jsp
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-pap.jsp b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-pap.jsp
index b8e2cab..c9ccb8b 100644
--- a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-pap.jsp
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-pap.jsp
@@ -49,11 +49,12 @@ limitations under the License.
    
    // Handler for onStateChange event
    update = function (type, s) {
+      var nc = s.p.getValue('color', '#E0E0E0');
       console.log("PAP: state updated. Event type = " + type);
       
       // change background color for message box
-      if (state.p.getValue('color') !== s.p.getValue('color')) {
-         document.getElementById(resdiv).style.background = s.p.getValue('color');
+      if (state.p.getValue('color') !== nc) {
+         document.getElementById(resdiv).style.background = nc;
       }
       state = s;
    };

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/04cd7efa/pluto-portal/src/main/webapp/portletHubImpl.js
----------------------------------------------------------------------
diff --git a/pluto-portal/src/main/webapp/portletHubImpl.js b/pluto-portal/src/main/webapp/portletHubImpl.js
index 2b6a482..f47c6ef 100644
--- a/pluto-portal/src/main/webapp/portletHubImpl.js
+++ b/pluto-portal/src/main/webapp/portletHubImpl.js
@@ -300,12 +300,19 @@ var portlet = portlet || {};
    /**
     * Called when the page state has been updated to allow the
     * browser history to be taken care of.
+    * @param      {boolean} replace    replace the state rather than pushing
     */
-   updateHistory = function (pid) {
+   updateHistory = function (replace) {
       var url = "x";
-      getUrl('RENDER', pid, {}).then(function (url) {
-         console.log("Updating history. URL=" + url);
-         history.pushState(pageState, "", url);
+      getUrl('RENDER', null, {}).then(function (url) {
+         var token = JSON.stringify(pageState);
+         console.log("Updating history. URL =" + url + ", token length =" + token.length

+            + ", token 30 chars =" + token.substring(0,30));
+         if (replace) {
+            history.replaceState(token, "");
+         } else {
+            history.pushState(token, "", url);
+         }
       });
    },
    
@@ -356,7 +363,7 @@ var portlet = portlet || {};
       pageState[pid].state = state;
       upids.push(pid);
       
-      updateHistory(pid);
+      updateHistory();
 
       
       // Use Promise to allow for potential server communication - 
@@ -418,7 +425,7 @@ var portlet = portlet || {};
    updatePageStateFromString = function (ustr, pid) {
       var states, tpid, state, upids = [], stateUpdated = false;
 
-      states = decodeUpdateString(ustr, pid);
+      states = decodeUpdateString(ustr);
 
       // Update states and collect IDs of affected portlets. 
       for (tpid in states) {
@@ -430,8 +437,10 @@ var portlet = portlet || {};
          }
       }
       
-      if (stateUpdated) {
-         updateHistory(pid);
+      // pid will be null or undefined when called from onpopstate routine.
+      // In that case, don't update history.
+      if (stateUpdated && pid) {
+         updateHistory();
       }
 
       return upids;
@@ -573,6 +582,11 @@ var portlet = portlet || {};
    
       var url = portlet.impl.getUrlBase(), ca = 'cacheLevelPage', parm, isAction = false,
           sep = "", name, names, vals, ii, str, id, ids, tpid, prpstrings;
+       
+      // If target portlet not defined for render URL, set it to null
+      if ((type === "RENDER") && pid === undefined) {
+         pid = null;
+      }
 
       // First add the appropriate window identifier according to URL type.
       // Note that no special window ID is added to a RENDER URL. 
@@ -624,7 +638,8 @@ var portlet = portlet || {};
 
          // add the state for the target portlet for on-action urls.
          // (Action URLs have only action parameters in the query string)
-         if (!isAction) {
+         // (for a render URL, pid can be null)
+         if (!isAction && pid !== null) {
             url += genPMWSString(pid);  // portlet mode & window state
             str = "";
             names = pageState[pid].state.parameters;
@@ -734,6 +749,18 @@ var portlet = portlet || {};
       });
 
    };
+   
+   /**
+    * Handler for history event that is fired when the back button is pressed.
+    */
+   window.onpopstate = function (ev) {
+      var upids;
+      if (ev.state) {
+         console.log("onpopstate fired. State = " + ev.state.substr(0, 30) + " ...<more>");
+         upids = updatePageStateFromString(ev.state);
+         updatePageStateAsynch(upids);
+      }
+   }
 
    
    /**
@@ -756,6 +783,7 @@ var portlet = portlet || {};
       // take care of moc data initialization      
       if (!isInitialized) {
          pageState = portlet.impl.getInitData();
+         updateHistory(true);
          isInitialized = true;
       }
       


Mime
View raw message