source: trunk/www/biomaterials/bioplates/events/view_event.jsp @ 6210

Last change on this file since 6210 was 6210, checked in by Nicklas Nordborg, 11 years ago

Fixes #1735: Include bioplate events in the item overview

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.9 KB
Line 
1<%-- $Id: view_event.jsp 6210 2012-12-06 13:35:47Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2010 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23--%>
24<%@ page pageEncoding="UTF-8" session="false"
25  import="net.sf.basedb.core.SessionControl"
26  import="net.sf.basedb.core.DbControl"
27  import="net.sf.basedb.core.SystemItems"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.ItemContext"
30  import="net.sf.basedb.core.Permission"
31  import="net.sf.basedb.core.CommonItem"
32  import="net.sf.basedb.core.BioPlate"
33  import="net.sf.basedb.core.BioPlateEvent"
34  import="net.sf.basedb.core.BioPlateEventParticipant"
35  import="net.sf.basedb.core.BioMaterialEvent"
36  import="net.sf.basedb.core.MeasuredBioMaterial"
37  import="net.sf.basedb.core.PhysicalBioAssay"
38  import="net.sf.basedb.core.Protocol"
39  import="net.sf.basedb.core.Hardware"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.ItemQuery"
42  import="net.sf.basedb.core.ItemResultList"
43  import="net.sf.basedb.core.Include"
44  import="net.sf.basedb.core.PluginDefinition"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.core.plugin.Plugin"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.PermissionUtil"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.Values"
53  import="net.sf.basedb.util.formatter.Formatter"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
56  import="net.sf.basedb.clients.web.extensions.JspContext"
57  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
58  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
59  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
60  import="java.util.Date"
61  import="java.util.Map"
62  import="java.util.Set"
63%>
64<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
65<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
66<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
67<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
68<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
69<%!
70  private static final Item itemType = Item.BIOPLATEEVENT;
71  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
72%>
73<%
74int bioPlateId = Values.getInt(request.getParameter("bioplate_id"));
75final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
76final String ID = sc.getId();
77final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
78final int itemId = cc.getId();
79final float scale = Base.getScale(sc);
80final DbControl dc = sc.newDbControl();
81try
82{
83  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
84  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
85
86  String title = null;
87  BioPlateEvent event = BioPlateEvent.getById(dc, itemId);
88 
89  // Load bioplates participating in this event
90  ItemQuery<BioPlateEventParticipant> participantQuery = event.getParticipants();
91  participantQuery.join(Hql.innerJoin(null, "bioPlate", "bpl", true));
92  participantQuery.include(Include.ALL);
93  participantQuery.order(Orders.asc(Hql.property("role")));
94  participantQuery.order(Orders.asc(Hql.property("index")));
95  participantQuery.order(Orders.asc(Hql.property("bpl", "name")));
96  ItemResultList<BioPlateEventParticipant> participants = participantQuery.list(dc);
97 
98  if (bioPlateId == 0)
99  {
100    for (BioPlateEventParticipant participant : participants)
101    {
102      try
103      {
104        bioPlateId = participant.getBioPlate().getId();
105        break;
106      }
107      catch (RuntimeException ex)
108      {}
109    }
110  }
111  BioPlate bioPlate = bioPlateId == 0 ? null : BioPlate.getById(dc, bioPlateId);
112 
113  final boolean usePermission = event.hasPermission(Permission.USE);
114  final boolean writePermission = event.hasPermission(Permission.WRITE);
115  final boolean deletePermission = event.hasPermission(Permission.DELETE);
116  final boolean sharePermission = event.hasPermission(Permission.SET_PERMISSION);
117  final boolean setOwnerPermission = event.hasPermission(Permission.SET_OWNER);
118  final boolean isRemoved = event.isRemoved();
119  final boolean isUsed = isRemoved && event.isUsed();
120  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
121  final boolean isOwner = event.isOwner();
122  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, event);
123  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
124  %>
125  <base:page title="<%=title%>">
126  <base:head scripts="table.js,tabcontrol.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css">
127    <ext:scripts context="<%=jspContext%>" />
128    <ext:stylesheets context="<%=jspContext%>" />
129    <script>
130    function editItem()
131    {
132      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
133    }
134    function shareItem()
135    {
136      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareEvent', 600, 400);
137    }
138    function deleteItem()
139    {
140      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>&bioplate_id=<%=bioPlateId%>');
141    }
142    function restoreItem()
143    {
144      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>&bioplate_id=<%=bioPlateId%>');
145    }
146    function deleteItemPermanently()
147    {
148      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
149    }
150    function itemDeleted()
151    {
152      Main.listItems('<%=ID%>', '<%=itemType.name()%>', '&bioplate_id=<%=bioPlateId%>');
153    }
154    function showUsingItems()
155    {
156      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
157    }
158    function setOwner()
159    {
160      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 300);
161    }
162    function runPlugin(cmd)
163    {
164      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 750, 500);
165    }
166    </script>
167  </base:head>
168  <base:body>
169    <%
170    if (bioPlate != null)
171    {
172      %>
173      <p:path><p:pathelement 
174        title="Bioplates" href="<%="../index.jsp?ID="+ID%>" /><p:pathelement 
175        title="<%=HTML.encodeTags(bioPlate.getName())%>" 
176          href="<%="index.jsp?ID="+ID+"&amp;bioplate_id="+bioPlateId%>" /><p:pathelement 
177        title="<%=HTML.encodeTags(event.getName())%>" /></p:path>
178      <%
179    }
180    else
181    {
182      %>
183      <p:path><p:pathelement 
184        title="Bioplate events" /><p:pathelement 
185        title="<%=HTML.encodeTags(event.getName())%>" /></p:path>
186      <%
187    }
188    %>
189    <t:tabcontrol id="main"
190      subclass="content mastertabcontrol"
191      active="properties">
192    <t:tab id="properties" title="Properties">
193      <div>
194      <table class="fullform bottomborder">
195      <tr>
196        <th class="itemstatus">
197          <base:icon 
198            image="shared.png" 
199            visible="<%=event.isShared()%>"
200            tooltip="This item is shared to other users, groups and/or projects"
201          />
202          <base:icon 
203            image="deleted.png"
204            onclick="deleteItemPermanently()"
205            tooltip="This item has been flagged for deletion. Click to delete it now."
206            enabled="<%=deletePermanentlyPermission %>"
207            visible="<%=isRemoved%>" 
208          />
209          <base:icon image="used.png" 
210            onclick="showUsingItems()"
211            tooltip="This item is used by other items and can't be permanently deleted. Show the items that are using this one"
212            visible="<%=isRemoved && isUsed%>" />
213        </th>
214        <td style="padding: 0px;">
215          <tbl:toolbar subclass="bottomborder">
216            <tbl:button 
217              disabled="<%=!writePermission%>" 
218              image="edit.png" 
219              onclick="editItem()" 
220              title="Edit&hellip;" 
221              tooltip="<%=writePermission ? "Edit this event" : "You do not have permission to edit this event"%>" 
222            />
223            <tbl:button 
224              disabled="<%=!deletePermission%>" 
225              image="delete.png" 
226              onclick="deleteItem()" 
227              title="Delete"
228              visible="<%=!event.isRemoved()%>"
229              tooltip="<%=deletePermission ? "Delete this event" : "You do not have permission to delete this event"%>" 
230            />
231            <tbl:button 
232              disabled="<%=!writePermission%>" 
233              image="restore.png" 
234              onclick="restoreItem()" 
235              title="Restore"
236              visible="<%=event.isRemoved()%>"
237              tooltip="<%=writePermission ? "Restore this event" : "You do not have permission to restore this event"%>" 
238            />
239            <tbl:button 
240              disabled="<%=!sharePermission%>"
241              image="share.png"
242              onclick="shareItem()" 
243              title="Share&hellip;" 
244              tooltip="<%=sharePermission ? "Share this event to other user, groups and projects" : "You do not have permission to share this event"%>"
245            />
246            <tbl:button 
247              disabled="<%=!setOwnerPermission%>"
248              image="take_ownership.png"
249              onclick="setOwner()" 
250              title="Set owner&hellip;"
251              tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
252            />
253            <tbl:button 
254              image="import.png" 
255              onclick="runPlugin('ImportItem')" 
256              title="Import&hellip;" 
257              tooltip="Import data" 
258              visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
259            />
260            <tbl:button 
261              image="export.png" 
262              onclick="runPlugin('ExportItem')" 
263              title="Export&hellip;" 
264              tooltip="Export data" 
265              visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
266            />
267            <tbl:button 
268              image="runplugin.png" 
269              onclick="runPlugin('RunPlugin')" 
270              title="Run plugin&hellip;" 
271              tooltip="Run a plugin" 
272              visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
273            />
274            <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
275              wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
276          </tbl:toolbar>
277        </td>
278      </tr>
279      <tr>
280        <th>Name</th>
281        <td><%=HTML.encodeTags(event.getName())%></td>
282      </tr>
283      <tr>
284        <th>Event date</th>
285        <td><%=dateFormatter.format(event.getEventDate())%></td>
286      </tr>
287      <tr>
288        <th>Registration date</th>
289        <td><%=dateFormatter.format(event.getEntryDate())%></td>
290      </tr>
291      <tr>
292        <th>Event type</th>
293        <td><base:propertyvalue item="<%=event%>" property="eventType" /></td>
294      </tr>
295      <tr>
296        <th>Protocol</th>
297        <td><base:propertyvalue item="<%=event%>" property="protocol"/></td>
298      </tr>
299      <tr>
300        <th>Hardware</th>
301        <td><base:propertyvalue item="<%=event%>" property="hardware"/></td>
302      </tr>
303      <tr>
304        <th>Owner</th>
305        <td><base:propertyvalue item="<%=event%>" property="owner" /></td>
306      </tr>
307      <tr>
308        <th>Description</th>
309        <td><%=HTML.niceFormat(event.getDescription())%></td>
310      </tr>
311      </table>
312      </div>
313     
314      <base:section 
315        id="participantSection" 
316        title="<%="Participating plates (" + participants.size() + ")"%>"
317        context="<%=cc%>"
318        >
319        <%
320        if (participants.size() == 0)
321        {
322          %>
323          <div class="messagecontainer note">
324          No plates are participating in this event
325          (or, you don't have permission to view them).
326          </div>
327          <%
328        }
329        else
330        {
331          %>
332          <tbl:table
333            id="participants"
334            columns="all"
335            >
336            <tbl:columndef
337              id="bioplate"
338              title="Bioplate"
339            />
340            <tbl:columndef 
341              id="role"
342              title="Role"
343            />
344            <tbl:columndef
345              id="description"
346              title="Description"
347            />
348            <tbl:data>
349              <tbl:headers>
350                <tbl:headerrow>
351                  <tbl:columnheaders />
352                </tbl:headerrow>
353              </tbl:headers>
354              <tbl:rows>
355                <%
356                for (BioPlateEventParticipant participant : participants)
357                {
358                  BioPlate plate = null;
359                  try
360                  {
361                    plate = participant.getBioPlate();
362                  }
363                  catch (PermissionDeniedException ex)
364                  {}
365                  %>
366                  <tbl:row>
367                    <tbl:cell column="bioplate"><base:icon 
368                      image="deleted.png" 
369                      tooltip="This item has been scheduled for deletion" 
370                      visible="<%=plate != null && plate.isRemoved()%>"
371                    /><%=Base.getLinkedName(ID, plate, true, true)%></tbl:cell>
372                    <tbl:cell column="role"><%=HTML.encodeTags(participant.getRole())%> [<%=participant.getIndex()%>]</tbl:cell>
373                    <tbl:cell column="description"><%=plate == null ? "" : HTML.encodeTags(plate.getDescription())%></tbl:cell>
374                  </tbl:row>
375                  <%
376                }
377                %>
378              </tbl:rows>
379            </tbl:data>
380          </tbl:table>
381          <%
382        }
383        %>
384      </base:section>
385      <%
386      // Biomaterial events linked with this event
387      ItemQuery<BioMaterialEvent> eventQuery = event.getBioMaterialEvents();
388      eventQuery.join(Hql.leftJoin("bioMaterial", "bm"));
389      eventQuery.join(Hql.leftJoin("physicalBioAssay", "pba"));
390      eventQuery.include(Include.ALL);
391      eventQuery.order(Orders.asc(Hql.property("bm", "name")));
392      eventQuery.order(Orders.asc(Hql.property("pba", "name")));
393      ItemResultList<BioMaterialEvent> events = eventQuery.list(dc);
394      %>
395      <base:section 
396        id="eventsSection" 
397        title="<%="Related biomaterial events (" + events.size() + ")"%>"
398        context="<%=cc%>"
399        >
400        <%
401        if (events.size() == 0)
402        {
403          %>
404          <div class="messagecontainer note">
405          No biomaterial events are linked to this event
406          (or, you don't have permission to view them).
407          </div>
408          <%
409        }
410        else
411        {
412          %>
413          <tbl:table
414            id="events"
415            columns="all"
416            >
417            <tbl:columndef
418              id="item"
419              title="Biomaterial/Bioassay"
420            />
421            <tbl:columndef
422              id="bioplate"
423              title="Bioplate"
424            />
425            <tbl:columndef
426              id="eventType"
427              title="Event type"
428            />
429            <tbl:columndef
430              id="comment"
431              title="Comment"
432            />
433            <tbl:data>
434              <tbl:headers>
435                <tbl:headerrow>
436                  <tbl:columnheaders />
437                </tbl:headerrow>
438              </tbl:headers>
439              <tbl:rows>
440                <%
441                for (BioMaterialEvent bmEvent : events)
442                {
443                  BioMaterialEvent.Type eventType = bmEvent.getEventType();
444                  CommonItem item = null;
445                  try
446                  {
447                    if (eventType == BioMaterialEvent.Type.BIOASSAY)
448                    {
449                      item = bmEvent.getPhysicalBioAssay();
450                    }
451                    else
452                    {
453                      item = bmEvent.getBioMaterial();
454                    }
455                  }
456                  catch (PermissionDeniedException ex)
457                  {}     
458                  %>
459                  <tbl:row>
460                    <tbl:cell column="item"><base:icon 
461                      image="deleted.png" 
462                      tooltip="This item has been scheduled for deletion" 
463                      visible="<%=item != null && item.isRemoved()%>"
464                    /><%=Base.getLinkedName(ID, item, true, true)%><%=item != null ? " (" +item.getType().toString() + ")" : "" %></tbl:cell>
465                    <tbl:cell column="bioplate"><base:propertyvalue item="<%=bmEvent%>" property="bioPlateEventParticipant.bioPlate" /></tbl:cell>
466                    <tbl:cell column="eventType"><%=eventType%></tbl:cell>
467                    <tbl:cell column="comment"><%=HTML.encodeTags(bmEvent.getComment())%></tbl:cell>
468                  </tbl:row>
469                  <%
470                }
471                %>
472              </tbl:rows>
473            </tbl:data>
474          </tbl:table>
475          <%
476        }
477        %>
478      </base:section>
479      <jsp:include page="../../../common/anytoany/list_anytoany.jsp">
480        <jsp:param name="ID" value="<%=ID%>" />
481        <jsp:param name="item_type" value="<%=itemType.name()%>" />
482        <jsp:param name="item_id" value="<%=itemId%>" />
483        <jsp:param name="title" value="Other items related to this event" />
484      </jsp:include>
485      </t:tab>
486      </t:tabcontrol>
487
488  </base:body>
489  </base:page>
490  <%
491}
492finally
493{
494  if (dc != null) dc.close();
495}
496
497%>
Note: See TracBrowser for help on using the repository browser.