You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mp...@apache.org on 2011/05/30 18:17:56 UTC
svn commit: r1129239 - in /incubator/rave/trunk/rave-portal/src/main:
java/org/apache/rave/portal/service/
java/org/apache/rave/portal/service/impl/
java/org/apache/rave/portal/web/api/rpc/ webapp/script/
Author: mpierce
Date: Mon May 30 16:17:56 2011
New Revision: 1129239
URL: http://svn.apache.org/viewvc?rev=1129239&view=rev
Log:
Intermediate commits for RAVE-41. Still need to implement the UI component to initiate the service call. The implementation follows the "move" and "add" operations.
Modified:
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java?rev=1129239&r1=1129238&r2=1129239&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java (original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java Mon May 30 16:17:56 2011
@@ -54,9 +54,10 @@ public interface PageService {
/**
* Deletes a specified widget from the specied page.
- * @param page_id the id of the page containing the widget to delete
- * @param widget_id the id of the widget to delete.
+ * @param widgetId the id of the widget to delete.
+ * @param regionId the ID of the region containing the widget to delete
+ * @param pageId the id of the page containing the widget to delete
* @return the updated Region. //TODO need to make sure this is the right return.
*/
- Region removeWidgetFromPage(long page_id, long widget_id);
+ Region removeWidgetFromPage(long regionWidgetId, long regionId);
}
\ No newline at end of file
Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java?rev=1129239&r1=1129238&r2=1129239&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java (original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java Mon May 30 16:17:56 2011
@@ -67,9 +67,10 @@ public class DefaultPageService implemen
@Override
@Transactional
- public Region removeWidgetFromPage(long pageId, long widgetId){
+ public Region removeWidgetFromPage(long regionWidgetId, long regionId){
//TODO must implement. Returns null for the time being.
- return null;
+ Region region = getFromRepository(regionId, regionRepository);
+ return removeWidgetInstance(regionWidgetId, region);
}
@Override
@@ -110,6 +111,14 @@ public class DefaultPageService implemen
target.getRegionWidgets().add(newPosition, widget);
}
+ private Region removeWidgetInstance(long regionWidgetId, Region region) {
+ RegionWidget regionWidget = findRegionWidgetById(regionWidgetId, region.getRegionWidgets());
+ region.getRegionWidgets().remove(regionWidget);
+ updateRenderSequences(region.getRegionWidgets());
+ regionRepository.save(region);
+ return region;
+ }
+
private static <T> T getFromRepository(long id, Repository<T> repo) {
T object = repo.get(id);
if(object == null) {
@@ -134,4 +143,5 @@ public class DefaultPageService implemen
}
throw new IllegalArgumentException("Invalid RegionWidget ID");
}
+
}
\ No newline at end of file
Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java?rev=1129239&r1=1129238&r2=1129239&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java (original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java Mon May 30 16:17:56 2011
@@ -19,6 +19,7 @@
package org.apache.rave.portal.web.api.rpc;
+import org.apache.rave.portal.model.Region;
import org.apache.rave.portal.model.RegionWidget;
import org.apache.rave.portal.service.PageService;
import org.apache.rave.portal.web.api.rpc.model.RpcOperation;
@@ -34,57 +35,102 @@ import org.springframework.web.bind.anno
@RequestMapping(value = "/api/rpc/page/*")
public class PageApi {
- private final PageService pageService;
+ private final PageService pageService;
- @Autowired
- public PageApi(PageService pageService) {
- this.pageService = pageService;
+ @Autowired
+ public PageApi(PageService pageService) {
+ this.pageService = pageService;
+ }
+
+ /**
+ * Adds a widget to the given page
+ *
+ * @param pageId
+ * the ID of the {@link org.apache.rave.portal.model.Page} to add
+ * the widget to
+ * @param widgetId
+ * the ID of the {@link org.apache.rave.portal.model.Widget} to
+ * add do the page
+ * @return a {@link RpcOperation} containing the new widget instance (
+ * {@link org.apache.rave.portal.model.RegionWidget }) or any errors
+ * encountered while performing the RPC operation
+ */
+ @ResponseBody
+ @RequestMapping(method = RequestMethod.POST, value = "{pageId}/widget/add")
+ public RpcResult<RegionWidget> addWidgetToPage(
+ @PathVariable final long pageId, @RequestParam final long widgetId) {
+
+ return new RpcOperation<RegionWidget>() {
+ @Override
+ public RegionWidget execute() {
+ return pageService.addWidgetToPage(pageId, widgetId);
+ }
+ }.getResult();
+ }
+
+ /**
+ * Moves a widget to a new location
+ * <p/>
+ * Moves can take place within a region, region to region, or between pages
+ *
+ * @param regionWidgetId
+ * the ID of the
+ * {@link org.apache.rave.portal.model.RegionWidget} to move
+ * @param newPosition
+ * the 0 based index within the region where the RegionWidget
+ * will now be located
+ * @param toRegion
+ * the Id of the {@link org.apache.rave.portal.model.Region }
+ * where the widget will now be located
+ * @param fromRegion
+ * the Id of the {@link org.apache.rave.portal.model.Region }
+ * where the widget is currently located
+ * @return a {@link RpcOperation} containing the updated widget instance (
+ * {@link org.apache.rave.portal.model.RegionWidget }) or any errors
+ * encountered while performing the RPC operation
+ */
+ @ResponseBody
+ @RequestMapping(method = RequestMethod.POST, value = "regionWidget/{regionWidgetId}/move")
+ public RpcResult<RegionWidget> moveWidgetOnPage(
+ @PathVariable final long regionWidgetId,
+ @RequestParam final int newPosition,
+ @RequestParam final long toRegion,
+ @RequestParam final long fromRegion) {
+
+ return new RpcOperation<RegionWidget>() {
+ @Override
+ public RegionWidget execute() {
+ return pageService.moveRegionWidget(regionWidgetId,
+ newPosition, toRegion, fromRegion);
+ }
+ }.getResult();
+ }
+
+ /**
+ * Deletes a widget
+ *
+ * @param pageId
+ * the ID of the {@link org.apache.rave.portal.model.Page}
+ * containing the widget region
+ * @param regionId
+ * the ID of the {@link org.apache.rave.portal.model.Region}
+ * containing the widget
+ * @param widgetId
+ * the ID of the {@link org.apache.rave.portal.model.Widget} to
+ * delete
+ * @return an {@link RpcOperation} containing the updated region or any
+ * errors encountered.
+ */
+ @ResponseBody
+ @RequestMapping(method=RequestMethod.POST, value="{pageId}/widget/delete")
+ public RpcResult<Region> removeWidgetFromPage(@PathVariable final long widgetId,
+ @RequestParam final long regionId) {
+ return new RpcOperation<Region>() {
+ @Override
+ public Region execute() {
+ return pageService.removeWidgetFromPage(widgetId, regionId);
+ }
+ }.getResult();
}
- /**
- * Adds a widget to the given page
- * @param pageId the ID of the {@link org.apache.rave.portal.model.Page} to add the widget to
- * @param widgetId the ID of the {@link org.apache.rave.portal.model.Widget} to add do the page
- * @return a {@link RpcOperation} containing the new widget instance ({@link org.apache.rave.portal.model.RegionWidget }) or
- * any errors encountered while performing the RPC operation
- */
- @ResponseBody
- @RequestMapping(method = RequestMethod.POST, value = "{pageId}/widget/add")
- public RpcResult<RegionWidget> addWidgetToPage(@PathVariable final long pageId,
- @RequestParam final long widgetId) {
-
- return new RpcOperation<RegionWidget>() {
- @Override
- public RegionWidget execute() {
- return pageService.addWidgetToPage(pageId, widgetId);
- }
- }.getResult();
- }
-
- /**
- * Moves a widget to a new location
- * <p/>
- * Moves can take place within a region, region to region, or between pages
- * @param regionWidgetId the ID of the {@link org.apache.rave.portal.model.RegionWidget} to move
- * @param newPosition the 0 based index within the region where the RegionWidget will now be located
- * @param toRegion the Id of the {@link org.apache.rave.portal.model.Region } where the widget will now be located
- * @param fromRegion the Id of the {@link org.apache.rave.portal.model.Region } where the widget is currently located
- * @return a {@link RpcOperation} containing the updated widget instance ({@link org.apache.rave.portal.model.RegionWidget }) or
- * any errors encountered while performing the RPC operation
- */
- @ResponseBody
- @RequestMapping(method = RequestMethod.POST, value = "regionWidget/{regionWidgetId}/move")
- public RpcResult<RegionWidget> moveWidgetOnPage(@PathVariable final long regionWidgetId,
- @RequestParam final int newPosition,
- @RequestParam final long toRegion,
- @RequestParam final long fromRegion) {
-
-
- return new RpcOperation<RegionWidget>() {
- @Override
- public RegionWidget execute() {
- return pageService.moveRegionWidget(regionWidgetId, newPosition, toRegion, fromRegion);
- }
- }.getResult();
- }
}
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=1129239&r1=1129238&r2=1129239&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 Mon May 30 16:17:56 2011
@@ -156,6 +156,14 @@ var rave = rave || (function() {
function getContext() {
return context;
}
+
+ /**
+ * Deletes the gadget/widget from the display.
+ * TODO: must be implemented.
+ */
+ function deleteWidgetFromPage() {
+ return null;
+ }
/**
* Public API
@@ -176,6 +184,7 @@ var rave = rave || (function() {
* Initialize Rave's drag and drop facilities
*/
initDragAndDrop : ui.init,
+
/**
* Creates a map of widgets by their type
*
@@ -214,6 +223,13 @@ var rave = rave || (function() {
/**
* Gets the current context
*/
- getContext: getContext
+ getContext: getContext,
+
+ /**
+ * Remove a selected gadget from the page
+ */
+ deleteGadget : deleteWidgetFromPage
+
+
}
})();
\ No newline at end of file
Modified: 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=1129239&r1=1129238&r2=1129239&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js Mon May 30 16:17:56 2011
@@ -1,4 +1,4 @@
-/*
+ /*
* 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
@@ -58,7 +58,8 @@ rave.api = rave.api || (function() {
function deleteWidgetOnPage(args) {
$.post(rave.getContext() + path + "page/" +args.pageId + "/widget/delete",
{
- //TODO must implement
+ widgetId: args.regionWidgetId,
+ regionId: rave.getObjectIdFromDomId(args.region.id)
},
function(result) {
if(results.error) {
@@ -90,7 +91,8 @@ rave.api = rave.api || (function() {
return {
moveWidget : moveWidgetOnPage,
- addWidgetToPage : addWidgetToPage
+ addWidgetToPage : addWidgetToPage,
+ removeWidget : deleteWidgetOnPage
}
})();