You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2014/12/12 06:41:09 UTC

[3/8] portals-pluto git commit: Added code to Portlet Hub to manipulate browser history. As first step, generate a render url for new page state and add it to browser history so that state is retained through page refresh and to allow bookmarking.

Added code to Portlet Hub to manipulate browser history. As first step,
generate a render url for new page state and add it to browser history
so that state is retained through page refresh and to allow bookmarking.


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

Branch: refs/heads/PortletHub
Commit: eadf8547ac0206c2051833816ce21974cade39f4
Parents: fe823c5
Author: Scott Nicklous <ms...@apache.org>
Authored: Fri Dec 5 14:58:49 2014 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Fri Dec 5 14:58:49 2014 +0100

----------------------------------------------------------------------
 pluto-portal/src/main/webapp/portlet.js        | 32 ++++++++++++++++---
 pluto-portal/src/main/webapp/portletHubImpl.js | 35 +++++++++++++++++++--
 2 files changed, 60 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/eadf8547/pluto-portal/src/main/webapp/portlet.js
----------------------------------------------------------------------
diff --git a/pluto-portal/src/main/webapp/portlet.js b/pluto-portal/src/main/webapp/portlet.js
index bfffb69..6cb71df 100644
--- a/pluto-portal/src/main/webapp/portlet.js
+++ b/pluto-portal/src/main/webapp/portlet.js
@@ -821,18 +821,40 @@ var portlet = portlet || {};
     */
    updatePageState = function (upids) {
       var ii;
-      
+
       if (upids.length === 0) {
          busy = false;
       } else {
-      for (ii = 0; ii < upids.length; ii++) {
-         _updateStateForPortlet(upids[ii]);
-      }
+         for (ii = 0; ii < upids.length; ii++) {
+            _updateStateForPortlet(upids[ii]);
+         }
       }
 
    },
 
    /**
+    * Accepts an object containing changed portlet IDs. This 
+    * function is meant to be used by the Portlet Hub impl in order 
+    * to initiate an unsolicited state update for the input list of 
+    * portlet IDs.
+    *
+    * @param    {string}   upids  array of portlet IDs to be updated 
+    * @private
+    */
+   updatePageStateAsynch = function (upids) {
+      
+      function update () {
+         if (busy) {
+            delay(update, 20);
+         } else {
+            busy = true;
+            updatePageState(upids);
+         }
+      }
+      update ();
+   },
+
+   /**
     * Updates the portlet state, taking the public render
     * parameters into account.
     * The portlet client requesting the change, represented
@@ -1146,7 +1168,7 @@ var portlet = portlet || {};
        * functions as passed in as an argument
        */
       return portlet.impl
-            .register(portletId)
+            .register(portletId, updatePageStateAsynch)
             .then(
                   function(portletImpl) {
 

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/eadf8547/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 6e22a99..2b6a482 100644
--- a/pluto-portal/src/main/webapp/portletHubImpl.js
+++ b/pluto-portal/src/main/webapp/portletHubImpl.js
@@ -47,6 +47,16 @@ var portlet = portlet || {};
     */
    pageState,
    
+   /**
+    * Callback function provided to the portlet hub to allow the the implementation
+    * to initiate an unsolicited portlet state update for an array of portlet IDs.
+    * @param   {string[]}  pid      An array of portlet IDs
+    * @returns {void}
+    * @function
+    * @private
+    */
+   updatePageStateAsynch,
+   
    
    /**
     * Determines if the specified portlet ID is present.
@@ -288,6 +298,18 @@ var portlet = portlet || {};
    },
    
    /**
+    * Called when the page state has been updated to allow the
+    * browser history to be taken care of.
+    */
+   updateHistory = function (pid) {
+      var url = "x";
+      getUrl('RENDER', pid, {}).then(function (url) {
+         console.log("Updating history. URL=" + url);
+         history.pushState(pageState, "", url);
+      });
+   },
+   
+   /**
     * sets state for the portlet. returns
     * array of IDs for portlets that were affected by the change, 
     * taking into account the public render parameters.
@@ -333,6 +355,8 @@ var portlet = portlet || {};
       // update state for the initiating portlet
       pageState[pid].state = state;
       upids.push(pid);
+      
+      updateHistory(pid);
 
       
       // Use Promise to allow for potential server communication - 
@@ -392,7 +416,7 @@ var portlet = portlet || {};
     * @private 
     */
    updatePageStateFromString = function (ustr, pid) {
-      var states, tpid, state, upids = [];
+      var states, tpid, state, upids = [], stateUpdated = false;
 
       states = decodeUpdateString(ustr, pid);
 
@@ -402,8 +426,13 @@ var portlet = portlet || {};
             state = states[tpid];
             pageState[tpid].state = state;
             upids.push(tpid);
+            stateUpdated = true;
          }
       }
+      
+      if (stateUpdated) {
+         updateHistory(pid);
+      }
 
       return upids;
    },
@@ -722,13 +751,15 @@ var portlet = portlet || {};
     * @private
     */
    portlet.impl = portlet.impl || {};
-   portlet.impl.register = function (pid) {
+   portlet.impl.register = function (pid, updateFunction) {
 
       // take care of moc data initialization      
       if (!isInitialized) {
          pageState = portlet.impl.getInitData();
          isInitialized = true;
       }
+      
+      updatePageStateAsynch = updateFunction;
 
       // stubs for accessing data for this portlet
       var stubs = {