source: trunk/www/admin/diskusage/list_users.jsp @ 7943

Last change on this file since 7943 was 7943, checked in by Nicklas Nordborg, 2 years ago

Merged BASE 3.18.1 to the trunk.

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.ButtonAction" 
63  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
64  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
65  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
66  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
67  import="java.util.List"
68  import="java.util.Map"
69%>
70<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
71<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
72<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
73<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
74<%!
75  private static final Item itemType = Item.DISKUSAGE;
76  private static final String subContext = "perUser";
77  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST, subContext);
78%>
79<%
80final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
81final String ID = sc.getId();
82final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null);
83final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
84final boolean impersonatePermission = sc.hasSystemPermission(Permission.ACT_AS_ANOTHER_USER);
85final boolean writePermission = sc.hasPermission(Permission.WRITE, Item.USER);
86final String showStatistics = Values.getString(cc.getSetting("showStatistics"), "full");
87
88final boolean hasLocation = "location".equals(showStatistics) || "full".equals(showStatistics);
89final boolean hasQuotaType = "quotaType".equals(showStatistics) || "full".equals(showStatistics);
90
91final DbControl dc = sc.newDbControl();
92ItemResultIterator<User> users = null;
93try
94{
95  DiskUsageStatistics du = sc.getSessionSetting("diskUsageStatistics");
96  if (du == null)
97  {
98    du = DiskUsage.getStatistics(dc);
99    sc.setSessionSetting("diskUsageStatistics", du);
100  }
101  du.setDbControl(dc);
102  List<QuotaType> quotaTypes = du.getQuotaTypes();
103 
104  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
105  try
106  {
107    final ItemQuery<User> query = Base.getConfiguredQuery(dc, cc, jspContext, true, User.getQuery(), mode);
108    query.include(Include.ALL);
109    users = query.iterate(dc);
110  }
111  catch (Throwable t)
112  {
113    cc.setMessage(t.getMessage());
114  }
115  int numListed = 0;
116  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
117  ExtensionsInvoker<ListColumnAction<User,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
118  %>
119  <base:page title="Disk usage" id="list-users">
120  <base:head scripts="table.js,tabcontrol-2.js,~diskusage.js" styles="table.css,toolbar.css,headertabcontrol.css">
121    <ext:scripts context="<%=jspContext%>" />
122    <ext:stylesheets context="<%=jspContext%>" />
123    <style>
124    table.special
125    {
126      border-width: 1px;
127      margin: 2px;
128      border-collapse: collapse;
129      width: calc(100% - 6px);
130    }
131    table.special td, table.special th
132    {
133      text-align: right;
134      border-right-width: 1px;
135      border-right-style: dotted;
136      padding: 1px 2px 1px 2px;
137    }
138    </style>
139  </base:head>
140 
141  <base:body>
142    <h1>Disk usage</h1>
143    <t:tabcontrol 
144      id="main" 
145      subclass="mastertabcontrol content" 
146      active="users">
147    <t:tab id="overview" title="Overview" data-cmd="Overview"/>
148    <t:tab id="users" title="Per user" data-cmd="ListUsers">
149    <tbl:table 
150      id="users" 
151      columns="<%=cc.getSetting("columns")%>"
152      sortby="<%=cc.getSortProperty()%>" 
153      direction="<%=cc.getSortDirection()%>"
154      action="index.jsp"
155      sc="<%=sc%>"
156      item="<%=itemType%>"
157      subcontext="<%=subContext%>"
158      filterrows="<%=cc.getFilterRows()%>"
159      subclass="fulltable"
160      stickyheaders="name"
161      >
162      <tbl:hidden 
163        name="subcontext"
164        value="<%=subContext%>"
165      />
166      <tbl:columndef 
167        id="name"
168        property="name"
169        datatype="string"
170        title="Name"
171        sortable="true" 
172        filterable="true"
173        exportable="true"
174        show="always" 
175      />
176      <tbl:columndef 
177        id="id"
178        clazz="uniquecol"
179        property="id"
180        datatype="int"
181        title="ID"
182        sortable="true"
183        filterable="true"
184        exportable="true"
185      />
186      <tbl:columndef
187        id="diskUsage"
188        title="Disk usage summary"
189        show="always"
190      />
191      <tbl:columndef 
192        id="login"
193        clazz="uniquecol"
194        property="login"
195        datatype="string"
196        title="Login"
197        sortable="true" 
198        filterable="true"
199        exportable="true"
200      />
201      <tbl:columndef 
202        id="systemId"
203        clazz="uniquecol"
204        property="systemId"
205        datatype="string"
206        title="System ID"
207        sortable="true"
208        filterable="true"
209        exportable="true"
210      />
211      <tbl:columndef 
212        id="externalId"
213        clazz="uniquecol"
214        property="externalId"
215        datatype="string"
216        title="External ID"
217        sortable="true" 
218        filterable="true"
219        exportable="true"
220      />
221      <tbl:columndef 
222        id="expirationDate"
223        property="expirationDate"
224        datatype="date"
225        title="Expiration date"
226        sortable="true" 
227        filterable="true"
228        exportable="true"
229        formatter="<%=FormatterFactory.getDateFormatter(sc)%>"
230      />
231      <tbl:columndef 
232        id="disabled"
233        property="disabled"
234        datatype="boolean"
235        title="Disabled"
236        sortable="true" 
237        filterable="true"
238        exportable="true"
239      />
240      <tbl:columndef 
241        id="multiuserAccount"
242        property="multiuserAccount"
243        datatype="boolean"
244        title="Multi-user account"
245        sortable="true" 
246        filterable="true"
247        exportable="true"
248      />
249      <tbl:columndef 
250        id="organisation"
251        property="organisation"
252        datatype="string"
253        title="Organisation"
254        sortable="true" 
255        filterable="true"
256        exportable="true"
257      />
258      <tbl:columndef 
259        id="address"
260        property="address"
261        datatype="string"
262        title="Address"
263        sortable="true" 
264        filterable="true"
265        exportable="true"
266      />
267      <tbl:columndef 
268        id="email"
269        property="email"
270        datatype="string"
271        title="Email"
272        sortable="true" 
273        filterable="true"
274        exportable="true"
275      />
276      <tbl:columndef 
277        id="phone"
278        property="phone"
279        datatype="string"
280        title="Phone"
281        sortable="true" 
282        filterable="true"
283        exportable="true"
284      />
285      <tbl:columndef 
286        id="fax"
287        property="fax"
288        datatype="string"
289        title="Fax"
290        sortable="true" 
291        filterable="true"
292        exportable="true"
293      />
294      <tbl:columndef 
295        id="url"
296        property="url"
297        datatype="string"
298        title="Url"
299        sortable="true" 
300        filterable="true"
301        exportable="true"
302      />
303      <tbl:columndef 
304        id="quota"
305        property="quota.name"
306        datatype="string"
307        title="Quota"
308        sortable="true" 
309        filterable="true"
310        exportable="true"
311      />
312      <tbl:columndef 
313        id="quotagroup"
314        property="quotaGroup.name"
315        datatype="string"
316        title="Quota group"
317        sortable="true" 
318        filterable="true"
319        exportable="true"
320      />
321      <tbl:columndef 
322        id="description"
323        property="description"
324        datatype="string"
325        title="Description" 
326        sortable="true" 
327        filterable="true" 
328        exportable="true"
329      />
330      <tbl:columndef 
331        id="xt-columns" 
332        extensions="<%=columnsInvoker%>" 
333        jspcontext="<%=jspContext%>" 
334      />
335      <div class="panelgroup bg-filled-50 bottomborder">
336        <tbl:toolbar
337          visible="<%=mode.hasToolbar()%>"
338          subclass="bottomborder"
339          >
340          <tbl:button 
341            id="btnColumns"
342            image="columns.png"
343            title="Columns&hellip;" 
344            tooltip="Show, hide and re-order columns" 
345          />
346          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
347            wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
348        </tbl:toolbar>
349        <tbl:panel>
350          <tbl:presetselector />
351          <tbl:navigator
352            page="<%=cc.getPage()%>" 
353            rowsperpage="<%=cc.getRowsPerPage()%>" 
354            totalrows="<%=users == null ? 0 : users.getTotalCount()%>" 
355          />
356          <b>Show summary</b>
357          <span id="changeSummary">
358          <label><input type="radio" name="showStatistics" value="total"
359            <%="total".equals(showStatistics) ? "checked" : ""%>>Total only</label>
360          <label><input type="radio" name="showStatistics" value="location"
361            <%="location".equals(showStatistics) ? "checked" : ""%>>Per location</label>
362          <label><input type="radio" name="showStatistics" value="quotaType"
363            <%="quotaType".equals(showStatistics) ? "checked" : ""%>>Per quota type</label>
364          <label><input type="radio" name="showStatistics" value="full"
365            <%="full".equals(showStatistics) ? "checked" : ""%>>Full</label>
366          </span>
367        </tbl:panel>
368      </div>
369      <tbl:data>
370        <tbl:headers>
371          <tbl:headerrow>
372            <tbl:header clazz="row-index bg-filled-100" />
373            <tbl:columnheaders />
374          </tbl:headerrow>
375          <%
376          int numFilters = cc.getNumPropertyFilters();
377          int numRows = cc.getFilterRows();
378          for (int filterNo = 0; filterNo < numRows; filterNo++)
379          {
380            boolean lastRow = filterNo == numRows-1;
381            %>
382            <tbl:headerrow>
383              <tbl:header subclass="row-index bg-filled-100">
384                <div class="index-<%=mode.getName()%>">
385                  <div class="index"></div>
386                  <div class="check">
387                    <base:icon 
388                      subclass="link table-check"
389                      image="check_uncheck.png" 
390                      tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
391                      visible="<%=lastRow && mode.hasCheck()%>"
392                    />
393                  </div>
394                  <div class="icons">
395                    <base:icon
396                      subclass="link table-filter-row-action"
397                      image="add.png"
398                      tooltip="Add extra filter row"
399                      visible="<%=lastRow%>"
400                    /><base:icon
401                      subclass="link table-filter-row-action"
402                      image="remove.png"
403                      tooltip="Remove this filter row"
404                      visible="<%=numRows > 1 || numFilters > 0 %>"
405                      data-remove-row="<%=filterNo%>"
406                    />
407                  </div>
408                </div>
409              </tbl:header>
410              <tbl:propertyfilter row="<%=filterNo%>" />
411            </tbl:headerrow>
412            <%
413          }
414          %>
415          <tbl:columnsubtitles />
416        </tbl:headers>
417        <tbl:rows>
418          <%
419          if (cc.getMessage() != null)
420          {
421            %>
422            <tbl:panel subclass="bg-filled-50">
423              <div class="messagecontainer error"><%=cc.getMessage()%></div>
424            </tbl:panel>
425            <%
426            cc.setMessage(null);
427          }
428          int index = cc.getPage()*cc.getRowsPerPage();
429          int selectedItemId = cc.getId();
430          if (users != null)
431          {           
432            while (users.hasNext())
433            {
434              User item = users.next();
435              int itemId = item.getId();
436              String name = HTML.encodeTags(item.getName());
437              String tooltip = mode.isSelectionMode() ? 
438                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
439              index++;
440              numListed++;
441              %>
442              <tbl:row>
443                <tbl:header clazz="row-index bg-filled-100">
444                  <div class="index-<%=mode.getName()%>">
445                    <div class="index <%=index>999?"index-smaller":""%>"><%=index%></div>
446                    <div class="check">
447                      <base:input
448                        type="checkbox" 
449                        name="<%=itemId%>" 
450                        value="<%=itemId%>" 
451                        title="<%=name%>" 
452                        checked="<%=cc.getSelected().contains(itemId)%>"
453                        visible="<%=mode.hasCheck()%>"
454                      />
455                      <base:input 
456                        type="radio" 
457                        name="item_id" 
458                        value="<%=itemId%>" 
459                        title="<%=name%>" 
460                        checked="<%=selectedItemId == itemId%>"
461                        visible="<%=mode.hasRadio()%>"
462                      />
463                    </div>
464                    <div class="icons">
465                      <base:icon 
466                        image="deleted.png"
467                        tooltip="This item has been scheduled for deletion" 
468                        visible="<%=item.isRemoved()%>"
469                      /><base:icon
470                        subclass="link auto-init"
471                        data-auto-init="impersonate-user"
472                        data-user-id="<%=itemId%>"
473                        image="login.png"
474                        tooltip="Login as this user"
475                        visible="<%=impersonatePermission%>"
476                      />
477                    </div>
478                  </div>
479                </tbl:header>
480                <tbl:cell column="name"><div 
481                  class="link auto-init"
482                  data-auto-init="item-link"
483                  data-item-type="USER"
484                  data-item-id="<%=itemId%>"
485                  data-no-edit="<%=writePermission ? 0 : 1 %>"
486                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
487                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
488                <tbl:cell column="diskUsage" style="padding: 0px;">
489                  <%
490                  DiskUsageStatistics.Summary summary = du.getSummary(item);
491                  long total = summary.getTotal();
492                  if (total > 0 && (hasLocation || hasQuotaType))
493                  {
494                    %>
495                    <table class="special bottomborder">
496                    <%
497                    if (hasLocation)
498                    {
499                      %>
500                      <tr class="bottomborder bg-filled-100">
501                        <%
502                        if (hasQuotaType)
503                        {
504                          %>
505                          <th>&nbsp;</th>
506                          <%
507                        }
508                        %>
509                        <th>Total</th>
510                        <td>Primary</td>
511                        <td>External</td>
512                        <td>Offline</td>
513                      </tr>
514                      <%
515                    }
516                    %> 
517                    <tr class="bottomborder <%=!hasLocation ? "bg-filled-100" : "" %>">
518                      <%
519                      if (hasQuotaType)
520                      {
521                        %>
522                        <th>Total</th>
523                        <%
524                      }
525                      %>
526                      <td><%=Values.formatBytes(total)%></td>
527                      <%
528                      if (hasLocation)
529                      {
530                        %>
531                        <td><%=Values.formatBytes(summary.getTotal(Location.PRIMARY))%></td>
532                        <td><%=Values.formatBytes(summary.getTotal(Location.EXTERNAL))%></td>
533                        <td><%=Values.formatBytes(summary.getTotal(Location.OFFLINE))%></td>
534                        <%
535                      }
536                      %>
537                    </tr>
538                    <%
539                    if (hasQuotaType && total > 0)
540                    {
541                      for (QuotaType qt : quotaTypes)
542                      {
543                        %>
544                        <tr>
545                          <td><%=HTML.encodeTags(qt.getName())%></td>
546                          <td><%=Values.formatBytes(summary.getTotal(qt))%></td>
547                          <%
548                          if (hasLocation)
549                          {
550                            %>
551                            <td><%=Values.formatBytes(summary.getTotal(qt, Location.PRIMARY))%></td>
552                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.EXTERNAL)) : "n/a"%></td>
553                            <td><%=qt.getSystemId().equals(QuotaType.FILE) ? Values.formatBytes(summary.getTotal(qt, Location.OFFLINE)) : "n/a"%></td>
554                            <%
555                          }
556                          %>
557                        </tr>
558                        <%
559                      }
560                    }
561                    %>
562                    </table>
563                    <%
564                  }
565                  else
566                  {
567                    %>
568                    &nbsp;<%=Values.formatBytes(total)%>
569                    <%
570                  }
571                  if (total > 0)
572                  {
573                    %>
574                    <base:icon image="gonext.png" 
575                      subclass="link auto-init"
576                      data-auto-init="view-details"
577                      data-item-type="USER"
578                      data-item-id="<%=itemId %>">View details</base:icon>
579                    <%
580                  }
581                  %>
582                </tbl:cell>
583                <tbl:cell column="login"><%=HTML.encodeTags(item.getLogin())%></tbl:cell>
584                <tbl:cell column="systemId"><%=Values.getString(item.getSystemId())%></tbl:cell>
585                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
586                <tbl:cell column="expirationDate" value="<%=item.getExpirationDate()%>" />
587                <tbl:cell column="disabled"><%=item.isDisabled() ? "yes" : "no" %></tbl:cell>
588                <tbl:cell column="multiuserAccount"><%=item.isMultiuserAccount() ? "yes" : "no" %></tbl:cell>
589                <tbl:cell column="organisation"><%=HTML.encodeTags(item.getOrganisation())%></tbl:cell>
590                <tbl:cell column="address"><%=HTML.encodeTags(item.getAddress())%></tbl:cell>
591                <tbl:cell column="email"><%=HTML.encodeTags(item.getEmail())%></tbl:cell>
592                <tbl:cell column="phone"><%=HTML.encodeTags(item.getPhone())%></tbl:cell>
593                <tbl:cell column="fax"><%=HTML.encodeTags(item.getFax())%></tbl:cell>
594                <tbl:cell column="url"><%=HTML.encodeTags(item.getUrl())%></tbl:cell>
595                <tbl:cell column="quota"
596                  ><base:propertyvalue 
597                    item="<%=item%>" 
598                    property="quota"
599                    enableEditLink="<%=mode.hasEditLink()%>" 
600                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
601                  /></tbl:cell>
602                <tbl:cell column="quotagroup"
603                  ><base:propertyvalue 
604                    item="<%=item%>" 
605                    property="quotaGroup"
606                    enableEditLink="<%=mode.hasEditLink()%>" 
607                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
608                  /></tbl:cell>
609                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
610                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
611                  <tbl:cell column="xt-columns" />
612                </tbl:xt-cells>
613              </tbl:row>
614              <%
615              }
616            }
617            if (numListed == 0)
618            {
619              %>
620              <tbl:panel subclass="bg-filled-50">
621                <div class="messagecontainer note">
622                <%=users == null || users.getTotalCount() == 0 ? "No users were found" : "No users on this page. Please select another page!" %>
623                </div>
624              </tbl:panel>
625              <%
626            }
627          %>
628        </tbl:rows>
629      </tbl:data>
630      </tbl:table>
631    </t:tab>
632    <t:tab id="groups" title="Per group" data-cmd="ListGroups"/>
633    </t:tabcontrol>
634
635  </base:body>
636  </base:page>
637  <%
638}
639finally
640{
641  if (users != null) users.close();
642  if (dc != null) dc.close();
643}
644%>
Note: See TracBrowser for help on using the repository browser.