rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfrank...@apache.org
Subject svn commit: r1127556 - in /incubator/rave/trunk/rave-portal/src: main/java/org/apache/rave/portal/model/ main/java/org/apache/rave/portal/web/controller/ main/java/org/apache/rave/portal/web/util/ main/resources/ main/webapp/WEB-INF/tags/ main/webapp/W...
Date Wed, 25 May 2011 15:31:47 GMT
Author: mfranklin
Date: Wed May 25 15:31:47 2011
New Revision: 1127556

URL: http://svn.apache.org/viewvc?rev=1127556&view=rev
Log:
Added client side components of widget store (Supports RAVE-32)

Added:
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/store.jsp
      - copied, changed from r1127477, incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_store.js
    incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js
Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
    incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/tags/rave_generic_page.tag
    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/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java

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=1127556&r1=1127555&r2=1127556&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
Wed May 25 15:31:47 2011
@@ -45,9 +45,21 @@ public class Widget {
     @Basic @Column(name="url")
     private String url;
 
+    @Basic @Column(name="thumbnail_url")
+    private String thumbnailUrl;
+
+    @Basic @Column(name="screenshot_url")
+    private String screenshotUrl;
+
     @Basic @Column(name="type")
     private String type;
 
+    @Basic @Column(name="author")
+    private String author;
+
+    @Basic @Column(name = "description")
+    private String description;
+
     /**
      * Gets the persistence unique identifier
      *
@@ -71,6 +83,39 @@ public class Widget {
 //
 // }
 
+
+    public String getScreenshotUrl() {
+        return screenshotUrl;
+    }
+
+    public void setScreenshotUrl(String screenshotUrl) {
+        this.screenshotUrl = screenshotUrl;
+    }
+
+    public String getAuthor() {
+        return author;
+    }
+
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getThumbnailUrl() {
+        return thumbnailUrl;
+    }
+
+    public void setThumbnailUrl(String thumbnailUrl) {
+        this.thumbnailUrl = thumbnailUrl;
+    }
+
     public String getType() {
         return type;
     }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java?rev=1127556&r1=1127555&r2=1127556&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
Wed May 25 15:31:47 2011
@@ -28,9 +28,10 @@ import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 
 @Controller
-@RequestMapping(value = "/store/*")
+@RequestMapping(value = {"/store/*", "/store" })
 public class WidgetStoreController {
 
     private final WidgetService widgetService;
@@ -41,14 +42,16 @@ public class WidgetStoreController {
     }
 
     @RequestMapping(method = RequestMethod.GET)
-    public String view(Model model) {
+    public String view(Model model, @RequestParam long referrerId) {
         model.addAttribute(ModelKeys.WIDGETS, widgetService.getAllWidgets());
+        model.addAttribute(ModelKeys.REFERER, referrerId);
         return ViewNames.STORE;
     }
 
     @RequestMapping(method = RequestMethod.GET, value = "widget/{widgetId}")
-    public String viewWidget(Model model, @PathVariable long widgetId) {
+    public String viewWidget(Model model, @PathVariable long widgetId, @RequestParam long
referrerId) {
         model.addAttribute(ModelKeys.WIDGET, widgetService.getWidget(widgetId));
+        model.addAttribute(ModelKeys.REFERER, referrerId);
         return ViewNames.WIDGET;
     }
 }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java?rev=1127556&r1=1127555&r2=1127556&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
Wed May 25 15:31:47 2011
@@ -24,4 +24,5 @@ public class ModelKeys {
     public final static String ERROR_MESSAGE = "errorMessage"; // an error message to be
reported to the user
     public static final String WIDGETS = "widgets"; // a list of widget objects
     public static final String WIDGET = "widget";
+    public static final String REFERER = "referrer";
 }
\ No newline at end of file

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=1127556&r1=1127555&r2=1127556&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 Wed May 25 15:31:47
2011
@@ -41,8 +41,8 @@ values (set(@user_id_6, next value for u
 
 --- gadget data ---
 -- wikipedia widget
-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');
+insert into widget (id, title, url, type, description, author)
+values(set(@wikipedia_widget_id, next value for widget_id_seq), 'Wikipedia','http://www.google.com/ig/modules/wikipedia.xml',
'OpenSocial', 'A Wikipedia Search and Go widget. Language choice.', 'James Lee');
 
 -- translate widget
 insert into widget (id, title, url, type)

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/tags/rave_generic_page.tag
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/tags/rave_generic_page.tag?rev=1127556&r1=1127555&r2=1127556&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/tags/rave_generic_page.tag (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/tags/rave_generic_page.tag Wed
May 25 15:31:47 2011
@@ -27,7 +27,7 @@ This tag will provide simple template la
   <head>
      <title>Rave Home</title>
      <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css"/>
-     <link rel="stylesheet" href="css/default.css"/>
+     <link rel="stylesheet" href="<c:url value="/css/default.css" />" />
   </head>
   <body>
 	<jsp:doBody/>

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=1127556&r1=1127555&r2=1127556&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 Wed May 25 15:31:47
2011
@@ -32,11 +32,11 @@
 --%><c:set var="opensocial_engine_url" value="${osProtocol}://${osRoot}${osGadget}"/><%--
 
 --%><rave:rave_generic_page>
+<c:set var="defaultPage" value="${pages[0]}"/>
 <div id="header">
     <a href="<spring:url value="/j_spring_security_logout" htmlEscape="true" />">Logout</a>
+    <a href="<spring:url value="/app/store?referrerId=${defaultPage.id}" />">Widget
Store</a>
 </div>
-
-<c:set var="defaultPage" value="${pages[0]}"/>
 <h1>Hello ${defaultPage.owner.username}, welcome to Rave!</h1>
 <script type="text/javascript">
     //Define the global widgets variable
@@ -60,6 +60,7 @@
 
 <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>
+<script src="<spring:url value="/script/rave_api.js"/>" type="text/javascript"></script>
 <script src="<spring:url value="/script/rave_opensocial.js"/>" type="text/javascript"></script>
 <script src="<spring:url value="/script/rave_wookie.js"/>" type="text/javascript"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

Copied: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/store.jsp (from r1127477,
incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/store.jsp?p2=incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/store.jsp&p1=incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp&r1=1127477&r2=1127556&rev=1127556&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/store.jsp Wed May 25 15:31:47
2011
@@ -22,5 +22,52 @@
 --%><%@ taglib tagdir="/WEB-INF/tags" prefix="rave"%><%--
 
 --%><rave:rave_generic_page>
+<div id="banner">
+    <span class="backToPage">
+        <a href="<spring:url value="/index.html" />">Back to Rave</a>
+    </span>
+</div>
 
+<div id="navigation">
+
+</div>
+<div id="content">
+    <c:forEach var="widget" items="${widgets}">
+        <div class="storeItem">
+            <div class="storeItemLeft">
+                <c:if test="${not empty widget.thumbnailUrl}">
+                    <img class="storeWidgetThumbnail" src="${widget.thumbnailUrl}"
+                         title="${widget.title}" alt="${widget.title}"
+                         width="120" height="60"/>
+                </c:if>
+            </div>
+            <div class="storeItemCenter">
+                <div id="widgetAdded_${widget.id}" class="storeButton">
+                    <button class="storeItemButton"
+                            id="addWidget_${widget.id}"
+                            onclick="rave.api.rpc.addWidgetToPage({widgetId: ${widget.id},
pageId: ${referrer}});">
+                        Add to Page
+                    </button>
+                </div>
+                <a class="secondaryPageItemTitle"
+                   href="<spring:url value="/app/store/widget/${widget.id}" />?referrerId=${referrer}">${widget.title}
+                </a>
+
+                <div class="storeWidgetAuthor">By:
+                ${widget.author}</div>
+                <div class="storeWidgetDesc">${widget.description}</div>
+            </div>
+            <div class="clear-float" >&nbsp;</div>
+        </div>
+    </c:forEach>
+</div>
+<script type="text/javascript">
+    var rave = rave || {
+        getContext : function() {
+            return "<spring:url value="/app/" />";
+        }
+    }
+</script>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
+<script src="<spring:url value="/script/rave_api.js"/>" type="text/javascript"></script>
 </rave:rave_generic_page>
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp?rev=1127556&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp (added)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/widget.jsp Wed May 25 15:31:47
2011
@@ -0,0 +1,101 @@
+<%--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+  
+     http://www.apache.org/licenses/LICENSE-2.0
+  
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+  
+--%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%--
+--%><%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %><%--
+--%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %><%--
+--%><%@ taglib tagdir="/WEB-INF/tags" prefix="rave"%><%--
+--%><jsp:useBean id="widget" scope="request" class="org.apache.rave.portal.model.Widget"
/><%--
+--%><rave:rave_generic_page>
+<div id="banner">
+    <span class="backToPage">
+        <a href="<spring:url value="/index.html" />">Back to Rave</a>
+    </span>
+    <span>
+        <a href="<spring:url value="/app/store?referrerId=${referrer}" />">Back
to Store</a>
+    </span>
+</div>
+
+<div id="navigation">
+
+</div>
+<div id="content">
+    <table id="storeWidgetDetail">
+        <tr>
+            <td class="widgetDetailLeft">
+                <c:if test="${not empty widget.thumbnailUrl}">
+                    <img class="storeWidgetThumbnail"
+                         src="${widget.thumbnailUrl}"
+                         title="${widget.title}}"
+                         alt="thumbnail"
+                         width="120" height="60"/>
+                </c:if>
+                <div class="widgetDetailMeta">
+                    <div class="widgetVersion"></div>
+                    <div class="widgetLastUpdated"></div>
+                </div>
+            </td>
+            <td class="widgetDetailRight" style="vertical-align: top; padding-left: 10px;">
+
+                <div class="storeWidgetDetail">
+                    <div class="secondaryPageItemTitle"
+                         style="display: inline-block; vertical-align: top; padding-top:
5px;">${widget.title}
+                    </div>
+                    <div id="widgetAdded_${widget.id}" class="storeButton">
+                        <button class="storeItemButton"
+                                id="addWidget_${widget.id}"
+                                onclick="rave.api.rpc.addWidgetToPage({widgetId: ${widget.id},
pageId: ${referrer}});">
+                            Add to Page
+                        </button>
+                    </div>
+                </div>
+
+
+                <div class="storeWidgetAuthor">
+                    By:
+                        ${widget.author}
+                </div>
+                <div class="storeWidgetDesc" >
+                    ${widget.description}
+                </div>
+            </td>
+            <td>
+                <div class="widgetScreenshotTitle">Widget Preview</div>
+                <div class="widgetScreenshot">
+                    <c:if test="${not empty widget.screenshotUrl}">
+                    <img src="${widget.screenshotUrl}"
+                         alt="screenshot"
+                         title="${widget.title} Screenshot"/>
+                    </c:if>
+                </div>
+            </td>
+        </tr>
+    </table>
+
+</div>
+<script type="text/javascript">
+    var rave = rave || {
+        getContext : function() {
+            return "<spring:url value="/app/" />";
+        }
+    }
+</script>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
+<script src="<spring:url value="/script/rave_api.js"/>" type="text/javascript"></script>
+
+</rave:rave_generic_page>
\ No newline at end of file

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=1127556&r1=1127555&r2=1127556&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 Wed May 25 15:31:47 2011
@@ -82,6 +82,10 @@ h1, h2, h3, h4, h5, h6 {
     margin-bottom: 0;
 }
 
+.clear-float {
+    clear: both;
+}
+
 .codehilite {
     background-color: #F00;
     padding: 0.01em 1em;
@@ -95,7 +99,7 @@ h1, h2, h3, h4, h5, h6 {
 }
 
 .widget-title-bar {
-    border: #999 solid 1px;
+    border: #b3c4cf solid 1px;
     color: #333;
 }
 
@@ -104,7 +108,7 @@ h1, h2, h3, h4, h5, h6 {
 }
 
 .widget {
-    border: #999 solid 1px;
+    border: #b3c4cf solid 1px;
     padding: 2px;
 }
 
@@ -121,12 +125,53 @@ h1, h2, h3, h4, h5, h6 {
     border: 1px solid black;
 }
 
+#storeWidgetDetail {
+    width: 100%;
+}
+
+.storeItem {
+    padding: 10px;
+    border: 1px solid #b3c4cf;
+}
+
+.widgetDetailRight {
+    width: 40%;
+}
+
+.storeItemLeft {
+   padding-left: 10px;
+    padding-right: 10px;
+    vertical-align: top;
+    width: 150px;
+
+}
+
+.storeItemCenter {
+    padding-left: 10px;
+    padding-right: 10px;
+    vertical-align: top;
+    margin-left: 150px;
+    float: left;
+    width: 50%;
+}
+
+.storeItems {
+    width: 50%;
+}
+
+.storeButton {
+    float: right;
+}
+
 .ui-sortable-placeholder {
     border: 1px dotted black;
     visibility: visible !important;
     background-color: #DDD;
 }
-.ui-sortable-placeholder * { visibility: hidden; }
+
+.ui-sortable-placeholder * {
+    visibility: hidden;
+}
 
 #navigation {
     border: 1px solid #e6ebed;
@@ -142,6 +187,8 @@ h1, h2, h3, h4, h5, h6 {
     margin: 20px 0 20px 0;
 }
 
+#storeTop
+
 #navigation img {
     padding-bottom: 15px;
     margin-left: auto;

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=1127556&r1=1127555&r2=1127556&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 Wed May 25 15:31:47 2011
@@ -85,7 +85,7 @@ var rave = rave || (function() {
             $(".region-dragging").removeClass("region-dragging");
             uiState.targetRegion = ui.item.parent().get(0);
             uiState.targetIndex = ui.item.index();
-            api.rpc.moveWidget(uiState);
+            rave.api.rpc.moveWidget(uiState);
             clearState();
         }
 
@@ -102,57 +102,6 @@ var rave = rave || (function() {
 
     })();
 
-    /**
-     * Sub namespace for managing API functions
-     *
-     * Divided into REST and RPC to match server-side API
-     */
-    var api = (function() {
-        var rpcApi = (function() {
-            var path = "api/rpc/";
-
-            function moveWidgetOnPage(state) {
-                $.post(getContext() + path + "page/regionWidget/" + extractObjectIdFromElementId(state.widget.id),
-                        {
-                            operation: "MOVE",
-                            new_position: state.targetIndex,
-                            to_region: extractObjectIdFromElementId(state.targetRegion.id),
-                            from_region: extractObjectIdFromElementId(state.currentRegion.id)
-                        },
-                        function(result) {
-                            if(result.error) { handleRpcError(result); }
-                        }
-                );
-            }
-
-            //TODO: Create a more robust error handling system and interrogation of RPC results
-            function handleRpcError(rpcResult) {
-                switch(rpcResult.errorCode) {
-                    case "NO_ERROR" :
-                        break;
-                    case "INVALID_PARAMS":
-                        alert("Rave attempted to update the server with your recent changes,
" +
-                              " but the changes were rejected by the server as invalid.");
-                        break;
-                    case "INTERNAL_ERROR":
-                        alert("Rave attempted to update the server with your recent changes,
" +
-                              " but the server encountered an internal error.");
-                        break;
-                }
-                console.log(rpcResult.errorMessage);
-            }
-
-            return {
-                moveWidget : moveWidgetOnPage
-            }
-
-        })();
-
-        return {
-            rpc : rpcApi
-        };
-    })();
-
     function initializeProviders() {
         for (var i = 0; i < providerList.length; i++) {
             providerList[i].init();

Added: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js?rev=1127556&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js (added)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js Wed May 25 15:31:47
2011
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var rave = rave || {};
+/**
+ * Namespace that provides client access to Rave server APIs
+ */
+rave.api = rave.api || (function() {
+    var rpcApi = (function() {
+        var path = "api/rpc/";
+
+        function moveWidgetOnPage(args) {
+            $.post(rave.getContext() + path + "page/regionWidget/" + rave.getObjectIdFromDomId(args.widget.id),
+                    {
+                        operation: "MOVE",
+                        new_position: args.targetIndex,
+                        to_region: rave.getObjectIdFromDomId(args.targetRegion.id),
+                        from_region: rave.getObjectIdFromDomId(args.currentRegion.id)
+                    },
+                    function(result) {
+                        if (result.error) {
+                            handleRpcError(result);
+                        }
+                    }
+            ).error(handleError);
+        }
+
+        function addWidgetToPage(args) {
+            $.post(rave.getContext() + path + "page/" + args.pageId,
+                    {
+                        operation: "ADD_COMPONENT",
+                        widgetId: args.widgetId
+                    },
+                    function(result) {
+                        if (result.error) {
+                            handleRpcError(result);
+                        }
+                    }).error(handleError);
+        }
+
+        function handleError(jqXhr, status, error) {
+            alert("Rave encountered an error while trying to contact the server.  Please
reload the page and try again. error: " + error);
+        }
+
+        //TODO: Create a more robust error handling system and interrogation of RPC results
+        function handleRpcError(rpcResult) {
+            switch (rpcResult.errorCode) {
+                case "NO_ERROR" :
+                    break;
+                case "INVALID_PARAMS":
+                    alert("Rave attempted to update the server with your recent changes,
" +
+                            " but the changes were rejected by the server as invalid.");
+                    break;
+                case "INTERNAL_ERROR":
+                    alert("Rave attempted to update the server with your recent changes,
" +
+                            " but the server encountered an internal error.");
+                    break;
+            }
+            console.log(rpcResult.errorMessage);
+        }
+
+        return {
+            moveWidget : moveWidgetOnPage,
+            addWidgetToPage : addWidgetToPage
+        }
+
+    })();
+
+    return {
+        rpc : rpcApi
+    };
+})();
+

Added: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_store.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_store.js?rev=1127556&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_store.js (added)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_store.js Wed May 25 15:31:47
2011
@@ -0,0 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java?rev=1127556&r1=1127555&r2=1127556&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
Wed May 25 15:31:47 2011
@@ -37,6 +37,8 @@ import static org.junit.Assert.assertTha
 
 public class WidgetStoreControllerTest {
 
+    private static final long WIDGET_ID = 1L;
+    private static final long REFERRER_ID = 35L;
     private WidgetStoreController controller;
     private WidgetService widgetService;
 
@@ -55,11 +57,12 @@ public class WidgetStoreControllerTest {
         expect(widgetService.getAllWidgets()).andReturn(widgets);
         replay(widgetService);
 
-        String view = controller.view(model);
+        String view = controller.view(model, REFERRER_ID);
 
         verify(widgetService);
         assertThat(view, is(equalTo(ViewNames.STORE)));
         assertThat(model.containsAttribute(ModelKeys.WIDGETS), is(true));
+        assertThat((Long)model.asMap().get(ModelKeys.REFERER), is(equalTo(REFERRER_ID)));
         assertThat(widgets, is(sameInstance(widgets)));
     }
 
@@ -68,10 +71,10 @@ public class WidgetStoreControllerTest {
         Model model = new ExtendedModelMap();
         Widget w = new Widget();
 
-        expect(widgetService.getWidget(1L)).andReturn(w);
+        expect(widgetService.getWidget(WIDGET_ID)).andReturn(w);
         replay(widgetService);
 
-        String view = controller.viewWidget(model, 1L);
+        String view = controller.viewWidget(model, WIDGET_ID, REFERRER_ID);
 
         verify(widgetService);
         assertThat(view, is(equalTo(ViewNames.WIDGET)));

Added: incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js?rev=1127556&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js (added)
+++ incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js Wed May 25 15:31:47
2011
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+describe("Rave API", function() {
+
+    describe("rpc", function() {
+
+        $ = {};
+        console = {log : function(msg) {}};
+
+        describe("addWidgetToPage", function() {
+            it("posts the correct values to RPC service for adding a widget to the page",
function() {
+
+                $.post = function(url, data, callback) {
+                    expect(url).toEqual("api/rpc/page/1");
+                    expect(data.widgetId).toEqual(2);
+                    expect(data.operation).toEqual("ADD_COMPONENT");
+                    expect(typeof(callback)).toEqual("function");
+                };
+                rave.api.rpc.addWidgetToPage({pageId: 1, widgetId: 2});
+            });
+        });
+        describe("moveWidget", function() {
+            it("posts the correct values to RPC service for adding a widget to the page",
function() {
+
+                $.post = function(url, data, callback) {
+                    expect(url).toEqual("api/rpc/page/regionWidget/3");
+                    expect(data.operation).toEqual("MOVE");
+                    expect(data.to_region).toEqual("1");
+                    expect(data.from_region).toEqual("2");
+                    expect(data.new_position).toEqual(3);
+                    expect(typeof(callback)).toEqual("function");
+                };
+                rave.api.rpc.moveWidget({targetRegion: {id:"region-1"}, currentRegion: {id:"region-2"},
targetIndex: 3, widget:{id:"widget-3-body"}});
+            });
+        });
+        describe("Error handling", function() {
+            it("displays the appropriate alert when invalid parameters are passed", function()
{
+
+                $.post = function(url, data, handler) {
+                    handler({error: true, errorCode: "INVALID_PARAMS"});
+                };
+                alert = function(str) {
+                    expect(str).toEqual("Rave attempted to update the server with your recent
changes, " +
+                            " but the changes were rejected by the server as invalid.");
+                };
+                rave.api.rpc.moveWidget({targetRegion: {id:"region-1"}, currentRegion: {id:"region-2"},
targetIndex: 3, widget:{id:"widget-3-body"}});
+
+            });
+            it("displays the appropriate alert when a server error occurs", function() {
+
+                $.post = function(url, data, handler) {
+                    handler({error: true, errorCode: "INTERNAL_ERROR"});
+                };
+                alert = function(str) {
+                    expect(str).toEqual("Rave attempted to update the server with your recent
changes, " +
+                            " but the server encountered an internal error.");
+                };
+                rave.api.rpc.moveWidget({targetRegion: {id:"region-1"}, currentRegion: {id:"region-2"},
targetIndex: 3, widget:{id:"widget-3-body"}});
+            });
+        });
+    })
+
+
+});
+



Mime
View raw message