You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mf...@apache.org on 2011/05/03 22:59:46 UTC

svn commit: r1099242 - in /incubator/rave/trunk/rave-portal: ./ src/main/java/org/apache/rave/portal/model/ src/main/resources/ src/main/webapp/WEB-INF/views/ src/main/webapp/script/ src/test/javascript/

Author: mfranklin
Date: Tue May  3 20:59:46 2011
New Revision: 1099242

URL: http://svn.apache.org/viewvc?rev=1099242&view=rev
Log:
Merged common container and modified to work within the rave.opensocial namespace.  (Supports RAVE-19)

Added:
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
    incubator/rave/trunk/rave-portal/src/test/javascript/
Modified:
    incubator/rave/trunk/rave-portal/pom.xml
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
    incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js

Modified: incubator/rave/trunk/rave-portal/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/pom.xml?rev=1099242&r1=1099241&r2=1099242&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/pom.xml (original)
+++ incubator/rave/trunk/rave-portal/pom.xml Tue May  3 20:59:46 2011
@@ -101,7 +101,7 @@ if needed you can specify it on the comm
         </dependency>
 
 
-         <!--Persistence-->
+        <!--Persistence-->
         <dependency>
             <groupId>org.apache.openjpa</groupId>
             <artifactId>openjpa-all</artifactId>
@@ -170,6 +170,23 @@ if needed you can specify it on the comm
                 </executions>
             </plugin>
             <plugin>
+                <groupId>com.github.searls</groupId>
+                <artifactId>jasmine-maven-plugin</artifactId>
+                <version>1.0.2-beta-2</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>resources</goal>
+                            <goal>testResources</goal>
+                            <goal>test</goal>
+                        </goals>
+                        <configuration>
+                            <jsSrcDir>${project.basedir}/src/main/webapp/js</jsSrcDir>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>org.codehaus.cargo</groupId>
                 <artifactId>cargo-maven2-plugin</artifactId>
                 <version>${cargo.version}</version>

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java?rev=1099242&r1=1099241&r2=1099242&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java (original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java Tue May  3 20:59:46 2011
@@ -42,6 +42,9 @@ public class Widget {
     @Basic @Column(name="url")
     private String url;
 
+    @Basic @Column(name="type")
+    private String type;
+
     /**
      * Gets the persistence unique identifier
      *
@@ -65,6 +68,13 @@ public class Widget {
 //
 // }
 
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
 
     public String getTitle() {
         return title;

Modified: incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql?rev=1099242&r1=1099241&r2=1099242&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql (original)
+++ incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql Tue May  3 20:59:46 2011
@@ -38,25 +38,25 @@ values (set(@user_id_6, next value for u
 
 --- gadget data ---
 -- wikipedia widget
-insert into widget (id, title, url)
-values(set(@wikipedia_widget_id, next value for widget_id_seq), 'Wikipedia','http://www.google.com/ig/modules/wikipedia.xml');
+insert into widget (id, title, url, type)
+values(set(@wikipedia_widget_id, next value for widget_id_seq), 'Wikipedia','http://www.google.com/ig/modules/wikipedia.xml', 'OpenSocial');
 
 -- translate widget
-insert into widget (id, title, url)
-values(set(@translate_widget_id, next value for widget_id_seq), 'Translate Gadget', 'http://www.google.com/ig/modules/dictionary.xml');
+insert into widget (id, title, url, type)
+values(set(@translate_widget_id, next value for widget_id_seq), 'Translate Gadget', 'http://www.google.com/ig/modules/dictionary.xml', 'OpenSocial');
 
 -- nytimes widget
-insert into widget (id, title, url)
-values(set(@nyt_widget_id, next value for widget_id_seq), 'NYTimes.com - Top Stories', 'http://widgets.nytimes.com/packages/html/igoogle/topstories.xml');
+insert into widget (id, title, url, type)
+values(set(@nyt_widget_id, next value for widget_id_seq), 'NYTimes.com - Top Stories', 'http://widgets.nytimes.com/packages/html/igoogle/topstories.xml', 'OpenSocial');
 
 -- google tabbed news widget
-insert into widget (id, title, url)
-values(set(@tabnews_widget_id, next value for widget_id_seq), 'Google News Gadget', 'http://www.gstatic.com/ig/modules/tabnews/tabnews.xml');
+insert into widget (id, title, url, type)
+values(set(@tabnews_widget_id, next value for widget_id_seq), 'Google News Gadget', 'http://www.gstatic.com/ig/modules/tabnews/tabnews.xml', 'OpenSocial');
 -- end widget data ----
 
 -- hamster widget
-insert into widget (id, title, url)
-values(set(@hamster_widget_id, next value for widget_id_seq), 'Pet Hamster', 'http://hosting.gmodules.com/ig/gadgets/file/112581010116074801021/hamster.xml');
+insert into widget (id, title, url, type)
+values(set(@hamster_widget_id, next value for widget_id_seq), 'Pet Hamster', 'http://hosting.gmodules.com/ig/gadgets/file/112581010116074801021/hamster.xml', 'OpenSocial');
 -- end widget data ----
 
 --- start page layout data ---

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp?rev=1099242&r1=1099241&r2=1099242&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp Tue May  3 20:59:46 2011
@@ -56,63 +56,22 @@
 </table>
 
 <script src="${opensocial_engine_url}/js/container.js?c=1&container=default&debug=1" type="text/javascript"></script>
+<script src="${pageContext.request.contextPath}/script/rave.js" type="text/javascript"></script>
 <script src="${pageContext.request.contextPath}/script/rave_opensocial.js" type="text/javascript"></script>
 
 <script type="text/javascript">
-    //TODO: Move much of this code out of this page and into the JS namespace Matt created.
-
-    //Create the common container instance.
-    var containerConfig = {};
-    containerConfig[osapi.container.ServiceConfig.API_PATH] = "/rpc";
-    containerConfig[osapi.container.ContainerConfig.RENDER_DEBUG] = "1";
-    var container = new osapi.container.Container(containerConfig);
+    rave.opensocial.init();
 
     //Enumerate all of our regionWidgets and collect up metadata about them.
     var widgets = [];
-    var widgetUrls = [];
     <c:forEach var="region" items="${defaultPage.regions}">
         <c:forEach var="regionWidget" items="${region.regionWidgets}">
-            widgets.push({regionWidgetId: ${regionWidget.id}, widgetUrl: "${regionWidget.widget.url}", userPrefs: {}});
-            widgetUrls.push("${regionWidget.widget.url}");
+            widgets.push({type: '${regionWidget.widget.type}', regionWidgetId: ${regionWidget.id}, widgetUrl: "${regionWidget.widget.url}", userPrefs: {}});
         </c:forEach>
     </c:forEach>
-
-    /**
-     * Tell the common container to pre-load the metadata for all the widgets we're going to ask it to render.  If we
-     * don't do this then when we call navigateGadget for each regionWidget the common container will fetch the metadata
-     * for each one at a time.  We also pass a callback function which will take the metadata retrieved from the preload
-     * so we can get all the default values for userPrefs and pass them along with our navigateGadget call.
-     *
-     * TODO: Prime the common container metadata cache with data we pull from our own persistent store so that we dont have
-     * to have common container fetch metadata on every page render.  See osapi.container.Container.prototype.preloadFromConfig_
-     * function which gets called from the osapi.container.Container constructor to get an idea of how this might be done.
-     *
-     * TODO: Use real userPrefs that we pull from our persistent store instead of the default values pulled from common
-     * containers metadata call.
-     *
-     * TODO: Get real moduleId's based on the regionWidget.id into the iframe URL.  Right now common container uses an
-     * internal counter for the mid parameter value with no external way to set it.
-    */
-    container.preloadGadgets(widgetUrls, function(response) {
-        for (var i = 0; i < widgets.length; i++) {
-            var widget = widgets[i];
-            var widgetMetadata = response[widget.widgetUrl];
-
-            for (var userPref in widgetMetadata.userPrefs) {
-                userPref = widgetMetadata.userPrefs[userPref];
-                widget.userPrefs[userPref.name] = userPref.defaultValue;
-            }
-
-            var renderParams = {};
-            renderParams[osapi.container.RenderParam.VIEW] = "home";
-            renderParams[osapi.container.RenderParam.WIDTH] = 250;
-            renderParams[osapi.container.RenderParam.HEIGHT] = 250;
-            renderParams[osapi.container.RenderParam.USER_PREFS] = widget.userPrefs;
-            var widgetBodyElement = document.getElementById(["widget-", widget.regionWidgetId, "-body"].join(""));
-            var gadgetSite = container.newGadgetSite(widgetBodyElement);
-            container.navigateGadget(gadgetSite , widget.widgetUrl, {}, renderParams);
-        }
-    });
+    //Get a map of widgets keyed by their type
+    var widgetMap = rave.createWidgetMap(widgets);
+    rave.opensocial.initGadgets(widgetMap[rave.opensocial.TYPE]);
 </script>
 
 </body>

Added: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js?rev=1099242&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js (added)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js Tue May  3 20:59:46 2011
@@ -0,0 +1,27 @@
+var rave = rave || (function(){
+
+    function mapWidgetsByType(widgets) {
+        var map = {};
+        for(var i=0; i < widgets.length; i++) {
+            var widget = widgets[i];
+            if(!map[widget.type]) {
+                map[widget.type] = [];
+            }
+            map[widget.type].push(widget);
+        }
+        return map;
+    }
+
+    /**
+     * Public API
+     */
+    return {
+        /**
+         * Creates a map of widgets by their type
+         *
+         * @param widgets list of widgets to map by type
+         */
+        createWidgetMap : mapWidgetsByType
+    }
+
+})();
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js?rev=1099242&r1=1099241&r2=1099242&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js Tue May  3 20:59:46 2011
@@ -17,6 +17,161 @@
  * under the License.
  */
 var rave = rave || {};
-rave.opensocial = rave.opensocial || {
+rave.opensocial = rave.opensocial || (function() {
+    var WIDGET_TYPE = "OpenSocial";
 
-};
\ No newline at end of file
+    var container;
+
+    /**
+     * Initialization
+     */
+
+    function initOpenSocial() {
+        initContainer();
+
+        container.rpcRegister('resize_iframe', resizeIframe);
+        container.rpcRegister('set_title', setTitle);
+        container.rpcRegister('requestNavigateTo', requestNavigateTo);
+        //container.rpcRegister('set_pref', null);
+        //container.rpcRegister('pubsub', null);
+
+    }
+
+    function initContainer() {
+        //Create the common container instance.
+        var containerConfig = {};
+        containerConfig[osapi.container.ServiceConfig.API_PATH] = "/rpc";
+        containerConfig[osapi.container.ContainerConfig.RENDER_DEBUG] = "1";
+        container = new osapi.container.Container(containerConfig);
+    }
+
+    /**
+     * Gets the container singleton or initializes if not instantiated
+     */
+    function getContainer() {
+        if (!container) {
+            initContainer();
+        }
+        return container;
+    }
+
+    /**
+     * Creates and renders the list of gadgets
+     *
+     * @param gadgets list of gadget objects that are to be rendered by the container
+     */
+    function createGadgetInstances(gadgets) {
+
+        //break out of the function if there are no OpenSocial gadgets
+        if(!gadgets || gadgets.length == 0) return;
+
+        //Create a list of gadget URLs from the gadget objects
+        var gadgetUrls = [];
+        for(var i = 0; i < gadgets.length; i++) {
+            gadgetUrls.push(gadgets[i].widgetUrl);
+        }
+
+        /**
+         * Tell the common container to pre-load the metadata for all the widgets we're going to ask it to render.  If we
+         * don't do this then when we call navigateGadget for each regionWidget the common container will fetch the metadata
+         * for each one at a time.  We also pass a callback function which will take the metadata retrieved from the preload
+         * so we can get all the default values for userPrefs and pass them along with our navigateGadget call.
+         *
+         * TODO: Prime the common container metadata cache with data we pull from our own persistent store so that we dont have
+         * to have common container fetch metadata on every page render.  See osapi.container.Container.prototype.preloadFromConfig_
+         * function which gets called from the osapi.container.Container constructor to get an idea of how this might be done.
+         *
+         * TODO: Use real userPrefs that we pull from our persistent store instead of the default values pulled from common
+         * containers metadata call.
+         *
+         * TODO: Get real moduleId's based on the regionWidget.id into the iframe URL.  Right now common container uses an
+         * internal counter for the mid parameter value with no external way to set it.
+         */
+        container.preloadGadgets(gadgetUrls, function(response) {
+            for (var i = 0; i < gadgets.length; i++) {
+                var gadget = gadgets[i];
+                var gadgetMetadata = response[gadget.widgetUrl];
+
+                for (var userPref in gadgetMetadata.userPrefs) {
+                    userPref = gadgetMetadata.userPrefs[userPref];
+                    gadget.userPrefs[userPref.name] = userPref.defaultValue;
+                }
+
+                var renderParams = {};
+                renderParams[osapi.container.RenderParam.VIEW] = "home";
+                renderParams[osapi.container.RenderParam.WIDTH] = 250;
+                renderParams[osapi.container.RenderParam.HEIGHT] = 250;
+                renderParams[osapi.container.RenderParam.USER_PREFS] = gadget.userPrefs;
+                var widgetBodyElement = document.getElementById(["widget-", gadget.regionWidgetId, "-body"].join(""));
+                var gadgetSite = container.newGadgetSite(widgetBodyElement);
+                container.navigateGadget(gadgetSite, gadget.widgetUrl, {}, renderParams);
+            }
+        });
+    }
+
+    /*
+     RPC Callback handlers
+     */
+
+    /**
+     * Resizes the iFrame when gadgets.window.adjustHeight is called
+     *
+     * @param height
+     */
+    function resizeIframe(height) {
+        var max = 0x7FFFFFFF;
+        if (height > max) {
+            height = max;
+        }
+
+        var element = document.getElementById(this.f);
+        if (element) {
+            element.style.height = height + 'px';
+        }
+    }
+
+    /**
+     * Sets the chrome title when gadgets.window.setTitle is caled
+     *
+     * @param title
+     */
+    function setTitle(title) {
+        var element = document.getElementById(this.f + '_title');
+        if (element) {
+            element.innerHTML = gadgets.util.escapeString(title);
+        }
+
+    }
+
+    /**
+     * Re-renders the gadget in the requested view with the parameters
+     *
+     * @param view target view
+     * @param opt_params
+     */
+    function requestNavigateTo(view, opt_params) {
+        //TODO: Implement this function
+        throw "Not Implemented!!!!!";
+    }
+
+    /**
+     * Exposed public API calls
+     */
+    return {
+        TYPE : WIDGET_TYPE,
+        /**
+         * Initializes the Rave OpenSocial machinery
+         */
+        init : initOpenSocial,
+        /**
+         * Gets a reference to the container singleton
+         */
+        container: getContainer,
+        /**
+         * Instantiates and renders the given gadgets list
+         * @param a list of gadgets to render
+         */
+        initGadgets: createGadgetInstances
+    };
+
+})();
\ No newline at end of file