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

Last change on this file since 5045 was 5045, checked in by Martin Svensson, 14 years ago

Fixes #360 Make subsections on view pages hideable.

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