rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfrank...@apache.org
Subject svn commit: r1125077 - in /incubator/rave/trunk/rave-portal/src: main/webapp/WEB-INF/views/ main/webapp/css/ main/webapp/script/ test/java/org/apache/rave/portal/web/renderer/ test/javascript/
Date Thu, 19 May 2011 19:56:18 GMT
Author: mfranklin
Date: Thu May 19 19:56:18 2011
New Revision: 1125077

URL: http://svn.apache.org/viewvc?rev=1125077&view=rev
Log:
Refactored loading of widgets to be more generic

Modified:
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
    incubator/rave/trunk/rave-portal/src/main/webapp/css/default.css
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_wookie.js
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
    incubator/rave/trunk/rave-portal/src/test/javascript/raveSpec.js

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=1125077&r1=1125076&r2=1125077&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 Thu May 19 19:56:18
2011
@@ -43,22 +43,21 @@
     //Define the global widgets variable
     var widgets = [];
 </script>
-<table>
-    <tr>
-        <c:forEach var="region" items="${defaultPage.regions}">
-            <td class="widgetWrapper">
-                <c:forEach var="regionWidget" items="${region.regionWidgets}">
-                    <div class="widgetChrome" id="widget-${regionWidget.id}-chrome">
-                            <span>${regionWidget.widget.title}</span>
-                    </div>
-                    <div class="widget" id="widget-${regionWidget.id}-body">
-                        <portal:render-widget regionWidget="${regionWidget}" />
-                    </div>
-                </c:forEach>
-            </td>
-        </c:forEach>
-    </tr>
-</table>
+<c:forEach var="region" items="${defaultPage.regions}">
+<div class="region" id="region-${region.id}" >
+    <c:forEach var="regionWidget" items="${region.regionWidgets}">
+    <div class="widget-wrapper">
+        <div class="widget-title-bar" >
+            <span id="widget-${regionWidget.id}-title">${regionWidget.widget.title}</span>
+        </div>
+        <div class="widget" id="widget-${regionWidget.id}-body">
+            <portal:render-widget regionWidget="${regionWidget}" />
+        </div>
+    </div>
+    </c:forEach>
+</div>
+</c:forEach>
+<div class="clear-float">&nbsp;</div>
 
 <script src="${opensocial_engine_url}/js/container.js?c=1&container=default&debug=1"
type="text/javascript"></script>
 <script src="<spring:url value="/script/rave.js"/>" type="text/javascript"></script>
@@ -66,11 +65,10 @@
 <script src="<spring:url value="/script/rave_wookie.js"/>" type="text/javascript"></script>
 
 <script type="text/javascript">
-    rave.opensocial.init();
+    rave.initProviders();
     //Get a map of widgets keyed by their type
-    var widgetMap = rave.createWidgetMap(widgets);
-    rave.opensocial.initGadgets(widgetMap[rave.opensocial.TYPE]);
-    rave.wookie.initWidgets(widgetMap[rave.wookie.TYPE]);
+    rave.initWidgets(rave.createWidgetMap(widgets));
+    rave.initDragAndDrop();
 </script>
 
 </rave:rave_generic_page>

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/css/default.css
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/css/default.css?rev=1125077&r1=1125076&r2=1125077&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/css/default.css (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/css/default.css Thu May 19 19:56:18 2011
@@ -87,11 +87,11 @@ h1,h2,h3,h4,h5,h6 {
   background: url(../images/rave_codehilite_bg.gif);
 }
 
-.widgetWrapper {
+.widget-wrapper {
     vertical-align: top;
 }
 
-.widgetChrome {
+.widget-title-bar {
     border: #777 solid 1px;
     color: #333;
 }

Modified: 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=1125077&r1=1125076&r2=1125077&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js Thu May 19 19:56:18 2011
@@ -17,6 +17,33 @@
  * under the License.
  */
 var rave = rave || (function(){
+    var providerList = [];
+
+    function initializeProviders() {
+        for(var i=0; i<providerList.length;i++) {
+            providerList[i].init();
+        }
+    }
+
+    function initializeDragAndDrop() {
+
+    }
+
+    function initializeWidgets(widgets) {
+        //Initialize the widgets for supported providers
+        for(var i=0; i<providerList.length;i++) {
+            var provider = providerList[i];
+            provider.initWidgets(widgets[provider.TYPE]);
+        }
+    }
+
+    function addProviderToList(provider) {
+        if(provider.hasOwnProperty("init")) {
+            providerList.push(provider);
+        } else {
+            throw "Attempted to register invalid provider";
+        }
+    }
 
     function mapWidgetsByType(widgets) {
         var map = {};
@@ -44,6 +71,21 @@ var rave = rave || (function(){
      */
     return {
         /**
+         * Initialize all of the registered providers
+         */
+        initProviders : initializeProviders,
+
+        /**
+         * Initializes the given set of widgets
+         * @param widgets a map of widgets by type
+         */
+        initWidgets : initializeWidgets,
+
+        /**
+         * Initialize Rave's drag and drop facilities
+         */
+        initDragAndDrop : initializeDragAndDrop,
+        /**
          * Creates a map of widgets by their type
          *
          * @param widgets list of widgets to map by type
@@ -58,7 +100,15 @@ var rave = rave || (function(){
          *
          * @param elementId the ID of the DOM element containing the widget
          */
-        getRegionWidgetIdFromElementId : extractRegionWidgetIdFromElementId
+        getRegionWidgetIdFromElementId : extractRegionWidgetIdFromElementId,
+
+        /**
+         * Registers a new provider with Rave.  All providers MUST have init and initWidgets
functions as well as a
+         * TYPE property exposed in its public API
+         *
+         * @param provider a valid Rave widget provider
+         */
+        registerProvider : addProviderToList
     }
 
 })();
\ 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=1125077&r1=1125076&r2=1125077&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 Thu May 19
19:56:18 2011
@@ -186,7 +186,7 @@ rave.opensocial = rave.opensocial || (fu
          * Instantiates and renders the given gadgets list
          * @param a list of gadgets to render
          */
-        initGadgets: createGadgetInstances,
+        initWidgets: createGadgetInstances,
 
         /**
          * Resets the current OpenSocial container
@@ -194,4 +194,7 @@ rave.opensocial = rave.opensocial || (fu
         reset: resetContainer
     };
 
-})();
\ No newline at end of file
+})();
+
+//Register teh widget provider with Rave
+rave.registerProvider(rave.opensocial);
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_wookie.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_wookie.js?rev=1125077&r1=1125076&r2=1125077&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_wookie.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_wookie.js Thu May 19 19:56:18
2011
@@ -39,6 +39,11 @@ rave.wookie = rave.wookie || (function()
      */
     return {
         TYPE : WIDGET_TYPE,
+
+        /**
+         * Init function required by Rave's initialization infrastructure
+         */
+        init : function() {},
         
         /**
          * Renders the given Widgets list
@@ -49,4 +54,6 @@ rave.wookie = rave.wookie || (function()
     };
 
 
-})();
\ No newline at end of file
+})();
+//Register teh widget provider with Rave
+rave.registerProvider(rave.wookie);
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java?rev=1125077&r1=1125076&r2=1125077&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
Thu May 19 19:56:18 2011
@@ -22,11 +22,9 @@ package org.apache.rave.portal.web.rende
 
 import org.apache.rave.portal.model.RegionWidget;
 import org.apache.rave.portal.model.Widget;
-import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 

Modified: incubator/rave/trunk/rave-portal/src/test/javascript/raveSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/javascript/raveSpec.js?rev=1125077&r1=1125076&r2=1125077&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/javascript/raveSpec.js (original)
+++ incubator/rave/trunk/rave-portal/src/test/javascript/raveSpec.js Thu May 19 19:56:18 2011
@@ -1,5 +1,70 @@
 describe("Rave", function() {
 
+    function getMockProvider(type) {
+        return (function() {
+            var called = false;
+            var widgetsCalled = false;
+            return {
+                TYPE : type,
+
+                init : function() {
+                    called = true;
+                },
+                initWidgets: function(widgets) {
+                    for(var i = 0; i<widgets.length;i++) {
+                        expect(widgets[i].type).toEqual(type);
+                    }
+                    widgetsCalled = true;
+                },
+                initWidgetsWasCalled : function() {
+                    return widgetsCalled;
+                },
+                initWasCalled : function() {
+                    return called;
+                }
+            };
+        })();
+    }
+
+    describe("initProviders", function() {
+
+        it("initializes all providers", function() {
+            var provider1 = getMockProvider("FOO");
+            var provider2 = getMockProvider("BAR");
+            rave.registerProvider(provider1);
+            rave.registerProvider(provider2);
+            rave.initProviders();
+            expect(provider1.initWasCalled()).toBeTruthy();
+            expect(provider2.initWasCalled()).toBeTruthy();
+        });
+    });
+
+    describe("registerProvider", function() {
+        it("throws error when invalid provider passed", function() {
+            expect(
+                    function() {
+                        rave.registerProvider({badProp: function() {
+                        } })
+                    }).toThrow(new Error("Attempted to register invalid provider"));
+        });
+    });
+
+    describe("initWidgets", function() {
+        it("calls the appropriate providers", function() {
+            var widgetMap = {
+                "FOO" : [{type:"FOO"}, {type:"FOO"}],
+                "BAR" : [{type:"BAR"}, {type:"BAR"}]
+            };
+            var provider1 = getMockProvider("FOO");
+            var provider2 = getMockProvider("BAR");
+            rave.registerProvider(provider1);
+            rave.registerProvider(provider2);
+            rave.initWidgets(widgetMap);
+            expect(provider1.initWidgetsWasCalled()).toBeTruthy();
+            expect(provider2.initWidgetsWasCalled()).toBeTruthy();
+        });
+    });
+
     describe("createWidgetMap", function() {
 
         it("builds a map keyed by type", function() {
@@ -38,30 +103,32 @@ describe("Rave", function() {
             expect(map["Unknown"]).toContain(widgets[4]);
         });
 
-        it("builds a map with no entries", function(){
+        it("builds a map with no entries", function() {
             var widgets = [];
             var map = rave.createWidgetMap(widgets);
             var count = 0;
-            for(i in map) {count++;}
+            for (i in map) {
+                count++;
+            }
             expect(count).toEqual(0);
         });
 
     });
-    
+
     describe("getRegionWidgetIdFromDomId", function() {
 
         it("returns the regionwidgetId from the bodyElementId when the body Id is 3 digits",
function() {
-           
+
             var id = rave.getRegionWidgetIdFromElementId("widget-203-id");
             expect(id).toEqual('203');
-        });    
+        });
         it("returns the regionwidgetId from the ElementId when the  Id is 2 digits", function()
{
-           
+
             var id = rave.getRegionWidgetIdFromElementId("widget-20-id");
             expect(id).toEqual('20');
-        });    
+        });
         it("returns the regionwidgetId from the ElementId when the  Id is 1 digits", function()
{
-           
+
             var id = rave.getRegionWidgetIdFromElementId("widget-2-id");
             expect(id).toEqual('2');
         });



Mime
View raw message