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