source: trunk/www/views/formulas/view_formula.jsp @ 5065

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

References #108: Logging the change history of an item

  • Added "Change history" tab to file and formula view pages
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.9 KB
Line 
1<%-- $Id: view_formula.jsp 5065 2009-08-19 12:42:25Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Nicklas Nordborg, 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.ItemResultList"
34  import="net.sf.basedb.core.MultiPermissions"
35  import="net.sf.basedb.core.Permission"
36  import="net.sf.basedb.core.Formula"
37  import="net.sf.basedb.core.Coloring"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.RawDataType"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.PluginDefinition"
42  import="net.sf.basedb.core.plugin.GuiContext"
43  import="net.sf.basedb.core.plugin.Plugin"
44  import="net.sf.basedb.core.Project"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.util.formatter.Formatter"
51  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
52  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
53  import="net.sf.basedb.clients.web.extensions.JspContext"
54  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
55  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
56  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
57  import="java.util.Date"
58  import="java.util.Collections"
59  import="java.util.List"
60  import="java.util.Map"
61  import="java.util.Set"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
65<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
66<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
67<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
68<%!
69  private static final Item itemType = Item.FORMULA;
70  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
71%>
72<%
73final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
74final String ID = sc.getId();
75final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
76final int itemId = cc.getId();
77final String tab = Values.getString(request.getParameter("tab"), "properties");
78final float scale = Base.getScale(sc);
79final DbControl dc = sc.newDbControl();
80try
81{
82  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
83  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
84
85  String title = null;
86  final Formula formula = Formula.getById(dc, itemId);
87  final RawDataType rawDataType = formula.getRawDataType();
88  final List<String> expressions = formula.getFormulas();
89  final Coloring coloring = formula.getColoring();
90 
91  final boolean writePermission = formula.hasPermission(Permission.WRITE);
92  final boolean deletePermission = formula.hasPermission(Permission.DELETE);
93  final boolean sharePermission = formula.hasPermission(Permission.SET_PERMISSION);
94  final boolean setOwnerPermission = formula.hasPermission(Permission.SET_OWNER);
95  final boolean isRemoved = formula.isRemoved();
96  final boolean isUsed = isRemoved && formula.isUsed();
97  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
98  final boolean isOwner = formula.isOwner();
99  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, formula);
100  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
101  %>
102  <base:page title="<%=title%>">
103  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.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%>', 'ShareFormula', 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="Formulas" href="<%="index.jsp?ID="+ID%>" />
161      <p:pathelement title="<%=HTML.encodeTags(formula.getName())%>" />
162    </p:path>
163   
164    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab" remember="false">
165    <t:tab id="properties" title="Properties">
166    <tbl:toolbar
167      >
168      <tbl:button 
169        disabled="<%=writePermission ? false : true%>" 
170        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
171        onclick="editItem()" 
172        title="Edit&hellip;" 
173        tooltip="<%=writePermission ? "Edit this formula" : "You do not have permission to edit this formula"%>" 
174      />
175      <tbl:button 
176        disabled="<%=deletePermission ? false : true%>" 
177        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
178        onclick="deleteItem()" 
179        title="Delete"
180        visible="<%=!formula.isRemoved()%>"
181        tooltip="<%=deletePermission ? "Delete this formula" : "You do not have permission to delete this formula"%>" 
182      />
183      <tbl:button 
184        disabled="<%=writePermission ? false : true%>" 
185        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
186        onclick="restoreItem()" 
187        title="Restore"
188        visible="<%=formula.isRemoved()%>"
189        tooltip="<%=writePermission ? "Restore this formula" : "You do not have permission to restore this formula"%>" 
190      />
191      <tbl:button 
192        disabled="<%=sharePermission ? false : true%>"
193        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
194        onclick="shareItem()" 
195        title="Share&hellip;" 
196        tooltip="<%=sharePermission ? "Share this formula to other user, groups and projects" : "You do not have permission to share this formula"%>"
197      />
198      <tbl:button 
199        disabled="<%=setOwnerPermission ? false : true%>"
200        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
201        onclick="setOwner()" 
202        title="Set owner&hellip;"
203        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
204      />
205      <tbl:button 
206        image="import.gif" 
207        onclick="runPlugin('ImportItem')" 
208        title="Import&hellip;" 
209        tooltip="Import data" 
210        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
211      />
212      <tbl:button 
213        image="export.gif" 
214        onclick="runPlugin('ExportItem')" 
215        title="Export&hellip;" 
216        tooltip="Export data" 
217        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
218      />
219      <tbl:button 
220        image="runplugin.gif" 
221        onclick="runPlugin('RunPlugin')" 
222        title="Run plugin&hellip;" 
223        tooltip="Run a plugin" 
224        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
225      />
226      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
227        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
228      <tbl:button
229        image="help.gif"
230        onclick="<%="Main.openHelp('" + ID +"', 'formula.view.properties')"%>"
231        title="Help&hellip;"
232        tooltip="Get help about this page"
233      />
234      </tbl:toolbar>
235    <div class="boxedbottom">
236      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(formula)%></i></div>
237      <%
238      if (formula.isRemoved() || formula.isShared())
239      {
240        %>
241        <div class="itemstatus">
242          <base:icon 
243            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
244            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
245            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
246            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
247          <base:icon image="used.gif" 
248            onclick="showUsingItems()"
249            tooltip="Show the items that are using this one"
250            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
251          <base:icon image="shared.gif" 
252            visible="<%=formula.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
253        </div>
254        <%
255      }
256      %>
257      <table class="form" cellspacing="0">
258      <tr>
259        <td class="prompt">Name</td>
260        <td><%=HTML.encodeTags(formula.getName())%></td>
261      </tr>
262      <tr>
263        <td class="prompt">Registered</td>
264        <td><%=dateFormatter.format(formula.getEntryDate())%></td>
265      </tr>
266      <tr>
267        <td class="prompt">Type</td>
268        <td><%=formula.getFormulaType()%></td>
269      </tr>
270      <tr>
271        <td class="prompt">Parser</td>
272        <td><%=formula.getParser()%></td>
273      </tr>
274      <tr>
275        <td class="prompt">Raw data type</td>
276        <td><%=rawDataType == null ? "<i>- none -</i>" : HTML.encodeTags(rawDataType.getName())%></td>
277      </tr>
278      <tr>
279        <td class="prompt">Channels</td>
280        <td><%=formula.getChannels()%></td>
281      </tr>
282      <tr valign="baseline">
283        <td class="prompt">Expressions</td>
284        <td>
285          <%
286          for (int i = 0; i < expressions.size(); ++i)
287          {
288            %>
289            <%=(i+1) + ": " + HTML.encodeTags(expressions.get(i))%><br>
290            <%
291          }
292          %>
293        </td>
294      </tr>
295      <tr>
296        <td class="prompt">Avg. method</td>
297        <td><%=formula.getAverageMethod().toString()%></td>
298      </tr>
299      <tr>
300        <td class="prompt">Source intensity transform</td>
301        <td><%=formula.getSourceIntensityTransform() == null ? "<i>- any -</i>" : formula.getSourceIntensityTransform().toString()%></td>
302      </tr>
303      <tr>
304        <td class="prompt">Result intensity transform</td>
305        <td><%=formula.getResultIntensityTransform() == null ? "<i>- any -</i>" : formula.getResultIntensityTransform().toString()%></td>
306      </tr>
307      <tr>
308        <td class="prompt">Use coloring</td>
309        <td>
310          <%=coloring.isUsingColors() ? "yes" : "no"%>
311          <%
312          if (coloring.isUsingColors())
313          {
314            %>
315            <b>Range</b> 
316            [<%=Values.formatNumber(coloring.getMinValue(), 2)%>,
317            <%=Values.formatNumber(coloring.getMidValue(), 2)%>,
318            <%=Values.formatNumber(coloring.getMaxValue(), 2)%>]
319            <b>Logarithmic</b> <%=coloring.isLogarithmic() ? "yes" : "no" %>
320            <%
321          }
322          %>
323        </td>
324      </tr>
325      <tr>
326        <td class="prompt">Owner</td>
327        <td><base:propertyvalue item="<%=formula%>" property="owner" /></td>
328      </tr>
329      <tr>
330        <td class="prompt">Description</td>
331        <td><%=HTML.niceFormat(formula.getDescription())%></td>
332      </tr>
333      </table>
334      <%     
335     
336      // Tables with users/groups/projects that this item is shared to
337      MultiPermissions mp = new MultiPermissions(Collections.singleton(formula));
338      ItemResultList<User> users = mp.getUsers().list(dc);
339      ItemResultList<Group> groups = mp.getGroups().list(dc);
340      ItemResultList<Project> projects = mp.getProjects().list(dc);
341      int totalShare = users.size() + groups.size() + projects.size();
342     
343      if (totalShare > 0)
344      {
345        %>
346        <base:section
347          id="sharedTo"
348          title="<%="Shared to (" + totalShare + ")"%>"
349          context="<%=cc%>"
350          >
351          <tbl:table 
352            id="itemsSharedTo"
353            clazz="itemlist"
354            columns="all"
355          >
356            <tbl:columndef 
357              id="itemType"
358              title="Item type"
359            />
360            <tbl:columndef 
361              id="name"
362              title="Name"
363            />
364            <tbl:columndef 
365              id="permissions"
366              title="Permissions"
367            />
368            <tbl:data>
369              <tbl:columns>
370              </tbl:columns>
371              <tbl:rows>
372              <%
373              for (Project project : projects)
374              {
375                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
376                %>     
377                <tbl:row>
378                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
379                  <tbl:cell column="name"><base:icon 
380                    image="deleted.gif" 
381                    tooltip="This item has been scheduled for deletion" 
382                    visible="<%=project.isRemoved()%>"
383                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
384                  <tbl:cell column="permissions">
385                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
386                  </tbl:cell>
387                </tbl:row>
388                <%
389              }
390              for (Group group : groups)
391              {
392                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
393                %>
394                <tbl:row>             
395                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
396                  <tbl:cell column="name"><base:icon 
397                    image="deleted.gif" 
398                    tooltip="This item has been scheduled for deletion" 
399                    visible="<%=group.isRemoved()%>"
400                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
401                  <tbl:cell column="permissions">
402                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
403                  </tbl:cell>
404                </tbl:row>
405                <% 
406              }
407              for (User user : users)
408              {
409                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
410                %>
411                <tbl:row>             
412                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
413                  <tbl:cell column="name"><base:icon 
414                    image="deleted.gif" 
415                    tooltip="This item has been scheduled for deletion" 
416                    visible="<%=user.isRemoved()%>"
417                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
418                  <tbl:cell column="permissions">
419                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
420                  </tbl:cell>
421                </tbl:row>
422                <%
423              }
424              %>
425              </tbl:rows>
426            </tbl:data>
427          </tbl:table>
428        </base:section>
429        <%
430      }
431      else
432      {
433        %>
434        <h4>Shared to</h4>
435        This formula is not shared
436        (or, you don't have permission to view the ones it is shared to).
437        <%
438      }     
439      %>
440
441    </div>
442    </t:tab>
443    <t:tab id="history" title="Change history" 
444      tooltip="Displays a log of all modifications made to this item"
445      visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>">
446      <%
447      if ("history".equals(tab))
448      {
449        %>
450        <jsp:include page="../../common/history/frameset.jsp">
451          <jsp:param name="source_type" value="<%=itemType.name()%>" />
452          <jsp:param name="source_id" value="<%=itemId%>" />
453          <jsp:param name="ID" value="<%=ID%>" />
454        </jsp:include>
455        <%
456      }
457      %>
458    </t:tab>
459    </t:tabcontrol>
460
461  </base:body>
462  </base:page>
463  <%
464}
465finally
466{
467  if (dc != null) dc.close();
468}
469
470%>
Note: See TracBrowser for help on using the repository browser.