source: trunk/www/lims/plates/view_plate.jsp @ 5062

Last change on this file since 5062 was 5062, checked in by Nicklas Nordborg, 14 years ago

References #108: Logging the change history of an item

  • Added "Change history" tab to view pages for Array lims items.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.2 KB
Line 
1<%-- $Id: view_plate.jsp 5062 2009-08-19 09:35:32Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Martin Svensson
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.SystemItems"
30  import="net.sf.basedb.core.Group"
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.AnnotationType"
35  import="net.sf.basedb.core.AnnotationSet"
36  import="net.sf.basedb.core.Plate"
37  import="net.sf.basedb.core.PlateType"
38  import="net.sf.basedb.core.PlateGeometry"
39  import="net.sf.basedb.core.PlateMapping"
40  import="net.sf.basedb.core.User"
41  import="net.sf.basedb.core.ItemQuery"
42  import="net.sf.basedb.core.Include"
43  import="net.sf.basedb.core.ItemResultIterator"
44  import="net.sf.basedb.core.ItemResultList"
45  import="net.sf.basedb.core.MultiPermissions"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.PluginDefinition"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.core.plugin.Plugin"
50  import="net.sf.basedb.core.Project"
51  import="net.sf.basedb.core.query.Orders"
52  import="net.sf.basedb.core.query.Hql"
53  import="net.sf.basedb.clients.web.Base"
54  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
55  import="net.sf.basedb.clients.web.PermissionUtil"
56  import="net.sf.basedb.clients.web.util.HTML"
57  import="net.sf.basedb.util.Values"
58  import="net.sf.basedb.util.formatter.Formatter"
59  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
60  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
61  import="net.sf.basedb.clients.web.extensions.JspContext"
62  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
63  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
64  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
65  import="java.util.Collections"
66  import="java.util.Date"
67  import="java.util.Map"
68  import="java.util.Set"
69  import="java.util.List"
70%>
71<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
72<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
73<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
74<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
75<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
76<%!
77  private static final Item itemType = Item.PLATE;
78  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
79%>
80<%
81final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
82final String ID = sc.getId();
83final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
84final int itemId = cc.getId();
85final String tab = Values.getString(request.getParameter("tab"), "properties");
86final float scale = Base.getScale(sc);
87final DbControl dc = sc.newDbControl();
88try
89{
90  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
91  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
92
93  String title = null;
94  Plate plate = Plate.getById(dc, itemId);
95 
96  PlateMapping currentPlateMapping = null;
97  try
98  {
99    currentPlateMapping = plate.getPlateMapping();
100  }
101  catch (PermissionDeniedException ex)
102  {}
103 
104  final boolean writePermission = plate.hasPermission(Permission.WRITE);
105  final boolean deletePermission = plate.hasPermission(Permission.DELETE);
106  final boolean sharePermission = plate.hasPermission(Permission.SET_PERMISSION);
107  final boolean setOwnerPermission = plate.hasPermission(Permission.SET_OWNER);
108  final boolean isRemoved = plate.isRemoved();
109  final boolean isUsed = isRemoved && plate.isUsed();
110  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
111  final boolean isOwner = plate.isOwner();
112  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, plate);
113  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
114  %>
115  <base:page title="<%=title%>">
116  <base:head scripts="tabcontrol.js,table.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css">
117    <ext:scripts context="<%=jspContext%>" />
118    <ext:stylesheets context="<%=jspContext%>" />
119    <script language="JavaScript">
120    function editItem()
121    {
122      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
123    }
124    function shareItem()
125    {
126      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'SharePlate', 600, 400);
127    }
128    function deleteItem()
129    {
130      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
131    }
132    function restoreItem()
133    {
134      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
135    }
136    function deleteItemPermanently()
137    {
138      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
139    }
140    function itemDeleted()
141    {
142      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
143    }
144    function showUsingItems()
145    {
146      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
147    }
148    function setOwner()
149    {
150      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
151    }
152    function runPlugin(cmd)
153    {
154      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
155    }
156    function viewWells()
157    {
158      location.href = 'wells/index.jsp?ID=<%=ID%>&plate_id=<%=itemId%>';
159    }
160    function viewEvents()
161    {
162      location.href = 'events/index.jsp?ID=<%=ID%>&plate_id=<%=itemId%>';
163    }
164    function switchTab(tabControlId, tabId)
165    {
166      if (tabId == 'history' && tabId != '<%=tab%>')
167      {
168        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=itemId%>&tab='+tabId;
169      }
170      else if (tabId == 'events')
171      {
172        viewEvents();
173      }
174      else if (tabId == 'wells')
175      {
176        viewWells();
177      }
178      else
179      {
180        TabControl.setActiveTab(tabControlId, tabId);
181      }
182    }
183    </script>
184  </base:head>
185  <base:body>
186    <p>
187    <p:path>
188      <p:pathelement title="Plates" href="<%="index.jsp?ID="+ID%>" />
189      <p:pathelement title="<%=HTML.encodeTags(plate.getName())%>" />
190    </p:path>
191   
192    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab" remember="false">
193    <t:tab id="properties" title="Properties">
194    <tbl:toolbar
195      >
196      <tbl:button 
197        disabled="<%=writePermission ? false : true%>" 
198        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
199        onclick="editItem()" 
200        title="Edit&hellip;" 
201        tooltip="<%=writePermission ? "Edit this plate" : "You do not have permission to edit this plate"%>" 
202      />
203      <tbl:button 
204        disabled="<%=deletePermission ? false : true%>" 
205        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
206        onclick="deleteItem()" 
207        title="Delete"
208        visible="<%=!plate.isRemoved()%>"
209        tooltip="<%=deletePermission ? "Delete this plate" : "You do not have permission to delete this plate"%>" 
210      />
211      <tbl:button 
212        disabled="<%=writePermission ? false : true%>" 
213        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
214        onclick="restoreItem()" 
215        title="Restore"
216        visible="<%=plate.isRemoved()%>"
217        tooltip="<%=writePermission ? "Restore this plate" : "You do not have permission to restore this plate"%>" 
218      />
219      <tbl:button 
220        disabled="<%=sharePermission ? false : true%>"
221        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
222        onclick="shareItem()" 
223        title="Share&hellip;" 
224        tooltip="<%=sharePermission ? "Share this plate to other user, groups and projects" : "You do not have permission to share this plate"%>"
225      />
226      <tbl:button 
227        disabled="<%=setOwnerPermission ? false : true%>"
228        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
229        onclick="setOwner()" 
230        title="Set owner&hellip;"
231        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
232      />
233      <tbl:button 
234        image="import.gif" 
235        onclick="runPlugin('ImportItem')" 
236        title="Import&hellip;" 
237        tooltip="Import data" 
238        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
239      />
240      <tbl:button 
241        image="export.gif" 
242        onclick="runPlugin('ExportItem')" 
243        title="Export&hellip;" 
244        tooltip="Export data" 
245        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
246      />
247      <tbl:button 
248        image="runplugin.gif" 
249        onclick="runPlugin('RunPlugin')" 
250        title="Run plugin&hellip;" 
251        tooltip="Run a plugin" 
252        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
253      />
254      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
255        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
256      <tbl:button
257        image="help.gif"
258        onclick="<%="Main.openHelp('" + ID +"', 'plate.view.properties')"%>"
259        title="Help&hellip;"
260        tooltip="Get help about this page"
261      />
262      </tbl:toolbar>
263    <div class="boxedbottom">
264      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(plate)%></i></div>
265      <%
266      if (plate.isRemoved() || plate.isShared())
267      {
268        %>
269        <div class="itemstatus">
270          <base:icon 
271            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
272            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
273            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
274            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
275          <base:icon image="used.gif" 
276            onclick="showUsingItems()"
277            tooltip="Show the items that are using this one"
278            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
279          <base:icon image="shared.gif" 
280            visible="<%=plate.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
281        </div>
282        <%
283      }
284      %>
285      <table class="form" cellspacing="0">
286      <tr>
287        <td class="prompt">Name</td>
288        <td><%=HTML.encodeTags(plate.getName())%></td>
289      </tr>
290      <tr>
291        <td class="prompt">Registered</td>
292        <td><%=dateFormatter.format(plate.getEntryDate())%></td>
293      </tr>
294      <tr>
295        <td class="prompt">Barcode</td>
296        <td><%=HTML.encodeTags(plate.getBarcode())%></td>
297      </tr>
298      <tr>
299        <td class="prompt">Destroyed</td>
300        <td><%=plate.isDestroyed() ? "yes" : "no"%></td>
301      </tr>
302      <tr>
303        <td class="prompt">Type</td>
304        <td><base:propertyvalue item="<%=plate%>" property="plateType" /></td>
305      </tr>
306      <tr>
307        <td class="prompt">Geometry</td>
308        <td><base:propertyvalue item="<%=plate%>" property="plateType.plateGeometry" /></td>
309      </tr>
310      <tr valign="baseline">
311        <td class="prompt">Merge mapping</td>
312        <td><%
313          if (currentPlateMapping != null && currentPlateMapping.getImage() != null)
314          {
315            %>
316            <img id="mappingImage" src="../../images/platemappings/<%=currentPlateMapping.getImage()%>" align="right">
317            <%
318          }
319          %>
320          <base:propertyvalue item="<%=plate%>" property="plateMapping" />
321        </td>
322      </tr>
323      <tr>
324        <td class="prompt">Owner</td>
325        <td><base:propertyvalue item="<%=plate%>" property="owner" /></td>
326      </tr>
327      <tr>
328        <td class="prompt">Description</td>
329        <td><%=HTML.niceFormat(plate.getDescription())%></td>
330      </tr>
331      </table>
332     
333      <%
334      ItemQuery<Plate> parentPlatesQuery = plate.getParentPlates();
335      parentPlatesQuery.include(Include.ALL);
336      parentPlatesQuery.order(Orders.asc(Hql.property("name")));
337      ItemResultList<Plate> parentPlates = parentPlatesQuery.list(dc);
338      if (parentPlates.size() == 0)
339      {
340        %>
341        <h4>Parent plates</h4>
342        This plate doesn't have any parents (or, you don't have permission to view them).
343        <%
344      }
345      else
346      {
347        %>
348        <base:section
349          id="parents"
350          title="<%="Parent plates (" + parentPlates.size() + ")"%>"
351          context="<%=cc%>"
352          >
353          <tbl:table
354            id="parentplates"
355            clazz="itemlist"
356            columns="all"
357            >
358          <tbl:columndef 
359            id="name"
360            title="Name"
361          />
362          <tbl:columndef 
363            id="index"
364            title="Index"
365          />
366          <tbl:columndef 
367            id="description"
368            title="Description"
369          />
370          <tbl:data>
371            <tbl:columns>
372            </tbl:columns>
373            <tbl:rows>
374            <%
375            for (Plate item : parentPlates)
376            {
377              %>
378              <tbl:row>
379                <tbl:cell column="name"><base:icon 
380                    image="deleted.gif" 
381                    tooltip="This item has been scheduled for deletion" 
382                    visible="<%=item.isRemoved()%>"
383                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
384                <tbl:cell column="index"><%=plate.getSourceIndex(item)+1%></tbl:cell>
385                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
386              </tbl:row>
387              <%
388            }
389            %>
390            </tbl:rows>
391          </tbl:data>
392          </tbl:table>
393        </base:section>
394        <%
395      }
396      %>
397      <%
398      ItemQuery<Plate> childPlatesQuery = plate.getChildPlates();
399      childPlatesQuery.include(Include.ALL);
400      childPlatesQuery.order(Orders.asc(Hql.property("name")));
401      ItemResultList<Plate> childPlates = childPlatesQuery.list(dc);
402      if (childPlates.size() == 0)
403      {
404        %>
405        <h4>Child plates</h4>
406        This plate doesn't have any children (or, you don't have permission to view them).
407        <%
408      }
409      else
410      {
411        %>
412        <base:section
413          id="children"
414          title="<%="Child plates (" + childPlates.size() + ")"%>"
415          context="<%=cc%>"
416          >
417          <tbl:table
418            id="childplates"
419            clazz="itemlist"
420            columns="all"
421            >
422          <tbl:columndef 
423            id="name"
424            title="Name"
425          />
426          <tbl:columndef
427            id="mapping"
428            title="Mapping"
429          />
430          <tbl:columndef 
431            id="index"
432            title="Index"
433          />
434          <tbl:columndef 
435            id="description"
436            title="Description"
437          />
438          <tbl:data>
439            <tbl:columns>
440            </tbl:columns>
441            <tbl:rows>
442            <%
443            for (Plate item : childPlates)
444            {
445              %>
446              <tbl:row>
447                <tbl:cell column="name"><base:icon 
448                    image="deleted.gif" 
449                    tooltip="This item has been scheduled for deletion" 
450                    visible="<%=item.isRemoved()%>"
451                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
452                <tbl:cell column="mapping"><base:propertyvalue item="<%=item%>" property="plateMapping" /></tbl:cell>
453                <tbl:cell column="index"><%=item.getSourceIndex(plate) + 1%></tbl:cell>
454                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
455              </tbl:row>
456              <%
457            }
458            %>
459            </tbl:rows>
460          </tbl:data>
461          </tbl:table>
462        </base:section>
463        <%
464      }     
465     
466      // Tables with users/groups/projects that this item is shared to
467      MultiPermissions mp = new MultiPermissions(Collections.singleton(plate));
468      ItemResultList<User> users = mp.getUsers().list(dc);
469      ItemResultList<Group> groups = mp.getGroups().list(dc);
470      ItemResultList<Project> projects = mp.getProjects().list(dc);
471      int totalShare = users.size() + groups.size() + projects.size();
472     
473      if (totalShare > 0)
474      {
475        %>
476        <base:section
477          id="sharedTo"
478          title="<%="Shared to (" + totalShare + ")"%>"
479          context="<%=cc%>"
480          >
481          <tbl:table 
482            id="itemsSharedTo"
483            clazz="itemlist"
484            columns="all"
485          >
486            <tbl:columndef 
487              id="itemType"
488              title="Item type"
489            />
490            <tbl:columndef 
491              id="name"
492              title="Name"
493            />
494            <tbl:columndef 
495              id="permissions"
496              title="Permissions"
497            />
498            <tbl:data>
499              <tbl:columns>
500              </tbl:columns>
501              <tbl:rows>
502              <%
503              for (Project project : projects)               
504              {
505                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
506                %>     
507                <tbl:row>
508                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
509                  <tbl:cell column="name"><base:icon 
510                    image="deleted.gif" 
511                    tooltip="This item has been scheduled for deletion" 
512                    visible="<%=project.isRemoved()%>"
513                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
514                  <tbl:cell column="permissions">
515                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
516                  </tbl:cell>
517                </tbl:row>
518                <%
519              }
520              for (Group group : groups)
521              {
522                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
523                %>
524                <tbl:row>             
525                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
526                  <tbl:cell column="name"><base:icon 
527                    image="deleted.gif" 
528                    tooltip="This item has been scheduled for deletion" 
529                    visible="<%=group.isRemoved()%>"
530                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
531                  <tbl:cell column="permissions">
532                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
533                  </tbl:cell>
534                </tbl:row>
535                <% 
536              }
537              for (User user : users)
538              {
539                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
540                %>
541                <tbl:row>             
542                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
543                  <tbl:cell column="name"><base:icon 
544                    image="deleted.gif" 
545                    tooltip="This item has been scheduled for deletion" 
546                    visible="<%=user.isRemoved()%>"
547                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
548                  <tbl:cell column="permissions">
549                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
550                  </tbl:cell>
551                </tbl:row>
552                <%
553              }
554              %>
555              </tbl:rows>
556            </tbl:data>
557          </tbl:table>
558        </base:section>
559        <%
560      }
561      else
562      {
563        %>
564        <h4>Shared to</h4>
565        This plate is not shared
566        (or, you don't have permission to view the ones it is shared to).
567        <%
568      }
569      %>
570
571
572    </div>
573      </t:tab>
574     
575      <t:tab id="annotations" title="Annotations" >
576        <div class="boxed">
577        <jsp:include page="../../common/annotations/list_annotations.jsp">
578          <jsp:param name="item_type" value="<%=itemType.name()%>" />
579          <jsp:param name="item_id" value="<%=itemId%>" />
580          <jsp:param name="ID" value="<%=ID%>" />
581        </jsp:include>
582        </div>
583      </t:tab>
584     
585      <t:tab id="events" title="Events" />
586      <t:tab id="wells" title="Wells" />
587      <t:tab id="history" title="Change history" 
588        tooltip="Displays a log of all modifications made to this item"
589        visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>">
590        <%
591        if ("history".equals(tab))
592        {
593          %>
594          <jsp:include page="../../common/history/frameset.jsp">
595            <jsp:param name="source_type" value="<%=itemType.name()%>" />
596            <jsp:param name="source_id" value="<%=itemId%>" />
597            <jsp:param name="ID" value="<%=ID%>" />
598          </jsp:include>
599          <%
600        }
601        %>
602      </t:tab>
603      </t:tabcontrol>
604
605  </base:body>
606  </base:page>
607  <%
608}
609finally
610{
611  if (dc != null) dc.close();
612}
613
614%>
Note: See TracBrowser for help on using the repository browser.