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