From 92fadc4bbfacfcfc8b639961b35c2dc873cf21fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 14 Oct 2010 10:34:20 +0200 Subject: [PATCH] Show posts of Sone and friends on index page. --- .../java/net/pterodactylus/sone/web/IndexPage.java | 34 ++++++++++++++++++++++ src/main/resources/i18n/sone.en.properties | 2 ++ src/main/resources/templates/index.html | 14 +++++++++ 3 files changed, 50 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java index 0e72938..3965aee 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -17,6 +17,13 @@ package net.pterodactylus.sone.web; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.template.Template; /** @@ -45,6 +52,33 @@ public class IndexPage extends SoneTemplatePage { * {@inheritDoc} */ @Override + protected void processTemplate(Request request, Template template) throws RedirectException { + super.processTemplate(request, template); + Sone sone = getCurrentSone(request.getToadletContext()); + List allPosts = new ArrayList(); + allPosts.addAll(sone.getPosts()); + for (Sone friendSone : sone.getFriendSones()) { + allPosts.addAll(friendSone.getPosts()); + } + Collections.sort(allPosts, new Comparator() { + + @Override + public int compare(Post leftPost, Post rightPost) { + return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime())); + } + + }); + template.set("posts", allPosts); + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override protected boolean requiresLogin() { return true; } diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 4bde225..d56627f 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -46,6 +46,8 @@ Page.Index.Title=Your Sone - Sone Page.Index.Page.Title=Your Sone Page.Index.Label.Text=Post text: Page.Index.Button.Post=Post! +Page.Index.PostList.Title=Posts by you and your friends +Page.Index.PostList.Text.NoPostYet=Nobody has written any posts yet. You should probably start it right now! Page.EditProfile.Title=Edit Profile - Sone Page.EditProfile.Page.Title=Edit Profile diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 154ff3e..7aa558b 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -14,4 +14,18 @@ +

<%= Page.Index.PostList.Title|l10n|html>

+ +
+ <%foreach posts post> +
+
<% post.sone.name|html>
+
<% post.text|html>
+
<% post.time|date format="MMM d, yyyy, HH:mm:ss">
+
+ <%foreachelse> +
<%= Page.Index.PostList.Text.NoPostYet|l10n|html>
+ <%/foreach> +
+ \ No newline at end of file -- 2.7.4