source: trunk/www/admin/diskusage/list_groups.jsp @ 6620

Last change on this file since 6620 was 6620, checked in by Nicklas Nordborg, 9 years ago

References #1890: Improve skinnability of BASE

Fixed special table in disk usage summary.

File size: 14.9 KB
Line 
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.clients.web.extensions.list.ListColumnUtil"
62  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
63  import="java.util.List"
64  import="java.util.Map"
65%>
66<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
67<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
68<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
69<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
70<%!
71  private static final Item itemType = Item.DISKUSAGE;
72  private static final String subContext = "perGroup";
73  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST, subContext);
74%>
75<%
76final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
77final String ID = sc.getId();
78final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null);
79final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
80final boolean writePermission = sc.hasPermission(Permission.WRITE, Item.GROUP);
81final String showStatistics = Values.getString(cc.getSetting("showStatistics"), 
82  Application.hasSecondaryStorage() ? "full" : "quotaType");
83
84final boolean hasLocation = "location".equals(showStatistics) || "full".equals(showStatistics);
85final boolean hasQuotaType = "quotaType".equals(showStatistics) || "full".equals(showStatistics);
86
87final DbControl dc = sc.newDbControl();
88ItemResultIterator<Group> groups = null;
89try
90{
91  DiskUsageStatistics du = (DiskUsageStatistics)sc.getSessionSetting("diskUsageStatistics");
92  if (du == null)
93  {
94    du = DiskUsage.getStatistics(dc);
95    sc.setSessionSetting("diskUsageStatistics", du);
96  }
97  du.setDbControl(dc);
98  List<QuotaType> quotaTypes = du.getQuotaTypes();
99 
100  try
101  {
102    final ItemQuery<Group> query = Base.getConfiguredQuery(dc, cc, true, Group.getQuery(), mode);
103    query.include(Include.ALL);
104    query.restrict(
105        Restrictions.neq(
106          Hql.property("quota"), null));
107    groups = query.iterate(dc);
108  }
109  catch (Throwable t)
110  {
111    cc.setMessage(t.getMessage());
112  }
113  int numListed = 0;
114  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
115  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
116  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
117  %>
118  <base:page title="Disk usage" id="list-groups">
119  <base:head scripts="table.js,tabcontrol-2.js,~diskusage.js" styles="table.css,toolbar.css,headertabcontrol.css">
120    <ext:scripts context="<%=jspContext%>" />
121    <ext:stylesheets context="<%=jspContext%>" />
122    <style>
123    table.special
124    {
125      border-width: 1px;
126      margin: 2px;
127      border-collapse: collapse;
128      width: calc(100% - 6px);
129    }
130    table.special td, table.special th
131    {
132      text-align: right;
133      border-right-width: 1px;
134      border-right-style: dotted;
135      padding: 1px 2px 1px 2px;
136    }
137    </style>
138  </base:head>
139  <base:body>
140    <h1>Disk usage</h1>
141    <t:tabcontrol 
142      id="main" 
143      subclass="mastertabcontrol content" 
144      active="groups">
145    <t:tab id="overview" title="Overview" data-cmd="Overview" />
146    <t:tab id="users" title="Per user" data-cmd="ListUsers" />
147    <t:tab id="groups" title="Per group" data-cmd="ListGroups">
148    <tbl:table 
149      id="groups" 
150      columns="<%=cc.getSetting("columns")%>"
151      sortby="<%=cc.getSortProperty()%>" 
152      direction="<%=cc.getSortDirection()%>"
153      action="index.jsp"
154      sc="<%=sc%>"
155      item="<%=itemType%>"
156      subcontext="<%=subContext%>"
157      subclass="fulltable"
158      >
159      <tbl:hidden 
160        name="subcontext"
161        value="<%=subContext%>"
162      />
163      <tbl:columndef 
164        id="name"
165        property="name"
166        datatype="string"
167        title="Name"
168        sortable="true" 
169        filterable="true"
170        exportable="true"
171        show="always" 
172      />
173      <tbl:columndef 
174        id="id"
175        clazz="uniquecol"
176        property="id"
177        datatype="int"
178        title="ID"
179        sortable="true"
180        filterable="true"
181        exportable="true"
182      />
183      <tbl:columndef
184        id="diskUsage"
185        title="Disk usage summary"
186        show="always"
187      />
188      <tbl:columndef 
189        id="quota"
190        property="quota.name"
191        datatype="string"
192        title="Quota"
193        sortable="true" 
194        filterable="true"
195        exportable="true"
196      />
197      <tbl:columndef 
198        id="xt-columns" 
199        extensions="<%=columnsInvoker%>" 
200        jspcontext="<%=jspContext%>" 
201      />
202      <div class="panelgroup bg-filled-50 bottomborder">
203        <tbl:toolbar
204          visible="<%=mode.hasToolbar()%>"
205          subclass="bottomborder"
206          >
207          <tbl:button 
208            id="btnColumns"
209            image="columns.png" 
210            title="Columns&hellip;" 
211            tooltip="Show, hide and re-order columns" 
212          />
213          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
214            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
215        </tbl:toolbar>
216        <tbl:panel>
217          <tbl:presetselector />
218          <tbl:navigator
219            page="<%=cc.getPage()%>" 
220            rowsperpage="<%=cc.getRowsPerPage()%>" 
221            totalrows="<%=groups == null ? 0 : groups.getTotalCount()%>" 
222          />
223          <b>Show summary</b>
224          <span id="changeSummary">
225          <label><input type="radio" name="showStatistics" value="total"
226            <%="total".equals(showStatistics) ? "checked" : ""%>>Total only</label>
227          <label><input type="radio" name="showStatistics" value="location"
228            <%="location".equals(showStatistics) ? "checked" : ""%>>Per location</label>
229          <label><input type="radio" name="showStatistics" value="quotaType"
230            <%="quotaType".equals(showStatistics) ? "checked" : ""%>>Per quota type</label>
231          <label><input type="radio" name="showStatistics" value="full"
232            <%="full".equals(showStatistics) ? "checked" : ""%>>Full</label>
233          </span>
234        </tbl:panel>
235      </div>
236
237      <tbl:data>
238        <tbl:headers>
239          <tbl:headerrow>
240            <tbl:header colspan="3" />
241            <tbl:columnheaders />
242          </tbl:headerrow>
243          <tbl:headerrow>
244            <tbl:header subclass="index" />
245            <tbl:header 
246              subclass="check" 
247              visible="<%=mode.hasCheck()%>"
248              ><base:icon 
249                id="check.uncheck"
250                image="check_uncheck.png" 
251                tooltip="Check/uncheck all" 
252                 
253              /></tbl:header>
254            <tbl:header 
255              subclass="check" 
256              visible="<%=mode.hasRadio()%>"
257              />
258            <tbl:header 
259              subclass="icons" 
260              visible="<%=mode.hasIcons()%>"
261              />
262            <tbl:propertyfilter />
263          </tbl:headerrow>
264        </tbl:headers>
265        <tbl:rows>
266          <%
267          if (cc.getMessage() != null)
268          {
269            %>
270            <tbl:panel subclass="bg-filled-50">
271              <div class="messagecontainer error"><%=cc.getMessage()%></div>
272            </tbl:panel>
273            <%
274            cc.setMessage(null);
275          }
276          int index = cc.getPage()*cc.getRowsPerPage();
277          int selectedItemId = cc.getId();
278          if (groups != null)
279          {           
280            while (groups.hasNext())
281            {
282              Group item = groups.next();
283              int itemId = item.getId();
284              String name = HTML.encodeTags(item.getName());
285              String tooltip = mode.isSelectionMode() ? 
286                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
287              index++;
288              numListed++;
289              %>
290              <tbl:row>
291                <tbl:header 
292                  clazz="index"
293                  ><%=index%></tbl:header>
294                <tbl:header 
295                  clazz="check" 
296                  visible="<%=mode.hasCheck()%>"
297                  ><input 
298                    type="checkbox" 
299                    name="<%=itemId%>" 
300                    value="<%=itemId%>" 
301                    title="<%=name%>" 
302                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
303                  ></tbl:header>
304                <tbl:header 
305                  clazz="check" 
306                  visible="<%=mode.hasRadio()%>"
307                  ><input 
308                    type="radio" 
309                    name="item_id" 
310                    value="<%=itemId%>" 
311                    title="<%=name%>" 
312                    <%=selectedItemId == itemId ? "checked" : ""%>
313                  ></tbl:header>
314                <tbl:header 
315                  clazz="icons" 
316                  visible="<%=mode.hasIcons()%>"
317                  ><base:icon 
318                    image="deleted.png" 
319                    tooltip="This item has been scheduled for deletion" 
320                    visible="<%=item.isRemoved()%>"
321                  />&nbsp;</tbl:header>
322                <tbl:cell column="name"><div 
323                  class="link auto-init"
324                  data-auto-init="item-link"
325                  data-item-type="GROUP"
326                  data-item-id="<%=itemId%>"
327                  data-no-edit="<%=writePermission ? 0 : 1 %>"
328                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
329                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
330                <tbl:cell column="diskUsage" style="padding: 0px;">
331                  <%
332                  DiskUsageStatistics.Summary summary = du.getSummary(item);
333                  long total = summary.getTotal();
334                  if (total > 0 && (hasLocation || hasQuotaType))
335                  {
336                    %>
337                    <table class="special bottomborder">
338                    <%
339                    if (hasLocation)
340                    {
341                      %>
342                      <tr class="bottomborder bg-filled-100">
343                        <%
344                        if (hasQuotaType)
345                        {
346                          %>
347                          <th></th>
348                          <%
349                        }
350                        %>
351                        <th>Total</th>
352                        <td>Primary</td>
353                        <td>Secondary</td>
354                        <td>Offline</td>
355                        <td>External</td>
356                      </tr>
357                      <%
358                    }
359                    %> 
360                    <tr class="bottomborder <%=!hasLocation ? "bg-filled-100" : "" %>">
361                      <%
362                      if (hasQuotaType)
363                      {
364                        %>
365                        <th>Total</th>
366                        <%
367                      }
368                      %>
369                      <td><%=Values.formatBytes(total)%></td>
370                      <%
371                      if (hasLocation)
372                      {
373                        %>
374                        <td><%=Values.formatBytes(summary.getTotal(Location.PRIMARY))%></td>
375                        <td><%=Values.formatBytes(summary.getTotal(Location.SECONDARY))%></td>
376                        <td><%=Values.formatBytes(summary.getTotal(Location.OFFLINE))%></td>
377                        <td><%=Values.formatBytes(summary.getTotal(Location.EXTERNAL))%></td>
378                        <%
379                      }
380                      %>
381                    </tr> 
382                    <%
383                    if (hasQuotaType && total > 0)
384                    {
385                      for (QuotaType qt : quotaTypes)
386                      {
387                        %>
388                        <tr>
389                          <td><%=HTML.encodeTags(qt.getName())%></td>
390                          <td><%=Values.formatBytes(summary.getTotal(qt))%></td>
391                          <%
392                          if (hasLocation)
393                          {
394                            %>
395                            <td><%=Values.formatBytes(summary.getTotal(qt, Location.PRIMARY))%></td>
396                            <td><%=qt.hasSecondaryLocation() ? Values.formatBytes(summary.getTotal(qt, Location.SECONDARY)) : "n/a"%></td>
397                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.OFFLINE)) : "n/a"%></td>
398                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.EXTERNAL)) : "n/a"%></td>
399                            <%
400                          }
401                          %>
402                        </tr>
403                        <%
404                      }
405                    }
406                    %>
407                    </table>
408                    <%
409                  }
410                  else
411                  {
412                    %>
413                    &nbsp;<%=Values.formatBytes(total)%>
414                    <%
415                  }
416                  if (total > 0)
417                  {
418                    %>
419                    <base:icon image="gonext.png" 
420                      subclass="link auto-init"
421                      data-auto-init="view-details"
422                      data-item-type="GROUP"
423                      data-item-id="<%=itemId %>">View details</base:icon>
424                    <%
425                  }
426                  %>
427                </tbl:cell>
428                <tbl:cell column="quota"
429                  ><base:propertyvalue 
430                    item="<%=item%>" 
431                    property="quota"
432                    enableEditLink="<%=mode.hasEditLink()%>" 
433                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
434                  /></tbl:cell>
435                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
436                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
437                  <tbl:cell column="xt-columns" />
438                </tbl:xt-cells>
439              </tbl:row>
440              <%
441              }
442            }
443            if (numListed == 0)
444            {
445              %>
446              <tbl:panel subclass="bg-filled-50">
447                <div class="messagecontainer note">
448                <%=groups == null || groups.getTotalCount() == 0 ? "No groups were found" : "No groups on this page. Please select another page!" %>
449                </div>
450              </tbl:panel>
451              <%
452            }
453            %>
454        </tbl:rows>
455      </tbl:data>
456    </tbl:table>
457    </t:tab>
458    </t:tabcontrol>
459
460  </base:body>
461  </base:page>
462  <%
463}
464finally
465{
466  if (groups != null) groups.close();
467  if (dc != null) dc.close();
468}
469%>
Note: See TracBrowser for help on using the repository browser.