From 6af1580390a2e33edbe650072f8624d7e29de63e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 20 Jun 2011 10:54:40 +0200 Subject: [PATCH] Order by name as default, store sort options in template differently. --- .../net/pterodactylus/sone/web/KnownSonesPage.java | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java index 0e42eb5..0eedec6 100644 --- a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java +++ b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java @@ -62,6 +62,9 @@ public class KnownSonesPage extends SoneTemplatePage { String sortField = request.getHttpRequest().getParam("sort"); String sortOrder = request.getHttpRequest().getParam("order"); String followedSones = request.getHttpRequest().getParam("followedSones"); + templateContext.set("sort", (sortField != null) ? sortField : "name"); + templateContext.set("order", (sortOrder != null) ? sortOrder : "asc"); + templateContext.set("followedSones", followedSones); final Sone currentSone = getCurrentSone(request.getToadletContext(), false); List knownSones = Filters.filteredList(new ArrayList(webInterface.getCore().getSones()), Sone.EMPTY_SONE_FILTER); if ((currentSone != null) && "show-only".equals(followedSones)) { @@ -72,7 +75,6 @@ public class KnownSonesPage extends SoneTemplatePage { return currentSone.hasFriend(sone.getId()); } }); - templateContext.set("followedSones", "show-only"); } else if ((currentSone != null) && "hide".equals(followedSones)) { knownSones = Filters.filteredList(knownSones, new Filter() { @@ -81,24 +83,19 @@ public class KnownSonesPage extends SoneTemplatePage { 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 ("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"); + } else { + if ("desc".equals(sortOrder)) { + Collections.sort(knownSones, new ReverseComparator(Sone.NICE_NAME_COMPARATOR)); + } else { + Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR); + } } Pagination sonePagination = new Pagination(knownSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", sonePagination); -- 2.7.4