]> source.dussan.org Git - gitblit.git/commitdiff
Fixes #1061 - Most recent first on filestore page 1070/head
authorPaul Martin <paul@paulsputer.com>
Wed, 27 Apr 2016 23:53:42 +0000 (00:53 +0100)
committerPaul Martin <paul@paulsputer.com>
Wed, 27 Apr 2016 23:53:42 +0000 (00:53 +0100)
src/main/java/com/gitblit/models/FilestoreModel.java
src/main/java/com/gitblit/wicket/pages/FilestorePage.java

index 2ed1ede90830a18572e6bce2284884346aed8d94..40b51e0b776aa0a738981b7a9e8e8305f1e33651 100644 (file)
@@ -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);
+       }
+
 }
 
index 7130f6c228688ea6d5685fa120c1c306a5c6bb76..29b3d60db83eff248309ddaa4d61986559d14ad6 100644 (file)
@@ -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