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

Last change on this file since 7914 was 7914, checked in by Nicklas Nordborg, 3 years ago

References #2237: Implement extension mechanism for query filtering

This should now work on all list pages.

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