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