]> source.dussan.org Git - gitblit.git/commitdiff
Fixes #1028 - FilestorePage now pages and filters 1046/head
authorPaul Martin <paul@paulsputer.com>
Thu, 7 Apr 2016 23:01:14 +0000 (00:01 +0100)
committerPaul Martin <paul@paulsputer.com>
Thu, 7 Apr 2016 23:01:14 +0000 (00:01 +0100)
src/main/java/com/gitblit/wicket/WicketUtils.java
src/main/java/com/gitblit/wicket/pages/FilestorePage.html
src/main/java/com/gitblit/wicket/pages/FilestorePage.java
src/main/resources/gitblit.css

index d9ff34a28212733935278c975651dbc43188be08..99c1e08f0a12108579d884baf557427b29fb852f 100644 (file)
@@ -417,6 +417,19 @@ public class WicketUtils {
                return new PageParameters(parameterMap);\r
        }\r
 \r
+       public static PageParameters newFilestorePageParameter(int pageNumber, String filter) {\r
+               Map<String, String> parameterMap = new HashMap<String, String>();\r
+               \r
+               if (pageNumber > 1) {\r
+                       parameterMap.put("pg", String.valueOf(pageNumber));\r
+               }\r
+               if (filter != null) {\r
+                       parameterMap.put("s", String.valueOf(filter));\r
+               }\r
+               \r
+               return new PageParameters(parameterMap);\r
+       }\r
+\r
        public static PageParameters newBlobDiffParameter(String repositoryName,\r
                        String baseCommitId, String commitId, String path) {\r
                Map<String, String> parameterMap = new HashMap<String, String>();\r
index e373e704a216ad96012a93657e8517e5144dbcd4..8b917e8a7fe235ba8c8c8592eb94e8d0f0084446 100644 (file)
@@ -8,8 +8,18 @@
 <wicket:extend>
 <div class="container">
        
-       <div class="markdown" style="padding: 10px 0px 5px 0px;">
-               <span wicket:id="repositoriesMessage">[repositories message]</span>
+       <div style="padding: 10px 0px 5px 0px;">
+               <table class="filestore-status">
+                       <tr>
+                               <td><a wicket:id="filterByOk" href="#"><span wicket:id="statusOkIcon"></span><span wicket:id="statusOkCount"></span></a></td>
+                               <td><a wicket:id="filterByPending" href="#"><span wicket:id="statusPendingIcon"></span><span wicket:id="statusPendingCount"></span></a></td>
+                               <td><a wicket:id="filterByInprogress" href="#"><span wicket:id="statusInprogressIcon"></span><span wicket:id="statusInprogressCount"></span></a></td>
+                               <td><a wicket:id="filterByError" href="#"><span wicket:id="statusErrorIcon"></span><span wicket:id="statusErrorCount"></span></a></td>
+                               <td><a wicket:id="filterByDeleted" href="#"><span wicket:id="statusDeletedIcon"></span><span wicket:id="statusDeletedCount"></span></a></td>
+                               <td></td>
+                               <td><span class="fa fa-fw fa-database"></span><span wicket:id="spaceAvailable"></span></td>
+                       </tr>
+               </table>
                <span style="float:right"><a href="#" wicket:id="filestoreHelp"><span wicket:id="helpMessage">[help message]</span></a></span>
        </div>
        
                        </tr>
        </tbody>
        </table>
+       
+       <!-- pager links -->
+       <div style="padding-bottom:5px;">
+               <a wicket:id="firstPageBottom"><wicket:message key="gb.pageFirst"></wicket:message></a> | <a wicket:id="prevPageBottom">&laquo; <wicket:message key="gb.pagePrevious"></wicket:message></a> | <a wicket:id="nextPageBottom"><wicket:message key="gb.pageNext"></wicket:message> &raquo;</a> 
+       </div>
 </div>
+
+       
 </wicket:extend>
 </body>
 </html>
\ No newline at end of file
index 7c3bb9d31aa615f9e5331ec1184aad49acca79b4..7130f6c228688ea6d5685fa120c1c306a5c6bb76 100644 (file)
 package com.gitblit.wicket.pages;
 
 import java.text.DateFormat;
-import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.wicket.Component;
+import org.apache.wicket.PageParameters;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
 import org.apache.wicket.markup.repeater.Item;
@@ -30,7 +29,9 @@ import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.markup.repeater.data.ListDataProvider;
 
 import com.gitblit.Constants;
+import com.gitblit.Keys;
 import com.gitblit.models.FilestoreModel;
+import com.gitblit.models.FilestoreModel.Status;
 import com.gitblit.models.UserModel;
 import com.gitblit.wicket.CacheControl;
 import com.gitblit.wicket.FilestoreUI;
@@ -47,10 +48,22 @@ import com.gitblit.wicket.CacheControl.LastModified;
 @CacheControl(LastModified.ACTIVITY)
 public class FilestorePage extends RootPage {
 
-       public FilestorePage() {
-               super();
+       public FilestorePage(PageParameters params) {
+               super(params);
                setupPage("", "");
 
+               int itemsPerPage = app().settings().getInteger(Keys.web.itemsPerPage, 20);
+               if (itemsPerPage <= 1) {
+                       itemsPerPage = 20;
+               }
+               
+               final int pageNumber = WicketUtils.getPage(params);
+               final String filter = WicketUtils.getSearchString(params);
+               
+               int prevPage = Math.max(0, pageNumber - 1);
+               int nextPage = pageNumber + 1;
+               boolean hasMore = false;
+               
                final UserModel user = (GitBlitWebSession.get().getUser() == null) ? UserModel.ANONYMOUS : GitBlitWebSession.get().getUser();
                final long nBytesUsed = app().filestore().getFilestoreUsedByteCount();
                final long nBytesAvailable = app().filestore().getFilestoreAvailableByteCount();
@@ -59,21 +72,88 @@ public class FilestorePage extends RootPage {
                if (files == null) {
                        files = new ArrayList<FilestoreModel>();
                }
-               
-               String message = MessageFormat.format(getString("gb.filestoreStats"), files.size(),
-                               FileUtils.byteCountToDisplaySize(nBytesUsed), FileUtils.byteCountToDisplaySize(nBytesAvailable) );
-
-               Component repositoriesMessage = new Label("repositoriesMessage", message)
-                               .setEscapeModelStrings(false).setVisible(message.length() > 0);
 
-               add(repositoriesMessage);
-
-               BookmarkablePageLink<Void> helpLink = new BookmarkablePageLink<Void>("filestoreHelp", FilestoreUsage.class);
-               helpLink.add(new Label("helpMessage", getString("gb.filestoreHelp")));
-               add(helpLink);
+               long nOk = 0;
+               long nPending = 0;
+               long nInprogress = 0;
+               long nError = 0;
+               long nDeleted = 0;
+               
+               for (FilestoreModel file : files) {
+                       switch (file.getStatus()) {
+                       case Available: { nOk++;} break;
+                       case Upload_Pending: { nPending++; } break;
+                       case Upload_In_Progress: { nInprogress++; } break;
+                       case Deleted: { nDeleted++; } break;
+                       default: { nError++; } break;
+                       }
+               }
+               
+               
+               BookmarkablePageLink<Void> itemOk = new BookmarkablePageLink<Void>("filterByOk", FilestorePage.class,
+                               WicketUtils.newFilestorePageParameter(prevPage, SortBy.ok.name()));
+               
+               BookmarkablePageLink<Void> itemPending = new BookmarkablePageLink<Void>("filterByPending", FilestorePage.class,
+                               WicketUtils.newFilestorePageParameter(prevPage, SortBy.pending.name()));
+               
+               BookmarkablePageLink<Void> itemInprogress = new BookmarkablePageLink<Void>("filterByInprogress", FilestorePage.class,
+                               WicketUtils.newFilestorePageParameter(prevPage, SortBy.inprogress.name()));
+               
+               BookmarkablePageLink<Void> itemError = new BookmarkablePageLink<Void>("filterByError", FilestorePage.class,
+                               WicketUtils.newFilestorePageParameter(prevPage, SortBy.error.name()));
 
-               DataView<FilestoreModel> filesView = new DataView<FilestoreModel>("fileRow",
-                               new ListDataProvider<FilestoreModel>(files)) {
+               BookmarkablePageLink<Void> itemDeleted = new BookmarkablePageLink<Void>("filterByDeleted", FilestorePage.class,
+                               WicketUtils.newFilestorePageParameter(prevPage, SortBy.deleted.name()));
+               
+               
+               List<FilestoreModel> filteredResults = new ArrayList<FilestoreModel>(files.size());
+               
+               if (filter == null) {
+                       filteredResults = files;
+               } else if (filter.equals(SortBy.ok.name())) {
+                       WicketUtils.setCssClass(itemOk, "filter-on");
+                       
+                       for (FilestoreModel item : files) {
+                               if (item.getStatus() == Status.Available) {
+                                       filteredResults.add(item);
+                               }
+                       }
+               } else if (filter.equals(SortBy.pending.name())) {
+                       WicketUtils.setCssClass(itemPending, "filter-on");
+                       
+                       for (FilestoreModel item : files) {
+                               if (item.getStatus() == Status.Upload_Pending) {
+                                       filteredResults.add(item);
+                               }
+                       }
+               } else if (filter.equals(SortBy.inprogress.name())) {
+                       WicketUtils.setCssClass(itemInprogress, "filter-on");
+                       
+                       for (FilestoreModel item : files) {
+                               if (item.getStatus() == Status.Upload_In_Progress) {
+                                       filteredResults.add(item);
+                               }
+                       }
+               } else if (filter.equals(SortBy.error.name())) {
+                       WicketUtils.setCssClass(itemError, "filter-on");
+                       
+                       for (FilestoreModel item : files) {
+                               if (item.isInErrorState()) {
+                                       filteredResults.add(item);
+                               }
+                       }
+               } else if (filter.equals(SortBy.deleted.name())) {
+                       WicketUtils.setCssClass(itemDeleted, "filter-on");
+                       
+                       for (FilestoreModel item : files) {
+                               if (item.getStatus() == Status.Deleted) {
+                                       filteredResults.add(item);
+                               }
+                       }
+               }
+               
+               DataView<FilestoreModel> filesView = new DataView<FilestoreModel>("fileRow", 
+                               new ListDataProvider<FilestoreModel>(filteredResults) , itemsPerPage) {
                        private static final long serialVersionUID = 1L;
                        private int counter;
 
@@ -106,6 +186,56 @@ public class FilestorePage extends RootPage {
 
                };
 
+
+               if (filteredResults.size() < itemsPerPage) {
+                       filesView.setCurrentPage(0);
+                       hasMore = false;
+               } else {
+                       filesView.setCurrentPage(pageNumber - 1);
+                       hasMore = true;
+               }
+
+               
                add(filesView);
+               
+               
+               add(new BookmarkablePageLink<Void>("firstPageBottom", FilestorePage.class).setEnabled(pageNumber > 1));
+               add(new BookmarkablePageLink<Void>("prevPageBottom", FilestorePage.class,
+                               WicketUtils.newFilestorePageParameter(prevPage, filter)).setEnabled(pageNumber > 1));
+               add(new BookmarkablePageLink<Void>("nextPageBottom", FilestorePage.class,
+                               WicketUtils.newFilestorePageParameter(nextPage, filter)).setEnabled(hasMore));
+               
+
+               itemOk.add(FilestoreUI.getStatusIcon("statusOkIcon", FilestoreModel.Status.Available));
+               itemPending.add(FilestoreUI.getStatusIcon("statusPendingIcon", FilestoreModel.Status.Upload_Pending));
+               itemInprogress.add(FilestoreUI.getStatusIcon("statusInprogressIcon", FilestoreModel.Status.Upload_In_Progress));
+               itemError.add(FilestoreUI.getStatusIcon("statusErrorIcon", FilestoreModel.Status.Error_Unknown));
+               itemDeleted.add(FilestoreUI.getStatusIcon("statusDeletedIcon", FilestoreModel.Status.Deleted));
+               
+               itemOk.add(new Label("statusOkCount", String.valueOf(nOk)));
+               itemPending.add(new Label("statusPendingCount", String.valueOf(nPending)));
+               itemInprogress.add(new Label("statusInprogressCount", String.valueOf(nInprogress)));
+               itemError.add(new Label("statusErrorCount", String.valueOf(nError)));
+               itemDeleted.add(new Label("statusDeletedCount", String.valueOf(nDeleted)));
+               
+               add(itemOk);
+               add(itemPending);
+               add(itemInprogress);
+               add(itemError);
+               add(itemDeleted);
+               
+               add(new Label("spaceAvailable", String.format("%s / %s",
+                               FileUtils.byteCountToDisplaySize(nBytesUsed),
+                               FileUtils.byteCountToDisplaySize(nBytesAvailable))));
+               
+               BookmarkablePageLink<Void> helpLink = new BookmarkablePageLink<Void>("filestoreHelp", FilestoreUsage.class);
+               helpLink.add(new Label("helpMessage", getString("gb.filestoreHelp")));
+               add(helpLink);
+
+       }
+               
+       protected enum SortBy {
+               ok, pending, inprogress, error, deleted;
        }
-}
+       
+}
\ No newline at end of file
index 1cae6d5fd15bc715d8fd4a6d53a1a04dbf4e792a..3318441a561e3efcbc3e6447f4924c59bbb08019 100644 (file)
@@ -2361,6 +2361,33 @@ div.markdown table.text th, div.markdown table.text td {
        color:#815b3a;\r
 }\r
 \r
+.filestore-status {\r
+       display: inline;\r
+       font-size: 1.2em;\r
+}\r
+\r
+table.filestore-status {\r
+       border:none!important;\r
+       border-spacing: 10px 0px;\r
+    border-collapse: separate;\r
+}\r
+\r
+.filestore-status tr td a {\r
+       border:none!important;\r
+       margin-right:1.5em!important;\r
+       padding:0.25em;\r
+}\r
+\r
+.filestore-status td a:hover, .filestore-status td a.filter-on {\r
+       background-color: #eee;\r
+       border-radius:5px;\r
+}\r
+\r
+.filestore-status span:nth-child(2) {\r
+       font-weight:800;\r
+       margin-left:0.25em;\r
+}\r
+\r
 .delete-patchset {\r
        color:#D51900;\r
        font-size: 1.2em;\r