1 | <%-- $Id$ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Nicklas Nordborg |
---|
4 | Copyright (C) 2007 Johan Enell |
---|
5 | |
---|
6 | This file is part of BASE - BioArray Software Environment. |
---|
7 | Available at http://base.thep.lu.se/ |
---|
8 | |
---|
9 | BASE is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 3 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | BASE is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | ------------------------------------------------------------------ |
---|
22 | |
---|
23 | @author Nicklas |
---|
24 | @version 2.0 |
---|
25 | --%> |
---|
26 | <%@ page pageEncoding="UTF-8" session="false" |
---|
27 | import="net.sf.basedb.core.SessionControl" |
---|
28 | import="net.sf.basedb.core.DbControl" |
---|
29 | import="net.sf.basedb.core.Application" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.Group" |
---|
32 | import="net.sf.basedb.core.Role" |
---|
33 | import="net.sf.basedb.core.Type" |
---|
34 | import="net.sf.basedb.core.ItemQuery" |
---|
35 | import="net.sf.basedb.core.Include" |
---|
36 | import="net.sf.basedb.core.ItemResultIterator" |
---|
37 | import="net.sf.basedb.core.ItemResultList" |
---|
38 | import="net.sf.basedb.core.ItemContext" |
---|
39 | import="net.sf.basedb.core.Permission" |
---|
40 | import="net.sf.basedb.core.PluginDefinition" |
---|
41 | import="net.sf.basedb.core.DiskUsage" |
---|
42 | import="net.sf.basedb.core.DiskUsageStatistics" |
---|
43 | import="net.sf.basedb.core.QuotaType" |
---|
44 | import="net.sf.basedb.core.Location" |
---|
45 | import="net.sf.basedb.core.query.Orders" |
---|
46 | import="net.sf.basedb.core.query.Hql" |
---|
47 | import="net.sf.basedb.core.query.Restrictions" |
---|
48 | import="net.sf.basedb.core.query.Expressions" |
---|
49 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
50 | import="net.sf.basedb.core.plugin.Plugin" |
---|
51 | import="net.sf.basedb.util.Enumeration" |
---|
52 | import="net.sf.basedb.clients.web.Base" |
---|
53 | import="net.sf.basedb.clients.web.ModeInfo" |
---|
54 | import="net.sf.basedb.clients.web.PermissionUtil" |
---|
55 | import="net.sf.basedb.clients.web.util.HTML" |
---|
56 | import="net.sf.basedb.util.Values" |
---|
57 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
58 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
59 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
60 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
61 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
62 | import="java.util.List" |
---|
63 | import="java.util.Map" |
---|
64 | %> |
---|
65 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
66 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
67 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
68 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
69 | <%! |
---|
70 | private static final Item itemType = Item.DISKUSAGE; |
---|
71 | private static final String subContext = "perGroup"; |
---|
72 | private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST, subContext); |
---|
73 | %> |
---|
74 | <% |
---|
75 | final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType); |
---|
76 | final String ID = sc.getId(); |
---|
77 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null); |
---|
78 | final ModeInfo mode = ModeInfo.get(request.getParameter("mode")); |
---|
79 | final boolean writePermission = sc.hasPermission(Permission.WRITE, Item.GROUP); |
---|
80 | final String showStatistics = Values.getString(cc.getSetting("showStatistics"), |
---|
81 | Application.hasSecondaryStorage() ? "full" : "quotaType"); |
---|
82 | |
---|
83 | final boolean hasLocation = "location".equals(showStatistics) || "full".equals(showStatistics); |
---|
84 | final boolean hasQuotaType = "quotaType".equals(showStatistics) || "full".equals(showStatistics); |
---|
85 | |
---|
86 | final DbControl dc = sc.newDbControl(); |
---|
87 | ItemResultIterator<Group> groups = null; |
---|
88 | try |
---|
89 | { |
---|
90 | DiskUsageStatistics du = (DiskUsageStatistics)sc.getSessionSetting("diskUsageStatistics"); |
---|
91 | if (du == null) |
---|
92 | { |
---|
93 | du = DiskUsage.getStatistics(dc); |
---|
94 | sc.setSessionSetting("diskUsageStatistics", du); |
---|
95 | } |
---|
96 | du.setDbControl(dc); |
---|
97 | List<QuotaType> quotaTypes = du.getQuotaTypes(); |
---|
98 | |
---|
99 | try |
---|
100 | { |
---|
101 | final ItemQuery<Group> query = Base.getConfiguredQuery(dc, cc, true, Group.getQuery(), mode); |
---|
102 | query.include(Include.ALL); |
---|
103 | query.restrict( |
---|
104 | Restrictions.neq( |
---|
105 | Hql.property("quota"), null)); |
---|
106 | groups = query.iterate(dc); |
---|
107 | } |
---|
108 | catch (Throwable t) |
---|
109 | { |
---|
110 | cc.setMessage(t.getMessage()); |
---|
111 | } |
---|
112 | int numListed = 0; |
---|
113 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null); |
---|
114 | ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext); |
---|
115 | %> |
---|
116 | <base:page title="Disk usage"> |
---|
117 | <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css"> |
---|
118 | <ext:scripts context="<%=jspContext%>" /> |
---|
119 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
120 | <script language="JavaScript"> |
---|
121 | var submitPage = 'index.jsp'; |
---|
122 | var formId = 'groups'; |
---|
123 | function editItem(itemId) |
---|
124 | { |
---|
125 | Main.viewOrEditItem('<%=ID%>', 'GROUP', itemId, true); |
---|
126 | } |
---|
127 | function viewItem(itemId) |
---|
128 | { |
---|
129 | Main.viewOrEditItem('<%=ID%>', 'GROUP', itemId, false); |
---|
130 | } |
---|
131 | function itemOnClick(evt, itemId) |
---|
132 | { |
---|
133 | Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem); |
---|
134 | } |
---|
135 | function configureColumns() |
---|
136 | { |
---|
137 | Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
138 | } |
---|
139 | function presetOnChange() |
---|
140 | { |
---|
141 | Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
142 | } |
---|
143 | function setShowStatistics() |
---|
144 | { |
---|
145 | document.forms[formId].submit(); |
---|
146 | } |
---|
147 | function viewDiskUsageDetails(groupId) |
---|
148 | { |
---|
149 | location.href = 'details/index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id='+groupId+'&item_type=GROUP'; |
---|
150 | } |
---|
151 | function switchTab(tabControlId, tabId) |
---|
152 | { |
---|
153 | if (tabId == 'overview') |
---|
154 | { |
---|
155 | location.href = 'index.jsp?ID=<%=ID%>&cmd=Overview'; |
---|
156 | } |
---|
157 | else if (tabId == 'users') |
---|
158 | { |
---|
159 | location.href = 'index.jsp?ID=<%=ID%>&cmd=ListUsers'; |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | TabControl.setActiveTab(tabControlId, tabId); |
---|
164 | } |
---|
165 | } |
---|
166 | </script> |
---|
167 | <style> |
---|
168 | table.special |
---|
169 | { |
---|
170 | border-collapse: collapse; |
---|
171 | } |
---|
172 | table.special td, table.special th |
---|
173 | { |
---|
174 | text-align: right; |
---|
175 | border-right: 1px dotted #A0A0A0; |
---|
176 | padding: 1px 2px 1px 2px; |
---|
177 | } |
---|
178 | </style> |
---|
179 | </base:head> |
---|
180 | |
---|
181 | <base:body> |
---|
182 | <h1>Disk usage</h1> |
---|
183 | <t:tabcontrol |
---|
184 | id="main" |
---|
185 | subclass="mastertabcontrol content" |
---|
186 | active="groups" switch="switchTab"> |
---|
187 | <t:tab id="overview" title="Overview" /> |
---|
188 | <t:tab id="users" title="Per user" /> |
---|
189 | <t:tab id="groups" title="Per group"> |
---|
190 | <tbl:table |
---|
191 | id="groups" |
---|
192 | columns="<%=cc.getSetting("columns")%>" |
---|
193 | sortby="<%=cc.getSortProperty()%>" |
---|
194 | direction="<%=cc.getSortDirection()%>" |
---|
195 | action="index.jsp" |
---|
196 | sc="<%=sc%>" |
---|
197 | item="<%=itemType%>" |
---|
198 | subcontext="<%=subContext%>" |
---|
199 | subclass="fulltable" |
---|
200 | > |
---|
201 | <tbl:hidden |
---|
202 | name="subcontext" |
---|
203 | value="<%=subContext%>" |
---|
204 | /> |
---|
205 | <tbl:columndef |
---|
206 | id="name" |
---|
207 | property="name" |
---|
208 | datatype="string" |
---|
209 | title="Name" |
---|
210 | sortable="true" |
---|
211 | filterable="true" |
---|
212 | exportable="true" |
---|
213 | show="always" |
---|
214 | /> |
---|
215 | <tbl:columndef |
---|
216 | id="id" |
---|
217 | clazz="uniquecol" |
---|
218 | property="id" |
---|
219 | datatype="int" |
---|
220 | title="ID" |
---|
221 | sortable="true" |
---|
222 | filterable="true" |
---|
223 | exportable="true" |
---|
224 | /> |
---|
225 | <tbl:columndef |
---|
226 | id="diskUsage" |
---|
227 | title="Disk usage summary" |
---|
228 | show="always" |
---|
229 | /> |
---|
230 | <tbl:columndef |
---|
231 | id="quota" |
---|
232 | property="quota.name" |
---|
233 | datatype="string" |
---|
234 | title="Quota" |
---|
235 | sortable="true" |
---|
236 | filterable="true" |
---|
237 | exportable="true" |
---|
238 | /> |
---|
239 | <div class="panelgroup bottomborder"> |
---|
240 | <tbl:toolbar |
---|
241 | visible="<%=mode.hasToolbar()%>" |
---|
242 | subclass="bottomborder" |
---|
243 | > |
---|
244 | <tbl:button |
---|
245 | image="columns.png" |
---|
246 | onclick="configureColumns()" |
---|
247 | title="Columns…" |
---|
248 | tooltip="Show, hide and re-order columns" |
---|
249 | /> |
---|
250 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
251 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
252 | </tbl:toolbar> |
---|
253 | <tbl:panel> |
---|
254 | <tbl:presetselector |
---|
255 | onchange="presetOnChange()" |
---|
256 | /> |
---|
257 | <tbl:navigator |
---|
258 | page="<%=cc.getPage()%>" |
---|
259 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
260 | totalrows="<%=groups == null ? 0 : groups.getTotalCount()%>" |
---|
261 | /> |
---|
262 | <b>Show summary</b> |
---|
263 | <input type="radio" name="showStatistics" value="total" |
---|
264 | <%="total".equals(showStatistics) ? "checked" : ""%> |
---|
265 | onclick="setShowStatistics()"><a |
---|
266 | href="javascript:document.forms[formId].showStatistics[0].click()">Total only</a> |
---|
267 | <input type="radio" name="showStatistics" value="location" |
---|
268 | <%="location".equals(showStatistics) ? "checked" : ""%> |
---|
269 | onclick="setShowStatistics()"><a |
---|
270 | href="javascript:document.forms[formId].showStatistics[1].click()">Per location</a> |
---|
271 | <input type="radio" name="showStatistics" value="quotaType" |
---|
272 | <%="quotaType".equals(showStatistics) ? "checked" : ""%> |
---|
273 | onclick="setShowStatistics()"><a |
---|
274 | href="javascript:document.forms[formId].showStatistics[2].click()">Per quota type</a> |
---|
275 | <input type="radio" name="showStatistics" value="full" |
---|
276 | <%="full".equals(showStatistics) ? "checked" : ""%> |
---|
277 | onclick="setShowStatistics()"><a |
---|
278 | href="javascript:document.forms[formId].showStatistics[3].click()">Full</a> |
---|
279 | </tbl:panel> |
---|
280 | </div> |
---|
281 | |
---|
282 | <tbl:data> |
---|
283 | <tbl:headers> |
---|
284 | <tbl:headerrow> |
---|
285 | <tbl:header colspan="3" /> |
---|
286 | <tbl:columnheaders /> |
---|
287 | </tbl:headerrow> |
---|
288 | <tbl:headerrow> |
---|
289 | <tbl:header subclass="index" /> |
---|
290 | <tbl:header |
---|
291 | subclass="check" |
---|
292 | visible="<%=mode.hasCheck()%>" |
---|
293 | ><base:icon |
---|
294 | image="check_uncheck.png" |
---|
295 | tooltip="Check/uncheck all" |
---|
296 | onclick="Forms.checkUncheck(document.forms[formId])" |
---|
297 | /></tbl:header> |
---|
298 | <tbl:header |
---|
299 | subclass="check" |
---|
300 | visible="<%=mode.hasRadio()%>" |
---|
301 | /> |
---|
302 | <tbl:header |
---|
303 | subclass="icons" |
---|
304 | visible="<%=mode.hasIcons()%>" |
---|
305 | /> |
---|
306 | <tbl:propertyfilter /> |
---|
307 | </tbl:headerrow> |
---|
308 | </tbl:headers> |
---|
309 | <tbl:rows> |
---|
310 | <% |
---|
311 | if (cc.getMessage() != null) |
---|
312 | { |
---|
313 | %> |
---|
314 | <tbl:panel clazz="messagepanel"> |
---|
315 | <div class="messagecontainer error"><%=cc.getMessage()%></div> |
---|
316 | </tbl:panel> |
---|
317 | <% |
---|
318 | cc.setMessage(null); |
---|
319 | } |
---|
320 | int index = cc.getPage()*cc.getRowsPerPage(); |
---|
321 | int selectedItemId = cc.getId(); |
---|
322 | if (groups != null) |
---|
323 | { |
---|
324 | while (groups.hasNext()) |
---|
325 | { |
---|
326 | Group item = groups.next(); |
---|
327 | int itemId = item.getId(); |
---|
328 | String name = HTML.encodeTags(item.getName()); |
---|
329 | String tooltip = mode.isSelectionMode() ? |
---|
330 | "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : ""); |
---|
331 | index++; |
---|
332 | numListed++; |
---|
333 | %> |
---|
334 | <tbl:row> |
---|
335 | <tbl:header |
---|
336 | clazz="index" |
---|
337 | ><%=index%></tbl:header> |
---|
338 | <tbl:header |
---|
339 | clazz="check" |
---|
340 | visible="<%=mode.hasCheck()%>" |
---|
341 | ><input |
---|
342 | type="checkbox" |
---|
343 | name="<%=itemId%>" |
---|
344 | value="<%=itemId%>" |
---|
345 | title="<%=name%>" |
---|
346 | <%=cc.getSelected().contains(itemId) ? "checked" : ""%> |
---|
347 | ></tbl:header> |
---|
348 | <tbl:header |
---|
349 | clazz="check" |
---|
350 | visible="<%=mode.hasRadio()%>" |
---|
351 | ><input |
---|
352 | type="radio" |
---|
353 | name="item_id" |
---|
354 | value="<%=itemId%>" |
---|
355 | title="<%=name%>" |
---|
356 | <%=selectedItemId == itemId ? "checked" : ""%> |
---|
357 | ></tbl:header> |
---|
358 | <tbl:header |
---|
359 | clazz="icons" |
---|
360 | visible="<%=mode.hasIcons()%>" |
---|
361 | ><base:icon |
---|
362 | image="deleted.png" |
---|
363 | tooltip="This item has been scheduled for deletion" |
---|
364 | visible="<%=item.isRemoved()%>" |
---|
365 | /> </tbl:header> |
---|
366 | <tbl:cell column="name"><div class="link" |
---|
367 | onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" |
---|
368 | title="<%=tooltip%>"><%=name%></div></tbl:cell> |
---|
369 | <tbl:cell column="id"><%=item.getId()%></tbl:cell> |
---|
370 | <tbl:cell column="diskUsage" style="padding: 0px;"> |
---|
371 | <% |
---|
372 | DiskUsageStatistics.Summary summary = du.getSummary(item); |
---|
373 | long total = summary.getTotal(); |
---|
374 | if (total > 0 && (hasLocation || hasQuotaType)) |
---|
375 | { |
---|
376 | %> |
---|
377 | <table class="special bottomborder"> |
---|
378 | <% |
---|
379 | if (hasLocation) |
---|
380 | { |
---|
381 | %> |
---|
382 | <tr class="bottomborder"> |
---|
383 | <% |
---|
384 | if (hasQuotaType) |
---|
385 | { |
---|
386 | %> |
---|
387 | <th></th> |
---|
388 | <% |
---|
389 | } |
---|
390 | %> |
---|
391 | <th>Total</th> |
---|
392 | <td>Primary</td> |
---|
393 | <td>Secondary</td> |
---|
394 | <td>Offline</td> |
---|
395 | <td>External</td> |
---|
396 | </tr> |
---|
397 | <% |
---|
398 | } |
---|
399 | %> |
---|
400 | <tr class="bottomborder" style="background: #D8D8D8;"> |
---|
401 | <% |
---|
402 | if (hasQuotaType) |
---|
403 | { |
---|
404 | %> |
---|
405 | <th>Total</th> |
---|
406 | <% |
---|
407 | } |
---|
408 | %> |
---|
409 | <td><%=Values.formatBytes(total)%></td> |
---|
410 | <% |
---|
411 | if (hasLocation) |
---|
412 | { |
---|
413 | %> |
---|
414 | <td><%=Values.formatBytes(summary.getTotal(Location.PRIMARY))%></td> |
---|
415 | <td><%=Values.formatBytes(summary.getTotal(Location.SECONDARY))%></td> |
---|
416 | <td><%=Values.formatBytes(summary.getTotal(Location.OFFLINE))%></td> |
---|
417 | <td><%=Values.formatBytes(summary.getTotal(Location.EXTERNAL))%></td> |
---|
418 | <% |
---|
419 | } |
---|
420 | %> |
---|
421 | </tr> |
---|
422 | <% |
---|
423 | if (hasQuotaType && total > 0) |
---|
424 | { |
---|
425 | for (QuotaType qt : quotaTypes) |
---|
426 | { |
---|
427 | %> |
---|
428 | <tr> |
---|
429 | <td><%=HTML.encodeTags(qt.getName())%></td> |
---|
430 | <td><%=Values.formatBytes(summary.getTotal(qt))%></td> |
---|
431 | <% |
---|
432 | if (hasLocation) |
---|
433 | { |
---|
434 | %> |
---|
435 | <td><%=Values.formatBytes(summary.getTotal(qt, Location.PRIMARY))%></td> |
---|
436 | <td><%=qt.hasSecondaryLocation() ? Values.formatBytes(summary.getTotal(qt, Location.SECONDARY)) : "n/a"%></td> |
---|
437 | <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.OFFLINE)) : "n/a"%></td> |
---|
438 | <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.EXTERNAL)) : "n/a"%></td> |
---|
439 | <% |
---|
440 | } |
---|
441 | %> |
---|
442 | </tr> |
---|
443 | <% |
---|
444 | } |
---|
445 | } |
---|
446 | %> |
---|
447 | </table> |
---|
448 | <% |
---|
449 | } |
---|
450 | else |
---|
451 | { |
---|
452 | %> |
---|
453 | <%=Values.formatBytes(total)%> |
---|
454 | <% |
---|
455 | } |
---|
456 | if (total > 0) |
---|
457 | { |
---|
458 | %> |
---|
459 | <base:icon image="gonext.png" |
---|
460 | onclick="<%="viewDiskUsageDetails(" + itemId + ")"%>">View details</base:icon> |
---|
461 | <% |
---|
462 | } |
---|
463 | %> |
---|
464 | </tbl:cell> |
---|
465 | <tbl:cell column="quota" |
---|
466 | ><base:propertyvalue |
---|
467 | item="<%=item%>" |
---|
468 | property="quota" |
---|
469 | enableEditLink="<%=mode.hasEditLink()%>" |
---|
470 | enablePropertyLink="<%=mode.hasPropertyLink()%>" |
---|
471 | /></tbl:cell> |
---|
472 | <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell> |
---|
473 | </tbl:row> |
---|
474 | <% |
---|
475 | } |
---|
476 | } |
---|
477 | if (numListed == 0) |
---|
478 | { |
---|
479 | %> |
---|
480 | <tbl:panel clazz="messagepanel"> |
---|
481 | <div class="messagecontainer note"> |
---|
482 | <%=groups == null || groups.getTotalCount() == 0 ? "No groups were found" : "No groups on this page. Please select another page!" %> |
---|
483 | </div> |
---|
484 | </tbl:panel> |
---|
485 | <% |
---|
486 | } |
---|
487 | %> |
---|
488 | </tbl:rows> |
---|
489 | </tbl:data> |
---|
490 | </tbl:table> |
---|
491 | </t:tab> |
---|
492 | </t:tabcontrol> |
---|
493 | |
---|
494 | </base:body> |
---|
495 | </base:page> |
---|
496 | <% |
---|
497 | } |
---|
498 | finally |
---|
499 | { |
---|
500 | if (groups != null) groups.close(); |
---|
501 | if (dc != null) dc.close(); |
---|
502 | } |
---|
503 | %> |
---|