source: trunk/www/admin/diskusage/details/view_details.jsp @ 6621

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

References #1890: Improve skinnability of BASE

Getting rid of some more hardcoded color values.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 16.4 KB
Line 
1<%-- $Id: view_details.jsp 6621 2014-11-24 13:15:23Z 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        >
311        <tbl:hidden
312          name="item_type"
313          value="<%=itemType.name()%>"
314        />
315        <tbl:columndef
316          id="type"
317          property="itemType"
318          datatype="int"
319          title="Item type"
320          enumeration="<%=itemTypes%>"
321          filterable="true"
322          sortable="true"
323          show="always"
324        />
325        <tbl:columndef 
326          id="name"
327          title="Name"
328          show="always" 
329        />
330        <tbl:columndef 
331          id="bytes"
332          property="bytes"
333          datatype="long"
334          title="Bytes"
335          sortable="true"
336          filterable="true"
337          exportable="true"
338          unit="<%=bytes%>"
339        />
340        <tbl:columndef 
341          id="location"
342          property="location"
343          datatype="int"
344          title="Location"
345          enumeration="<%=locations%>"
346          filterable="true"
347          sortable="true"
348        />
349        <tbl:columndef 
350          id="owner"
351          property="user.name"
352          datatype="string"
353          title="Owner"
354          sortable="true" 
355          filterable="true"
356          exportable="true"
357        />
358        <tbl:columndef 
359          id="group"
360          property="group.name"
361          datatype="string"
362          title="Group"
363          sortable="true" 
364          filterable="true"
365          exportable="true"
366        />
367        <tbl:columndef 
368          id="description"
369          title="Description"
370        />
371        <div class="panelgroup topborder leftborder rightborder bg-filled-50">
372          <tbl:toolbar subclass="bottomborder">
373            <tbl:button 
374              id="btnDeleteItems"
375              image="delete.png"
376              title="Delete" 
377              tooltip="Mark the selected items for deletion" 
378              disabled="<%=totalCount <= 0%>"
379            />
380            <tbl:button 
381              id="btnRestoreItems"
382              image="restore.png"
383              title="Restore" 
384              tooltip="Restore the selected items"
385              disabled="<%=totalCount <= 0%>"
386            />
387            <tbl:button 
388              id="btnShareItems"
389              image="share.png"
390              title="Share&hellip;" 
391              tooltip="Share the selected items"
392              disabled="<%=totalCount <= 0%>"
393            />
394            <tbl:button 
395              id="btnColumns"
396              image="columns.png" 
397              title="Columns&hellip;" 
398              tooltip="Show, hide and re-order columns" 
399            />
400          </tbl:toolbar>
401          <tbl:panel>
402            <tbl:presetselector
403              disableremoved="true"
404            />
405            <tbl:navigator
406              page="<%=cc.getPage()%>" 
407              rowsperpage="<%=cc.getRowsPerPage()%>" 
408              totalrows="<%=totalCount%>"
409            />
410          </tbl:panel>
411        </div>
412        <tbl:data>
413          <tbl:headers>
414            <tbl:headerrow>
415              <tbl:header colspan="3" />
416              <tbl:columnheaders />
417            </tbl:headerrow>
418            <tbl:headerrow>
419              <tbl:header subclass="index" />
420              <tbl:header 
421                subclass="check"
422                ><base:icon 
423                  id="check.uncheck"
424                  image="check_uncheck.png" 
425                  tooltip="Check/uncheck all" 
426                   
427                /></tbl:header>
428              <tbl:header 
429                subclass="icons" 
430                />
431              <tbl:propertyfilter />
432            </tbl:headerrow>
433          </tbl:headers>
434          <tbl:rows>
435          <%
436          if (cc.getMessage() != null)
437          {
438            %>
439            <tbl:panel subclass="bg-filled-50">
440              <div class="messagecontainer error"><%=HTML.encodeTags(cc.getMessage())%></div>
441            </tbl:panel>
442            <%
443            cc.setMessage(null);
444          }
445          int index = cc.getPage()*cc.getRowsPerPage();
446          if (diskUsage != null)
447          {
448            while (diskUsage.hasNext())
449            {
450              DiskUsage du = diskUsage.next();
451              DiskConsumable item = null;
452              boolean hasReadPermission = true;
453              boolean hasWritePermission = false;
454              boolean isRemoved = false;
455              int consumableId = 0;
456              try
457              {
458                item = du.getItem();
459                consumableId = item.getId();
460                hasWritePermission = item.hasPermission(Permission.WRITE);
461              }
462              catch (PermissionDeniedException ex)
463              {
464                hasReadPermission = false;
465              }
466              String name = "";
467              String description = "";
468              if (item instanceof File)
469              {
470                File file = (File)item;
471                name = file.getPath().toString();
472                description = file.getDescription();
473              }
474              else if (item instanceof Nameable)
475              {
476                Nameable nameable = (Nameable)item;
477                name = nameable.getName();
478                description = nameable.getDescription();
479              }
480              else if (item != null)
481              {
482                name = item.toString();
483              }
484              if (item instanceof Removable)
485              {
486                isRemoved = ((Removable)item).isRemoved();
487              }
488              String link = hasReadPermission ? 
489                Base.getLink(ID, HTML.encodeTags(name), du.getItemType(), 
490                consumableId, hasWritePermission) : "<i>- denied -</i>";
491              index++;
492              numListed++;
493              %>
494              <tbl:row>
495                <tbl:header 
496                  clazz="index"
497                  ><%=index%></tbl:header>
498                <tbl:header 
499                  clazz="check" 
500                  ><input 
501                    type="checkbox" 
502                    name="item:<%=du.getItemType().name()%>" 
503                    value="<%=consumableId%>"
504                  ></tbl:header>
505                <tbl:header 
506                  clazz="icons" 
507                  ><base:icon 
508                    image="deleted.png" 
509                    tooltip="This item has been marked for deletion" 
510                    visible="<%=isRemoved%>"
511                  />&nbsp;</tbl:header>
512                <tbl:cell column="type"><%=du.getItemType()%></tbl:cell>
513                <tbl:cell column="name"><%=link%></tbl:cell>
514                <tbl:cell column="bytes"><%=Values.formatBytes(du.getBytes())%></tbl:cell>
515                <tbl:cell column="location"><%=du.getLocation()%></tbl:cell>
516                <tbl:cell column="owner"><base:propertyvalue item="<%=du%>" property="user" /></tbl:cell>
517                <tbl:cell column="group"><base:propertyvalue item="<%=du%>" property="group" /></tbl:cell>
518                <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell>
519              </tbl:row>
520              <%
521              }
522            }
523            if (numListed == 0)
524            {
525              %>
526              <tbl:panel subclass="bg-filled-50">
527                <div class="messagecontainer note">
528                <%=totalCount == 0 ? "No items were found" : "No items on this page. Please select another page!" %>
529                </div>
530              </tbl:panel>
531              <%
532            }
533          %>
534          </tbl:rows>
535        </tbl:data>
536      </tbl:table>
537      </base:section>
538    </t:tab>
539    </t:tabcontrol>
540
541  </base:body>
542  </base:page>
543  <%
544}
545finally
546{
547  if (dc != null) dc.close();
548}
549
550%>
Note: See TracBrowser for help on using the repository browser.