source: trunk/www/admin/pluginconfigurations/view_configuration.jsp @ 5937

Last change on this file since 5937 was 5937, checked in by Nicklas Nordborg, 11 years ago

References #1655: GUI improvements

  • Fixes rest of view pages in biomaterials menu.
  • Use SVG filter to make disabled button images grayscale.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.3 KB
Line 
1<%-- $Id: view_configuration.jsp 5937 2012-01-27 11:00:26Z 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 pageEncoding="UTF-8" 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.ItemResultIterator"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.PluginDefinition"
36  import="net.sf.basedb.core.PluginConfiguration"
37  import="net.sf.basedb.core.ParameterInfo"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.BasicItem"
40  import="net.sf.basedb.core.File"
41  import="net.sf.basedb.core.MultiPermissions"
42  import="net.sf.basedb.core.Nameable"
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.Project"
48  import="net.sf.basedb.util.JarClassLoader"
49  import="net.sf.basedb.util.ToStringComparator"
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.Values"
55  import="net.sf.basedb.util.formatter.Formatter"
56  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
57  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
58  import="net.sf.basedb.clients.web.extensions.JspContext"
59  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
60  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
61  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
62  import="java.util.Map"
63  import="java.util.Set"
64  import="java.util.TreeSet"
65  import="java.util.List"
66  import="java.util.Collections"
67  import="java.util.Date"
68%>
69<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
70<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
71<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
72<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
73<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
74<%!
75  private static final Item itemType = Item.PLUGINCONFIGURATION;
76  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
77%>
78<%
79final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
80final String ID = sc.getId();
81final String root = request.getContextPath() + "/";
82final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
83final int itemId = cc.getId();
84final String tab = Values.getString(request.getParameter("tab"), "properties");
85final float scale = Base.getScale(sc);
86final DbControl dc = sc.newDbControl();
87try
88{
89  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
90  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
91  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
92
93  String title = null;
94  PluginConfiguration configuration = PluginConfiguration.getById(dc, itemId);
95 
96  final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
97  final boolean writePermission = configuration.hasPermission(Permission.WRITE);
98  final boolean deletePermission = configuration.hasPermission(Permission.DELETE);
99  final boolean sharePermission = configuration.hasPermission(Permission.SET_PERMISSION);
100  final boolean setOwnerPermission = configuration.hasPermission(Permission.SET_OWNER);
101  final boolean isRemoved = configuration.isRemoved();
102  final boolean isUsed = isRemoved && configuration.isUsed();
103  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
104  final boolean isOwner = configuration.isOwner();
105
106  final Set<GuiContext> contexts = new TreeSet<GuiContext>(new ToStringComparator<GuiContext>(false));
107  PluginDefinition plugin = null;
108  Nameable nameableProxy = null;
109  boolean readPlugin = true;
110  boolean configurable = false;
111  try
112  {
113    plugin = configuration.getPluginDefinition();
114    contexts.addAll(plugin.getGuiContexts());
115    configurable = plugin.isInteractive() && plugin.supportsConfigurations();
116  }
117  catch (PermissionDeniedException ex)
118  {
119    readPlugin = false;
120  }
121  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, configuration);
122  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
123  %>
124 
125<%@page import="net.sf.basedb.core.Type"%><base:page title="<%=title%>">
126  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
127    <ext:scripts context="<%=jspContext%>" />
128    <ext:stylesheets context="<%=jspContext%>" />
129    <script language="JavaScript">
130    function editItem()
131    {
132      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
133    }
134    function copyItem()
135    {
136      Main.copyItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
137    }
138    function shareItem()
139    {
140      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareConfiguration', 600, 400);
141    }
142    function deleteItem()
143    {
144      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
145    }
146    function restoreItem()
147    {
148      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
149    }
150    function deleteItemPermanently()
151    {
152      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
153    }
154    function itemDeleted()
155    {
156      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
157    }
158    function showUsingItems()
159    {
160      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
161    }
162    function setOwner()
163    {
164      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 300);
165    }
166    function runPlugin(cmd)
167    {
168      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 750, 500);
169    }
170    function configure()
171    {
172      Main.openPopup('../../common/plugin/index.jsp?ID=<%=ID%>&cmd=ConfigurePlugin&pluginconfiguration_id=<%=itemId%>', 'ConfigurePlugin', 750, 500);
173    }
174    function switchTab(tabControlId, tabId)
175    {
176      if (TabControl.isActive(tabControlId, tabId)) return;
177      if (tabId == 'history' && tabId != '<%=tab%>')
178      {
179        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=itemId%>&tab='+tabId;
180      }
181      else
182      {
183        TabControl.setActiveTab(tabControlId, tabId);
184      }
185    }
186    </script>
187  </base:head>
188  <base:body>
189    <p>
190    <p:path>
191      <p:pathelement title="Plugin configurations" href="<%="index.jsp?ID="+ID%>" />
192      <p:pathelement title="<%=HTML.encodeTags(configuration.getName())%>" />
193    </p:path>
194   
195    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab" remember="false">
196    <t:tab id="properties" title="Properties">
197    <tbl:toolbar
198      >
199      <tbl:button 
200        disabled="<%=writePermission ? false : true%>" 
201        image="edit.gif" 
202        onclick="editItem()" 
203        title="Edit&hellip;" 
204        tooltip="<%=writePermission ? "Edit this plugin configuration" : "You do not have permission to edit this plugin configuration"%>" 
205      />
206      <tbl:button 
207        disabled="<%=!createPermission%>" 
208        image="<%=createPermission ? "copy.gif" : "copy_disabled.gif"%>"
209        onclick="copyItem()" 
210        title="Copy&hellip;" 
211        tooltip="<%=createPermission ? "Create a copy of this configuration" : "You do not have permission to create new configurations"%>"
212      />
213      <tbl:button 
214        disabled="<%=deletePermission ? false : true%>" 
215        image="delete.gif" 
216        onclick="deleteItem()" 
217        title="Delete"
218        visible="<%=!configuration.isRemoved()%>"
219        tooltip="<%=deletePermission ? "Delete this plugin configuration" : "You do not have permission to delete this plugin configuration"%>" 
220      />
221      <tbl:button 
222        disabled="<%=writePermission ? false : true%>" 
223        image="restore.gif" 
224        onclick="restoreItem()" 
225        title="Restore"
226        visible="<%=configuration.isRemoved()%>"
227        tooltip="<%=writePermission ? "Restore this plugin configuration" : "You do not have permission to restore this plugin configuration"%>" 
228      />
229      <tbl:button 
230        disabled="<%=sharePermission ? false : true%>"
231        image="share.gif"
232        onclick="shareItem()" 
233        title="Share&hellip;" 
234        tooltip="<%=sharePermission ? "Share this plugin configuration to other user, groups and projects" : "You do not have permission to share this plugin configuration"%>"
235      />
236      <tbl:button 
237        disabled="<%=setOwnerPermission ? false : true%>"
238        image="take_ownership.png"
239        onclick="setOwner()" 
240        title="Set owner&hellip;"
241        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
242      />
243      <tbl:button 
244        image="import.gif" 
245        onclick="runPlugin('ImportItem')" 
246        title="Import&hellip;" 
247        tooltip="Import data" 
248        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
249      />
250      <tbl:button 
251        image="export.gif" 
252        onclick="runPlugin('ExportItem')" 
253        title="Export&hellip;" 
254        tooltip="Export data" 
255        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
256      />
257      <tbl:button 
258        image="runplugin.gif" 
259        onclick="runPlugin('RunPlugin')" 
260        title="Run plugin&hellip;" 
261        tooltip="Run a plugin" 
262        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
263      />
264      <tbl:button
265        image="runplugin.gif"
266        onclick="configure()"
267        title="Configure&hellip;"
268        tooltip="Configure this plugin"
269        visible="<%=configurable && writePermission%>"
270      />
271      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
272        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
273      <tbl:button
274        image="help.png"
275        onclick="<%="Main.openHelp('" + ID +"', 'pluginconfiguration.view.properties')"%>"
276        title="Help&hellip;"
277        tooltip="Get help about this page"
278      />
279      </tbl:toolbar>
280    <div class="boxedbottom">
281      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(configuration)%></i></div>
282      <%
283      if (configuration.isRemoved() || configuration.isShared())
284      {
285        %>
286        <div class="itemstatus">
287          <base:icon 
288            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
289            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
290            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
291            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
292          <base:icon image="used.gif" 
293            onclick="showUsingItems()"
294            tooltip="Show the items that are using this one"
295            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
296          <base:icon image="shared.gif" 
297            visible="<%=configuration.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
298        </div>
299        <%
300      }
301      %>
302      <table class="form" cellspacing="0">
303      <tr>
304        <td class="prompt">Name</td>
305        <td><%=HTML.encodeTags(configuration.getName())%></td>
306      </tr>
307      <tr>
308        <td class="prompt">Registered</td>
309        <td><%=dateFormatter.format(configuration.getEntryDate())%></td>
310      </tr>
311      <tr>
312        <td class="prompt">Plugin</td>
313        <td>
314          <%=Base.getLinkedName(ID, plugin, plugin == null, true)%>
315        </td>
316      </tr>
317      <tr>
318        <td class="prompt">Type</td>
319        <td><%=plugin == null ? "<i>- denied -</i>" : plugin.getMainType().toString()%></td>
320      </tr>
321      <tr>
322        <td class="prompt">Owner</td>
323        <td><base:propertyvalue item="<%=configuration%>" property="owner" /></td>
324      </tr>
325      <tr >
326        <td class="prompt">Description</td>
327        <td><%=HTML.niceFormat(configuration.getDescription())%></td>
328      </tr>
329      </table>
330      <jsp:include page="../../common/anytoany/list_anytoany.jsp">
331        <jsp:param name="ID" value="<%=ID%>" />
332        <jsp:param name="item_type" value="<%=itemType.name()%>" />
333        <jsp:param name="item_id" value="<%=itemId%>" />
334        <jsp:param name="title" value="Other items related to this plugin configuration" />
335      </jsp:include>
336   
337      <%   
338      // Tables with users/groups/projects that this item is shared to
339      MultiPermissions mp = new MultiPermissions(Collections.singleton(configuration));
340      List<User> users = mp.getUsers().list(dc);
341      List<Group> groups = mp.getGroups().list(dc);
342      List<Project> projects = mp.getProjects().list(dc);
343      int totalShare = users.size() + groups.size() + projects.size();
344     
345      if (totalShare > 0)
346      {
347        %>
348        <base:section
349          id="sharedTo"
350          title="<%="Shared to (" + totalShare + ")"%>"
351          context="<%=cc%>"
352          >
353          <tbl:table 
354            id="itemsSharedTo"
355           
356            columns="all"
357          >
358            <tbl:columndef 
359              id="itemType"
360              title="Item type"
361            />
362            <tbl:columndef 
363              id="name"
364              title="Name"
365            />
366            <tbl:columndef 
367              id="permissions"
368              title="Permissions"
369            />
370            <tbl:data>
371              <tbl:columns>
372              </tbl:columns>
373              <tbl:rows>
374              <%
375              for (Project project : projects)
376              {             
377                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
378                %>     
379                <tbl:row>
380                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
381                  <tbl:cell column="name"><base:icon 
382                    image="deleted.gif" 
383                    tooltip="This item has been scheduled for deletion" 
384                    visible="<%=project.isRemoved()%>"
385                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
386                  <tbl:cell column="permissions">
387                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
388                  </tbl:cell>
389                </tbl:row>
390                <%
391              }
392              for (Group group : groups)
393              {
394                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
395                %>
396                <tbl:row>             
397                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
398                  <tbl:cell column="name"><base:icon 
399                    image="deleted.gif" 
400                    tooltip="This item has been scheduled for deletion" 
401                    visible="<%=group.isRemoved()%>"
402                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
403                  <tbl:cell column="permissions">
404                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
405                  </tbl:cell>
406                </tbl:row>
407                <% 
408              }
409              for (User user : users)
410              {               
411                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
412                %>
413                <tbl:row>             
414                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
415                  <tbl:cell column="name"><base:icon 
416                    image="deleted.gif" 
417                    tooltip="This item has been scheduled for deletion" 
418                    visible="<%=user.isRemoved()%>"
419                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
420                  <tbl:cell column="permissions">
421                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
422                  </tbl:cell>
423                </tbl:row>
424                <%
425              }
426              %>
427              </tbl:rows>
428            </tbl:data>
429          </tbl:table>
430        </base:section>
431        <%
432      }
433      else
434      {
435        %>
436        <h4>Shared to</h4>
437        This configuration is not shared
438        (or, you don't have permission to view the ones it is shared to).
439        <%
440      }
441      %>
442    </div>
443
444      </t:tab>
445     
446      <t:tab id="parameters" title="Configuration parameters" >
447      <div class="boxed">
448      <table class="form" cellspacing="0">
449      <%
450      if (plugin != null)
451      {
452        List<String> names = new java.util.ArrayList<String>(configuration.getParameterNames());
453        if (names == null || names.size() == 0)
454        {
455          %>
456          No parameters has been specified.
457          <%
458        }
459        else
460        {
461          Collections.sort(names);
462          for (String name : names)
463          {
464            StringBuilder sb = new StringBuilder();
465            String displayValue = "";
466            String description = "";
467            try
468            {
469              ParameterInfo pi = configuration.getParameterInfo(name);
470              if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
471              description = HTML.encodeTags(pi.getDescription());
472              List<?> values = pi.getValues();
473              int i = 0;
474              for (Object value : values)
475              {
476                if (value != null)
477                {
478                  if (i > 0) sb.append(", ");
479                  i++;
480                  if (value instanceof BasicItem)
481                  {
482                    BasicItem item = (BasicItem)value;
483                    String itemName = "";
484                    if (item instanceof File)
485                    {
486                      sb.append(Base.getLinkedFile(ID, (File)item, false, true, true, root));
487                    }
488                    else 
489                    {
490                      if (item instanceof Nameable)
491                      {
492                        itemName = ((Nameable)item).getName();
493                      }
494                      else
495                      {
496                        itemName = item.toString();
497                      }
498                      sb.append(Base.getLink(ID, HTML.encodeTags(itemName), 
499                        item.getType(), item.getId(), item.hasPermission(Permission.WRITE)));
500                    }
501                  }
502                  else if (value instanceof Date)
503                  {
504                    if (pi.getValueType() == Type.TIMESTAMP)
505                    {
506                      sb.append(dateTimeFormatter.format((Date)value));
507                    }
508                    else
509                    {
510                      sb.append(dateFormatter.format((Date)value));
511                    }
512                  }
513                  else
514                  {
515                    sb.append(HTML.encodeTags(value.toString()));
516                  }
517                }
518              }
519              displayValue = sb.toString();
520            }
521            catch (Throwable ex)
522            {
523              displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
524            }
525            %>
526            <tr>
527              <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
528              <td>
529                <%=displayValue%>
530              </td>
531            </tr>
532            <%
533          }
534        }
535      }
536      %>
537      </table>
538      </div>
539      </t:tab>
540     
541      <t:tab id="annotations" title="Annotations" 
542        tooltip="View annotation values" 
543        visible="<%=plugin != null && plugin.supports("net.sf.basedb.core.plugin.AnnotationSetterPlugin") %>">
544        <div class="boxed">
545        <jsp:include page="../../common/annotations/list_annotations.jsp">
546          <jsp:param name="item_type" value="<%=itemType.name()%>" />
547          <jsp:param name="item_id" value="<%=itemId%>" />
548          <jsp:param name="ID" value="<%=ID%>" />
549        </jsp:include>
550        </div>
551      </t:tab>
552      <t:tab id="history" title="Change history" 
553        tooltip="Displays a log of all modifications made to this item"
554        visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>">
555        <%
556        if ("history".equals(tab))
557        {
558          %>
559          <jsp:include page="../../common/history/frameset.jsp">
560            <jsp:param name="source_type" value="<%=itemType.name()%>" />
561            <jsp:param name="source_id" value="<%=itemId%>" />
562            <jsp:param name="ID" value="<%=ID%>" />
563          </jsp:include>
564          <%
565        }
566        %>
567      </t:tab>
568      </t:tabcontrol>
569
570  </base:body>
571  </base:page>
572  <%
573}
574finally
575{
576  if (dc != null) dc.close();
577}
578
579%>
Note: See TracBrowser for help on using the repository browser.