Author: agilliland
Date: Tue Jul  3 10:07:11 2007
New Revision: 552916

URL: http://svn.apache.org/viewvc?view=rev&rev=552916
Log:
simplifying subscription management UI.  We no longer let users hack away at 
the details of a subscription because there should be no need, the details come 
from the feed itself.  So now we simply let users add and remove subscriptions 
to groups by entering in feed urls and everything else is done for them.

We also get the added bonus of having newly added subscriptions being fetched 
when they are added rather than at some undertermined amount of time 
afterwards, so setting up new planets and groups can happen instantaneously now.


Modified:
    
roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/admin/struts2/PlanetGroupForm.java
    roller/trunk/apps/planet/web/WEB-INF/jsps/admin/PlanetGroupForm.jsp

Modified: 
roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/admin/struts2/PlanetGroupForm.java
URL: 
http://svn.apache.org/viewvc/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/admin/struts2/PlanetGroupForm.java?view=diff&rev=552916&r1=552915&r2=552916
==============================================================================
--- 
roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/admin/struts2/PlanetGroupForm.java
 (original)
+++ 
roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/admin/struts2/PlanetGroupForm.java
 Tue Jul  3 10:07:11 2007
@@ -19,11 +19,13 @@
 package org.apache.roller.planet.ui.admin.struts2;
 
 import com.opensymphony.xwork2.Preparable;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.planet.PlanetException;
 import org.apache.roller.planet.business.PlanetFactory;
 import org.apache.roller.planet.business.PlanetManager;
+import org.apache.roller.planet.business.fetcher.FeedFetcher;
 import org.apache.roller.planet.pojos.Planet;
 import org.apache.roller.planet.pojos.PlanetGroup;
 import org.apache.roller.planet.pojos.Subscription;
@@ -48,6 +50,7 @@
     private String planetid = null;
     private String groupid = null;
     private String subid = null;
+    private String addSubUrl = null;
     
     
     /**
@@ -100,14 +103,61 @@
         setSuccess("PlanetGroupForm.message.saveSucceeded");
         return INPUT;
     }
-
+    
+    
+    // Validation - sub url cannot be null, must be valid url
+    public String addSub() {
+        // add a planet subscription
+        log.debug("Adding Planet Subscription ...");
+        
+        PlanetManager pMgr = PlanetFactory.getPlanet().getPlanetManager();
+        try {
+            PlanetGroup group = getGroup();
+            if(group == null) {
+                setError("PlanetSubscriptionForm.error.groupNull");
+                return INPUT;
+            }
+            
+            // check if this subscription already exists before adding it
+            Subscription sub = pMgr.getSubscription(getAddSubUrl());
+            if(sub == null) {
+                // sub doesn't exist yet, so we need to fetch it
+                FeedFetcher fetcher = 
PlanetFactory.getPlanet().getFeedFetcher();
+                sub = fetcher.fetchSubscription(getAddSubUrl());
+                
+                // save new sub
+                pMgr.saveSubscription(sub);
+            }
+            
+            // add the sub to the group
+            group.getSubscriptions().add(sub);
+            sub.getGroups().add(group);
+            pMgr.saveGroup(group);
+            
+            // flush changes
+            PlanetFactory.getPlanet().flush();
+            
+            // clear field after success
+            setAddSubUrl(null);
+            
+        } catch (PlanetException ex) {
+            log.error("Error adding subscription", ex);
+            setError("PlanetSubscriptionForm.error.saveFailed");
+            return INPUT;
+        }
+        
+        setSuccess("PlanetSubscriptionForm.message.saveSucceeded");
+        return INPUT;
+    }
+    
+    
     public String deleteSub() {
         // delete a planet subscription
         log.debug("Deleting Planet Subscription ...");
         
-        PlanetManager pmgr= PlanetFactory.getPlanet().getPlanetManager();
+        PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
         try {
-            if(getSubid() != null && !"".equals(getSubid())) {
+            if(!StringUtils.isEmpty(getSubid())) {
                 Subscription sub = pmgr.getSubscriptionById(getSubid());
                 if(sub == null) {
                     setError("PlanetGroupForm.error.nullSubscription");
@@ -121,9 +171,10 @@
                 }
                 
                 
setSuccess("PlanetGroupForm.message.subscriptionDeleteSucceeded", 
sub.getTitle());
+            } else {
+                setError("PlanetGroupForm.error.subscriptionNull");
             }
             
-            setError("PlanetGroupForm.error.subscriptionNull");
             return INPUT;
             
         } catch (PlanetException ex) {
@@ -132,6 +183,7 @@
             return INPUT;
         }
     }
+    
 
     public String getPlanetid() {
         return planetid;
@@ -163,6 +215,14 @@
 
     public void setGroup(PlanetGroup group) {
         this.group = group;
+    }
+
+    public String getAddSubUrl() {
+        return addSubUrl;
+    }
+
+    public void setAddSubUrl(String addSubUrl) {
+        this.addSubUrl = addSubUrl;
     }
     
 }

Modified: roller/trunk/apps/planet/web/WEB-INF/jsps/admin/PlanetGroupForm.jsp
URL: 
http://svn.apache.org/viewvc/roller/trunk/apps/planet/web/WEB-INF/jsps/admin/PlanetGroupForm.jsp?view=diff&rev=552916&r1=552915&r2=552916
==============================================================================
--- roller/trunk/apps/planet/web/WEB-INF/jsps/admin/PlanetGroupForm.jsp 
(original)
+++ roller/trunk/apps/planet/web/WEB-INF/jsps/admin/PlanetGroupForm.jsp Tue Jul 
 3 10:07:11 2007
@@ -66,28 +66,25 @@
                 <table class="data">
                     <tr>
                         <th><s:text name="PlanetGroupForm.subsTitle" /></th>
-                        <th><s:text name="PlanetGroupForm.subsSiteURL" /></th>
                         <th><s:text name="PlanetGroupForm.subsFeedURL" /></th>
                         <th><s:text name="PlanetGroupForm.action" /></th>
                     </tr>
                     
                     <s:iterator value="group.subscriptions" status="status">
-                        <s:url id="editurl" action="PlanetSubscriptionForm" 
includeParams="get">
-                            <s:param name="subid"><s:property 
value="id"/></s:param>
-                        </s:url>
                         <tr class='<s:if 
test="#status.even">evenRow</s:if><s:else>oddRow</s:else>'>
-                            <td><s:a href="%{editurl}"><s:property 
value="title"/></s:a></td>
-                            <td><img src='<s:url 
value="/planet-ui/images/world_link.png"/>' /><a href='<s:property 
value="siteURL"/>'><s:text name="PlanetGroupForm.subsSiteURL" /></a></td>
+                            <td><a href='<s:property 
value="siteURL"/>'><s:property value="title"/></a></td>
                             <td><img src='<s:url 
value="/planet-ui/images/feed_link.png"/>' /><a href='<s:property 
value="feedURL"/>'><s:text name="PlanetGroupForm.subsFeedURL" /></a></td>
                             <td><img src='<s:url 
value="/planet-ui/images/delete.png"/>' /><a href="javascript: void(0);" 
onclick="confirmSubDelete('<s:property value="id"/>', '<s:property 
value="title"/>');"><s:text name="PlanetGroupForm.deleteSub"/></a></td>
                         </tr>
                     </s:iterator>
                 </table>
                 
-                <s:url id="addsuburl" action="PlanetSubscriptionForm">
-                    <s:param name="groupid"><s:property 
value="group.id"/></s:param>
-                </s:url>
-                <p><img src='<s:url value="/planet-ui/images/feed_add.png"/>' 
/><s:a href="%{addsuburl}"><s:text name="PlanetGroupForm.addSub"/></s:a></p>
+                <p><img src='<s:url value="/planet-ui/images/feed_add.png"/>' 
/><s:text name="PlanetGroupForm.addSub"/></p>
+                <s:form action="PlanetGroupForm!addSub">
+                    <s:hidden name="groupid" />
+                    <s:textfield 
label="%{getText('PlanetSubscriptionForm.feedURL')}" name="addSubUrl" size="60" 
/>
+                    <s:submit />
+                </s:form>
                 
             </s:if>
             


Reply via email to