source: trunk/www/admin/pluginconfigurations/list_configurations.jsp @ 3452

Last change on this file since 3452 was 3452, checked in by Nicklas Nordborg, 16 years ago

Fixes #558 and #568

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.0 KB
Line 
1<%-- $Id: list_configurations.jsp 3452 2007-06-05 11:58:36Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.PluginConfiguration"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.PluginDefinition"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.core.plugin.GuiContext"
43  import="net.sf.basedb.core.plugin.Plugin"
44  import="net.sf.basedb.util.Enumeration"
45  import="net.sf.basedb.util.JarClassLoader"
46  import="net.sf.basedb.util.ToStringComparator"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.ModeInfo"
49  import="net.sf.basedb.clients.web.PermissionUtil"
50  import="net.sf.basedb.clients.web.util.HTML"
51  import="net.sf.basedb.util.Values"
52  import="net.sf.basedb.clients.web.util.NameablePluginAdaptor"
53  import="java.util.List"
54  import="java.util.Map"
55  import="java.util.Set"
56  import="java.util.EnumSet"
57  import="java.util.TreeSet"
58%>
59<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
60<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
61<%!
62  private static final Item itemType = Item.PLUGINCONFIGURATION;
63  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
64  private static final Enumeration<String, String> itemTypes = new Enumeration<String, String>();
65  private static final Enumeration<String, String> mainTypes = new Enumeration<String, String>();
66
67  static
68  {
69    Set<Item> temp = new TreeSet<Item>(new ToStringComparator<Item>(false));
70    temp.addAll(EnumSet.complementOf(EnumSet.of(Item.SYSTEM)));
71    for (Item item : temp)
72    {
73      itemTypes.add(Integer.toString(item.getValue()), item.toString());
74    }
75    for (Plugin.MainType v : Plugin.MainType.values())
76    {
77      mainTypes.add(Integer.toString(v.getValue()), v.toString());
78    }
79  }
80%>
81<%
82final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
83final String ID = sc.getId();
84final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
85final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
86
87final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
88final String callback = request.getParameter("callback");
89final String title = mode.generateTitle("plugin configuration", "plugin configurations");
90final DbControl dc = sc.newDbControl();
91ItemResultIterator<PluginConfiguration> configurations = null;
92try
93{
94  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
95  try
96  {
97    final ItemQuery<PluginConfiguration> query = Base.getConfiguredQuery(cc, true, PluginConfiguration.getQuery(), mode);
98    query.join(Hql.innerJoin("pluginDefinition", Item.PLUGINDEFINITION.getAlias()));
99    query.join(Hql.leftJoin(Item.PLUGINDEFINITION.getAlias(), "guiContexts", "ctx", null, false));
100    query.setDistinct(true);
101    configurations = query.iterate(dc);
102  }
103  catch (Throwable t)
104  {
105    cc.setMessage(t.getMessage());
106  }
107  int numListed = 0;
108  %>
109  <base:page title="<%=title==null ? "Plugin configurations" : title%>" type="<%=mode.getPageType()%>">
110  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
111    <script language="JavaScript">
112    var submitPage = 'index.jsp';
113    var formId = 'configurations';
114    function newItem()
115    {
116      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
117    }
118    function editItem(itemId)
119    {
120      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
121    }
122    function viewItem(itemId)
123    {
124      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
125    }
126    function copyItem(itemId)
127    {
128      Main.copyItem('<%=ID%>', '<%=itemType.name()%>', itemId);
129    }
130    function itemOnClick(evt, itemId)
131    {
132      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
133    }
134    function deleteItems()
135    {
136      var frm = document.forms[formId];
137      if (Forms.numChecked(frm) == 0)
138      {
139        alert('Please select at least one item in the list');
140        return;
141      }
142      frm.action = submitPage;
143      frm.cmd.value = 'DeleteItems';
144      frm.submit();
145    }
146    function restoreItems()
147    {
148      var frm = document.forms[formId];
149      if (Forms.numChecked(frm) == 0)
150      {
151        alert('Please select at least one item in the list');
152        return;
153      }
154      frm.action = submitPage;
155      frm.cmd.value = 'RestoreItems';
156      frm.submit();
157    }
158    function unloadItems()
159    {
160      var frm = document.forms[formId];
161      if (Forms.numChecked(frm) == 0)
162      {
163        alert('Please select at least one item in the list');
164        return;
165      }
166      frm.action = submitPage;
167      frm.cmd.value = 'UnloadItems';
168      frm.submit();
169    }
170    function takeOwnership()
171    {
172      var frm = document.forms[formId];
173      if (Forms.numChecked(frm) == 0)
174      {
175        alert('Please select at least one item in the list');
176        return;
177      }
178      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
179      {
180        frm.action = submitPage;
181        frm.cmd.value = 'TakeOwnershipOfItems';
182        frm.submit();
183      }
184    }
185    function shareItem(itemId)
186    {
187      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareConfigurations', 500, 400);
188    }
189    function shareItems()
190    {
191      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
192    }
193    function configureColumns()
194    {
195      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
196    }
197    function runPlugin(cmd)
198    {
199      Table.submitToPopup(formId, cmd, 740, 540);
200    }
201    function returnSelected()
202    {
203      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
204      window.close();
205    }
206    function presetOnChange()
207    {
208      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
209    }
210    function configurePlugin(itemId)
211    {
212      Main.openPopup('../../common/plugin/index.jsp?ID=<%=ID%>&cmd=ConfigurePlugin&pluginconfiguration_id='+itemId, 'ConfigurePlugin', 800, 600);
213    }
214    </script>
215  </base:head>
216 
217  <base:body>
218    <%
219    if (cc.getMessage() != null)
220    {
221      %>
222      <div class="error"><%=cc.getMessage()%></div>
223      <%
224      cc.setMessage(null);
225    }
226    %>
227    <tbl:table 
228      id="configurations" 
229      clazz="itemlist" 
230      columns="<%=cc.getSetting("columns")%>"
231      sortby="<%=cc.getSortProperty()%>" 
232      direction="<%=cc.getSortDirection()%>"
233      title="<%=title%>"
234      action="index.jsp"
235      sc="<%=sc%>"
236      item="<%=itemType%>"
237      >
238      <tbl:hidden 
239        name="mode" 
240        value="<%=mode.getName()%>" 
241      />
242      <tbl:hidden 
243        name="callback" 
244        value="<%=callback%>" 
245        skip="<%=callback == null%>" 
246      />
247      <tbl:columndef 
248        id="name"
249        property="name"
250        datatype="string"
251        title="Name"
252        sortable="true" 
253        filterable="true"
254        exportable="true"
255        show="always" 
256      />
257      <tbl:columndef 
258        id="pluginType"
259        property="pluginDefinition.mainType"
260        datatype="int"
261        enumeration="<%=mainTypes%>"
262        title="Type"
263        sortable="true" 
264        filterable="true"
265        exportable="true"
266      />
267      <tbl:columndef 
268        id="contexts"
269        property="$ctx.itemType"
270        datatype="int"
271        enumeration="<%=itemTypes%>"
272        title="Items"
273        sortable="false" 
274        filterable="true"
275        exportable="false"
276      />
277      <tbl:columndef 
278        id="pluginDefinition"
279        property="pluginDefinition.name"
280        datatype="string"
281        title="Plugin definition"
282        sortable="true" 
283        filterable="true"
284        exportable="true"
285      />
286      <tbl:columndef 
287        id="owner"
288        property="owner.name"
289        datatype="string"
290        title="Owner"
291        sortable="true" 
292        filterable="true"
293        exportable="true"
294      />
295      <tbl:columndef 
296        id="description"
297        property="description"
298        datatype="string"
299        title="Description" 
300        sortable="true" 
301        filterable="true" 
302        exportable="true"
303      />
304      <tbl:columndef 
305        id="actions"
306        title="Actions"
307      />
308      <tbl:columndef
309        id="permission"
310        title="Permission"
311      />
312      <tbl:toolbar
313        visible="<%=mode.hasToolbar()%>"
314        >
315        <tbl:button 
316          disabled="<%=createPermission ? false : true%>" 
317          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
318          onclick="newItem()" 
319          title="New&hellip;" 
320          tooltip="<%=createPermission ? "Create new configuration" : "You do not have permission to create configurations"%>" 
321        />
322        <tbl:button 
323          image="delete.gif"
324          onclick="deleteItems()" 
325          title="Delete" 
326          tooltip="Delete the selected items" 
327        />
328        <tbl:button 
329          image="restore.gif"
330          onclick="restoreItems()" 
331          title="Restore" 
332          tooltip="Restore the selected (deleted) items"
333        />
334        <tbl:button 
335          image="share.gif"
336          onclick="shareItems()" 
337          title="Share&hellip;" 
338          tooltip="Share the selected items"
339        />
340        <tbl:button 
341          image="take_ownership.png"
342          onclick="takeOwnership()" 
343          title="Take ownership&hellip;"
344          tooltip="Take ownership of the selected items"
345        />
346        <tbl:button 
347          image="columns.gif" 
348          onclick="configureColumns()" 
349          title="Columns&hellip;" 
350          tooltip="Show, hide and re-order columns" 
351        />
352        <tbl:button 
353          image="import.gif" 
354          onclick="runPlugin('ImportItems')" 
355          title="Import&hellip;" 
356          tooltip="Import data" 
357          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
358        />
359        <tbl:button 
360          image="export.gif" 
361          onclick="runPlugin('ExportItems')" 
362          title="Export&hellip;" 
363          tooltip="Export data" 
364          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
365        />
366        <tbl:button 
367          image="runplugin.gif" 
368          onclick="runPlugin('RunListPlugin')" 
369          title="Run plugin&hellip;" 
370          tooltip="Run a plugin" 
371          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
372        />
373      </tbl:toolbar>
374      <tbl:navigator
375        page="<%=cc.getPage()%>" 
376        rowsperpage="<%=cc.getRowsPerPage()%>" 
377        totalrows="<%=configurations == null ? 0 : configurations.getTotalCount()%>" 
378        visible="<%=mode.hasNavigator()%>"
379      />
380      <tbl:data>
381        <tbl:columns>
382        <tbl:presetselector 
383          clazz="columnheader"
384          colspan="3"
385          onchange="presetOnChange()"
386        />
387        </tbl:columns>
388
389        <tr>
390          <tbl:header 
391            clazz="index"
392            >&nbsp;</tbl:header>
393          <tbl:header 
394            clazz="check" 
395            visible="<%=mode.hasCheck()%>"
396            ><base:icon 
397              image="check_uncheck.gif" 
398              tooltip="Check/uncheck all" 
399              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
400            /></tbl:header>
401          <tbl:header 
402            clazz="check" 
403            visible="<%=mode.hasRadio()%>"
404            >&nbsp;</tbl:header>
405          <tbl:header 
406            clazz="icons" 
407            visible="<%=mode.hasIcons()%>"
408            >&nbsp;</tbl:header>
409          <tbl:propertyfilter />
410        </tr>
411         
412          <tbl:rows>
413          <%
414          int index = cc.getPage()*cc.getRowsPerPage();
415          int selectedItemId = cc.getId();
416          Set<GuiContext> contexts = new TreeSet<GuiContext>(new ToStringComparator<GuiContext>(false));
417          if (configurations != null)
418          {           
419            while (configurations.hasNext())
420            {
421              PluginConfiguration item = configurations.next();
422              PluginDefinition plugin = null;
423              contexts.clear();
424              try
425              {
426                plugin = item.getPluginDefinition();
427                contexts.addAll(plugin.getGuiContexts());
428              }
429              catch (PermissionDeniedException ex)
430              {}
431              int itemId = item.getId();
432              String openSharePopup = "shareItem("+itemId+")";
433              String openCopyPopup = "copyItem("+itemId+")";
434              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
435              boolean writePermission = item.hasPermission(Permission.WRITE);
436              String name = HTML.encodeTags(item.getName());
437              String tooltip = mode.isSelectionMode() ? 
438                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
439              index++;
440              numListed++;
441              %>
442              <tbl:row>
443                <tbl:header 
444                  clazz="index"
445                  ><%=index%></tbl:header>
446                <tbl:header 
447                  clazz="check" 
448                  visible="<%=mode.hasCheck()%>"
449                  ><input 
450                    type="checkbox" 
451                    name="<%=itemId%>" 
452                    value="<%=itemId%>" 
453                    title="<%=name%>" 
454                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
455                  ></tbl:header>
456                <tbl:header 
457                  clazz="check" 
458                  visible="<%=mode.hasRadio()%>"
459                  ><input 
460                    type="radio" 
461                    name="item_id" 
462                    value="<%=itemId%>" 
463                    title="<%=name%>" 
464                    <%=selectedItemId == itemId ? "checked" : ""%>
465                  ></tbl:header>
466                <tbl:header 
467                  clazz="icons" 
468                  visible="<%=mode.hasIcons()%>"
469                  ><base:icon 
470                    image="deleted.gif" 
471                    tooltip="This item has been scheduled for deletion" 
472                    visible="<%=item.isRemoved()%>"
473                  /><base:icon 
474                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
475                    onclick="<%=sharePermission ? openSharePopup : null%>"
476                    tooltip="This item is shared to other users, groups and/or projects" 
477                    visible="<%=item.isShared()%>"
478                  />&nbsp;</tbl:header>
479                <tbl:cell column="name"><div class="link" 
480                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
481                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
482                <tbl:cell column="pluginType"><%=plugin == null ? "<i>- denied -</i>" : plugin.getMainType().toString()%></tbl:cell>
483                <tbl:cell column="contexts"><%=plugin == null ? "<i>- denied -</i>" : (contexts.isEmpty() ? "<i>- none -</i>" : Values.getString(contexts, ", ", true))%></tbl:cell>
484                <tbl:cell column="pluginDefinition"><%=mode.hasPropertyLink() ? Base.getLinkedName(ID, new NameablePluginAdaptor(plugin), plugin == null, mode.hasEditLink()): Base.getEncodedName(new NameablePluginAdaptor(plugin), plugin == null)%></a></tbl:cell>
485                <tbl:cell column="owner"
486                  ><base:propertyvalue 
487                    item="<%=item%>" 
488                    property="owner"
489                    enableEditLink="<%=mode.hasEditLink()%>" 
490                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
491                  /></tbl:cell>
492                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
493                <tbl:cell column="actions">
494                  <%
495                  if (plugin != null && plugin.isInteractive() && plugin.supportsConfigurations())
496                  {
497                    %>
498                    <base:icon image="runplugin.gif" 
499                      onclick="<%="configurePlugin(" + itemId + ")"%>"
500                      tooltip="Configure this plugin " 
501                      visible="<%=writePermission%>" />
502                    <%
503                  }
504                  %>
505                  <base:icon
506                    image="copy.gif"
507                    onclick="<%=openCopyPopup%>"
508                    tooltip="Create a copy of this item"
509                    visible="<%=createPermission%>"
510                  />
511                </tbl:cell>
512                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
513              </tbl:row>
514              <%
515              }
516            }
517          %>
518          </tbl:rows>
519      </tbl:data>
520      <%
521      if (numListed == 0)
522      {
523        %>
524        <tbl:panel><%=configurations == null || configurations.getTotalCount() == 0 ? "No configurations were found" : "No configurations on this page. Please select another page!" %></tbl:panel>
525        <%
526      }
527      else
528      {
529        %>
530        <tbl:navigator
531          page="<%=cc.getPage()%>" 
532          rowsperpage="<%=cc.getRowsPerPage()%>" 
533          totalrows="<%=configurations == null ? 0 : configurations.getTotalCount()%>" 
534          visible="<%=mode.hasNavigator()%>"
535          locked="true"
536        />
537        <%
538      }
539      %>
540    </tbl:table>
541    <base:buttongroup align="center" clazz="fixedatbottom">
542      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
543      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
544      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
545    </base:buttongroup>
546    <br><br><br>
547  </base:body>
548  </base:page>
549  <%
550}
551finally
552{
553  if (configurations != null) configurations.close();
554  if (dc != null) dc.close();
555}
556%>
Note: See TracBrowser for help on using the repository browser.