From: David ‘Bombe’ Roden Date: Mon, 20 Jun 2011 05:53:02 +0000 (+0200) Subject: Add filter and sort options to “known Sones” page. X-Git-Tag: 0.6.6^2~70^2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9a254c2af6f176c8a95ef6accfdb288ad159d125;hp=-c;p=Sone.git Add filter and sort options to “known Sones” page. --- 9a254c2af6f176c8a95ef6accfdb288ad159d125 diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java index 7c8f9ad..0e42eb5 100644 --- a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java +++ b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java @@ -23,6 +23,8 @@ import java.util.List; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.collection.Pagination; +import net.pterodactylus.util.collection.ReverseComparator; +import net.pterodactylus.util.filter.Filter; import net.pterodactylus.util.filter.Filters; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; @@ -57,11 +59,49 @@ public class KnownSonesPage extends SoneTemplatePage { @Override protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); + String sortField = request.getHttpRequest().getParam("sort"); + String sortOrder = request.getHttpRequest().getParam("order"); + String followedSones = request.getHttpRequest().getParam("followedSones"); + final Sone currentSone = getCurrentSone(request.getToadletContext(), false); List knownSones = Filters.filteredList(new ArrayList(webInterface.getCore().getSones()), Sone.EMPTY_SONE_FILTER); - Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR); + if ((currentSone != null) && "show-only".equals(followedSones)) { + knownSones = Filters.filteredList(knownSones, new Filter() { + + @Override + public boolean filterObject(Sone sone) { + return currentSone.hasFriend(sone.getId()); + } + }); + templateContext.set("followedSones", "show-only"); + } else if ((currentSone != null) && "hide".equals(followedSones)) { + knownSones = Filters.filteredList(knownSones, new Filter() { + + @Override + public boolean filterObject(Sone sone) { + return !currentSone.hasFriend(sone.getId()); + } + }); + templateContext.set("followedSones", "hide"); + } + if ("name".equals(sortField)) { + if ("desc".equals(sortOrder)) { + Collections.sort(knownSones, new ReverseComparator(Sone.NICE_NAME_COMPARATOR)); + } else { + Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR); + } + templateContext.set("sort", "name"); + templateContext.set("order", "desc".equals(sortOrder) ? "desc" : "asc"); + } else if ("activity".equals(sortField)) { + if ("asc".equals(sortOrder)) { + Collections.sort(knownSones, new ReverseComparator(Sone.LAST_ACTIVITY_COMPARATOR)); + } else { + Collections.sort(knownSones, Sone.LAST_ACTIVITY_COMPARATOR); + } + templateContext.set("sort", "activity"); + templateContext.set("order", "asc".equals(sortOrder) ? "asc" : "desc"); + } Pagination sonePagination = new Pagination(knownSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", sonePagination); templateContext.set("knownSones", sonePagination.getItems()); } - } diff --git a/src/main/resources/static/css/sone.css b/src/main/resources/static/css/sone.css index 1dda47e..d38cea7 100644 --- a/src/main/resources/static/css/sone.css +++ b/src/main/resources/static/css/sone.css @@ -680,3 +680,7 @@ textarea { color: red; font-style: italic; } + +#sone #sort-options { + margin-bottom: 1em; +} diff --git a/src/main/resources/templates/knownSones.html b/src/main/resources/templates/knownSones.html index 33f0e27..fde1060 100644 --- a/src/main/resources/templates/knownSones.html +++ b/src/main/resources/templates/knownSones.html @@ -1,8 +1,52 @@ <%include include/head.html> + +

<%= Page.KnownSones.Page.Title|l10n|html>

+ +
+
+
+ Sort: + + +
+ <%ifnull !currentSone> +
+ Followed Sones: + +
+ <%/if> +
+ +
+
+
<%= page|store key=pageParameter>