You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FilestorePage.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2015 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.pages;
  17. import java.text.DateFormat;
  18. import java.text.MessageFormat;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import org.apache.commons.io.FileUtils;
  23. import org.apache.wicket.Component;
  24. import org.apache.wicket.markup.html.basic.Label;
  25. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  26. import org.apache.wicket.markup.repeater.Item;
  27. import org.apache.wicket.markup.repeater.data.DataView;
  28. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  29. import com.gitblit.Constants;
  30. import com.gitblit.models.FilestoreModel;
  31. import com.gitblit.models.UserModel;
  32. import com.gitblit.wicket.CacheControl;
  33. import com.gitblit.wicket.FilestoreUI;
  34. import com.gitblit.wicket.GitBlitWebSession;
  35. import com.gitblit.wicket.RequiresAdminRole;
  36. import com.gitblit.wicket.WicketUtils;
  37. import com.gitblit.wicket.CacheControl.LastModified;
  38. /**
  39. * Page to display the current status of the filestore.
  40. * Certain errors also displayed to aid in fault finding
  41. *
  42. * @author Paul Martin
  43. */
  44. @CacheControl(LastModified.ACTIVITY)
  45. public class FilestorePage extends RootPage {
  46. public FilestorePage() {
  47. super();
  48. setupPage("", "");
  49. final UserModel user = (GitBlitWebSession.get().getUser() == null) ? UserModel.ANONYMOUS : GitBlitWebSession.get().getUser();
  50. final long nBytesUsed = app().filestore().getFilestoreUsedByteCount();
  51. final long nBytesAvailable = app().filestore().getFilestoreAvailableByteCount();
  52. List<FilestoreModel> files = app().filestore().getAllObjects(user);
  53. if (files == null) {
  54. files = new ArrayList<FilestoreModel>();
  55. }
  56. String message = MessageFormat.format(getString("gb.filestoreStats"), files.size(),
  57. FileUtils.byteCountToDisplaySize(nBytesUsed), FileUtils.byteCountToDisplaySize(nBytesAvailable) );
  58. Component repositoriesMessage = new Label("repositoriesMessage", message)
  59. .setEscapeModelStrings(false).setVisible(message.length() > 0);
  60. add(repositoriesMessage);
  61. BookmarkablePageLink<Void> helpLink = new BookmarkablePageLink<Void>("filestoreHelp", FilestoreUsage.class);
  62. helpLink.add(new Label("helpMessage", getString("gb.filestoreHelp")));
  63. add(helpLink);
  64. DataView<FilestoreModel> filesView = new DataView<FilestoreModel>("fileRow",
  65. new ListDataProvider<FilestoreModel>(files)) {
  66. private static final long serialVersionUID = 1L;
  67. private int counter;
  68. @Override
  69. protected void onBeforeRender() {
  70. super.onBeforeRender();
  71. counter = 0;
  72. }
  73. @Override
  74. public void populateItem(final Item<FilestoreModel> item) {
  75. final FilestoreModel entry = item.getModelObject();
  76. DateFormat dateFormater = new SimpleDateFormat(Constants.ISO8601);
  77. UserModel user = app().users().getUserModel(entry.getChangedBy());
  78. user = user == null ? UserModel.ANONYMOUS : user;
  79. Label icon = FilestoreUI.getStatusIcon("status", entry);
  80. item.add(icon);
  81. item.add(new Label("on", dateFormater.format(entry.getChangedOn())));
  82. item.add(new Label("by", user.getDisplayName()));
  83. item.add(new Label("oid", entry.oid));
  84. item.add(new Label("size", FileUtils.byteCountToDisplaySize(entry.getSize())));
  85. WicketUtils.setAlternatingBackground(item, counter);
  86. counter++;
  87. }
  88. };
  89. add(filesView);
  90. }
  91. }