rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlu...@apache.org
Subject svn commit: r1178944 - in /incubator/rave/trunk: rave-demo-gadgets/src/main/webapp/ rave-portal-resources/src/main/webapp/script/ rave-portal-resources/src/test/javascript/
Date Tue, 04 Oct 2011 20:20:37 GMT
Author: carlucci
Date: Tue Oct  4 20:20:37 2011
New Revision: 1178944

URL: http://svn.apache.org/viewvc?rev=1178944&view=rev
Log:
RAVE-230: implement OpenSocial requestNavigateTo function

Since we currently only support two OpenSocial views in Rave (HOME and CANVAS), the initial
implementation of our requestNavigateTo only supports those two view types.  As new OpenSocial
view types are supported in Rave they can easily be supported in the requestNavigateTo function
as well.  Also, I modified the canvas-nav.xml gadget to demo/test this feature.

Modified:
    incubator/rave/trunk/rave-demo-gadgets/src/main/webapp/canvas-nav.xml
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js
    incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js
    incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js

Modified: incubator/rave/trunk/rave-demo-gadgets/src/main/webapp/canvas-nav.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-demo-gadgets/src/main/webapp/canvas-nav.xml?rev=1178944&r1=1178943&r2=1178944&view=diff
==============================================================================
--- incubator/rave/trunk/rave-demo-gadgets/src/main/webapp/canvas-nav.xml (original)
+++ incubator/rave/trunk/rave-demo-gadgets/src/main/webapp/canvas-nav.xml Tue Oct  4 20:20:37
2011
@@ -20,29 +20,31 @@
   $Id:$
 -->
 <Module>
-<ModulePrefs title="" author="" author_email="" height="250" description="">
-  <Require feature="dynamic-height" />
-  <Require feature="views" />
-</ModulePrefs>
-
-
-   <Content type="html" view="home">
-   <![CDATA[
-      Normal view!
-   ]]>
-   </Content>
-
-   <Content type="html" view="canvas">
-   <![CDATA[
-     Canvas view.
-     ]]>
-   </Content>
-
-<Content type="html" view="default">
-   <![CDATA[
-     Default view.
-     ]]>
-   </Content>
+    <ModulePrefs title="" author="" author_email="" height="250" description="">
+        <Require feature="dynamic-height" />
+        <Require feature="views" />
+    </ModulePrefs>
+
+
+    <Content type="html" view="home">
+       <![CDATA[
+          <div>Normal view.</div>
+          <button onclick="gadgets.views.requestNavigateTo('canvas');">Go to Canvas</button>
  
+       ]]>
+    </Content>
+
+    <Content type="html" view="canvas">
+       <![CDATA[
+         <div>Canvas view.</div>
+         <button onclick="gadgets.views.requestNavigateTo('home');">Go to Home</button>
+       ]]>
+    </Content>
+
+    <Content type="html" view="default">
+       <![CDATA[
+         Default view.
+       ]]>
+    </Content>
 
- </Module>
+</Module>
 

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js?rev=1178944&r1=1178943&r2=1178944&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js Tue Oct  4 20:20:37
2011
@@ -159,7 +159,7 @@ var rave = rave || (function() {
             
             // hide the collapse/restore toggle icon in canvas mode
             $("#widget-" + args.data.id + "-collapse").hide();
-            var widget = getWidgetById(args.data.id);
+            var widget = rave.getWidgetById(args.data.id);
             if(typeof widget != "undefined" && isFunction(widget.maximize)) {
                 widget.maximize();
             }
@@ -180,7 +180,7 @@ var rave = rave || (function() {
                                               
             // re-show the collapse/restore toggle icon
             $("#widget-" + args.data.id + "-collapse").show();
-            var widget = getWidgetById(args.data.id);
+            var widget = rave.getWidgetById(args.data.id);
             // if the widget is collapsed execute the collapse function
             // otherwise execute the minimize function
             if(typeof widget != "undefined"){
@@ -514,7 +514,9 @@ var rave = rave || (function() {
 
         return {
           init : init,          
-          toggleCollapseWidgetIcon: toggleCollapseWidgetIcon
+          toggleCollapseWidgetIcon: toggleCollapseWidgetIcon,
+          maximizeAction: maximizeAction,
+          minimizeAction: minimizeAction
         };
 
     })();
@@ -703,6 +705,20 @@ var rave = rave || (function() {
          * @param obj the object to check
          * @return true if obj is a function, false otherwise
          */
-        isFunction: isFunction
+        isFunction: isFunction,
+        
+        /***
+         * Maximize the widget view
+         * 
+         * @param args the argument object
+         */
+        maximizeWidget: ui.maximizeAction,
+
+        /***
+         * Minimize the widget view (render in non full-screen mode)
+         * 
+         * @param args the argument object
+         */
+        minimizeWidget: ui.minimizeAction
     }
 })();

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js?rev=1178944&r1=1178943&r2=1178944&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js Tue
Oct  4 20:20:37 2011
@@ -283,14 +283,25 @@ rave.opensocial = rave.opensocial || (fu
     }
       
     /**
-     * Re-renders the gadget in the requested view with the parameters
+     * Re-renders the gadget in the requested view
      *
-     * @param view target view
-     * @param opt_params
+     * @param args RPC event args
+     * @param viewName the view name to render
      */
-    function requestNavigateTo(view, opt_params) {
-        //TODO RAVE-230: Implement this function
-        throw "Not Implemented!!!!!";
+    function requestNavigateTo(args, viewName) {       
+        var widgetId = rave.getObjectIdFromDomId(args.gs.getActiveGadgetHolder().getElement().id);
+        var fnArgs = {};
+        fnArgs.data = {}
+        fnArgs.data.id = widgetId;
+        
+        switch(viewName) {
+            case VIEW_NAMES.CANVAS:  
+                rave.maximizeWidget(fnArgs);
+                break;
+            case VIEW_NAMES.HOME:            
+                rave.minimizeWidget(fnArgs);
+                break;
+        }       
     }
 
     /**

Modified: incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js?rev=1178944&r1=1178943&r2=1178944&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js Tue
Oct  4 20:20:37 2011
@@ -127,6 +127,19 @@ describe("Rave OpenSocial", function() {
                 },
                 wasCalled : function() {return called; }
             }
+        } 
+        
+        function getMockRequestNavigateToArgs(id) {
+            return {
+                f : "frameId",               
+                gs : {
+                    getActiveGadgetHolder : function() {
+                        return {getElement : function() {
+                            return { id : id }
+                        }}
+                    }
+                }
+            }
         }
 
         it("resizes Iframe if argument is less than height", function() {
@@ -170,5 +183,43 @@ describe("Rave OpenSocial", function() {
             expect(mockElement.innerHTML).toEqual("TITLE");
             expect(document.getElementById).toHaveBeenCalledWith("widget-7-title");
         });
+        
+        it("requestNavigateTo changes the view to CANVAS", function() {
+            var VIEW_NAME = "canvas";
+            var expectedArgs = {};
+            expectedArgs.data = {};
+            expectedArgs.data.id = "7";           
+            spyOn(rave, "maximizeWidget");
+
+            rave.opensocial.init();
+            container.rpcHooks()["requestNavigateTo"](getMockRequestNavigateToArgs("widget-"
+ expectedArgs.data.id + "-body"), VIEW_NAME);            
+            expect(rave.maximizeWidget).toHaveBeenCalledWith(expectedArgs);
+        });
+        
+        it("requestNavigateTo changes the view to HOME", function() {
+            var VIEW_NAME = "home";
+            var expectedArgs = {};
+            expectedArgs.data = {};
+            expectedArgs.data.id = "7";           
+            spyOn(rave, "minimizeWidget");
+
+            rave.opensocial.init();
+            container.rpcHooks()["requestNavigateTo"](getMockRequestNavigateToArgs("widget-"
+ expectedArgs.data.id + "-body"), VIEW_NAME);            
+            expect(rave.minimizeWidget).toHaveBeenCalledWith(expectedArgs);
+        });        
+        
+        it("requestNavigateTo does not throw an error if an unknown view is passed", function()
{
+            var VIEW_NAME = "___UNKNOWN___";
+            var expectedArgs = {};
+            expectedArgs.data = {};
+            expectedArgs.data.id = "7";           
+            spyOn(rave, "minimizeWidget");
+            spyOn(rave, "maximizeWidget");
+
+            rave.opensocial.init();
+            container.rpcHooks()["requestNavigateTo"](getMockRequestNavigateToArgs("widget-"
+ expectedArgs.data.id + "-body"), VIEW_NAME);            
+            expect(rave.minimizeWidget).wasNotCalled();
+            expect(rave.maximizeWidget).wasNotCalled();
+        });         
     });
 });
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js?rev=1178944&r1=1178943&r2=1178944&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js Tue Oct  4
20:20:37 2011
@@ -339,10 +339,6 @@ describe("Rave", function() {
         });
 
     });
-
-    describe("Handle resize maximize event", function(){
-
-    });
     
     describe("isFunction", function() {
 
@@ -440,4 +436,162 @@ describe("Rave", function() {
         });        
        
     });    
+    
+    describe("change widget view state", function(){
+        //Creates a simple mock jquery object that mocks the functions used in this suite
+        function createMockJQuery() {
+            var expression;
+            var classMap = [];                        
+            var valuesMap = {};
+            
+            $ = function(expr) {
+
+                if (typeof expr != "undefined") {
+                    expression = expr;
+                }
+
+                return {
+                    expression : function () {
+                        return expression;
+                    },
+                    hasClass : function (className) {
+                        return classMap.indexOf(className) != -1;
+                    },
+                    addClass : function (className) {
+                        classMap.push(className);
+                    },
+                    removeClass: function(className) {                        
+                        var idx = classMap.indexOf(className); 
+                        if (idx != -1) {
+                            classMap.splice(idx, 1); 
+                        }
+                        return this;
+                    },
+                    sortable: function(option, attrName, attrValue) {
+                        valuesMap["sortableOption"] = option;
+                        valuesMap["sortableAttrName"] = attrName;
+                        valuesMap["sortableAttrValue"] = attrValue;
+                    },
+                    unbind: function(eventName) {
+                        valuesMap["unbindEventName"] = eventName;
+                    },
+                    click: function(args, fn) {
+                        valuesMap["clickArgs"] = args;
+                        valuesMap["clickFn"] = fn;
+                    },
+                    button: function(option, attrName, attrArgs) {
+                        valuesMap["buttonOption"] = option;
+                        valuesMap["buttonAttrName"] = attrName;
+                        valuesMap["buttonAttrArgs"] = attrArgs;
+                    },
+                    hide: function() {
+                        valuesMap["hideWasCalled"] = true;
+                    },
+                    show: function() {
+                        valuesMap["showWasCalled"] = true;
+                    },                    
+                    height: function() {
+                        
+                    },
+                    width: function() {
+                        
+                    },
+                    css: function() {
+                        
+                    },
+                    prepend: function() {
+                        
+                    },
+                    remove: function() {
+                        valuesMap["removeWasCalled"] = true;
+                    },
+                    getValue: function(varName) {
+                        return valuesMap[varName];
+                    }                    
+                }
+            };            
+        }
+        
+        it("successfully maximizes the widget", function() {                            
     
+            createMockJQuery();
+            
+            var mockWidget = {   
+                maximizeWasCalled: false,                
+                maximize: function() { this.maximizeWasCalled = true; }
+            }
+                                      
+            var args = {};
+            args.data = {};
+            args.data.id = 99;
+            spyOn(rave, "getWidgetById").andReturn(mockWidget);
+            
+            rave.maximizeWidget(args);                      
+           
+            // verify the sortable parameters                        
+            expect($().getValue("sortableOption")).toEqual("option");
+            expect($().getValue("sortableAttrName")).toEqual("disabled");
+            expect($().getValue("sortableAttrValue")).toEqual(true);            
+            // verify the CSS styles
+            expect($().hasClass("widget-wrapper-canvas")).toEqual(true);
+            expect($().hasClass("widget-wrapper")).toEqual(false);
+            // verify the unbind parameter
+            expect($().getValue("unbindEventName")).toEqual("click");
+            // verify the click parameters
+            expect($().getValue("clickArgs")).toEqual({id: args.data.id});
+            expect(rave.isFunction($().getValue("clickFn"))).toEqual(true);
+            // verify the button parameters
+            expect($().getValue("buttonOption")).toEqual("option");
+            expect($().getValue("buttonAttrName")).toEqual("icons");
+            expect($().getValue("buttonAttrArgs")).toEqual({primary:"ui-icon-arrowthick-1-sw"});
                    
+            // verify getWidgetById called
+            expect(rave.getWidgetById).toHaveBeenCalledWith(args.data.id); 
+            // verify hide was called
+            expect($().getValue("hideWasCalled")).toEqual(true);                 
+            // verify widget.maximize was called
+            expect(mockWidget.maximizeWasCalled).toEqual(true);
+                   
+        });        
+        
+        it("successfully minimizes the widget", function() {                            
     
+            createMockJQuery();
+            
+            var mockWidget = {   
+                minimizeWasCalled: false,                
+                minimize: function() { this.minimizeWasCalled = true; }
+            }
+                                      
+            var args = {};
+            args.data = {};
+            args.data.id = 99;
+            spyOn(rave, "getWidgetById").andReturn(mockWidget);
+            
+            rave.minimizeWidget(args);                      
+            
+            // verify remove was called
+            expect($().getValue("removeWasCalled")).toEqual(true);        
+            // verify the sortable parameters
+            expect($().getValue("sortableOption")).toEqual("option");
+            expect($().getValue("sortableAttrName")).toEqual("disabled");
+            expect($().getValue("sortableAttrValue")).toEqual(false);            
+            // verify the CSS styles
+            expect($().hasClass("widget-wrapper-canvas")).toEqual(false);
+            expect($().hasClass("widget-wrapper")).toEqual(true);
+            // verify the unbind parameter
+            expect($().getValue("unbindEventName")).toEqual("click");
+            // verify the click parameters
+            expect($().getValue("clickArgs")).toEqual({id: args.data.id});
+            expect(rave.isFunction($().getValue("clickFn"))).toEqual(true);
+            // verify the button parameters
+            expect($().getValue("buttonOption")).toEqual("option");
+            expect($().getValue("buttonAttrName")).toEqual("icons");
+            expect($().getValue("buttonAttrArgs")).toEqual({primary:"ui-icon-arrow-4-diag"});
                    
+            // verify show was called
+            expect($().getValue("showWasCalled")).toEqual(true);                 
+            // verify getWidgetById called
+            expect(rave.getWidgetById).toHaveBeenCalledWith(args.data.id);              
    
+            // verify widget.minimize was called
+            expect(mockWidget.minimizeWasCalled).toEqual(true);             
+        });          
+        
+    });
 });
\ No newline at end of file



Mime
View raw message