From: David ‘Bombe’ Roden Date: Thu, 31 May 2012 10:05:08 +0000 (+0200) Subject: Add images-per-post option. X-Git-Tag: 0.8.2^2~8 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=f44aa96bb0b188ffcb33b6c7fbdc5a86815d04b7 Add images-per-post option. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 89867f4..4001f46 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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(10, new IntegerRangeValidator(1, Integer.MAX_VALUE))); + options.addIntegerOption("ImagesPerPage", new DefaultOption(9, new IntegerRangeValidator(1, Integer.MAX_VALUE))); options.addIntegerOption("CharactersPerPost", new DefaultOption(400, new OrValidator(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator(-1)))); options.addIntegerOption("PostCutOffLength", new DefaultOption(200, new OrValidator(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator(-1)))); options.addBooleanOption("RequireFullAccess", new DefaultOption(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 -1 if the * posts should not be cut off. * diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java index fbc8cf9..ab962d8 100644 --- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -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()); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 3fe965e..8a85604 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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 diff --git a/src/main/resources/templates/options.html b/src/main/resources/templates/options.html index 94e01dc..3b954c4 100644 --- a/src/main/resources/templates/options.html +++ b/src/main/resources/templates/options.html @@ -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); }); @@ -107,6 +110,12 @@ <%/if>

+

<%= Page.Options.Option.ImagesPerPage.Description|l10n|html>

+ <%if =images-per-page|in collection=fieldErrors> +

<%= Page.Options.Warnings.ValueNotChanged|l10n|html>

+ <%/if> +

+

<%= Page.Options.Option.CharactersPerPost.Description|l10n|html>

<%if =characters-per-post|in collection=fieldErrors>

<%= Page.Options.Warnings.ValueNotChanged|l10n|html>