[jboss-cvs] JBossBlog SVN: r246 - in trunk: resources/META-INF and 13 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 6 11:38:48 EST 2008


Author: adamw
Date: 2008-03-06 11:38:48 -0500 (Thu, 06 Mar 2008)
New Revision: 246

Added:
   trunk/src/action/org/jboss/blog/session/feed/dao/HighlightsFeedDao.java
   trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsDeleteListener.java
   trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsFeedModBean.java
   trunk/src/action/org/jboss/blog/session/security/filtering/
   trunk/src/action/org/jboss/blog/session/security/filtering/GroupsSecurity.java
   trunk/src/action/org/jboss/blog/session/security/filtering/HighlightsSecurity.java
   trunk/src/model/org/jboss/blog/model/feed/HighlightsFeed.java
   trunk/view/manage/highlights/
   trunk/view/manage/highlights/highlights_edit.xhtml
   trunk/view/manage/highlights/highlights_mod.xhtml
   trunk/view/manage/highlights/post_add.xhtml
Removed:
   trunk/src/action/org/jboss/blog/session/security/GroupsSecurity.java
Modified:
   trunk/resources/META-INF/persistence-design.xml
   trunk/resources/META-INF/persistence-dev.xml
   trunk/resources/META-INF/persistence-prod.xml
   trunk/resources/WEB-INF/components.xml
   trunk/resources/WEB-INF/pages.xml
   trunk/resources/messages_en.properties
   trunk/src/action/org/jboss/blog/session/feed/mod/PropositionsCountBean.java
   trunk/src/action/org/jboss/blog/session/view/PostViewBean.java
   trunk/src/tools/org/jboss/blog/tools/GeneralTools.java
   trunk/view/common/post.xhtml
   trunk/view/search/search.xhtml
   trunk/view/view/feed.xhtml
   trunk/view/view/post.xhtml
Log:


Modified: trunk/resources/META-INF/persistence-design.xml
===================================================================
--- trunk/resources/META-INF/persistence-design.xml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/resources/META-INF/persistence-design.xml	2008-03-06 16:38:48 UTC (rev 246)
@@ -11,7 +11,8 @@
         <class>org.jboss.blog.model.Group</class>
         <class>org.jboss.blog.model.feed.Feed</class>
         <class>org.jboss.blog.model.feed.RemoteFeed</class>
-        <class>org.jboss.blog.model.feed.AggregatedFeed</class>
+        <class>org.jboss.blog.model.feed.AggregatedFeed</class> 
+        <class>org.jboss.blog.model.feed.HighlightsFeed</class>
         <class>org.jboss.blog.model.Category</class>
         <class>org.jboss.blog.model.Post</class>
         <class>org.jboss.blog.model.Enclosure</class>

Modified: trunk/resources/META-INF/persistence-dev.xml
===================================================================
--- trunk/resources/META-INF/persistence-dev.xml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/resources/META-INF/persistence-dev.xml	2008-03-06 16:38:48 UTC (rev 246)
@@ -12,6 +12,7 @@
         <class>org.jboss.blog.model.feed.Feed</class>
         <class>org.jboss.blog.model.feed.RemoteFeed</class>
         <class>org.jboss.blog.model.feed.AggregatedFeed</class>
+        <class>org.jboss.blog.model.feed.HighlightsFeed</class>
         <class>org.jboss.blog.model.Category</class>
         <class>org.jboss.blog.model.Post</class>
         <class>org.jboss.blog.model.Enclosure</class>

Modified: trunk/resources/META-INF/persistence-prod.xml
===================================================================
--- trunk/resources/META-INF/persistence-prod.xml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/resources/META-INF/persistence-prod.xml	2008-03-06 16:38:48 UTC (rev 246)
@@ -12,6 +12,7 @@
         <class>org.jboss.blog.model.feed.Feed</class>
         <class>org.jboss.blog.model.feed.RemoteFeed</class>
         <class>org.jboss.blog.model.feed.AggregatedFeed</class>
+        <class>org.jboss.blog.model.feed.HighlightsFeed</class>
         <class>org.jboss.blog.model.Category</class>
         <class>org.jboss.blog.model.Post</class>
         <class>org.jboss.blog.model.Enclosure</class>

Modified: trunk/resources/WEB-INF/components.xml
===================================================================
--- trunk/resources/WEB-INF/components.xml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/resources/WEB-INF/components.xml	2008-03-06 16:38:48 UTC (rev 246)
@@ -72,6 +72,6 @@
     </component>
 
      <component name="stringTools">
-        <property name="summaryLength">1000</property>
+        <property name="summaryLength">500</property>
     </component>
 </components>

Modified: trunk/resources/WEB-INF/pages.xml
===================================================================
--- trunk/resources/WEB-INF/pages.xml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/resources/WEB-INF/pages.xml	2008-03-06 16:38:48 UTC (rev 246)
@@ -199,6 +199,41 @@
         </navigation>
     </page>
 
+    <!-- Manage highlights feeds -->
+
+    <page view-id="/manage/highlights/highlights_add.xhtml" login-required="true">
+        <begin-conversation flush-mode="manual" join="true" />
+        <action execute="#{highlightsFeedMod.getHighlightsFeed}"/>
+
+        <navigation>
+            <redirect view-id="/manage/feed_add.xhtml">
+                <message severity="INFO">#{messages['blog.feed.highlights.adding.info']}</message>
+            </redirect>
+        </navigation>
+    </page>
+
+    <page view-id="/manage/highlights/highlights_edit.xhtml" login-required="true">
+        <begin-conversation flush-mode="manual" join="true" />
+        <param name="name" converterId="feedConverter" value="#{feedMod.feed}" />
+        <restrict>#{identity.hasPermission('feed', 'edit', feedMod.feed, feedMod.feed.group)}</restrict>
+        <navigation from-action="#{highlightsFeedMod.saveExisting}">
+            <end-conversation />
+            <redirect view-id="/manage/index.xhtml" />
+        </navigation>
+    </page>
+
+    <page view-id="/manage/highlights/post_add.xhtml" login-required="true">
+        <begin-conversation flush-mode="manual" join="true" />
+        <param name="post" converterId="postConverter" value="#{highlightsFeedMod.post}" />
+        <restrict>#{identity.hasPermission('management', 'view')}</restrict>
+        <navigation from-action="#{highlightsFeedMod.addPost}">
+            <end-conversation />
+            <redirect view-id="/manage/highlights/highlights_edit.xhtml">
+                <param name="name" value="#{highlightsFeedMod.selectedFeed.name}" />    
+            </redirect>
+        </navigation>
+    </page>
+
     <!-- Manage groups -->
 
     <page view-id="*">

Modified: trunk/resources/messages_en.properties
===================================================================
--- trunk/resources/messages_en.properties	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/resources/messages_en.properties	2008-03-06 16:38:48 UTC (rev 246)
@@ -130,6 +130,13 @@
 
 blog.configuration.saved=Configuration saved.
 
+blog.feed.highlights.adding.info=A highlights feed lets you create a feed out of selected, arbitrary posts. \
+  After adding a new highlights feed, you'll be able to add posts to it by navigating to the post and clicking \
+  a link there. If you'd like to change the order in which the posts appear, or delete some, you'll just need to \
+  edit this feeds 'specific' properties.
+blog.feed.highlights.updated=Highlights feed '{0}' updated.
+blog.feed.highlights.post.added=Post '{0}' added to highlights feed '{1}'.
+
 blog.security.group.admin.added=Group {0} added to administrators.
 blog.security.group.admin.deleted=Group {0} deleted from administrators.
 

Copied: trunk/src/action/org/jboss/blog/session/feed/dao/HighlightsFeedDao.java (from rev 240, trunk/src/action/org/jboss/blog/session/feed/dao/RemoteFeedDao.java)
===================================================================
--- trunk/src/action/org/jboss/blog/session/feed/dao/HighlightsFeedDao.java	                        (rev 0)
+++ trunk/src/action/org/jboss/blog/session/feed/dao/HighlightsFeedDao.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,33 @@
+package org.jboss.blog.session.feed.dao;
+
+import org.jboss.blog.model.feed.HighlightsFeed;
+import org.jboss.blog.model.RestrictedPost;
+import org.jboss.blog.session.feed.type.FeedType;
+import org.jboss.blog.session.update.UpdateException;
+import org.jboss.blog.tools.GeneralTools;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:adam at warski.org">Adam Warski</a>
+ */
+ at FeedType(
+        name = "highlights",
+        addPage = "/manage/highlights/highlights_add.xhtml",
+        editPage = "/manage/highlights/highlights_edit.xhtml",
+        model = HighlightsFeed.class)
+public class HighlightsFeedDao implements FeedDao {
+    private HighlightsFeed highlightsFeed;
+
+    public HighlightsFeedDao(HighlightsFeed highlightsFeed) {
+        this.highlightsFeed = highlightsFeed;
+    }
+
+    public List<? extends RestrictedPost> getPosts(int from, int to) {
+        return GeneralTools.subList(highlightsFeed.getSelectedPosts(), from, to);
+    }
+
+    public void update() throws UpdateException {
+
+    }
+}
\ No newline at end of file

Added: trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsDeleteListener.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsDeleteListener.java	                        (rev 0)
+++ trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsDeleteListener.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,31 @@
+package org.jboss.blog.session.feed.mod;
+
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Observer;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.ScopeType;
+import org.jboss.blog.model.Post;
+import org.jboss.blog.model.feed.HighlightsFeed;
+
+import javax.persistence.EntityManager;
+
+/**
+ * @author <a href="mailto:adam at warski.org">Adam Warski</a>
+ */
+ at Name("highlightsDeleteListener")
+ at Scope(ScopeType.STATELESS)
+public class HighlightsDeleteListener {
+    @In
+    private EntityManager entityManager;
+
+    @Observer("org.jboss.blog.post.before_delete")
+    public void beforePostDeleted(Post postToDelete) {
+        for (Object feedObj : entityManager.createQuery("select feed from HighlightsFeed feed").getResultList()) {
+            HighlightsFeed feed = (HighlightsFeed) feedObj;
+            feed.getSelectedPosts().remove(postToDelete);
+        }
+
+        entityManager.flush();
+    }
+}

Copied: trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsFeedModBean.java (from rev 240, trunk/src/action/org/jboss/blog/session/feed/mod/RemoteFeedModBean.java)
===================================================================
--- trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsFeedModBean.java	                        (rev 0)
+++ trunk/src/action/org/jboss/blog/session/feed/mod/HighlightsFeedModBean.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,138 @@
+package org.jboss.blog.session.feed.mod;
+
+import org.jboss.blog.model.feed.HighlightsFeed;
+import org.jboss.blog.model.Post;
+import org.jboss.blog.session.feed.InvalidFeedTypeException;
+import org.jboss.blog.tools.GeneralTools;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.security.Restrict;
+import org.jboss.seam.faces.FacesMessages;
+
+import javax.faces.application.FacesMessage;
+import javax.persistence.EntityManager;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:adam at warski.org">Adam Warski</a>
+ */
+ at Scope(ScopeType.CONVERSATION)
+ at Name("highlightsFeedMod")
+public class HighlightsFeedModBean implements Serializable {
+    @In
+    private FeedModBean feedMod;
+
+    @In
+    private EntityManager entityManager;
+
+    @In
+    private FacesMessages facesMessages;
+
+    private HighlightsFeed highlightsFeed;
+
+    private Post post;
+
+    private HighlightsFeed selectedFeed;
+
+    private int[] positions;
+
+    private void initPositions(List<Post> posts) {
+        positions = new int[posts.size()];
+        for (int i=0; i<positions.length; i++) {
+            positions[i] = i;
+        }
+    }
+
+    public HighlightsFeed getHighlightsFeed() throws InvalidFeedTypeException {
+        if (highlightsFeed == null) {
+            if (feedMod.getFeed() == null) {
+                highlightsFeed = new HighlightsFeed();
+                feedMod.initNewFeed(highlightsFeed);
+
+                highlightsFeed.setSelectedPosts(new ArrayList<Post>());
+            } else {
+                if (feedMod.getFeed() instanceof HighlightsFeed) {
+                    highlightsFeed = (HighlightsFeed) feedMod.getFeed();
+                } else {
+                    throw new InvalidFeedTypeException();
+                }
+            }
+
+            initPositions(highlightsFeed.getSelectedPosts());
+        }
+
+        return highlightsFeed;
+    }
+
+    public HighlightsFeed getSelectedFeed() {
+        return selectedFeed;
+    }
+
+    public void setSelectedFeed(HighlightsFeed selectedFeed) {
+        this.selectedFeed = selectedFeed;
+    }
+
+    public Post getPost() {
+        return post;
+    }
+
+    public void setPost(Post post) {
+        this.post = post;
+    }
+
+    public int[] getPositions() {
+        return positions;
+    }
+
+    public void setPositions(int[] positions) {
+        this.positions = positions;
+    }
+
+    public void moveUp(int rowNumber) throws InvalidFeedTypeException {
+        GeneralTools.moveElement(getHighlightsFeed().getSelectedPosts(), rowNumber, rowNumber-1);
+    }
+
+    public void moveDown(int rowNumber) throws InvalidFeedTypeException {
+        GeneralTools.moveElement(getHighlightsFeed().getSelectedPosts(), rowNumber, rowNumber+1);
+    }
+
+    public void moveTo(int rowNumber) throws InvalidFeedTypeException {
+        GeneralTools.moveElement(getHighlightsFeed().getSelectedPosts(), rowNumber, positions[rowNumber]);
+        positions[rowNumber] = rowNumber;
+    }
+
+    public void delete(int rowNumber) throws InvalidFeedTypeException {
+        getHighlightsFeed().getSelectedPosts().remove(rowNumber);
+
+        initPositions(getHighlightsFeed().getSelectedPosts());
+    }
+
+    @Restrict("#{identity.hasPermission('feed', 'edit', feedMod.feed, feedMod.feed.group)}")
+    public void saveExisting() throws InvalidFeedTypeException {
+        entityManager.flush();
+
+        facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_INFO, "blog.feed.highlights.updated",
+                getHighlightsFeed().getName());
+
+        Events.instance().raiseEvent("org.jboss.blog.feed.updated", getHighlightsFeed());
+    }
+
+    @Restrict("#{identity.hasPermission('feed', 'edit', highlightsFeedMod.selectedFeed, highlightsFeedMod.selectedFeed.group)}")
+    public void addPost() {
+        if (!getSelectedFeed().getSelectedPosts().contains(getPost())) {
+            getSelectedFeed().getSelectedPosts().add(getPost());
+
+            entityManager.flush();
+
+            facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_INFO, "blog.feed.highlights.post.added",
+                    getPost().getTitle(), getSelectedFeed().getName());
+
+            Events.instance().raiseEvent("org.jboss.blog.feed.updated", getSelectedFeed());
+        }
+    }
+}
\ No newline at end of file

Modified: trunk/src/action/org/jboss/blog/session/feed/mod/PropositionsCountBean.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/feed/mod/PropositionsCountBean.java	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/src/action/org/jboss/blog/session/feed/mod/PropositionsCountBean.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -6,7 +6,7 @@
 import org.jboss.seam.ScopeType;
 import org.jboss.blog.service.GroupsService;
 import org.jboss.blog.model.Group;
-import org.jboss.blog.session.security.GroupsSecurity;
+import org.jboss.blog.session.security.filtering.GroupsSecurity;
 
 /**
  * @author <a href="mailto:adam at warski.org">Adam Warski</a>

Deleted: trunk/src/action/org/jboss/blog/session/security/GroupsSecurity.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/security/GroupsSecurity.java	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/src/action/org/jboss/blog/session/security/GroupsSecurity.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -1,48 +0,0 @@
-package org.jboss.blog.session.security;
-
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.AutoCreate;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.ScopeType;
-import org.jboss.blog.model.Group;
-import org.jboss.blog.model.feed.Feed;
-
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author <a href="mailto:adam at warski.org">Adam Warski</a>
- */
- at Name("groupsSecurity")
- at Scope(ScopeType.STATELESS)
- at AutoCreate
-public class GroupsSecurity {
-    @In
-    private FeedsIdentity identity;
-
-    public List<Group> filterForFeedMod(List<Group> groups) {
-        List<Group> allowedGroups = new ArrayList<Group>();
-
-        for (Group group : groups) {
-            if (identity.hasPermission("feed", "add", group)) {
-                allowedGroups.add(group);
-            }
-        }
-
-        return allowedGroups;
-    }
-
-    public List<Group> filterForFeedMod(Feed feed, List<Group> groups, boolean add) {
-        List<Group> allowedGroups = new ArrayList<Group>();
-
-        for (Group group : groups) {
-            if ((identity.hasPermission("feed", "add", feed, group)) ||
-                    ((!add) && identity.hasPermission("feed", "edit", feed, group))) {
-                allowedGroups.add(group);
-            }
-        }
-
-        return allowedGroups;
-    }
-}

Copied: trunk/src/action/org/jboss/blog/session/security/filtering/GroupsSecurity.java (from rev 240, trunk/src/action/org/jboss/blog/session/security/GroupsSecurity.java)
===================================================================
--- trunk/src/action/org/jboss/blog/session/security/filtering/GroupsSecurity.java	                        (rev 0)
+++ trunk/src/action/org/jboss/blog/session/security/filtering/GroupsSecurity.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,49 @@
+package org.jboss.blog.session.security.filtering;
+
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.ScopeType;
+import org.jboss.blog.model.Group;
+import org.jboss.blog.model.feed.Feed;
+import org.jboss.blog.session.security.FeedsIdentity;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:adam at warski.org">Adam Warski</a>
+ */
+ at Name("groupsSecurity")
+ at Scope(ScopeType.STATELESS)
+ at AutoCreate
+public class GroupsSecurity {
+    @In
+    private FeedsIdentity identity;
+
+    public List<Group> filterForFeedMod(List<Group> groups) {
+        List<Group> allowedGroups = new ArrayList<Group>();
+
+        for (Group group : groups) {
+            if (identity.hasPermission("feed", "add", group)) {
+                allowedGroups.add(group);
+            }
+        }
+
+        return allowedGroups;
+    }
+
+    public List<Group> filterForFeedMod(Feed feed, List<Group> groups, boolean add) {
+        List<Group> allowedGroups = new ArrayList<Group>();
+
+        for (Group group : groups) {
+            if ((identity.hasPermission("feed", "add", feed, group)) ||
+                    ((!add) && identity.hasPermission("feed", "edit", feed, group))) {
+                allowedGroups.add(group);
+            }
+        }
+
+        return allowedGroups;
+    }
+}

Added: trunk/src/action/org/jboss/blog/session/security/filtering/HighlightsSecurity.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/security/filtering/HighlightsSecurity.java	                        (rev 0)
+++ trunk/src/action/org/jboss/blog/session/security/filtering/HighlightsSecurity.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,45 @@
+package org.jboss.blog.session.security.filtering;
+
+import org.jboss.seam.annotations.*;
+import org.jboss.seam.ScopeType;
+import org.jboss.blog.model.feed.HighlightsFeed;
+import org.jboss.blog.session.security.FeedsIdentity;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:adam at warski.org">Adam Warski</a>
+ */
+ at Name("highlightsSecurity")
+ at Scope(ScopeType.CONVERSATION)
+ at AutoCreate
+public class HighlightsSecurity {
+    @In
+    private EntityManager entityManager;
+
+    @In
+    private FeedsIdentity identity;
+
+    private List<HighlightsFeed> feeds;
+
+    private void initFeeds() {
+        feeds = new ArrayList<HighlightsFeed>();
+
+        for (Object feedObj : entityManager.createQuery("select feed from HighlightsFeed feed").getResultList()) {
+            HighlightsFeed feed = (HighlightsFeed) feedObj;
+            if (identity.hasPermission("feed", "edit", feed, feed.getGroup())) {
+                feeds.add(feed);
+            }
+        }
+    }
+
+    public List<HighlightsFeed> getFeeds() {
+        if (feeds == null) {
+            initFeeds();
+        }
+
+        return feeds;
+    }
+}

Modified: trunk/src/action/org/jboss/blog/session/view/PostViewBean.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/view/PostViewBean.java	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/src/action/org/jboss/blog/session/view/PostViewBean.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -35,6 +35,8 @@
     // TODO: the delete method shouldn't be here
     @Restrict("#{identity.hasPermission('post', 'delete', postView.post, postView.post.feed, postView.post.feed.group)}")
     public void delete() {
+        Events.instance().raiseEvent("org.jboss.blog.post.before_delete", post);
+
         entityManager.remove(entityManager.merge(post));
 
         facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_INFO, "blog.post.deleted", post.getTitle());

Added: trunk/src/model/org/jboss/blog/model/feed/HighlightsFeed.java
===================================================================
--- trunk/src/model/org/jboss/blog/model/feed/HighlightsFeed.java	                        (rev 0)
+++ trunk/src/model/org/jboss/blog/model/feed/HighlightsFeed.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,27 @@
+package org.jboss.blog.model.feed;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.jboss.blog.model.Post;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:adam at warski.org">Adam Warski</a>
+ */
+ at Entity
+ at Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
+public class HighlightsFeed extends Feed {
+    @ManyToMany
+    private List<Post> selectedPosts;
+
+    public List<Post> getSelectedPosts() {
+        return selectedPosts;
+    }
+
+    public void setSelectedPosts(List<Post> selectedPosts) {
+        this.selectedPosts = selectedPosts;
+    }
+}

Modified: trunk/src/tools/org/jboss/blog/tools/GeneralTools.java
===================================================================
--- trunk/src/tools/org/jboss/blog/tools/GeneralTools.java	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/src/tools/org/jboss/blog/tools/GeneralTools.java	2008-03-06 16:38:48 UTC (rev 246)
@@ -99,6 +99,36 @@
         return list.subList(from, Math.min(to, list.size()));
     }
 
+    public static <T> void moveElement(List<T> list, int from, int to) {
+        if (from < 0 || from > list.size() || to < 0 || to > list.size()) {
+            return;
+        }
+
+        if (from == to) {
+            return;
+        }
+
+        T toMove = list.get(from);
+
+        if (from < to) {
+            int currentIndex = from;
+            while (currentIndex != to) {
+                list.set(currentIndex, list.get(currentIndex + 1));
+                currentIndex++;
+            }
+
+            list.set(to, toMove);
+        } else {
+            int currentIndex = from;
+            while (currentIndex != to) {
+                list.set(currentIndex, list.get(currentIndex - 1));
+                currentIndex--;
+            }
+
+            list.set(to, toMove);
+        }
+    }
+
     public static int compareDates(Date date1, Date date2) {
         long seconds1 = date1.getTime() / 1000;
         long seconds2 = date2.getTime() / 1000;

Modified: trunk/view/common/post.xhtml
===================================================================
--- trunk/view/common/post.xhtml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/view/common/post.xhtml	2008-03-06 16:38:48 UTC (rev 246)
@@ -20,6 +20,13 @@
         [ <a href="#{post.link}">View original post</a> ]
     </p>
 
+    <s:div rendered="#{showAddToHighlights}">
+        <s:link value="Add this post to a highlights feed ..." view="/manage/highlights/post_add.xhtml"
+                rendered="#{identity.hasPermission('management', 'view') and highlightsSecurity.feeds.size() > 0}">
+            <f:param name="post" value="#{post.titleAsId}" />
+        </s:link>
+    </s:div>
+
     <ui:repeat var="image" value="#{post.images}">
         <img src="#{image.url}" alt="#{image.title}" width="180" />
     </ui:repeat>

Copied: trunk/view/manage/highlights/highlights_edit.xhtml (from rev 240, trunk/view/manage/remote/remote_edit.xhtml)
===================================================================
--- trunk/view/manage/highlights/highlights_edit.xhtml	                        (rev 0)
+++ trunk/view/manage/highlights/highlights_edit.xhtml	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,18 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:s="http://jboss.com/products/seam/taglib"
+                xmlns:ui="http://java.sun.com/jsf/facelets"
+                xmlns:f="http://java.sun.com/jsf/core"
+                xmlns:h="http://java.sun.com/jsf/html"
+                xmlns:rich="http://richfaces.org/rich"
+                xmlns:a="http://richfaces.org/a4j"
+                template="../../layout/template.xhtml">
+    <ui:define name="header">
+        Edit highlights feed: #{feedMod.feed.name}
+    </ui:define>
+
+    <ui:define name="body">
+        <ui:include src="highlights_mod.xhtml" />
+    </ui:define>
+</ui:composition>

Copied: trunk/view/manage/highlights/highlights_mod.xhtml (from rev 240, trunk/view/manage/remote/remote_mod.xhtml)
===================================================================
--- trunk/view/manage/highlights/highlights_mod.xhtml	                        (rev 0)
+++ trunk/view/manage/highlights/highlights_mod.xhtml	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,71 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:s="http://jboss.com/products/seam/taglib"
+                xmlns:ui="http://java.sun.com/jsf/facelets"
+                xmlns:f="http://java.sun.com/jsf/core"
+                xmlns:h="http://java.sun.com/jsf/html"
+                xmlns:rich="http://richfaces.org/rich"
+                xmlns:a="http://richfaces.org/a4j">
+    <div class="adminforms">
+        <h:form>
+            <s:div rendered="#{highlightsFeedMod.highlightsFeed.selectedPosts.size == 0}">
+                There are no posts selected.
+            </s:div>
+
+            <s:div id="postsTable">
+                <table class="basetablestyle" >
+                    <a:repeat rowKeyVar="rowNumber" var="post" value="#{highlightsFeedMod.highlightsFeed.selectedPosts}">
+                        <tr class="#{(rowNumber%2 == 0) ? 'evenRow' : 'oddRow'}">
+                            <td>
+                                #{rowNumber}
+                            </td>
+                            <td>
+                                <ui:include src="../../common/post.xhtml">
+                                    <ui:param name="post" value="#{post}" />
+                                    <ui:param name="showSummary" value="true" />
+                                    <ui:param name="showAddToHighlights" value="false" />
+                                </ui:include>
+                            </td>
+                            <td>
+                                <a:commandLink value="Move up" action="#{highlightsFeedMod.moveUp(rowNumber)}"
+                                               reRender="postsTable" rendered="#{rowNumber != 0}" />
+                            </td>
+                            <td>
+                                <a:commandLink value="Move down" action="#{highlightsFeedMod.moveDown(rowNumber)}"
+                                               reRender="postsTable"
+                                               rendered="#{rowNumber != highlightsFeedMod.highlightsFeed.selectedPosts.size()-1}"/>
+                            </td>
+                            <td>
+                                <a:commandLink value="Move to position:" action="#{highlightsFeedMod.moveTo(rowNumber)}"
+                                               reRender="postsTable" />
+                            </td>
+                            <td>
+                                <h:inputText size="2" maxlength="2" value="#{highlightsFeedMod.positions[rowNumber]}" />
+                            </td>
+                            <td>
+                                <a:commandLink value="Delete" action="#{highlightsFeedMod.delete(rowNumber)}"
+                                               reRender="postsTable" />
+                            </td>
+                        </tr>
+                    </a:repeat>
+                </table>
+            </s:div>
+
+            <s:div styleClass="formbuttons">
+                <ul>
+                    <li>
+                        <h:commandButton value="Save" action="#{highlightsFeedMod.saveExisting}"
+                                         styleClass="submit" />
+                    </li>
+                    <li>
+                        <s:button value="Cancel" view="/manage/index.xhtml" propagation="end" styleClass="submit" />
+                    </li>
+                    <li>
+                        <ui:include src="../../common/ajax_status.xhtml" />
+                    </li>
+                </ul>
+            </s:div>
+        </h:form>
+    </div>
+</ui:composition>

Added: trunk/view/manage/highlights/post_add.xhtml
===================================================================
--- trunk/view/manage/highlights/post_add.xhtml	                        (rev 0)
+++ trunk/view/manage/highlights/post_add.xhtml	2008-03-06 16:38:48 UTC (rev 246)
@@ -0,0 +1,52 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:s="http://jboss.com/products/seam/taglib"
+                xmlns:ui="http://java.sun.com/jsf/facelets"
+                xmlns:f="http://java.sun.com/jsf/core"
+                xmlns:h="http://java.sun.com/jsf/html"
+                xmlns:rich="http://richfaces.org/rich"
+                xmlns:a="http://richfaces.org/a4j"
+                template="../../layout/template.xhtml">
+    <ui:define name="header">
+        Add post '#{highlightsFeedMod.post.title}' to a highlights feed
+    </ui:define>
+
+    <ui:define name="body">
+        <div class="QuickstartMargin" id="QuickStart">
+            <ul>
+                <li>
+                    <p>After selecting a highlights feed, you'll be able to change the order of the posts.</p>
+                </li>
+            </ul>
+        </div>
+
+        <div class="adminforms">
+            <h:form>
+                <h:panelGrid columns="2">
+                    <h:outputLabel for="feeds">Highlights feed:</h:outputLabel>
+                    <h:panelGroup>
+                        <h:selectOneListbox id="feeds" value="#{highlightsFeedMod.selectedFeed}" required="true">
+                            <s:selectItems var="feed" value="#{highlightsSecurity.feeds}" label="#{feed.title}" />
+                            <s:convertEntity />
+                        </h:selectOneListbox>
+
+                        <a:outputPanel id="feedsMessage">
+                            <h:message for="feeds" styleClass="error" />
+                        </a:outputPanel>
+                    </h:panelGroup>
+                </h:panelGrid>
+                <div id="proceed" class="formbuttons">
+                    <ul>
+                        <li>
+                            <h:commandButton value="Select" action="#{highlightsFeedMod.addPost}" styleClass="submit"/>
+                        </li>
+                        <li>
+                            <s:button value="Cancel" view="/home.xhtml" styleClass="submit"/>
+                        </li>
+                    </ul>
+                </div>
+            </h:form>
+        </div>
+    </ui:define>
+</ui:composition>

Modified: trunk/view/search/search.xhtml
===================================================================
--- trunk/view/search/search.xhtml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/view/search/search.xhtml	2008-03-06 16:38:48 UTC (rev 246)
@@ -38,8 +38,8 @@
                 <ui:repeat var="result" value="#{postSearch.results}">
                     <ui:include src="../common/post.xhtml">
                         <ui:param name="post" value="#{result[1]}" />
-                        <ui:param name="showLinkToSeparatePage" value="true" />
                         <ui:param name="showSummary" value="true" />
+                        <ui:param name="showAddToHighlights" value="false" />
                         <ui:param name="additionalHeader"
                                   value="(#{postSearch.formatScore(result[0])}%)" />
                     </ui:include>

Modified: trunk/view/view/feed.xhtml
===================================================================
--- trunk/view/view/feed.xhtml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/view/view/feed.xhtml	2008-03-06 16:38:48 UTC (rev 246)
@@ -30,6 +30,7 @@
                 <ui:include src="../common/post.xhtml">
                     <ui:param name="post" value="#{post}" />
                     <ui:param name="showSummary" value="false" />
+                    <ui:param name="showAddToHighlights" value="true" />
                 </ui:include>
 
                 <br />

Modified: trunk/view/view/post.xhtml
===================================================================
--- trunk/view/view/post.xhtml	2008-03-06 08:33:09 UTC (rev 245)
+++ trunk/view/view/post.xhtml	2008-03-06 16:38:48 UTC (rev 246)
@@ -38,6 +38,7 @@
             <ui:include src="../common/post.xhtml">
                 <ui:param name="post" value="#{post}" />
                 <ui:param name="showSummary" value="false" />
+                <ui:param name="showAddToHighlights" value="true" />
             </ui:include>
         </div>
     </ui:define>




More information about the jboss-cvs-commits mailing list