source: trunk/www/admin/annotationtypes/view_annotationtype.jsp @ 5070

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

References #108: Logging the change history of an item

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