Add images-per-post option.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 31 May 2012 10:05:08 +0000 (12:05 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 31 May 2012 10:05:08 +0000 (12:05 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/web/OptionsPage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/options.html

index 89867f4..4001f46 100644 (file)
@@ -2165,6 +2165,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        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/ImagesPerPage").setValue(options.getIntegerOption("ImagesPerPage").getReal());
                        configuration.getIntValue("Option/CharactersPerPost").setValue(options.getIntegerOption("CharactersPerPost").getReal());
                        configuration.getIntValue("Option/PostCutOffLength").setValue(options.getIntegerOption("PostCutOffLength").getReal());
                        configuration.getBooleanValue("Option/RequireFullAccess").setValue(options.getBooleanOption("RequireFullAccess").getReal());
@@ -2251,6 +2252,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
 
                }));
                options.addIntegerOption("PostsPerPage", new DefaultOption<Integer>(10, new IntegerRangeValidator(1, Integer.MAX_VALUE)));
+               options.addIntegerOption("ImagesPerPage", new DefaultOption<Integer>(9, new IntegerRangeValidator(1, Integer.MAX_VALUE)));
                options.addIntegerOption("CharactersPerPost", new DefaultOption<Integer>(400, new OrValidator<Integer>(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator<Integer>(-1))));
                options.addIntegerOption("PostCutOffLength", new DefaultOption<Integer>(200, new OrValidator<Integer>(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator<Integer>(-1))));
                options.addBooleanOption("RequireFullAccess", new DefaultOption<Boolean>(false));
@@ -2291,6 +2293,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
 
                loadConfigurationValue("InsertionDelay");
                loadConfigurationValue("PostsPerPage");
+               loadConfigurationValue("ImagesPerPage");
                loadConfigurationValue("CharactersPerPost");
                loadConfigurationValue("PostCutOffLength");
                options.getBooleanOption("RequireFullAccess").set(configuration.getBooleanValue("Option/RequireFullAccess").getValue(null));
@@ -2674,6 +2677,39 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                }
 
                /**
+                * Returns the number of images to show per page.
+                *
+                * @return The number of images to show per page
+                */
+               public int getImagesPerPage() {
+                       return options.getIntegerOption("ImagesPerPage").get();
+               }
+
+               /**
+                * Validates the number of images per page.
+                *
+                * @param imagesPerPage
+                *            The number of images per page
+                * @return {@code true} if the number of images per page was valid,
+                *         {@code false} otherwise
+                */
+               public boolean validateImagesPerPage(Integer imagesPerPage) {
+                       return options.getIntegerOption("ImagesPerPage").validate(imagesPerPage);
+               }
+
+               /**
+                * Sets the number of images per page.
+                *
+                * @param imagesPerPage
+                *            The number of images per page
+                * @return This preferences object
+                */
+               public Preferences setImagesPerPage(Integer imagesPerPage) {
+                       options.getIntegerOption("ImagesPerPage").set(imagesPerPage);
+                       return this;
+               }
+
+               /**
                 * Returns the number of characters per post, or <code>-1</code> if the
                 * posts should not be cut off.
                 *
index fbc8cf9..ab962d8 100644 (file)
@@ -90,6 +90,12 @@ public class OptionsPage extends SoneTemplatePage {
                        } else {
                                preferences.setPostsPerPage(postsPerPage);
                        }
+                       Integer imagesPerPage = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("images-per-page", 4), null);
+                       if (!preferences.validateImagesPerPage(imagesPerPage)) {
+                               fieldErrors.add("images-per-page");
+                       } else {
+                               preferences.setImagesPerPage(imagesPerPage);
+                       }
                        Integer charactersPerPost = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("characters-per-post", 10), null);
                        if (!preferences.validateCharactersPerPost(charactersPerPost)) {
                                fieldErrors.add("characters-per-post");
@@ -146,6 +152,7 @@ public class OptionsPage extends SoneTemplatePage {
                }
                templateContext.set("insertion-delay", preferences.getInsertionDelay());
                templateContext.set("posts-per-page", preferences.getPostsPerPage());
+               templateContext.set("images-per-page", preferences.getImagesPerPage());
                templateContext.set("characters-per-post", preferences.getCharactersPerPost());
                templateContext.set("post-cut-off-length", preferences.getPostCutOffLength());
                templateContext.set("require-full-access", preferences.isRequireFullAccess());
index 3fe965e..8a85604 100644 (file)
@@ -55,6 +55,7 @@ Page.Options.Option.ShowAvatars.Always.Description=Always show custom avatars. B
 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.Option.ImagesPerPage.Description=The number of images to display on a page before pagination controls are being shown.
 Page.Options.Option.CharactersPerPost.Description=The number of characters to display from a post before cutting it off and showing a link to expand it (-1 to disable). The actual length of the snippet is determined by the option below.
 Page.Options.Option.PostCutOffLength.Description=The number of characters that are displayed if a post is deemed to long (see option above).
 Page.Options.Option.RequireFullAccess.Description=Whether to deny access to Sone to any host that has not been granted full access.
@@ -408,6 +409,7 @@ WebInterface.DefaultText.UploadImage.Description=Image description
 WebInterface.DefaultText.EditImage.Title=Image title
 WebInterface.DefaultText.EditImage.Description=Image description
 WebInterface.DefaultText.Option.PostsPerPage=Number of posts to show on a page
+WebInterface.DefaultText.Option.ImagesPerPage=Number of images to show on a page
 WebInterface.DefaultText.Option.CharactersPerPost=Number of characters a post must have to be shortened
 WebInterface.DefaultText.Option.PostCutOffLength=Number of characters for the snippet of the shortened post
 WebInterface.DefaultText.Option.PositiveTrust=The positive trust to assign
index 94e01dc..3b954c4 100644 (file)
@@ -8,6 +8,9 @@
                        getTranslation("WebInterface.DefaultText.Option.PostsPerPage", function(postsPerPageText) {
                                registerInputTextareaSwap("#sone #options input[name=posts-per-page]", postsPerPageText, "posts-per-page", true, true);
                        });
+                       getTranslation("WebInterface.DefaultText.Option.ImagesPerPage", function(imagesPerPageText) {
+                               registerInputTextareaSwap("#sone #options input[name=images-per-page]", imagesPerPageText, "images-per-page", true, true);
+                       });
                        getTranslation("WebInterface.DefaultText.Option.CharactersPerPost", function(postsPerPageText) {
                                registerInputTextareaSwap("#sone #options input[name=characters-per-post]", postsPerPageText, "characters-per-post", true, true);
                        });
                <%/if>
                <p><input type="text" name="posts-per-page" value="<% posts-per-page|html>" /></p>
 
+               <p><%= Page.Options.Option.ImagesPerPage.Description|l10n|html></p>
+               <%if =images-per-page|in collection=fieldErrors>
+                       <p class="warning"><%= Page.Options.Warnings.ValueNotChanged|l10n|html></p>
+               <%/if>
+               <p><input type="text" name="images-per-page" value="<% images-per-page|html>" /></p>
+
                <p><%= Page.Options.Option.CharactersPerPost.Description|l10n|html></p>
                <%if =characters-per-post|in collection=fieldErrors>
                        <p class="warning"><%= Page.Options.Warnings.ValueNotChanged|l10n|html></p>