source: branches/2.1/www/biomaterials/extracts/view_extract.jsp @ 2969

Last change on this file since 2969 was 2969, checked in by Nicklas Nordborg, 17 years ago

Fixes #448: Setting 'Used quantity' for pooled sources of sample, extracts and labeled extract doesn't work

Also, fixed incorrect links on view pages and added 'used quantity' as a column in listings of
children.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.9 KB
Line 
1<%-- $Id: view_extract.jsp 2969 2006-11-28 12:40:05Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.SystemItems"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Extract"
35  import="net.sf.basedb.core.LabeledExtract"
36  import="net.sf.basedb.core.Sample"
37  import="net.sf.basedb.core.BioMaterialEvent"
38  import="net.sf.basedb.core.Protocol"
39  import="net.sf.basedb.core.User"
40  import="net.sf.basedb.core.ItemQuery"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.Include"
43  import="net.sf.basedb.core.query.Orders"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.core.query.Restrictions"
46  import="net.sf.basedb.core.query.Expressions"
47  import="net.sf.basedb.core.PermissionDeniedException"
48  import="net.sf.basedb.core.PluginDefinition"
49  import="net.sf.basedb.core.plugin.GuiContext"
50  import="net.sf.basedb.core.plugin.Plugin"
51  import="net.sf.basedb.core.Type"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.PermissionUtil"
54  import="net.sf.basedb.clients.web.util.HTML"
55  import="net.sf.basedb.util.Values"
56  import="java.util.Date"
57  import="java.util.Map"
58  import="java.util.Set"
59  import="java.util.List"
60%>
61<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
62<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
63<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
64<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
65<%!
66  private static final Item itemType = Item.EXTRACT;
67  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
68%>
69<%
70final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
71final String ID = sc.getId();
72final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
73final int itemId = cc.getId();
74final String tab = Values.getString(request.getParameter("tab"), "properties");
75final float scale = Base.getScale(sc);
76final DbControl dc = sc.newDbControl();
77try
78{
79  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
80
81  String title = null;
82  Extract extract = Extract.getById(dc, itemId);
83  BioMaterialEvent creationEvent = extract.getCreationEvent();
84 
85  final boolean writePermission = extract.hasPermission(Permission.WRITE);
86  final boolean deletePermission = extract.hasPermission(Permission.DELETE);
87  final boolean sharePermission = extract.hasPermission(Permission.SET_PERMISSION);
88  final boolean usePermission = extract.hasPermission(Permission.USE);
89 
90  %>
91
92  <base:page title="<%=title%>">
93  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
94    <script language="JavaScript">
95    function editItem()
96    {
97      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
98    }
99    function shareItem()
100    {
101      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareExtract', 500, 400);
102    }
103    function deleteItem()
104    {
105      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
106    }
107    function restoreItem()
108    {
109      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
110    }
111    function runPlugin(cmd)
112    {
113      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
114    }
115    function viewEvents()
116    {
117      location.href = '../events/index.jsp?ID=<%=ID%>&cmd=List&biomaterial_id=<%=itemId%>&biomaterial_type=<%=itemType.name()%>';
118    }
119    function switchTab(tabControlId, tabId)
120    {
121      if (tabId == 'events')
122      {
123        viewEvents();
124      }
125      else
126      {
127        TabControl.setActiveTab(tabControlId, tabId);
128      }
129    }
130    function newLabeledExtract()
131    {
132      Main.viewOrEditItem('<%=ID%>', 'LABELEDEXTRACT', 0, true, '&extract_id=<%=itemId%>')
133    }
134    </script>
135  </base:head>
136  <base:body>
137    <p>
138    <p:path>
139      <p:pathelement title="Extracts" href="<%="index.jsp?ID="+ID%>" />
140      <p:pathelement title="<%=HTML.encodeTags(extract.getName())%>" />
141    </p:path>
142   
143    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab">
144    <t:tab id="properties" title="Properties">
145
146    <tbl:toolbar
147      >
148      <tbl:button 
149        disabled="<%=writePermission ? false : true%>" 
150        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
151        onclick="editItem()" 
152        title="Edit&hellip;" 
153        tooltip="<%=writePermission ? "Edit this extract" : "You do not have permission to edit this extract"%>" 
154      />
155      <tbl:button 
156        disabled="<%=deletePermission ? false : true%>" 
157        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
158        onclick="deleteItem()" 
159        title="Delete"
160        visible="<%=!extract.isRemoved()%>"
161        tooltip="<%=deletePermission ? "Delete this extract" : "You do not have permission to delete this extract"%>" 
162      />
163      <tbl:button 
164        disabled="<%=writePermission ? false : true%>" 
165        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
166        onclick="restoreItem()" 
167        title="Restore"
168        visible="<%=extract.isRemoved()%>"
169        tooltip="<%=writePermission ? "Restore this extract" : "You do not have permission to restore this extract"%>" 
170      />
171      <tbl:button 
172        disabled="<%=sharePermission ? false : true%>"
173        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
174        onclick="shareItem()" 
175        title="Share&hellip;" 
176        tooltip="<%=sharePermission ? "Share this extract to other user, groups and projects" : "You do not have permission to share this extract"%>"
177      />
178      <tbl:button
179        image="add.png"
180        onclick="newLabeledExtract()"
181        title="New labeled extract&hellip;"
182        tooltip="Create a new labeled extract from this extract"
183        visible="<%=sc.hasPermission(Permission.CREATE, Item.LABELEDEXTRACT) && usePermission %>"
184      />
185      <tbl:button 
186        image="import.gif" 
187        onclick="runPlugin('ImportItem')" 
188        title="Import&hellip;" 
189        tooltip="Import data" 
190        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
191      />
192      <tbl:button 
193        image="export.gif" 
194        onclick="runPlugin('ExportItem')" 
195        title="Export&hellip;" 
196        tooltip="Export data" 
197        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
198      />
199      <tbl:button 
200        image="runplugin.gif" 
201        onclick="runPlugin('RunPlugin')" 
202        title="Run plugin&hellip;" 
203        tooltip="Run a plugin" 
204        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
205      />
206      <tbl:button
207        image="help.gif"
208        onclick="<%="Main.openHelp('" + ID +"', 'extract.view.properties')"%>"
209        title="Help&hellip;"
210        tooltip="Get help about this page"
211      />
212      </tbl:toolbar>
213    <div class="boxedbottom">
214      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(extract)%></i></div>
215      <%
216      if (extract.isRemoved() || extract.isShared())
217      {
218        %>
219        <div class="itemstatus">
220          <base:icon image="deleted.gif" 
221            visible="<%=extract.isRemoved()%>"> This item has been flagged for deletion<br></base:icon>
222          <base:icon image="shared.gif" 
223            visible="<%=extract.isShared()%>"> This item is shared to other user, groups and/or projects</base:icon>
224        </div>
225        <%
226      }
227      %>
228      <table class="form" cellspacing=0>
229      <tr>
230        <td class="prompt">Name</td>
231        <td><%=HTML.encodeTags(extract.getName())%></td>
232      </tr>
233      <tr>
234        <td class="prompt">External ID</td>
235        <td><%=HTML.encodeTags(extract.getExternalId())%></td>
236      </tr>
237      <tr>
238        <td class="prompt">Created</td>
239        <td><%=Values.formatDate(creationEvent.getEventDate())%></td>
240      </tr>
241      <tr>
242        <td class="prompt">Registered</td>
243        <td><%=Values.formatDate(creationEvent.getEntryDate())%></td>
244      </tr>
245      <%
246      if (!extract.isPooled())
247      {
248        %>
249        <tr>
250          <td class="prompt">Sample</td>
251          <td><base:propertyvalue item="<%=extract%>" property="parent"/> 
252            <%
253            try
254            {
255            %>
256              <%=extract.getSample() != null ? "(" + Values.formatNumber(creationEvent.getUsedQuantity(extract.getSample()), 2, " µg") + ")" : ""%>
257            <%
258            }
259            catch (PermissionDeniedException ex)
260            {}
261            %> 
262
263          </td>
264        </tr>
265        <%
266      }
267      %>
268      <tr>
269        <td class="prompt">Protocol</td>
270        <td><base:propertyvalue item="<%=creationEvent%>" property="protocol"/></td>
271      </tr>
272      <tr>
273        <td class="prompt">Original quantity</td>
274        <td><%=Values.formatNumber(extract.getOriginalQuantity(), 2, " µg")%></td>
275      </tr>
276      <tr>
277        <td class="prompt">Remaining quantity</td>
278        <td><%=Values.formatNumber(extract.getRemainingQuantity(), 2, " µg")%></td>
279      </tr>
280      <tr>
281        <td class="prompt">Owner</td>
282        <td><base:propertyvalue item="<%=extract%>" property="owner"/></td>
283      </tr>
284      <tr valign="baseline">
285        <td class="prompt">Description</td>
286        <td><%=HTML.niceFormat(extract.getDescription())%></td>
287      </tr>
288      </table>
289 
290      <%
291      if (extract.isPooled())
292      {
293        ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)creationEvent.getSources();
294        extractsQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
295        extractsQuery.order(Orders.asc(Hql.property("name")));
296        ItemResultList<Extract> extracts = extractsQuery.list(dc);
297        %>
298        <h4 class="docked">Pooled from extracts</h4>
299        <tbl:table
300          id="pooled"
301          clazz="itemlist"
302          columns="all"
303          >
304        <tbl:columndef 
305          id="name"
306          title="Name"
307        />
308        <tbl:columndef 
309          id="quantity"
310          title="Used quantity (µg)"
311        />
312        <tbl:columndef 
313          id="description"
314          title="Description"
315        />
316        <tbl:data>
317          <tbl:columns>
318          </tbl:columns>
319          <tbl:rows>
320          <%
321          for (Extract item : extracts)
322          {
323            %>
324            <tbl:row>
325              <tbl:cell column="name"><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
326              <tbl:cell column="quantity"><%=Values.formatNumber(creationEvent.getUsedQuantity(item), 2)%></tbl:cell>
327              <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
328            </tbl:row>
329            <%
330          }
331          %>
332          </tbl:rows>
333        </tbl:data>
334        </tbl:table>
335        <%
336      }
337      ItemQuery<LabeledExtract> labeledExtractQuery = LabeledExtract.getQuery();
338      labeledExtractQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
339      labeledExtractQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter("extracts")));
340      labeledExtractQuery.setParameter("extracts", itemId, Type.INT);
341      labeledExtractQuery.order(Orders.asc(Hql.property("name")));
342      ItemResultList<LabeledExtract> labeledExtracts = labeledExtractQuery.list(dc);
343     
344      if (labeledExtracts.size() == 0)
345      {
346        %>
347        <h4>Labeled extracts</h4>
348        No labeled extracts have been created from this extract
349        (or you don't have the permission to view them)
350        <%
351      }
352      else
353      {
354        %>
355        <h4 class="docked">Labeled extracts</h4>
356        <tbl:table
357          id="labeledextracts"
358          clazz="itemlist"
359          columns="all"
360          >
361          <tbl:columndef
362            id="name"
363            title="Name"
364          />         
365          <tbl:columndef 
366            id="quantity"
367            title="Used quantity (µg)"
368          />
369          <tbl:columndef
370            id="description"
371            title="Description"
372          />
373          <tbl:data>
374            <tbl:columns></tbl:columns>
375            <tbl:rows>
376              <%
377              for (LabeledExtract lbe : labeledExtracts)
378              {
379                %>
380                <tbl:row>
381                  <tbl:cell column="name"><%=Base.getLinkedName(ID, lbe, false, true)%></tbl:cell>
382                  <tbl:cell column="quantity"><%=Values.formatNumber(lbe.getCreationEvent().getUsedQuantity(extract), 2)%></tbl:cell>
383                  <tbl:cell column="description"><%=HTML.encodeTags(lbe.getDescription())%></tbl:cell>
384                </tbl:row>
385                <%
386              }
387              %>
388            </tbl:rows>
389          </tbl:data>
390        </tbl:table>
391        <%
392      }
393      %>
394     
395    </div>
396      </t:tab>
397     
398      <t:tab id="annotations" title="Annotations" >
399        <div class="boxed">
400        <jsp:include page="../../common/annotations/list_annotations.jsp">
401          <jsp:param name="item_type" value="<%=itemType.name()%>" />
402          <jsp:param name="item_id" value="<%=itemId%>" />
403          <jsp:param name="ID" value="<%=ID%>" />
404        </jsp:include>
405        </div>
406      </t:tab>
407     
408      <t:tab id="events" title="Events" />
409     
410      </t:tabcontrol>
411
412
413  </base:body>
414  </base:page>
415  <%
416}
417finally
418{
419  if (dc != null) dc.close();
420}
421
422%>
Note: See TracBrowser for help on using the repository browser.