source: trunk/www/views/sessions/list_sessions.jsp @ 5425

Last change on this file since 5425 was 5425, checked in by Nicklas Nordborg, 13 years ago

References #1514: Fix character encoding of jsp files

I hope this fixes most of the issues, including the reporter list filtering in many places. Let's keep an eye open for more issues until it is time to release 2.16

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.4 KB
Line 
1<%-- $Id: list_sessions.jsp 5425 2010-09-23 13:30:07Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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 session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.Session"
31  import="net.sf.basedb.core.User"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.PluginDefinition"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.query.Hql"
41  import="net.sf.basedb.core.query.Restrictions"
42  import="net.sf.basedb.core.query.Expressions"
43  import="net.sf.basedb.core.plugin.GuiContext"
44  import="net.sf.basedb.core.plugin.Plugin"
45  import="net.sf.basedb.util.Enumeration"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.ModeInfo"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.util.Values"
51  import="net.sf.basedb.util.formatter.Formatter"
52  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
53  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
54  import="net.sf.basedb.clients.web.extensions.JspContext"
55  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
56  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
57  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
58  import="java.util.List"
59  import="java.util.Map"
60  import="java.util.Date"
61%>
62<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
63<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
64<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
65<%!
66  private static final Item itemType = Item.SESSION;
67  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
68%>
69<%
70final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
71final String ID = sc.getId();
72final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
73final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
74
75final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
76final String callback = request.getParameter("callback");
77final String title = mode.generateTitle("session", "sessions");
78final DbControl dc = sc.newDbControl();
79ItemResultIterator<Session> sessions = null;
80try
81{
82  final User user = cc.getInclude().contains(Include.OTHERS) ? 
83    null : User.getById(dc, sc.getLoggedInUserId());
84  final ItemQuery<Session> query = Base.getConfiguredQuery(cc, true, Session.getQuery(user), mode);
85
86  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
87  try
88  {
89    sessions = query.iterate(dc);
90  }
91  catch (Throwable t)
92  {
93    cc.setMessage(t.getMessage());
94  }
95  int numListed = 0;
96  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
97  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
98  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
99  %>
100  <base:page title="<%=title==null ? "Sessions" : title%>" type="<%=mode.getPageType()%>">
101  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
102    <ext:scripts context="<%=jspContext%>" />
103    <ext:stylesheets context="<%=jspContext%>" />
104    <script language="JavaScript">
105    var submitPage = 'index.jsp';
106    var formId = 'sessions';
107    function viewItem(itemId)
108    {
109      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
110    }
111    function itemOnClick(evt, itemId)
112    {
113      viewItem(itemId);
114    }
115    function configureColumns()
116    {
117      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
118    }
119    function runPlugin(cmd)
120    {
121      Table.submitToPopup(formId, cmd, 740, 540);
122    }
123    function returnSelected()
124    {
125      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
126      window.close();
127    }
128    function presetOnChange()
129    {
130      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
131    }
132    </script>
133  </base:head>
134 
135  <base:body>
136    <%
137    if (cc.getMessage() != null)
138    {
139      %>
140      <div class="error"><%=cc.getMessage()%></div>
141      <%
142      cc.setMessage(null);
143    }
144    %>
145    <tbl:table 
146      id="sessions" 
147      clazz="itemlist" 
148      columns="<%=cc.getSetting("columns")%>"
149      sortby="<%=cc.getSortProperty()%>" 
150      direction="<%=cc.getSortDirection()%>"
151      title="<%=title%>"
152      action="index.jsp"
153      sc="<%=sc%>"
154      item="<%=itemType%>"
155      >
156      <tbl:hidden 
157        name="mode" 
158        value="<%=mode.getName()%>" 
159      />
160      <tbl:hidden 
161        name="callback" 
162        value="<%=callback%>" 
163        skip="<%=callback == null%>" 
164      />
165      <tbl:columndef 
166        id="id"
167        clazz="uniquecol"
168        property="id"
169        datatype="int"
170        title="ID"
171        sortable="true"
172        filterable="true"
173        exportable="true"
174      />
175      <tbl:columndef 
176        id="loginTime"
177        property="loginTime"
178        datatype="timestamp"
179        title="Login time"
180        sortable="true" 
181        filterable="true"
182        exportable="true"
183        show="always" 
184      />
185      <tbl:columndef 
186        id="logoutTime"
187        property="logoutTime"
188        datatype="timestamp"
189        title="Logout time"
190        sortable="true" 
191        filterable="true"
192        exportable="true"
193        formatter="<%=dateTimeFormatter%>"
194      />
195      <tbl:columndef 
196        id="impersonated"
197        property="impersonated"
198        datatype="boolean"
199        title="Impersonated"
200        sortable="true" 
201        filterable="true"
202        exportable="true"
203      />
204      <tbl:columndef 
205        id="client"
206        property="client.name"
207        datatype="string"
208        title="Client application" 
209        sortable="true" 
210        filterable="true" 
211        exportable="true"
212      />
213      <tbl:columndef 
214        id="remoteId"
215        property="remoteId"
216        datatype="string"
217        title="Remote ID" 
218        sortable="true" 
219        filterable="true" 
220        exportable="true"
221      />
222      <tbl:columndef 
223        id="comment"
224        property="loginComment"
225        datatype="string"
226        title="Comment" 
227        sortable="true" 
228        filterable="true" 
229        exportable="true"
230      />
231      <tbl:columndef 
232        id="user"
233        property="user.name"
234        datatype="string"
235        title="User" 
236        sortable="true" 
237        filterable="true" 
238        exportable="true"
239      />
240      <tbl:columndef
241        id="permission"
242        title="Permission"
243      />
244      <tbl:toolbar
245        visible="<%=mode.hasToolbar()%>"
246        >
247        <tbl:button 
248          image="columns.gif" 
249          onclick="configureColumns()" 
250          title="Columns&hellip;" 
251          tooltip="Show, hide and re-order columns" 
252        />
253        <tbl:button 
254          image="export.gif" 
255          onclick="runPlugin('ExportItems')" 
256          title="Export&hellip;" 
257          tooltip="Export data" 
258          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
259        />
260        <tbl:button 
261          image="runplugin.gif" 
262          onclick="runPlugin('RunListPlugin')" 
263          title="Run plugin&hellip;" 
264          tooltip="Run a plugin" 
265          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
266        />
267        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
268          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
269      </tbl:toolbar>
270      <tbl:navigator
271        page="<%=cc.getPage()%>" 
272        rowsperpage="<%=cc.getRowsPerPage()%>" 
273        totalrows="<%=sessions == null ? 0 : sessions.getTotalCount()%>" 
274        visible="<%=mode.hasNavigator()%>"
275      />
276      <tbl:data>
277        <tbl:columns>
278        <tbl:presetselector 
279          clazz="columnheader"
280          colspan="3"
281          onchange="presetOnChange()"
282        />
283        </tbl:columns>
284
285        <tr>
286          <tbl:header 
287            clazz="index"
288            >&nbsp;</tbl:header>
289          <tbl:header 
290            clazz="check" 
291            visible="<%=mode.hasCheck()%>"
292            ><base:icon 
293              image="check_uncheck.gif" 
294              tooltip="Check/uncheck all" 
295              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
296            /></tbl:header>
297          <tbl:header 
298            clazz="check" 
299            visible="<%=mode.hasRadio()%>"
300            >&nbsp;</tbl:header>
301          <tbl:header 
302            clazz="icons" 
303            visible="<%=mode.hasIcons()%>"
304            >&nbsp;</tbl:header>
305          <tbl:propertyfilter />
306        </tr>
307         
308          <tbl:rows>
309          <%
310          int index = cc.getPage()*cc.getRowsPerPage();
311          int selectedItemId = cc.getId();
312          if (sessions != null)
313          {
314            String tooltip = mode.isSelectionMode() ?
315              "Select this item" : "View this item";
316            while (sessions.hasNext())
317            {
318              Session item = sessions.next();
319              int itemId = item.getId();
320              String name = "TODO";
321              index++;
322              numListed++;
323              %>
324              <tbl:row>
325                <tbl:header 
326                  clazz="index"
327                  ><%=index%></tbl:header>
328                <tbl:header 
329                  clazz="check" 
330                  visible="<%=mode.hasCheck()%>"
331                  ><input 
332                    type="checkbox" 
333                    name="<%=itemId%>" 
334                    value="<%=itemId%>" 
335                    title="<%=name%>" 
336                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
337                  ></tbl:header>
338                <tbl:header 
339                  clazz="check" 
340                  visible="<%=mode.hasRadio()%>"
341                  ><input 
342                    type="radio" 
343                    name="item_id" 
344                    value="<%=itemId%>" 
345                    title="<%=name%>" 
346                    <%=selectedItemId == itemId ? "checked" : ""%>
347                  ></tbl:header>
348                <tbl:header 
349                  clazz="icons" 
350                  visible="<%=mode.hasIcons()%>"
351                  >&nbsp;</tbl:header>
352                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
353                <tbl:cell column="loginTime"><div class="link" onclick="itemOnClick(event, <%=itemId%>)" 
354                  title="<%=tooltip%>"><%=dateTimeFormatter.format(item.getLoginTime())%></div></tbl:cell>
355                <tbl:cell column="logoutTime" value="<%=item.getLogoutTime()%>" />
356                <tbl:cell column="impersonated"><%=item.getImpersonated()%></tbl:cell>
357                <tbl:cell column="remoteId"><%=HTML.encodeTags(item.getRemoteId())%></tbl:cell>
358                <tbl:cell column="comment"><%=HTML.encodeTags(item.getLoginComment())%></tbl:cell>
359                <tbl:cell column="user"
360                  ><base:propertyvalue 
361                    item="<%=item%>" 
362                    property="user"
363                    enableEditLink="<%=mode.hasEditLink()%>" 
364                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
365                  /></tbl:cell>
366                <tbl:cell column="client"
367                  ><base:propertyvalue 
368                    item="<%=item%>" 
369                    property="client"
370                    enableEditLink="<%=mode.hasEditLink()%>" 
371                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
372                  /></tbl:cell>
373                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
374            </tbl:row>
375              <%
376              }
377            }
378          %>
379          </tbl:rows>
380      </tbl:data>
381      <%
382      if (numListed == 0)
383      {
384        %>
385        <tbl:panel><%=sessions == null || sessions.getTotalCount() == 0 ? "No sessions were found" : "No sessions on this page. Please select another page!" %></tbl:panel>
386        <%
387      }
388      else
389      {
390        %>
391        <tbl:navigator
392          page="<%=cc.getPage()%>" 
393          rowsperpage="<%=cc.getRowsPerPage()%>" 
394          totalrows="<%=sessions == null ? 0 : sessions.getTotalCount()%>" 
395          visible="<%=mode.hasNavigator()%>"
396          locked="true"
397        />
398        <%
399      }
400      %>
401    </tbl:table>
402    <base:buttongroup align="center" clazz="fixedatbottom">
403      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
404      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
405      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
406    </base:buttongroup>
407    <br><br><br>
408  </base:body>
409  </base:page>
410  <%
411}
412finally
413{
414  if (sessions != null) sessions.close();
415  if (dc != null) dc.close();
416}
417%>
Note: See TracBrowser for help on using the repository browser.