From: Paul Martin Date: Wed, 27 Apr 2016 23:53:42 +0000 (+0100) Subject: Fixes #1061 - Most recent first on filestore page X-Git-Tag: v1.8.0~7^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1070%2Fhead;p=gitblit.git Fixes #1061 - Most recent first on filestore page --- 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