From f3963f0b12055ba6710b9b28ddc93a5b5fe91d67 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 22 Sep 2017 16:39:00 +0300 Subject: Initial getNotifications query * using Java 8 DateTime API where possible --- .../pebble/extension/FormatterExtension.java | 6 ++---- .../pebble/extension/filters/PrettyTimeFilter.java | 5 +++-- .../pebble/extension/filters/TimestampFilter.java | 23 ++++++++++++++++++++++ .../src/main/webapp/WEB-INF/views/macros/tree.html | 6 +++--- .../main/webapp/WEB-INF/views/partial/message.html | 6 +++--- .../webapp/WEB-INF/views/partial/thread_list.html | 6 +++--- .../src/main/webapp/WEB-INF/views/pm_inbox.html | 2 +- .../src/main/webapp/WEB-INF/views/pm_sent.html | 2 +- .../src/main/webapp/WEB-INF/views/thread.html | 6 +++--- 9 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java (limited to 'juick-www/src/main') diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java index 7702a316..c8244df4 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java @@ -17,10 +17,7 @@ package com.mitchellbosecke.pebble.extension; -import com.mitchellbosecke.pebble.extension.filters.FormatMessageFilter; -import com.mitchellbosecke.pebble.extension.filters.FormatRepliesFilter; -import com.mitchellbosecke.pebble.extension.filters.PrettyTimeFilter; -import com.mitchellbosecke.pebble.extension.filters.TagsListFilter; +import com.mitchellbosecke.pebble.extension.filters.*; import java.util.HashMap; import java.util.Map; @@ -35,6 +32,7 @@ public class FormatterExtension extends AbstractExtension { filters.put("formatMessage", new FormatMessageFilter()); filters.put("formatReplies", new FormatRepliesFilter()); filters.put("prettyTime", new PrettyTimeFilter()); + filters.put("timestamp", new TimestampFilter()); filters.put("tagsList", new TagsListFilter()); return filters; } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java index 08e657c8..1d58ce79 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java @@ -21,6 +21,7 @@ import com.juick.util.PrettyTimeFormatter; import com.mitchellbosecke.pebble.extension.Filter; import com.mitchellbosecke.pebble.template.EvaluationContext; +import java.time.Instant; import java.util.Date; import java.util.List; import java.util.Locale; @@ -35,10 +36,10 @@ public class PrettyTimeFilter implements Filter { @Override public Object apply(Object input, Map args) { - if (input instanceof Date) { + if (input instanceof Instant) { EvaluationContext context = (EvaluationContext) args.get("_context"); Locale locale = context.getLocale(); - return formatter.format(locale, (Date)input); + return formatter.format(locale, Date.from((Instant)input)); } throw new IllegalArgumentException("invalid input"); } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java new file mode 100644 index 00000000..35efb314 --- /dev/null +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java @@ -0,0 +1,23 @@ +package com.mitchellbosecke.pebble.extension.filters; + +import com.mitchellbosecke.pebble.extension.Filter; + +import java.time.Instant; +import java.util.Date; +import java.util.List; +import java.util.Map; + +public class TimestampFilter implements Filter { + @Override + public Object apply(Object input, Map args) { + if (input instanceof Instant) { + return Date.from((Instant)input); + } + throw new IllegalArgumentException("invalid input"); + } + + @Override + public List getArgumentNames() { + return null; + } +} diff --git a/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html b/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html index 09ba5365..f0c283e9 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html +++ b/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html @@ -20,9 +20,9 @@ diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/message.html b/juick-www/src/main/webapp/WEB-INF/views/partial/message.html index b3ff86cd..f3a42ff2 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/partial/message.html +++ b/juick-www/src/main/webapp/WEB-INF/views/partial/message.html @@ -7,9 +7,9 @@
diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html b/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html index 275ffeaf..918c4fb0 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html +++ b/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html @@ -18,9 +18,9 @@ diff --git a/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html b/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html index a8a8a1e9..156877c0 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html +++ b/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html @@ -12,7 +12,7 @@ {{ msg.user.name }} -
{{ msg.date }}
+
{{ msg.timestamp | prettyTime }}
{{ msg | formatMessage }}
diff --git a/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html b/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html index 48aaa7e1..08b9585a 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html +++ b/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html @@ -19,7 +19,7 @@ {{ msg.user.name }} -
{{ msg.date }}
+
{{ msg.timestamp | prettyTime }}
{{ msg | formatMessage }}
diff --git a/juick-www/src/main/webapp/WEB-INF/views/thread.html b/juick-www/src/main/webapp/WEB-INF/views/thread.html index 5f1cb148..57d7e0a1 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/thread.html +++ b/juick-www/src/main/webapp/WEB-INF/views/thread.html @@ -6,9 +6,9 @@