source: trunk/www/admin/protocols/view_protocol.jsp @ 5069

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

References #108: Logging the change history of an item

  • Enabled logging for experiments
  • Added "Change history" tab to experiments, plugin configuration and protocol
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.6 KB
Line 
1<%-- $Id: view_protocol.jsp 5069 2009-08-20 08:53:16Z 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.Protocol"
35  import="net.sf.basedb.core.ProtocolType"
36  import="net.sf.basedb.core.AnnotationType"
37  import="net.sf.basedb.core.File"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.PluginDefinition"
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.MultiPermissions"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.core.Project"
48  import="net.sf.basedb.core.query.Orders"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
52  import="net.sf.basedb.clients.web.PermissionUtil"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.formatter.Formatter"
55  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
56  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
57  import="net.sf.basedb.clients.web.extensions.JspContext"
58  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
59  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
60  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
61  import="java.util.Date"
62  import="net.sf.basedb.util.Values"
63  import="java.util.Collections"
64  import="java.util.Map"
65  import="java.util.Set"
66%>
67<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
68<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
69<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
70<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
71<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
72<%!
73  private static final Item itemType = Item.PROTOCOL;
74  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
75%>
76<%
77final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
78final String ID = sc.getId();
79final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
80final int itemId = cc.getId();
81final String tab = Values.getString(request.getParameter("tab"), "properties");
82final float scale = Base.getScale(sc);
83final DbControl dc = sc.newDbControl();
84try
85{
86  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
87  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
88
89  String title = null;
90  Protocol protocol = Protocol.getById(dc, itemId);
91 
92  final boolean writePermission = protocol.hasPermission(Permission.WRITE);
93  final boolean deletePermission = protocol.hasPermission(Permission.DELETE);
94  final boolean sharePermission = protocol.hasPermission(Permission.SET_PERMISSION);
95  final boolean setOwnerPermission = protocol.hasPermission(Permission.SET_OWNER);
96  final boolean isRemoved = protocol.isRemoved();
97  final boolean isUsed = isRemoved && protocol.isUsed();
98  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
99  final boolean isOwner = protocol.isOwner();
100  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, protocol);
101  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
102  %>
103  <base:page title="<%=title%>">
104  <base:head scripts="tabcontrol.js,table.js" styles="toolbar.css,headertabcontrol.css,path.css,table.css">
105    <ext:scripts context="<%=jspContext%>" />
106    <ext:stylesheets context="<%=jspContext%>" />
107    <script language="JavaScript">
108    function editItem()
109    {
110      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
111    }
112    function shareItem()
113    {
114      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareProtocol', 600, 400);
115    }
116    function deleteItem()
117    {
118      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
119    }
120    function restoreItem()
121    {
122      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
123    }
124    function deleteItemPermanently()
125    {
126      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
127    }
128    function itemDeleted()
129    {
130      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
131    }
132    function showUsingItems()
133    {
134      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
135    }
136    function setOwner()
137    {
138      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
139    }
140    function runPlugin(cmd)
141    {
142      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
143    }
144    function switchTab(tabControlId, tabId)
145    {
146      if (TabControl.isActive(tabControlId, tabId)) return;
147      if (tabId == 'history' && tabId != '<%=tab%>')
148      {
149        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=itemId%>&tab='+tabId;
150      }
151      else
152      {
153        TabControl.setActiveTab(tabControlId, tabId);
154      }
155    }
156    </script>
157  </base:head>
158  <base:body>
159    <p>
160    <p:path>
161      <p:pathelement title="Protocols" href="<%="index.jsp?ID="+ID%>" />
162      <p:pathelement title="<%=HTML.encodeTags(protocol.getName())%>" />
163    </p:path>
164   
165    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab" remember="false">
166    <t:tab id="properties" title="Properties">
167   
168    <tbl:toolbar
169      >
170      <tbl:button 
171        disabled="<%=writePermission ? false : true%>" 
172        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
173        onclick="editItem()" 
174        title="Edit&hellip;" 
175        tooltip="<%=writePermission ? "Edit this protocol" : "You do not have permission to edit this protocol"%>" 
176      />
177      <tbl:button 
178        disabled="<%=deletePermission ? false : true%>" 
179        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
180        onclick="deleteItem()" 
181        title="Delete"
182        visible="<%=!protocol.isRemoved()%>"
183        tooltip="<%=deletePermission ? "Delete this protocol" : "You do not have permission to delete this protocol"%>" 
184      />
185      <tbl:button 
186        disabled="<%=writePermission ? false : true%>" 
187        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
188        onclick="restoreItem()" 
189        title="Restore"
190        visible="<%=protocol.isRemoved()%>"
191        tooltip="<%=writePermission ? "Restore this protocol" : "You do not have permission to restore this protocol"%>" 
192      />
193      <tbl:button 
194        disabled="<%=sharePermission ? false : true%>"
195        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
196        onclick="shareItem()" 
197        title="Share&hellip;" 
198        tooltip="<%=sharePermission ? "Share this protocol to other user, groups and projects" : "You do not have permission to share this protocol"%>"
199      />
200      <tbl:button 
201        disabled="<%=setOwnerPermission ? false : true%>"
202        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
203        onclick="setOwner()" 
204        title="Set owner&hellip;"
205        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
206      />
207      <tbl:button 
208        image="import.gif" 
209        onclick="runPlugin('ImportItem')" 
210        title="Import&hellip;" 
211        tooltip="Import data" 
212        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
213      />
214      <tbl:button 
215        image="export.gif" 
216        onclick="runPlugin('ExportItem')" 
217        title="Export&hellip;" 
218        tooltip="Export data" 
219        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
220      />
221      <tbl:button 
222        image="runplugin.gif" 
223        onclick="runPlugin('RunPlugin')" 
224        title="Run plugin&hellip;" 
225        tooltip="Run a plugin" 
226        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
227      />
228      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
229        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
230      <tbl:button
231        image="help.gif"
232        onclick="<%="Main.openHelp('" + ID +"', 'protocol.view.properties')"%>"
233        title="Help&hellip;"
234        tooltip="Get help about this page"
235      />
236      </tbl:toolbar>
237    <div class="boxedbottom">
238      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(protocol)%></i></div>
239      <%
240      if (protocol.isRemoved() || protocol.isShared())
241      {
242        %>
243        <div class="itemstatus">
244          <base:icon 
245            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
246            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
247            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
248            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
249          <base:icon image="used.gif" 
250            onclick="showUsingItems()"
251            tooltip="Show the items that are using this one"
252            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
253          <base:icon image="shared.gif" 
254            visible="<%=protocol.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
255        </div>
256        <%
257      }
258      %>
259      <table class="form" cellspacing="0">
260      <tr>
261        <td class="prompt">Name</td>
262        <td><%=HTML.encodeTags(protocol.getName())%></td>
263      </tr>
264      <tr>
265        <td class="prompt">Type</td>
266        <td><base:propertyvalue item="<%=protocol%>" property="protocolType" /></td>
267      </tr>
268      <tr>
269        <td class="prompt">Registered</td>
270        <td><%=dateFormatter.format(protocol.getEntryDate())%></td>
271      </tr>
272      <tr>
273        <td class="prompt">File</td>
274        <td><base:propertyvalue item="<%=protocol%>" property="file" /></td>
275      </tr>
276      <tr>
277        <td class="prompt">Owner</td>
278        <td><base:propertyvalue item="<%=protocol%>" property="owner" /></td>
279      </tr>
280      <tr>
281        <td class="prompt">Description</td>
282        <td><%=HTML.niceFormat(protocol.getDescription())%></td>
283      </tr>
284      </table>
285
286      <%
287      ItemQuery<AnnotationType> parameterQuery = protocol.getParameters();
288      parameterQuery.include(Include.ALL);
289      parameterQuery.order(Orders.asc(Hql.property("name")));
290      ItemResultList<AnnotationType> parameters = parameterQuery.list(dc);
291      if (parameters.size() == 0)
292      {
293        %>
294        <h4>Parameters</h4>
295        No parameters has been added to this protocol
296        (or, you don't have permission to view them).
297        <%
298      }
299      else
300      {
301        %>
302        <base:section
303          id="parameters"
304          title="<%="Parameters (" + parameters.size() + ")"%>"
305          context="<%=cc%>"
306          >       
307          <tbl:table
308            id="parameters"
309            clazz="itemlist"
310            columns="all"
311            >
312          <tbl:columndef 
313            id="name"
314            title="Name"
315          />
316          <tbl:columndef
317            id="values"
318            title="Values"
319          />
320          <tbl:columndef 
321            id="description"
322            title="Description"
323          />
324          <tbl:data>
325            <tbl:columns>
326            </tbl:columns>
327            <tbl:rows>
328            <%
329            for (AnnotationType item : parameters)
330            {
331              %>
332              <tbl:row>
333                <tbl:cell column="name"><base:icon 
334                    image="deleted.gif" 
335                    tooltip="This item has been scheduled for deletion" 
336                    visible="<%=item.isRemoved()%>"
337                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
338                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
339                <tbl:cell column="values">
340                <%=item.isEnumeration() ? 
341                  "Enumeration: " + HTML.encodeTags(Values.getString(item.getValues(), ", ", true)) :
342                  item.getValueType()%>
343                </tbl:cell>
344              </tbl:row>
345              <%
346            }
347            %>
348            </tbl:rows>
349          </tbl:data>
350          </tbl:table>
351        </base:section>
352        <%
353      }     
354     
355      // Tables with users/groups/projects that this item is shared to
356      MultiPermissions mp = new MultiPermissions(Collections.singleton(protocol));
357      ItemResultList<User> users = mp.getUsers().list(dc);
358      ItemResultList<Group> groups = mp.getGroups().list(dc);
359      ItemResultList<Project> projects = mp.getProjects().list(dc);
360      int totalShare = (users.size() + groups.size() + projects.size());
361      if (totalShare > 0)
362      {
363        %>
364        <base:section 
365          id="sharedTo" 
366          title="<%="Shared to (" + totalShare + ")"%>"
367          context="<%=cc%>"
368          >       
369          <tbl:table 
370            id="itemsSharedTo"
371            clazz="itemlist"
372            columns="all"
373          >
374            <tbl:columndef 
375              id="itemType"
376              title="Item type"
377            />
378            <tbl:columndef 
379              id="name"
380              title="Name"
381            />
382            <tbl:columndef 
383              id="permissions"
384              title="Permissions"
385            />
386            <tbl:data>
387              <tbl:columns>
388              </tbl:columns>
389              <tbl:rows>
390              <%
391              for (Project project : projects)
392              {
393                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
394                %>     
395                <tbl:row>
396                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
397                  <tbl:cell column="name"><base:icon 
398                    image="deleted.gif" 
399                    tooltip="This item has been scheduled for deletion" 
400                    visible="<%=project.isRemoved()%>"
401                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
402                  <tbl:cell column="permissions">
403                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
404                  </tbl:cell>
405                </tbl:row>
406                <%
407              }
408              for (Group group : groups)
409              {
410                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
411                %>
412                <tbl:row>             
413                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
414                  <tbl:cell column="name"><base:icon 
415                    image="deleted.gif" 
416                    tooltip="This item has been scheduled for deletion" 
417                    visible="<%=group.isRemoved()%>"
418                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
419                  <tbl:cell column="permissions">
420                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
421                  </tbl:cell>
422                </tbl:row>
423                <% 
424              }
425              for (User user : users)
426              {
427                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
428                %>
429                <tbl:row>             
430                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
431                  <tbl:cell column="name"><base:icon 
432                    image="deleted.gif" 
433                    tooltip="This item has been scheduled for deletion" 
434                    visible="<%=user.isRemoved()%>"
435                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
436                  <tbl:cell column="permissions">
437                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
438                  </tbl:cell>
439                </tbl:row>
440                <%
441              }
442              %>
443              </tbl:rows>
444            </tbl:data>
445          </tbl:table>
446        </base:section>
447        <%
448      }
449      else
450      {
451        %>
452        <h4>Shared to</h4>
453        This protocol is not shared
454        (or, you don't have permission to view the ones it is shared to).
455        <%
456      }
457      %> 
458    </div>
459    </t:tab>
460     
461    <t:tab id="annotations" title="Annotations" 
462      tooltip="View annotation values">
463      <div class="boxed">
464      <jsp:include page="../../common/annotations/list_annotations.jsp">
465        <jsp:param name="item_type" value="<%=itemType.name()%>" />
466        <jsp:param name="item_id" value="<%=itemId%>" />
467        <jsp:param name="ID" value="<%=ID%>" />
468      </jsp:include>
469      </div>
470    </t:tab>
471    <t:tab id="history" title="Change history" 
472      tooltip="Displays a log of all modifications made to this item"
473      visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>">
474      <%
475      if ("history".equals(tab))
476      {
477        %>
478        <jsp:include page="../../common/history/frameset.jsp">
479          <jsp:param name="source_type" value="<%=itemType.name()%>" />
480          <jsp:param name="source_id" value="<%=itemId%>" />
481          <jsp:param name="ID" value="<%=ID%>" />
482        </jsp:include>
483        <%
484      }
485      %>
486    </t:tab>
487    </t:tabcontrol>
488
489  </base:body>
490  </base:page>
491  <%
492}
493finally
494{
495  if (dc != null) dc.close();
496}
497
498%>
Note: See TracBrowser for help on using the repository browser.