From 17a6c6da2144a479169b90e055a1283d91a3e9ce Mon Sep 17 00:00:00 2001 From: Paul Martin Date: Thu, 28 Apr 2016 00:53:42 +0100 Subject: [PATCH] Fixes #1061 - Most recent first on filestore page --- .../com/gitblit/models/FilestoreModel.java | 7 ++- .../gitblit/wicket/pages/FilestorePage.java | 44 ++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gitblit/models/FilestoreModel.java b/src/main/java/com/gitblit/models/FilestoreModel.java index 2ed1ede9..40b51e0b 100644 --- a/src/main/java/com/gitblit/models/FilestoreModel.java +++ b/src/main/java/com/gitblit/models/FilestoreModel.java @@ -31,7 +31,7 @@ import com.gitblit.Constants; * @author Paul Martin * */ -public class FilestoreModel implements Serializable { +public class FilestoreModel implements Serializable, Comparable { private static final long serialVersionUID = 1L; @@ -217,5 +217,10 @@ public class FilestoreModel implements Serializable { } } + @Override + public int compareTo(FilestoreModel o) { + return this.oid.compareTo(o.oid); + } + } diff --git a/src/main/java/com/gitblit/wicket/pages/FilestorePage.java b/src/main/java/com/gitblit/wicket/pages/FilestorePage.java index 7130f6c2..29b3d60d 100644 --- a/src/main/java/com/gitblit/wicket/pages/FilestorePage.java +++ b/src/main/java/com/gitblit/wicket/pages/FilestorePage.java @@ -18,15 +18,20 @@ package com.gitblit.wicket.pages; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.wicket.PageParameters; +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.markup.repeater.data.DataView; -import org.apache.wicket.markup.repeater.data.ListDataProvider; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; import com.gitblit.Constants; import com.gitblit.Keys; @@ -153,7 +158,7 @@ public class FilestorePage extends RootPage { } DataView filesView = new DataView("fileRow", - new ListDataProvider(filteredResults) , itemsPerPage) { + new SortableFilestoreProvider(filteredResults) , itemsPerPage) { private static final long serialVersionUID = 1L; private int counter; @@ -238,4 +243,39 @@ public class FilestorePage extends RootPage { ok, pending, inprogress, error, deleted; } + private static class SortableFilestoreProvider extends SortableDataProvider { + + private static final long serialVersionUID = 1L; + + private List list; + + protected SortableFilestoreProvider(List list) { + this.list = list; + } + + @Override + public int size() { + if (list == null) { + return 0; + } + return list.size(); + } + + @Override + public IModel model(FilestoreModel header) { + return new Model(header); + } + + @Override + public Iterator iterator(int first, int count) { + Collections.sort(list, new Comparator() { + @Override + public int compare(FilestoreModel o1, FilestoreModel o2) { + return o2.getChangedOn().compareTo(o1.getChangedOn()); + } + }); + return list.subList(first, first + count).iterator(); + } + } + } \ No newline at end of file -- 2.39.5