source: trunk/www/admin/diskusage/details/view_details.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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.1 KB
Line 
1<%-- $Id: view_details.jsp 6707 2015-02-02 13:20:03Z nicklas $
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.SystemItems"
30  import="net.sf.basedb.core.BasicItem"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.Location"
33  import="net.sf.basedb.core.ItemContext"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.DiskUsage"
36  import="net.sf.basedb.core.DiskUsageStatistics"
37  import="net.sf.basedb.core.DiskConsumable"
38  import="net.sf.basedb.core.Quota"
39  import="net.sf.basedb.core.User"
40  import="net.sf.basedb.core.Group"
41  import="net.sf.basedb.core.Nameable"
42  import="net.sf.basedb.core.Removable"
43  import="net.sf.basedb.core.File"
44  import="net.sf.basedb.core.QuotaType"
45  import="net.sf.basedb.core.Metadata"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.PluginDefinition"
48  import="net.sf.basedb.core.ItemQuery"
49  import="net.sf.basedb.core.ItemResultIterator"
50  import="net.sf.basedb.core.Include"
51  import="net.sf.basedb.core.Quantity"
52  import="net.sf.basedb.core.Unit"
53  import="net.sf.basedb.util.Enumeration"
54  import="net.sf.basedb.core.query.Orders"
55  import="net.sf.basedb.core.query.Hql"
56  import="net.sf.basedb.core.plugin.GuiContext"
57  import="net.sf.basedb.core.plugin.Plugin"
58  import="net.sf.basedb.util.units.UnitUtil"
59  import="net.sf.basedb.clients.web.Base"
60  import="net.sf.basedb.clients.web.PermissionUtil"
61  import="net.sf.basedb.clients.web.util.HTML"
62  import="net.sf.basedb.util.Values"
63  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
64  import="net.sf.basedb.clients.web.extensions.JspContext"
65  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
66  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
67  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
68  import="java.util.Map"
69  import="java.util.List"
70%>
71<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
72<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
73<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
74<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
75<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
76<%!
77  private static final String subContext = "diskUsage";
78  private static final Enumeration<String, String> itemTypes = new Enumeration<String, String>();
79  static
80  {
81    for (Item item : Metadata.getDiskConsumableItems())
82    {
83      itemTypes.add(String.valueOf(item.getValue()), item.toString());
84    }
85  }
86  private static final Enumeration<String, String> locations = new Enumeration<String, String>();
87  static
88  {
89    for (Location l : Location.values())
90    {
91      locations.add(String.valueOf(l.getValue()), l.toString());
92    }
93  }
94%>
95<%
96final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
97final String ID = sc.getId();
98final Item itemType = Item.valueOf(request.getParameter("item_type"));
99final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null);
100final int itemId = cc.getId();
101final float scale = Base.getScale(sc);
102final DbControl dc = sc.newDbControl();
103ItemResultIterator<DiskUsage> diskUsage = null;
104try
105{
106  Unit bytes = UnitUtil.getUnit(dc, Quantity.STORAGE_SIZE, "B");
107  String title = null;
108  User user = null;
109  Group group = null;
110  boolean writePermission = false;
111  final boolean hasDiskUsagePermission = sc.hasPermission(Permission.READ, Item.DISKUSAGE);
112  DiskUsageStatistics statistics = (DiskUsageStatistics)sc.getSessionSetting("diskUsageStatistics");
113  String returnCmd = null;
114  if (statistics == null)
115  {
116    statistics = DiskUsage.getStatistics(dc);
117    sc.setSessionSetting("diskUsageStatistics", statistics);
118  }
119  statistics.setDbControl(dc);
120  List<QuotaType> quotaTypes = statistics.getQuotaTypes();
121  DiskUsageStatistics.Summary summary = null;
122  if (itemType == Item.USER)
123  {
124    user = User.getById(dc, itemId);
125    title = user.getName() + " (user)";
126    writePermission = user.hasPermission(Permission.WRITE);
127    summary = statistics.getSummary(user);
128    returnCmd = "ListUsers";
129  }
130  else
131  {
132    group = Group.getById(dc, itemId);
133    title = group.getName() + " (group)";
134    writePermission = group.hasPermission(Permission.WRITE);
135    summary = statistics.getSummary(group);
136    returnCmd = "ListGroups";
137  }
138  long totalCount = 0;
139  int numListed = 0;
140  try
141  {
142    final ItemQuery<DiskUsage> query = Base.getConfiguredQuery(dc, cc, true, DiskUsage.getQuery(user, group), null);
143    diskUsage = query.iterate(dc);
144    totalCount = diskUsage.getTotalCount();
145  }
146  catch (Throwable t)
147  {
148    cc.setMessage(t.getMessage());
149  }
150  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, 
151      GuiContext.list(Item.DISKUSAGE), user == null ? group : user);
152  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
153  %>
154  <base:page >
155  <base:head scripts="table.js,tabcontrol-2.js,~details.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css">
156    <ext:scripts context="<%=jspContext%>" />
157    <ext:stylesheets context="<%=jspContext%>" />
158    <style>
159    table.special
160    {
161      width: auto;
162    }
163    table.special td, table.special tr:first-child th
164    {
165      text-align: right;
166      border-right-width: 1px;
167      border-right-style: dotted;
168    }
169    </style>
170  </base:head>
171  <base:body>
172    <p:path><p:pathelement 
173      title="Disk usage" enabled="<%=hasDiskUsagePermission%>"
174        href="<%="../index.jsp?ID="+ID+"&cmd="+returnCmd%>" 
175      /><p:pathelement title="<%=HTML.encodeTags(title)%>" 
176      /></p:path>
177     
178    <div id="page-data" class="datacontainer" 
179      data-item-id="<%=itemId%>" data-item-type="<%=itemType.name()%>"></div>
180   
181    <t:tabcontrol id="main" 
182      subclass="mastertabcontrol content">
183    <t:tab id="details" title="Details">
184      <div>
185      <table class="fullform" style="height: auto;">
186      <tr>
187        <th class="itemstatus"></th>
188        <td style="padding: 0px;">
189          <tbl:toolbar subclass="bottomborder bg-filled-50">
190            <tbl:button 
191              id="btnEdit"
192              disabled="<%=!writePermission%>" 
193              image="edit.png" 
194              title="Edit&hellip;" 
195              tooltip="<%=writePermission ? "Edit this item" : "You do not have permission to edit this item"%>" 
196            />
197            <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
198              wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
199            <tbl:button
200              image="help.png"
201              subclass="auto-init"
202              data-auto-init="help"
203              data-help-id="diskusage.details"
204              title="Help&hellip;"
205              tooltip="Get help about this page"
206            />
207          </tbl:toolbar>
208        </td>
209      </tr>
210      </table>
211      <table style="width: 100%; height: 8em;" class="bottomborder">
212      <tr valign="top">
213        <td style="width: 50%; height: 100%;">
214          <%
215          if (user != null)
216          {
217            %>
218            <table class="fullform">
219            <tr>
220              <th>Name</th>
221              <td><%=Base.getLinkedName(ID, user, false, true)%></td>
222            </tr>
223            <tr>
224              <th>Quota</th>
225              <td><base:propertyvalue item="<%=user%>" property="quota" /></td>
226            </tr>
227            <tr>
228              <th>Quota group</th>
229              <td><base:propertyvalue item="<%=user%>" property="quotaGroup" /></td>
230            </tr>
231            <tr class="dynamic">
232              <th>Description</th>
233              <td><%=HTML.niceFormat(user.getDescription())%></td>
234            </tr>
235            </table>
236            <%
237          }
238          else if (group != null)
239          {
240            %>
241            <table class="fullform">
242            <tr>
243              <th>Name</th>
244              <td><%=Base.getLinkedName(ID, group, false, true)%></td>
245            </tr>
246            <tr>
247              <th>Quota</th>
248              <td><base:propertyvalue item="<%=group%>" property="quota" /></td>
249            </tr>
250            <tr class="dynamic">
251              <th>Description</th>
252              <td><%=HTML.niceFormat(group.getDescription())%></td>
253            </tr>
254            </table>
255            <%
256          }
257          %>
258        </td>
259        <td style="width: 50%; height: 100%;" class="leftborder">
260          <table class="special fullform">
261          <tr>
262            <th style="width: 10em;"></th>
263            <th style="width: 12em;">Total</td>
264            <th style="width: 12em;">Primary</td>
265            <th style="width: 12em;">Secondary</td>
266            <th style="width: 12em;">Offline</td>
267            <th style="width: 12em;">External</td>
268          </tr>
269          <tr style="border-top-width: 1px;" class="highlight">
270            <th>Total</th>
271            <td><%=Values.formatBytes(summary.getTotal())%></td>
272            <td><%=Values.formatBytes(summary.getTotal(Location.PRIMARY))%></td>
273            <td><%=Values.formatBytes(summary.getTotal(Location.SECONDARY))%></td>
274            <td><%=Values.formatBytes(summary.getTotal(Location.OFFLINE))%></td>     
275            <td><%=Values.formatBytes(summary.getTotal(Location.EXTERNAL))%></td>     
276          </tr>
277          <%
278          for (QuotaType qt : quotaTypes)
279          {
280            %>
281            <tr class="highlight">
282              <th><%=HTML.encodeTags(qt.getName())%></th>
283              <td><%=Values.formatBytes(summary.getTotal(qt))%></td>
284              <td><%=Values.formatBytes(summary.getTotal(qt, Location.PRIMARY))%></td>
285              <td><%=qt.hasSecondaryLocation() ? Values.formatBytes(summary.getTotal(qt, Location.SECONDARY)) : "n/a"%></td>
286              <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.OFFLINE)) : "n/a"%></td>
287              <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.EXTERNAL)) : "n/a"%></td>
288            </tr>
289            <%
290          }
291          %>
292          </table>
293        </td>
294      </tr>
295      </table>
296      </div>
297   
298    <base:section id="itemsSection" 
299      title="<%="Disk consuming items (" + totalCount + ")"%>" 
300      context="<%=cc%>">
301      <tbl:table 
302        id="items" 
303        columns="<%=cc.getSetting("columns")%>"
304        sortby="<%=cc.getSortProperty()%>" 
305        direction="<%=cc.getSortDirection()%>"
306        action="index.jsp"
307        sc="<%=sc%>"
308        item="<%=itemType%>"
309        subcontext="<%=subContext%>"
310        filterrows="<%=cc.getFilterRows()%>"
311        >
312        <tbl:hidden
313          name="item_type"
314          value="<%=itemType.name()%>"
315        />
316        <tbl:columndef
317          id="type"
318          property="itemType"
319          datatype="int"
320          title="Item type"
321          enumeration="<%=itemTypes%>"
322          filterable="true"
323          sortable="true"
324          show="always"
325        />
326        <tbl:columndef 
327          id="name"
328          title="Name"
329          show="always" 
330        />
331        <tbl:columndef 
332          id="bytes"
333          property="bytes"
334          datatype="long"
335          title="Bytes"
336          sortable="true"
337          filterable="true"
338          exportable="true"
339          unit="<%=bytes%>"
340        />
341        <tbl:columndef 
342          id="location"
343          property="location"
344          datatype="int"
345          title="Location"
346          enumeration="<%=locations%>"
347          filterable="true"
348          sortable="true"
349        />
350        <tbl:columndef 
351          id="owner"
352          property="user.name"
353          datatype="string"
354          title="Owner"
355          sortable="true" 
356          filterable="true"
357          exportable="true"
358        />
359        <tbl:columndef 
360          id="group"
361          property="group.name"
362          datatype="string"
363          title="Group"
364          sortable="true" 
365          filterable="true"
366          exportable="true"
367        />
368        <tbl:columndef 
369          id="description"
370          title="Description"
371        />
372        <div class="panelgroup topborder leftborder rightborder bg-filled-50">
373          <tbl:toolbar subclass="bottomborder">
374            <tbl:button 
375              id="btnDeleteItems"
376              image="delete.png"
377              title="Delete" 
378              tooltip="Mark the selected items for deletion" 
379              disabled="<%=totalCount <= 0%>"
380            />
381            <tbl:button 
382              id="btnRestoreItems"
383              image="restore.png"
384              title="Restore" 
385              tooltip="Restore the selected items"
386              disabled="<%=totalCount <= 0%>"
387            />
388            <tbl:button 
389              id="btnShareItems"
390              image="share.png"
391              title="Share&hellip;" 
392              tooltip="Share the selected items"
393              disabled="<%=totalCount <= 0%>"
394            />
395            <tbl:button 
396              id="btnColumns"
397              image="columns.png" 
398              title="Columns&hellip;" 
399              tooltip="Show, hide and re-order columns" 
400            />
401          </tbl:toolbar>
402          <tbl:panel>
403            <tbl:presetselector
404              disableremoved="true"
405            />
406            <tbl:navigator
407              page="<%=cc.getPage()%>" 
408              rowsperpage="<%=cc.getRowsPerPage()%>" 
409              totalrows="<%=totalCount%>"
410            />
411          </tbl:panel>
412        </div>
413        <tbl:data>
414          <tbl:headers>
415            <tbl:headerrow>
416              <tbl:header colspan="3" />
417              <tbl:columnheaders />
418            </tbl:headerrow>
419          <%
420          int numFilters = cc.getNumPropertyFilters();
421          int numRows = cc.getFilterRows();
422          for (int filterNo = 0; filterNo < numRows; filterNo++)
423          {
424            boolean lastRow = filterNo == numRows-1;
425            %>
426            <tbl:headerrow>
427              <tbl:header subclass="index" />
428              <tbl:header 
429                subclass="check" 
430                ><base:icon 
431                  id="check.uncheck"
432                  image="check_uncheck.png" 
433                  tooltip="Check/uncheck all" 
434                  visible="<%=lastRow%>"
435                /></tbl:header>
436              <tbl:header 
437                subclass="icons" 
438                >
439                <base:icon
440                  subclass="link table-filter-row-action"
441                  image="add.png"
442                  tooltip="Add extra filter row"
443                  visible="<%=lastRow%>"
444                /><base:icon
445                  subclass="link table-filter-row-action"
446                  image="remove.png"
447                  tooltip="Remove this filter row"
448                  visible="<%=numRows > 1 || numFilters > 0 %>"
449                  data-remove-row="<%=filterNo%>"
450                />
451              </tbl:header>
452              <tbl:propertyfilter row="<%=filterNo%>" />
453            </tbl:headerrow>
454            <%
455          }
456          %>
457          </tbl:headers>
458          <tbl:rows>
459          <%
460          if (cc.getMessage() != null)
461          {
462            %>
463            <tbl:panel subclass="bg-filled-50">
464              <div class="messagecontainer error"><%=HTML.encodeTags(cc.getMessage())%></div>
465            </tbl:panel>
466            <%
467            cc.setMessage(null);
468          }
469          int index = cc.getPage()*cc.getRowsPerPage();
470          if (diskUsage != null)
471          {
472            while (diskUsage.hasNext())
473            {
474              DiskUsage du = diskUsage.next();
475              DiskConsumable item = null;
476              boolean hasReadPermission = true;
477              boolean hasWritePermission = false;
478              boolean isRemoved = false;
479              int consumableId = 0;
480              try
481              {
482                item = du.getItem();
483                consumableId = item.getId();
484                hasWritePermission = item.hasPermission(Permission.WRITE);
485              }
486              catch (PermissionDeniedException ex)
487              {
488                hasReadPermission = false;
489              }
490              String name = "";
491              String description = "";
492              if (item instanceof File)
493              {
494                File file = (File)item;
495                name = file.getPath().toString();
496                description = file.getDescription();
497              }
498              else if (item instanceof Nameable)
499              {
500                Nameable nameable = (Nameable)item;
501                name = nameable.getName();
502                description = nameable.getDescription();
503              }
504              else if (item != null)
505              {
506                name = item.toString();
507              }
508              if (item instanceof Removable)
509              {
510                isRemoved = ((Removable)item).isRemoved();
511              }
512              String link = hasReadPermission ? 
513                Base.getLink(ID, HTML.encodeTags(name), du.getItemType(), 
514                consumableId, hasWritePermission) : "<i>- denied -</i>";
515              index++;
516              numListed++;
517              %>
518              <tbl:row>
519                <tbl:header 
520                  clazz="index"
521                  ><%=index%></tbl:header>
522                <tbl:header 
523                  clazz="check" 
524                  ><input 
525                    type="checkbox" 
526                    name="item:<%=du.getItemType().name()%>" 
527                    value="<%=consumableId%>"
528                  ></tbl:header>
529                <tbl:header 
530                  clazz="icons" 
531                  ><base:icon 
532                    image="deleted.png" 
533                    tooltip="This item has been marked for deletion" 
534                    visible="<%=isRemoved%>"
535                  />&nbsp;</tbl:header>
536                <tbl:cell column="type"><%=du.getItemType()%></tbl:cell>
537                <tbl:cell column="name"><%=link%></tbl:cell>
538                <tbl:cell column="bytes"><%=Values.formatBytes(du.getBytes())%></tbl:cell>
539                <tbl:cell column="location"><%=du.getLocation()%></tbl:cell>
540                <tbl:cell column="owner"><base:propertyvalue item="<%=du%>" property="user" /></tbl:cell>
541                <tbl:cell column="group"><base:propertyvalue item="<%=du%>" property="group" /></tbl:cell>
542                <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell>
543              </tbl:row>
544              <%
545              }
546            }
547            if (numListed == 0)
548            {
549              %>
550              <tbl:panel subclass="bg-filled-50">
551                <div class="messagecontainer note">
552                <%=totalCount == 0 ? "No items were found" : "No items on this page. Please select another page!" %>
553                </div>
554              </tbl:panel>
555              <%
556            }
557          %>
558          </tbl:rows>
559        </tbl:data>
560      </tbl:table>
561      </base:section>
562    </t:tab>
563    </t:tabcontrol>
564
565  </base:body>
566  </base:page>
567  <%
568}
569finally
570{
571  if (dc != null) dc.close();
572}
573
574%>
Note: See TracBrowser for help on using the repository browser.