summaryrefslogtreecommitdiffstats
path: root/src/main/java/com
diff options
context:
space:
mode:
authorPaul Martin <paul@paulsputer.com>2016-04-28 20:43:17 +0100
committerPaul Martin <paul@paulsputer.com>2016-04-28 20:43:17 +0100
commitb753682ec04c89c8ebb5b451d7d82661ffa31391 (patch)
tree31ee06e50cc90f440f8b7981e4007a1355fe6fb6 /src/main/java/com
parentb32fa68832412374a1a905525a4e395d35b4d1ae (diff)
parent17a6c6da2144a479169b90e055a1283d91a3e9ce (diff)
downloadgitblit-b753682ec04c89c8ebb5b451d7d82661ffa31391.tar.gz
gitblit-b753682ec04c89c8ebb5b451d7d82661ffa31391.zip
Merge pull request #1070 from gitblit/1061-filestoreSortByDate
Fixes #1061 - Most recent first on filestore page
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/gitblit/models/FilestoreModel.java7
-rw-r--r--src/main/java/com/gitblit/wicket/pages/FilestorePage.java44
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<FilestoreModel> {
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<FilestoreModel> filesView = new DataView<FilestoreModel>("fileRow",
- new ListDataProvider<FilestoreModel>(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<FilestoreModel> {
+
+ private static final long serialVersionUID = 1L;
+
+ private List<FilestoreModel> list;
+
+ protected SortableFilestoreProvider(List<FilestoreModel> list) {
+ this.list = list;
+ }
+
+ @Override
+ public int size() {
+ if (list == null) {
+ return 0;
+ }
+ return list.size();
+ }
+
+ @Override
+ public IModel<FilestoreModel> model(FilestoreModel header) {
+ return new Model<FilestoreModel>(header);
+ }
+
+ @Override
+ public Iterator<FilestoreModel> iterator(int first, int count) {
+ Collections.sort(list, new Comparator<FilestoreModel>() {
+ @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