Add “new version” notification, set current and latest version in all templates.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 9 Jan 2011 20:50:51 +0000 (21:50 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 9 Jan 2011 20:50:51 +0000 (21:50 +0100)
pom.xml
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/notify/newVersionNotification.html [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index e1fe047..e9ff09c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
                <dependency>
                        <groupId>net.pterodactylus</groupId>
                        <artifactId>utils</artifactId>
-                       <version>0.7.6</version>
+                       <version>0.7.7</version>
                </dependency>
                <dependency>
                        <groupId>junit</groupId>
index 23ca247..3d4cb80 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.main.SonePlugin;
 import net.pterodactylus.sone.web.page.Page;
 import net.pterodactylus.sone.web.page.TemplatePage;
 import net.pterodactylus.util.template.Template;
@@ -188,6 +189,10 @@ public class SoneTemplatePage extends TemplatePage {
                super.processTemplate(request, template);
                template.set("currentSone", getCurrentSone(request.getToadletContext(), false));
                template.set("request", request);
+               template.set("currentVersion", SonePlugin.VERSION);
+               template.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
+               template.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
+               template.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
        }
 
        /**
index c11a3cc..6085ff8 100644 (file)
@@ -142,6 +142,9 @@ public class WebInterface implements CoreListener {
        /** The “Sone locked” notification. */
        private final ListNotification<Sone> lockedSonesNotification;
 
+       /** The “new version” notification. */
+       private final TemplateNotification newVersionNotification;
+
        /**
         * Creates a new web interface.
         *
@@ -190,6 +193,9 @@ public class WebInterface implements CoreListener {
 
                Template lockedSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/lockedSonesNotification.html"));
                lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
+
+               Template newVersionTemplate = templateFactory.createTemplate(createReader("/templates/notify/newVersionNotification.html"));
+               newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
        }
 
        //
@@ -706,6 +712,9 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void updateFound(Version version, long releaseTime) {
+               newVersionNotification.set("version", version);
+               newVersionNotification.set("releaseTime", releaseTime);
+               notificationManager.addNotification(newVersionNotification);
        }
 
        /**
index 533a01b..1dbfabc 100644 (file)
@@ -191,3 +191,4 @@ Notification.SoneIsBeingRescued.Text=The following Sones are currently being res
 Notification.SoneRescued.Text=The following Sones have been rescued:
 Notification.SoneRescued.Text.RememberToUnlock=Please remember to control the posts and replies you have given and don’t forget to unlock your Sones!
 Notification.LockedSones.Text=The following Sones have been locked for more than 5 minutes. Please check if you really want to keep these Sones locked:
+Notification.NewVersion.Text=A new version of the Sone plugin was found: Version {version}.
diff --git a/src/main/resources/templates/notify/newVersionNotification.html b/src/main/resources/templates/notify/newVersionNotification.html
new file mode 100644 (file)
index 0000000..23a5855
--- /dev/null
@@ -0,0 +1 @@
+<div class="text"><%= Notification.NewVersion.Text|l10n|html|replace needle="{version}" replacementKey=version></div>