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

Last change on this file since 3552 was 3552, checked in by Martin Svensson, 16 years ago

References #375. Only wants to do a commit before the weekend.

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