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

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

References #1912: Add more filter rows in list pages

Implemented in disk usage and change history lists.

File size: 15.7 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      filterrows="<%=cc.getFilterRows()%>"
158      subclass="fulltable"
159      >
160      <tbl:hidden 
161        name="subcontext"
162        value="<%=subContext%>"
163      />
164      <tbl:columndef 
165        id="name"
166        property="name"
167        datatype="string"
168        title="Name"
169        sortable="true" 
170        filterable="true"
171        exportable="true"
172        show="always" 
173      />
174      <tbl:columndef 
175        id="id"
176        clazz="uniquecol"
177        property="id"
178        datatype="int"
179        title="ID"
180        sortable="true"
181        filterable="true"
182        exportable="true"
183      />
184      <tbl:columndef
185        id="diskUsage"
186        title="Disk usage summary"
187        show="always"
188      />
189      <tbl:columndef 
190        id="quota"
191        property="quota.name"
192        datatype="string"
193        title="Quota"
194        sortable="true" 
195        filterable="true"
196        exportable="true"
197      />
198      <tbl:columndef 
199        id="xt-columns" 
200        extensions="<%=columnsInvoker%>" 
201        jspcontext="<%=jspContext%>" 
202      />
203      <div class="panelgroup bg-filled-50 bottomborder">
204        <tbl:toolbar
205          visible="<%=mode.hasToolbar()%>"
206          subclass="bottomborder"
207          >
208          <tbl:button 
209            id="btnColumns"
210            image="columns.png" 
211            title="Columns&hellip;" 
212            tooltip="Show, hide and re-order columns" 
213          />
214          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
215            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
216        </tbl:toolbar>
217        <tbl:panel>
218          <tbl:presetselector />
219          <tbl:navigator
220            page="<%=cc.getPage()%>" 
221            rowsperpage="<%=cc.getRowsPerPage()%>" 
222            totalrows="<%=groups == null ? 0 : groups.getTotalCount()%>" 
223          />
224          <b>Show summary</b>
225          <span id="changeSummary">
226          <label><input type="radio" name="showStatistics" value="total"
227            <%="total".equals(showStatistics) ? "checked" : ""%>>Total only</label>
228          <label><input type="radio" name="showStatistics" value="location"
229            <%="location".equals(showStatistics) ? "checked" : ""%>>Per location</label>
230          <label><input type="radio" name="showStatistics" value="quotaType"
231            <%="quotaType".equals(showStatistics) ? "checked" : ""%>>Per quota type</label>
232          <label><input type="radio" name="showStatistics" value="full"
233            <%="full".equals(showStatistics) ? "checked" : ""%>>Full</label>
234          </span>
235        </tbl:panel>
236      </div>
237
238      <tbl:data>
239        <tbl:headers>
240          <tbl:headerrow>
241            <tbl:header colspan="3" />
242            <tbl:columnheaders />
243          </tbl:headerrow>
244          <%
245          int numFilters = cc.getNumPropertyFilters();
246          int numRows = cc.getFilterRows();
247          for (int filterNo = 0; filterNo < numRows; filterNo++)
248          {
249            boolean lastRow = filterNo == numRows-1;
250            %>
251            <tbl:headerrow>
252              <tbl:header subclass="index" />
253              <tbl:header 
254                subclass="check" 
255                visible="<%=mode.hasCheck()%>"
256                ><base:icon 
257                  id="check.uncheck"
258                  image="check_uncheck.png" 
259                  tooltip="Check/uncheck all" 
260                  visible="<%=lastRow%>"
261                /></tbl:header>
262              <tbl:header 
263                subclass="check" 
264                visible="<%=mode.hasRadio()%>"
265                />
266              <tbl:header 
267                subclass="icons" 
268                visible="<%=mode.hasIcons()%>"
269                >
270                <base:icon
271                  subclass="link table-filter-row-action"
272                  image="add.png"
273                  tooltip="Add extra filter row"
274                  visible="<%=lastRow%>"
275                /><base:icon
276                  subclass="link table-filter-row-action"
277                  image="remove.png"
278                  tooltip="Remove this filter row"
279                  visible="<%=numRows > 1 || numFilters > 0 %>"
280                  data-remove-row="<%=filterNo%>"
281                />
282              </tbl:header>
283              <tbl:propertyfilter row="<%=filterNo%>" />
284            </tbl:headerrow>
285            <%
286          }
287          %>
288        </tbl:headers>
289        <tbl:rows>
290          <%
291          if (cc.getMessage() != null)
292          {
293            %>
294            <tbl:panel subclass="bg-filled-50">
295              <div class="messagecontainer error"><%=cc.getMessage()%></div>
296            </tbl:panel>
297            <%
298            cc.setMessage(null);
299          }
300          int index = cc.getPage()*cc.getRowsPerPage();
301          int selectedItemId = cc.getId();
302          if (groups != null)
303          {           
304            while (groups.hasNext())
305            {
306              Group item = groups.next();
307              int itemId = item.getId();
308              String name = HTML.encodeTags(item.getName());
309              String tooltip = mode.isSelectionMode() ? 
310                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
311              index++;
312              numListed++;
313              %>
314              <tbl:row>
315                <tbl:header 
316                  clazz="index"
317                  ><%=index%></tbl:header>
318                <tbl:header 
319                  clazz="check" 
320                  visible="<%=mode.hasCheck()%>"
321                  ><input 
322                    type="checkbox" 
323                    name="<%=itemId%>" 
324                    value="<%=itemId%>" 
325                    title="<%=name%>" 
326                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
327                  ></tbl:header>
328                <tbl:header 
329                  clazz="check" 
330                  visible="<%=mode.hasRadio()%>"
331                  ><input 
332                    type="radio" 
333                    name="item_id" 
334                    value="<%=itemId%>" 
335                    title="<%=name%>" 
336                    <%=selectedItemId == itemId ? "checked" : ""%>
337                  ></tbl:header>
338                <tbl:header 
339                  clazz="icons" 
340                  visible="<%=mode.hasIcons()%>"
341                  ><base:icon 
342                    image="deleted.png" 
343                    tooltip="This item has been scheduled for deletion" 
344                    visible="<%=item.isRemoved()%>"
345                  />&nbsp;</tbl:header>
346                <tbl:cell column="name"><div 
347                  class="link auto-init"
348                  data-auto-init="item-link"
349                  data-item-type="GROUP"
350                  data-item-id="<%=itemId%>"
351                  data-no-edit="<%=writePermission ? 0 : 1 %>"
352                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
353                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
354                <tbl:cell column="diskUsage" style="padding: 0px;">
355                  <%
356                  DiskUsageStatistics.Summary summary = du.getSummary(item);
357                  long total = summary.getTotal();
358                  if (total > 0 && (hasLocation || hasQuotaType))
359                  {
360                    %>
361                    <table class="special bottomborder">
362                    <%
363                    if (hasLocation)
364                    {
365                      %>
366                      <tr class="bottomborder bg-filled-100">
367                        <%
368                        if (hasQuotaType)
369                        {
370                          %>
371                          <th></th>
372                          <%
373                        }
374                        %>
375                        <th>Total</th>
376                        <td>Primary</td>
377                        <td>Secondary</td>
378                        <td>Offline</td>
379                        <td>External</td>
380                      </tr>
381                      <%
382                    }
383                    %> 
384                    <tr class="bottomborder <%=!hasLocation ? "bg-filled-100" : "" %>">
385                      <%
386                      if (hasQuotaType)
387                      {
388                        %>
389                        <th>Total</th>
390                        <%
391                      }
392                      %>
393                      <td><%=Values.formatBytes(total)%></td>
394                      <%
395                      if (hasLocation)
396                      {
397                        %>
398                        <td><%=Values.formatBytes(summary.getTotal(Location.PRIMARY))%></td>
399                        <td><%=Values.formatBytes(summary.getTotal(Location.SECONDARY))%></td>
400                        <td><%=Values.formatBytes(summary.getTotal(Location.OFFLINE))%></td>
401                        <td><%=Values.formatBytes(summary.getTotal(Location.EXTERNAL))%></td>
402                        <%
403                      }
404                      %>
405                    </tr> 
406                    <%
407                    if (hasQuotaType && total > 0)
408                    {
409                      for (QuotaType qt : quotaTypes)
410                      {
411                        %>
412                        <tr>
413                          <td><%=HTML.encodeTags(qt.getName())%></td>
414                          <td><%=Values.formatBytes(summary.getTotal(qt))%></td>
415                          <%
416                          if (hasLocation)
417                          {
418                            %>
419                            <td><%=Values.formatBytes(summary.getTotal(qt, Location.PRIMARY))%></td>
420                            <td><%=qt.hasSecondaryLocation() ? Values.formatBytes(summary.getTotal(qt, Location.SECONDARY)) : "n/a"%></td>
421                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.OFFLINE)) : "n/a"%></td>
422                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.EXTERNAL)) : "n/a"%></td>
423                            <%
424                          }
425                          %>
426                        </tr>
427                        <%
428                      }
429                    }
430                    %>
431                    </table>
432                    <%
433                  }
434                  else
435                  {
436                    %>
437                    &nbsp;<%=Values.formatBytes(total)%>
438                    <%
439                  }
440                  if (total > 0)
441                  {
442                    %>
443                    <base:icon image="gonext.png" 
444                      subclass="link auto-init"
445                      data-auto-init="view-details"
446                      data-item-type="GROUP"
447                      data-item-id="<%=itemId %>">View details</base:icon>
448                    <%
449                  }
450                  %>
451                </tbl:cell>
452                <tbl:cell column="quota"
453                  ><base:propertyvalue 
454                    item="<%=item%>" 
455                    property="quota"
456                    enableEditLink="<%=mode.hasEditLink()%>" 
457                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
458                  /></tbl:cell>
459                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
460                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
461                  <tbl:cell column="xt-columns" />
462                </tbl:xt-cells>
463              </tbl:row>
464              <%
465              }
466            }
467            if (numListed == 0)
468            {
469              %>
470              <tbl:panel subclass="bg-filled-50">
471                <div class="messagecontainer note">
472                <%=groups == null || groups.getTotalCount() == 0 ? "No groups were found" : "No groups on this page. Please select another page!" %>
473                </div>
474              </tbl:panel>
475              <%
476            }
477            %>
478        </tbl:rows>
479      </tbl:data>
480    </tbl:table>
481    </t:tab>
482    </t:tabcontrol>
483
484  </base:body>
485  </base:page>
486  <%
487}
488finally
489{
490  if (groups != null) groups.close();
491  if (dc != null) dc.close();
492}
493%>
Note: See TracBrowser for help on using the repository browser.