From 91aad771ac411b317139bab1b862e9d9cfd4e59d Mon Sep 17 00:00:00 2001 From: Paul Martin Date: Fri, 8 Apr 2016 00:01:14 +0100 Subject: Fixes #1028 - FilestorePage now pages and filters --- src/main/java/com/gitblit/wicket/WicketUtils.java | 13 ++ .../com/gitblit/wicket/pages/FilestorePage.html | 21 ++- .../com/gitblit/wicket/pages/FilestorePage.java | 166 ++++++++++++++++++--- src/main/resources/gitblit.css | 27 ++++ 4 files changed, 207 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/WicketUtils.java b/src/main/java/com/gitblit/wicket/WicketUtils.java index d9ff34a2..99c1e08f 100644 --- a/src/main/java/com/gitblit/wicket/WicketUtils.java +++ b/src/main/java/com/gitblit/wicket/WicketUtils.java @@ -417,6 +417,19 @@ public class WicketUtils { return new PageParameters(parameterMap); } + public static PageParameters newFilestorePageParameter(int pageNumber, String filter) { + Map parameterMap = new HashMap(); + + if (pageNumber > 1) { + parameterMap.put("pg", String.valueOf(pageNumber)); + } + if (filter != null) { + parameterMap.put("s", String.valueOf(filter)); + } + + return new PageParameters(parameterMap); + } + public static PageParameters newBlobDiffParameter(String repositoryName, String baseCommitId, String commitId, String path) { Map parameterMap = new HashMap(); diff --git a/src/main/java/com/gitblit/wicket/pages/FilestorePage.html b/src/main/java/com/gitblit/wicket/pages/FilestorePage.html index e373e704..8b917e8a 100644 --- a/src/main/java/com/gitblit/wicket/pages/FilestorePage.html +++ b/src/main/java/com/gitblit/wicket/pages/FilestorePage.html @@ -8,8 +8,18 @@
-
- [repositories message] +
+ + + + + + + + + + +
[help message]
@@ -31,7 +41,14 @@ + + +
+ | « | » +
+ + \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/FilestorePage.java b/src/main/java/com/gitblit/wicket/pages/FilestorePage.java index 7c3bb9d3..7130f6c2 100644 --- a/src/main/java/com/gitblit/wicket/pages/FilestorePage.java +++ b/src/main/java/com/gitblit/wicket/pages/FilestorePage.java @@ -16,13 +16,12 @@ 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(); } - - 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 helpLink = new BookmarkablePageLink("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 itemOk = new BookmarkablePageLink("filterByOk", FilestorePage.class, + WicketUtils.newFilestorePageParameter(prevPage, SortBy.ok.name())); + + BookmarkablePageLink itemPending = new BookmarkablePageLink("filterByPending", FilestorePage.class, + WicketUtils.newFilestorePageParameter(prevPage, SortBy.pending.name())); + + BookmarkablePageLink itemInprogress = new BookmarkablePageLink("filterByInprogress", FilestorePage.class, + WicketUtils.newFilestorePageParameter(prevPage, SortBy.inprogress.name())); + + BookmarkablePageLink itemError = new BookmarkablePageLink("filterByError", FilestorePage.class, + WicketUtils.newFilestorePageParameter(prevPage, SortBy.error.name())); - DataView filesView = new DataView("fileRow", - new ListDataProvider(files)) { + BookmarkablePageLink itemDeleted = new BookmarkablePageLink("filterByDeleted", FilestorePage.class, + WicketUtils.newFilestorePageParameter(prevPage, SortBy.deleted.name())); + + + List filteredResults = new ArrayList(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 filesView = new DataView("fileRow", + new ListDataProvider(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("firstPageBottom", FilestorePage.class).setEnabled(pageNumber > 1)); + add(new BookmarkablePageLink("prevPageBottom", FilestorePage.class, + WicketUtils.newFilestorePageParameter(prevPage, filter)).setEnabled(pageNumber > 1)); + add(new BookmarkablePageLink("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 helpLink = new BookmarkablePageLink("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 diff --git a/src/main/resources/gitblit.css b/src/main/resources/gitblit.css index 1cae6d5f..3318441a 100644 --- a/src/main/resources/gitblit.css +++ b/src/main/resources/gitblit.css @@ -2361,6 +2361,33 @@ div.markdown table.text th, div.markdown table.text td { color:#815b3a; } +.filestore-status { + display: inline; + font-size: 1.2em; +} + +table.filestore-status { + border:none!important; + border-spacing: 10px 0px; + border-collapse: separate; +} + +.filestore-status tr td a { + border:none!important; + margin-right:1.5em!important; + padding:0.25em; +} + +.filestore-status td a:hover, .filestore-status td a.filter-on { + background-color: #eee; + border-radius:5px; +} + +.filestore-status span:nth-child(2) { + font-weight:800; + margin-left:0.25em; +} + .delete-patchset { color:#D51900; font-size: 1.2em; -- cgit v1.2.3