source: trunk/www/admin/diskusage/list_users.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: 19.2 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.User"
32  import="net.sf.basedb.core.Group"
33  import="net.sf.basedb.core.Role"
34  import="net.sf.basedb.core.Type"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.Include"
37  import="net.sf.basedb.core.ItemResultIterator"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.ItemContext"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.PluginDefinition"
42  import="net.sf.basedb.core.DiskUsage"
43  import="net.sf.basedb.core.DiskUsageStatistics"
44  import="net.sf.basedb.core.QuotaType"
45  import="net.sf.basedb.core.Location"
46  import="net.sf.basedb.core.query.Orders"
47  import="net.sf.basedb.core.query.Hql"
48  import="net.sf.basedb.core.query.Restrictions"
49  import="net.sf.basedb.core.query.Expressions"
50  import="net.sf.basedb.core.plugin.GuiContext"
51  import="net.sf.basedb.core.plugin.Plugin"
52  import="net.sf.basedb.util.Enumeration"
53  import="net.sf.basedb.clients.web.Base"
54  import="net.sf.basedb.clients.web.ModeInfo"
55  import="net.sf.basedb.clients.web.PermissionUtil"
56  import="net.sf.basedb.clients.web.util.HTML"
57  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
58  import="net.sf.basedb.util.Values"
59  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
60  import="net.sf.basedb.clients.web.extensions.JspContext"
61  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
62  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
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 = "perUser";
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 impersonatePermission = sc.hasSystemPermission(Permission.ACT_AS_ANOTHER_USER);
83final boolean writePermission = sc.hasPermission(Permission.WRITE, Item.USER);
84final String showStatistics = Values.getString(cc.getSetting("showStatistics"), 
85  Application.hasSecondaryStorage() ? "full" : "quotaType");
86
87final boolean hasLocation = "location".equals(showStatistics) || "full".equals(showStatistics);
88final boolean hasQuotaType = "quotaType".equals(showStatistics) || "full".equals(showStatistics);
89
90final DbControl dc = sc.newDbControl();
91ItemResultIterator<User> users = null;
92try
93{
94  DiskUsageStatistics du = (DiskUsageStatistics)sc.getSessionSetting("diskUsageStatistics");
95  if (du == null)
96  {
97    du = DiskUsage.getStatistics(dc);
98    sc.setSessionSetting("diskUsageStatistics", du);
99  }
100  du.setDbControl(dc);
101  List<QuotaType> quotaTypes = du.getQuotaTypes();
102 
103  try
104  {
105    final ItemQuery<User> query = Base.getConfiguredQuery(dc, cc, true, User.getQuery(), mode);
106    query.include(Include.ALL);
107    users = 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-users">
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 
140  <base:body>
141    <h1>Disk usage</h1>
142    <t:tabcontrol 
143      id="main" 
144      subclass="mastertabcontrol content" 
145      active="users">
146    <t:tab id="overview" title="Overview" data-cmd="Overview"/>
147    <t:tab id="users" title="Per user" data-cmd="ListUsers">
148    <tbl:table 
149      id="users" 
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="login"
190        clazz="uniquecol"
191        property="login"
192        datatype="string"
193        title="Login"
194        sortable="true" 
195        filterable="true"
196        exportable="true"
197      />
198      <tbl:columndef 
199        id="systemId"
200        clazz="uniquecol"
201        property="systemId"
202        datatype="string"
203        title="System ID"
204        sortable="true"
205        filterable="true"
206        exportable="true"
207      />
208      <tbl:columndef 
209        id="externalId"
210        clazz="uniquecol"
211        property="externalId"
212        datatype="string"
213        title="External ID"
214        sortable="true" 
215        filterable="true"
216        exportable="true"
217      />
218      <tbl:columndef 
219        id="expirationDate"
220        property="expirationDate"
221        datatype="date"
222        title="Expiration date"
223        sortable="true" 
224        filterable="true"
225        exportable="true"
226        formatter="<%=FormatterFactory.getDateFormatter(sc)%>"
227      />
228      <tbl:columndef 
229        id="disabled"
230        property="disabled"
231        datatype="boolean"
232        title="Disabled"
233        sortable="true" 
234        filterable="true"
235        exportable="true"
236      />
237      <tbl:columndef 
238        id="multiuserAccount"
239        property="multiuserAccount"
240        datatype="boolean"
241        title="Multi-user account"
242        sortable="true" 
243        filterable="true"
244        exportable="true"
245      />
246      <tbl:columndef 
247        id="organisation"
248        property="organisation"
249        datatype="string"
250        title="Organisation"
251        sortable="true" 
252        filterable="true"
253        exportable="true"
254      />
255      <tbl:columndef 
256        id="address"
257        property="address"
258        datatype="string"
259        title="Address"
260        sortable="true" 
261        filterable="true"
262        exportable="true"
263      />
264      <tbl:columndef 
265        id="email"
266        property="email"
267        datatype="string"
268        title="Email"
269        sortable="true" 
270        filterable="true"
271        exportable="true"
272      />
273      <tbl:columndef 
274        id="phone"
275        property="phone"
276        datatype="string"
277        title="Phone"
278        sortable="true" 
279        filterable="true"
280        exportable="true"
281      />
282      <tbl:columndef 
283        id="fax"
284        property="fax"
285        datatype="string"
286        title="Fax"
287        sortable="true" 
288        filterable="true"
289        exportable="true"
290      />
291      <tbl:columndef 
292        id="url"
293        property="url"
294        datatype="string"
295        title="Url"
296        sortable="true" 
297        filterable="true"
298        exportable="true"
299      />
300      <tbl:columndef 
301        id="quota"
302        property="quota.name"
303        datatype="string"
304        title="Quota"
305        sortable="true" 
306        filterable="true"
307        exportable="true"
308      />
309      <tbl:columndef 
310        id="quotagroup"
311        property="quotaGroup.name"
312        datatype="string"
313        title="Quota group"
314        sortable="true" 
315        filterable="true"
316        exportable="true"
317      />
318      <tbl:columndef 
319        id="description"
320        property="description"
321        datatype="string"
322        title="Description" 
323        sortable="true" 
324        filterable="true" 
325        exportable="true"
326      />
327      <tbl:columndef 
328        id="xt-columns" 
329        extensions="<%=columnsInvoker%>" 
330        jspcontext="<%=jspContext%>" 
331      />
332      <div class="panelgroup bg-filled-50 bottomborder">
333        <tbl:toolbar
334          visible="<%=mode.hasToolbar()%>"
335          subclass="bottomborder"
336          >
337          <tbl:button 
338            id="btnColumns"
339            image="columns.png"
340            title="Columns&hellip;" 
341            tooltip="Show, hide and re-order columns" 
342          />
343          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
344            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
345        </tbl:toolbar>
346        <tbl:panel>
347          <tbl:presetselector />
348          <tbl:navigator
349            page="<%=cc.getPage()%>" 
350            rowsperpage="<%=cc.getRowsPerPage()%>" 
351            totalrows="<%=users == null ? 0 : users.getTotalCount()%>" 
352          />
353          <b>Show summary</b>
354          <span id="changeSummary">
355          <label><input type="radio" name="showStatistics" value="total"
356            <%="total".equals(showStatistics) ? "checked" : ""%>>Total only</label>
357          <label><input type="radio" name="showStatistics" value="location"
358            <%="location".equals(showStatistics) ? "checked" : ""%>>Per location</label>
359          <label><input type="radio" name="showStatistics" value="quotaType"
360            <%="quotaType".equals(showStatistics) ? "checked" : ""%>>Per quota type</label>
361          <label><input type="radio" name="showStatistics" value="full"
362            <%="full".equals(showStatistics) ? "checked" : ""%>>Full</label>
363          </span>
364        </tbl:panel>
365      </div>
366      <tbl:data>
367        <tbl:headers>
368          <tbl:headerrow>
369            <tbl:header colspan="3" />
370            <tbl:columnheaders />
371          </tbl:headerrow>
372          <tbl:headerrow>
373            <tbl:header subclass="index" />
374            <tbl:header 
375              subclass="check" 
376              visible="<%=mode.hasCheck()%>"
377              ><base:icon 
378                id="check.uncheck"
379                image="check_uncheck.png" 
380                tooltip="Check/uncheck all" 
381                 
382              /></tbl:header>
383            <tbl:header 
384              subclass="check" 
385              visible="<%=mode.hasRadio()%>"
386              />
387            <tbl:header 
388              subclass="icons" 
389              visible="<%=mode.hasIcons()%>"
390              />
391            <tbl:propertyfilter />
392          </tbl:headerrow>
393        </tbl:headers>
394        <tbl:rows>
395          <%
396          if (cc.getMessage() != null)
397          {
398            %>
399            <tbl:panel subclass="bg-filled-50">
400              <div class="messagecontainer error"><%=cc.getMessage()%></div>
401            </tbl:panel>
402            <%
403            cc.setMessage(null);
404          }
405          int index = cc.getPage()*cc.getRowsPerPage();
406          int selectedItemId = cc.getId();
407          if (users != null)
408          {           
409            while (users.hasNext())
410            {
411              User item = users.next();
412              int itemId = item.getId();
413              String name = HTML.encodeTags(item.getName());
414              String tooltip = mode.isSelectionMode() ? 
415                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
416              index++;
417              numListed++;
418              %>
419              <tbl:row>
420                <tbl:header 
421                  clazz="index"
422                  ><%=index%></tbl:header>
423                <tbl:header 
424                  clazz="check" 
425                  visible="<%=mode.hasCheck()%>"
426                  ><input 
427                    type="checkbox" 
428                    name="<%=itemId%>" 
429                    value="<%=itemId%>" 
430                    title="<%=name%>" 
431                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
432                  ></tbl:header>
433                <tbl:header 
434                  clazz="check" 
435                  visible="<%=mode.hasRadio()%>"
436                  ><input 
437                    type="radio" 
438                    name="item_id" 
439                    value="<%=itemId%>" 
440                    title="<%=name%>" 
441                    <%=selectedItemId == itemId ? "checked" : ""%>
442                  ></tbl:header>
443                <tbl:header 
444                  clazz="icons" 
445                  visible="<%=mode.hasIcons()%>"
446                  ><base:icon 
447                    image="deleted.png" 
448                    tooltip="This item has been scheduled for deletion" 
449                    visible="<%=item.isRemoved()%>"
450                  /><base:icon
451                    subclass="link auto-init"
452                    data-auto-init="impersonate-user"
453                    data-user-id="<%=itemId%>"
454                    image="login.png"
455                    tooltip="Login as this user"
456                    visible="<%=impersonatePermission%>"
457                  /></tbl:header>
458                <tbl:cell column="name"><div 
459                  class="link auto-init"
460                  data-auto-init="item-link"
461                  data-item-type="USER"
462                  data-item-id="<%=itemId%>"
463                  data-no-edit="<%=writePermission ? 0 : 1 %>"
464                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
465                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
466                <tbl:cell column="diskUsage" style="padding: 0px;">
467                  <%
468                  DiskUsageStatistics.Summary summary = du.getSummary(item);
469                  long total = summary.getTotal();
470                  if (total > 0 && (hasLocation || hasQuotaType))
471                  {
472                    %>
473                    <table class="special bottomborder">
474                    <%
475                    if (hasLocation)
476                    {
477                      %>
478                      <tr class="bottomborder bg-filled-100">
479                        <%
480                        if (hasQuotaType)
481                        {
482                          %>
483                          <th>&nbsp;</th>
484                          <%
485                        }
486                        %>
487                        <th>Total</th>
488                        <td>Primary</td>
489                        <td>Secondary</td>
490                        <td>Offline</td>
491                        <td>External</td>
492                      </tr>
493                      <%
494                    }
495                    %> 
496                    <tr class="bottomborder <%=!hasLocation ? "bg-filled-100" : "" %>">
497                      <%
498                      if (hasQuotaType)
499                      {
500                        %>
501                        <th>Total</th>
502                        <%
503                      }
504                      %>
505                      <td><%=Values.formatBytes(total)%></td>
506                      <%
507                      if (hasLocation)
508                      {
509                        %>
510                        <td><%=Values.formatBytes(summary.getTotal(Location.PRIMARY))%></td>
511                        <td><%=Values.formatBytes(summary.getTotal(Location.SECONDARY))%></td>
512                        <td><%=Values.formatBytes(summary.getTotal(Location.OFFLINE))%></td>
513                        <td><%=Values.formatBytes(summary.getTotal(Location.EXTERNAL))%></td>
514                        <%
515                      }
516                      %>
517                    </tr>
518                    <%
519                    if (hasQuotaType && total > 0)
520                    {
521                      for (QuotaType qt : quotaTypes)
522                      {
523                        %>
524                        <tr>
525                          <td><%=HTML.encodeTags(qt.getName())%></td>
526                          <td><%=Values.formatBytes(summary.getTotal(qt))%></td>
527                          <%
528                          if (hasLocation)
529                          {
530                            %>
531                            <td><%=Values.formatBytes(summary.getTotal(qt, Location.PRIMARY))%></td>
532                            <td><%=qt.hasSecondaryLocation() ? Values.formatBytes(summary.getTotal(qt, Location.SECONDARY)) : "n/a"%></td>
533                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.OFFLINE)) : "n/a"%></td>
534                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.EXTERNAL)) : "n/a"%></td>
535                            <%
536                          }
537                          %>
538                        </tr>
539                        <%
540                      }
541                    }
542                    %>
543                    </table>
544                    <%
545                  }
546                  else
547                  {
548                    %>
549                    &nbsp;<%=Values.formatBytes(total)%>
550                    <%
551                  }
552                  if (total > 0)
553                  {
554                    %>
555                    <base:icon image="gonext.png" 
556                      subclass="link auto-init"
557                      data-auto-init="view-details"
558                      data-item-type="USER"
559                      data-item-id="<%=itemId %>">View details</base:icon>
560                    <%
561                  }
562                  %>
563                </tbl:cell>
564                <tbl:cell column="login"><%=HTML.encodeTags(item.getLogin())%></tbl:cell>
565                <tbl:cell column="systemId"><%=Values.getString(item.getSystemId())%></tbl:cell>
566                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
567                <tbl:cell column="expirationDate" value="<%=item.getExpirationDate()%>" />
568                <tbl:cell column="disabled"><%=item.isDisabled() ? "yes" : "no" %></tbl:cell>
569                <tbl:cell column="multiuserAccount"><%=item.isMultiuserAccount() ? "yes" : "no" %></tbl:cell>
570                <tbl:cell column="organisation"><%=HTML.encodeTags(item.getOrganisation())%></tbl:cell>
571                <tbl:cell column="address"><%=HTML.encodeTags(item.getAddress())%></tbl:cell>
572                <tbl:cell column="email"><%=HTML.encodeTags(item.getEmail())%></tbl:cell>
573                <tbl:cell column="phone"><%=HTML.encodeTags(item.getPhone())%></tbl:cell>
574                <tbl:cell column="fax"><%=HTML.encodeTags(item.getFax())%></tbl:cell>
575                <tbl:cell column="url"><%=HTML.encodeTags(item.getUrl())%></tbl:cell>
576                <tbl:cell column="quota"
577                  ><base:propertyvalue 
578                    item="<%=item%>" 
579                    property="quota"
580                    enableEditLink="<%=mode.hasEditLink()%>" 
581                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
582                  /></tbl:cell>
583                <tbl:cell column="quotagroup"
584                  ><base:propertyvalue 
585                    item="<%=item%>" 
586                    property="quotaGroup"
587                    enableEditLink="<%=mode.hasEditLink()%>" 
588                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
589                  /></tbl:cell>
590                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
591                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
592                  <tbl:cell column="xt-columns" />
593                </tbl:xt-cells>
594              </tbl:row>
595              <%
596              }
597            }
598            if (numListed == 0)
599            {
600              %>
601              <tbl:panel subclass="bg-filled-50">
602                <div class="messagecontainer note">
603                <%=users == null || users.getTotalCount() == 0 ? "No users were found" : "No users on this page. Please select another page!" %>
604                </div>
605              </tbl:panel>
606              <%
607            }
608          %>
609        </tbl:rows>
610      </tbl:data>
611      </tbl:table>
612    </t:tab>
613    <t:tab id="groups" title="Per group" data-cmd="ListGroups"/>
614    </t:tabcontrol>
615
616  </base:body>
617  </base:page>
618  <%
619}
620finally
621{
622  if (users != null) users.close();
623  if (dc != null) dc.close();
624}
625%>
Note: See TracBrowser for help on using the repository browser.