Allow user to configuration the number of posts shown on a page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 04:11:19 +0000 (06:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 04:11:19 +0000 (06:11 +0200)
This resolves #123.

src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/web/IndexPage.java
src/main/java/net/pterodactylus/sone/web/OptionsPage.java
src/main/java/net/pterodactylus/sone/web/SearchPage.java
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/options.html

index 9fe4a28..93caddd 100644 (file)
@@ -1680,6 +1680,7 @@ public class Core implements IdentityListener, UpdateListener {
                try {
                        configuration.getIntValue("Option/ConfigurationVersion").setValue(0);
                        configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal());
+                       configuration.getIntValue("Option/PostsPerPage").setValue(options.getIntegerOption("PostsPerPage").getReal());
                        configuration.getIntValue("Option/PositiveTrust").setValue(options.getIntegerOption("PositiveTrust").getReal());
                        configuration.getIntValue("Option/NegativeTrust").setValue(options.getIntegerOption("NegativeTrust").getReal());
                        configuration.getStringValue("Option/TrustComment").setValue(options.getStringOption("TrustComment").getReal());
@@ -1753,6 +1754,7 @@ public class Core implements IdentityListener, UpdateListener {
                        }
 
                }));
+               options.addIntegerOption("PostsPerPage", new DefaultOption<Integer>(25));
                options.addIntegerOption("PositiveTrust", new DefaultOption<Integer>(75));
                options.addIntegerOption("NegativeTrust", new DefaultOption<Integer>(-25));
                options.addStringOption("TrustComment", new DefaultOption<String>("Set from Sone Web Interface"));
@@ -1772,6 +1774,7 @@ public class Core implements IdentityListener, UpdateListener {
                }
 
                options.getIntegerOption("InsertionDelay").set(configuration.getIntValue("Option/InsertionDelay").getValue(null));
+               options.getIntegerOption("PostsPerPage").set(configuration.getIntValue("Option/PostsPerPage").getValue(null));
                options.getIntegerOption("PositiveTrust").set(configuration.getIntValue("Option/PositiveTrust").getValue(null));
                options.getIntegerOption("NegativeTrust").set(configuration.getIntValue("Option/NegativeTrust").getValue(null));
                options.getStringOption("TrustComment").set(configuration.getStringValue("Option/TrustComment").getValue(null));
@@ -1961,6 +1964,27 @@ public class Core implements IdentityListener, UpdateListener {
                }
 
                /**
+                * Returns the number of posts to show per page.
+                *
+                * @return The number of posts to show per page
+                */
+               public int getPostsPerPage() {
+                       return options.getIntegerOption("PostsPerPage").get();
+               }
+
+               /**
+                * Sets the number of posts to show per page.
+                *
+                * @param postsPerPage
+                *            The number of posts to show per page
+                * @return This preferences object
+                */
+               public Preferences setPostsPerPage(Integer postsPerPage) {
+                       options.getIntegerOption("PostsPerPage").set(postsPerPage);
+                       return this;
+               }
+
+               /**
                 * Returns the positive trust.
                 *
                 * @return The positive trust
index ad59f30..e675311 100644 (file)
@@ -75,7 +75,7 @@ public class IndexPage extends SoneTemplatePage {
                }
                allPosts = Filters.filteredList(allPosts, Post.FUTURE_POSTS_FILTER);
                Collections.sort(allPosts, Post.TIME_COMPARATOR);
-               Pagination<Post> pagination = new Pagination<Post>(allPosts, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
+               Pagination<Post> pagination = new Pagination<Post>(allPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
                templateContext.set("pagination", pagination);
                templateContext.set("posts", pagination.getItems());
        }
index 77b4950..39cacc6 100644 (file)
@@ -63,6 +63,8 @@ public class OptionsPage extends SoneTemplatePage {
                        }
                        Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
                        preferences.setInsertionDelay(insertionDelay);
+                       Integer postsPerPage = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("posts-per-page", 4), null);
+                       preferences.setPostsPerPage(postsPerPage);
                        Integer positiveTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3));
                        preferences.setPositiveTrust(positiveTrust);
                        Integer negativeTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("negative-trust", 4));
@@ -85,6 +87,7 @@ public class OptionsPage extends SoneTemplatePage {
                        templateContext.set("auto-follow", currentSone.getOptions().getBooleanOption("AutoFollow").get());
                }
                templateContext.set("insertion-delay", preferences.getInsertionDelay());
+               templateContext.set("posts-per-page", preferences.getPostsPerPage());
                templateContext.set("positive-trust", preferences.getPositiveTrust());
                templateContext.set("negative-trust", preferences.getNegativeTrust());
                templateContext.set("trust-comment", preferences.getTrustComment());
index 7381f80..1d1aa36 100644 (file)
@@ -103,8 +103,8 @@ public class SearchPage extends SoneTemplatePage {
                List<Post> resultPosts = Converters.convertList(sortedPostHits, new HitConverter<Post>());
 
                /* pagination. */
-               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("sonePage"), 0));
-               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
+               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("sonePage"), 0));
+               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
 
                templateContext.set("sonePagination", sonePagination);
                templateContext.set("soneHits", sonePagination.getItems());
index 53702f7..14c4f94 100644 (file)
@@ -83,7 +83,7 @@ public class ViewSonePage extends SoneTemplatePage {
                List<Post> sonePosts = sone.getPosts();
                sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone));
                Collections.sort(sonePosts, Post.TIME_COMPARATOR);
-               Pagination<Post> postPagination = new Pagination<Post>(sonePosts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
+               Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
                templateContext.set("postPagination", postPagination);
                templateContext.set("posts", postPagination.getItems());
                Set<Reply> replies = sone.getReplies();
@@ -105,7 +105,7 @@ public class ViewSonePage extends SoneTemplatePage {
 
                });
 
-               Pagination<Post> repliedPostPagination = new Pagination<Post>(posts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("repliedPostPage"), 0));
+               Pagination<Post> repliedPostPagination = new Pagination<Post>(posts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("repliedPostPage"), 0));
                templateContext.set("repliedPostPagination", repliedPostPagination);
                templateContext.set("repliedPosts", repliedPostPagination.getItems());
        }
index 4e18d5d..282e9b7 100644 (file)
@@ -36,6 +36,7 @@ Page.Options.Section.SoneSpecificOptions.NotLoggedIn=These options are only avai
 Page.Options.Option.AutoFollow.Description=If a new Sone is discovered, follow it automatically.
 Page.Options.Section.RuntimeOptions.Title=Runtime Behaviour
 Page.Options.Option.InsertionDelay.Description=The number of seconds the Sone inserter waits after a modification of a Sone before it is being inserted.
+Page.Options.Option.PostsPerPage.Description=The number of posts to display on a page before pagination controls are being shown.
 Page.Options.Section.TrustOptions.Title=Trust Settings
 Page.Options.Option.PositiveTrust.Description=The amount of positive trust you want to assign to other Sones by clicking the checkmark below a post or reply.
 Page.Options.Option.NegativeTrust.Description=The amount of trust you want to assign to other Sones by clicking the red X below a post or reply. This value should be negative.
@@ -266,6 +267,7 @@ WebInterface.DefaultText.BirthMonth=Month
 WebInterface.DefaultText.BirthYear=Year
 WebInterface.DefaultText.FieldName=Field name
 WebInterface.DefaultText.Option.InsertionDelay=Time to wait after a Sone is modified before insert (in seconds)
+WebInterface.DefaultText.Option.PostsPerPage=Number of posts to show on a page
 WebInterface.DefaultText.Search=What are you looking for?
 WebInterface.Confirmation.DeletePostButton=Yes, delete!
 WebInterface.Confirmation.DeleteReplyButton=Yes, delete!
index 4086306..76cbfc4 100644 (file)
@@ -5,6 +5,9 @@
                        getTranslation("WebInterface.DefaultText.Option.InsertionDelay", function(insertionDelayDefaultText) {
                                registerInputTextareaSwap("#sone #options input[name=insertion-delay]", insertionDelayDefaultText, "insertion-delay", true, true);
                        });
+                       getTranslation("WebInterface.DefaultText.Option.PostsPerPage", function(postsPerPageText) {
+                               registerInputTextareaSwap("#sone #options input[name=posts-per-page]", postsPerPageText, "posts-per-page", true, true);
+                       });
                });
        </script>
 
@@ -31,6 +34,9 @@
                <p><%= Page.Options.Option.InsertionDelay.Description|l10n|html></p>
                <p><input type="text" name="insertion-delay" value="<% insertion-delay|html>" /></p>
 
+               <p><%= Page.Options.Option.PostsPerPage.Description|l10n|html></p>
+               <p><input type="text" name="posts-per-page" value="<% posts-per-page|html>" /></p>
+
                <h2><%= Page.Options.Section.TrustOptions.Title|l10n|html></h2>
 
                <p><%= Page.Options.Option.PositiveTrust.Description|l10n|html></p>