James Moger
2015-11-18 6069be20b5ebb786a1b890fa9c91350ffd355b0f
commit | author | age
bd0e83 1 /*
PM 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
18 import java.text.DateFormat;
19 import java.text.MessageFormat;
20 import java.text.SimpleDateFormat;
21 import java.util.List;
22
23 import org.apache.commons.io.FileUtils;
24 import org.apache.wicket.Component;
25 import org.apache.wicket.markup.html.basic.Label;
26 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
27 import org.apache.wicket.markup.repeater.Item;
28 import org.apache.wicket.markup.repeater.data.DataView;
29 import org.apache.wicket.markup.repeater.data.ListDataProvider;
30
31 import com.gitblit.Constants;
32 import com.gitblit.models.FilestoreModel;
33 import com.gitblit.models.UserModel;
34 import com.gitblit.wicket.FilestoreUI;
6069be 35 import com.gitblit.wicket.RequiresAdminRole;
bd0e83 36 import com.gitblit.wicket.WicketUtils;
PM 37
38 /**
39  * Page to display the current status of the filestore.
6069be 40  * Certain errors also displayed to aid in fault finding
bd0e83 41  *
PM 42  * @author Paul Martin
43  */
6069be 44 @RequiresAdminRole
bd0e83 45 public class FilestorePage extends RootPage {
PM 46
47     public FilestorePage() {
48         super();
49         setupPage("", "");
6069be 50
bd0e83 51         final List<FilestoreModel> files = app().filestore().getAllObjects();
PM 52         final long nBytesUsed = app().filestore().getFilestoreUsedByteCount();
53         final long nBytesAvailable = app().filestore().getFilestoreAvailableByteCount();
6069be 54
JM 55         String message = MessageFormat.format(getString("gb.filestoreStats"), files.size(),
56                 FileUtils.byteCountToDisplaySize(nBytesUsed), FileUtils.byteCountToDisplaySize(nBytesAvailable) );
bd0e83 57
PM 58         Component repositoriesMessage = new Label("repositoriesMessage", message)
59                 .setEscapeModelStrings(false).setVisible(message.length() > 0);
6069be 60
bd0e83 61         add(repositoriesMessage);
6069be 62
bd0e83 63         BookmarkablePageLink<Void> helpLink = new BookmarkablePageLink<Void>("filestoreHelp", FilestoreUsage.class);
PM 64         helpLink.add(new Label("helpMessage", getString("gb.filestoreHelp")));
65         add(helpLink);
6069be 66
bd0e83 67
PM 68         DataView<FilestoreModel> filesView = new DataView<FilestoreModel>("fileRow",
69                 new ListDataProvider<FilestoreModel>(files)) {
70             private static final long serialVersionUID = 1L;
71             private int counter;
72
73             @Override
74             protected void onBeforeRender() {
75                 super.onBeforeRender();
76                 counter = 0;
77             }
78
79             @Override
80             public void populateItem(final Item<FilestoreModel> item) {
81                 final FilestoreModel entry = item.getModelObject();
6069be 82
bd0e83 83                 DateFormat dateFormater = new SimpleDateFormat(Constants.ISO8601);
6069be 84
bd0e83 85                 UserModel user = app().users().getUserModel(entry.getChangedBy());
PM 86                 user = user == null ? UserModel.ANONYMOUS : user;
6069be 87
bd0e83 88                 Label icon = FilestoreUI.getStatusIcon("status", entry);
PM 89                 item.add(icon);
90                 item.add(new Label("on", dateFormater.format(entry.getChangedOn())));
91                 item.add(new Label("by", user.getDisplayName()));
6069be 92
bd0e83 93                 item.add(new Label("oid", entry.oid));
6069be 94                 item.add(new Label("size", FileUtils.byteCountToDisplaySize(entry.getSize())));
JM 95
bd0e83 96                 WicketUtils.setAlternatingBackground(item, counter);
PM 97                 counter++;
98             }
99
100         };
6069be 101
bd0e83 102         add(filesView);
PM 103     }
104 }