source: trunk/www/views/jobs/list_jobs.jsp @ 3593

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

Fixes #692: Jobs that are part of an experiment should use permissions from that experiment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.1 KB
Line 
1<%-- $Id: list_jobs.jsp 3593 2007-07-24 07:55:04Z 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.Job"
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.Hql"
41  import="net.sf.basedb.core.query.Restrictions"
42  import="net.sf.basedb.core.query.Expressions"
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.clients.web.Base"
47  import="net.sf.basedb.clients.web.ModeInfo"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.util.Values"
51  import="net.sf.basedb.util.formatter.Formatter"
52  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
53  import="java.util.List"
54  import="java.util.Map"
55  import="java.util.Date"
56%>
57<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
58<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
59<%!
60  private static final Item itemType = Item.JOB;
61  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
62 
63  private static final Enumeration<String, String> status = new Enumeration<String, String>();
64  private static final Enumeration<String, String> pluginTypes = new Enumeration<String, String>();
65  private static final Enumeration<String, String> execTime = new Enumeration<String, String>();
66  static
67  {
68    for (Job.Status s : Job.Status.values())
69    {
70      status.add(Integer.toString(s.getValue()), HTML.encodeTags(s.toString()));
71    }
72    for (Plugin.MainType pt : Plugin.MainType.values())
73    {
74      pluginTypes.add(Integer.toString(pt.getValue()), HTML.encodeTags(pt.toString()));
75    }
76    for (Job.ExecutionTime et : Job.ExecutionTime.values())
77    {
78      execTime.add(Integer.toString(et.getValue()), HTML.encodeTags(et.toString()));
79    }
80  }
81%>
82<%
83final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
84final String ID = sc.getId();
85final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
86final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
87
88final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
89final String callback = request.getParameter("callback");
90final String title = mode.generateTitle("job", "jobs");
91final DbControl dc = sc.newDbControl();
92ItemResultIterator<Job> jobs = null;
93try
94{
95  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
96  try
97  {
98    final ItemQuery<Job> query = Base.getConfiguredQuery(cc, true, Job.getQuery(), mode);
99    jobs = query.iterate(dc);
100  }
101  catch (Throwable t)
102  {
103    cc.setMessage(t.getMessage());
104  }
105  int numListed = 0;
106  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
107  %>
108  <base:page title="<%=title==null ? "Jobs" : title%>" type="<%=mode.getPageType()%>">
109  <base:head scripts="menu.js,table.js" styles="menu.css,table.css,progressbar.css">
110    <script language="JavaScript">
111    var submitPage = 'index.jsp';
112    var formId = 'jobs';
113    function viewItem(itemId)
114    {
115      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
116    }
117    function itemOnClick(evt, itemId)
118    {
119      viewItem(itemId);
120    }
121    function deleteItems()
122    {
123      var frm = document.forms[formId];
124      if (Forms.numChecked(frm) == 0)
125      {
126        alert('Please select at least one item in the list');
127        return;
128      }
129      frm.action = submitPage;
130      frm.cmd.value = 'DeleteItems';
131      frm.submit();
132    }
133    function restoreItems()
134    {
135      var frm = document.forms[formId];
136      if (Forms.numChecked(frm) == 0)
137      {
138        alert('Please select at least one item in the list');
139        return;
140      }
141      frm.action = submitPage;
142      frm.cmd.value = 'RestoreItems';
143      frm.submit();
144    }
145    function takeOwnership()
146    {
147      var frm = document.forms[formId];
148      if (Forms.numChecked(frm) == 0)
149      {
150        alert('Please select at least one item in the list');
151        return;
152      }
153      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
154      {
155        frm.action = submitPage;
156        frm.cmd.value = 'TakeOwnershipOfItems';
157        frm.submit();
158      }
159    }
160    function configureColumns()
161    {
162      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
163    }
164    function runPlugin(cmd)
165    {
166      Table.submitToPopup(formId, cmd, 740, 540);
167    }
168    function returnSelected()
169    {
170      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
171      window.close();
172    }
173    function presetOnChange()
174    {
175      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
176    }
177    </script>
178  </base:head>
179 
180  <base:body>
181    <%
182    if (cc.getMessage() != null)
183    {
184      %>
185      <div class="error"><%=cc.getMessage()%></div>
186      <%
187      cc.setMessage(null);
188    }
189    %>
190    <tbl:table 
191      id="jobs" 
192      clazz="itemlist" 
193      columns="<%=cc.getSetting("columns")%>"
194      sortby="<%=cc.getSortProperty()%>" 
195      direction="<%=cc.getSortDirection()%>"
196      title="<%=title%>"
197      action="index.jsp"
198      sc="<%=sc%>"
199      item="<%=itemType%>"
200      >
201      <tbl:hidden 
202        name="mode" 
203        value="<%=mode.getName()%>" 
204      />
205      <tbl:hidden 
206        name="callback" 
207        value="<%=callback%>" 
208        skip="<%=callback == null%>" 
209      />
210      <tbl:columndef 
211        id="name"
212        property="name"
213        datatype="string"
214        title="Name"
215        sortable="true" 
216        filterable="true"
217        exportable="true"
218        show="always" 
219      />
220      <tbl:columndef 
221        id="owner"
222        property="owner.name"
223        datatype="string"
224        title="Owner"
225        sortable="true" 
226        filterable="true"
227        exportable="true"
228      />
229      <tbl:columndef 
230        id="priority"
231        property="priority"
232        datatype="int"
233        title="Priority"
234        sortable="true" 
235        filterable="true"
236        exportable="true"
237      />
238      <tbl:columndef 
239        id="status"
240        property="status"
241        datatype="int"
242        enumeration="<%=status%>"
243        title="Status"
244        sortable="true" 
245        filterable="true"
246        exportable="true"
247      />
248      <tbl:columndef 
249        id="statusMessage"
250        property="statusMessage"
251        datatype="string"
252        title="Status message"
253        sortable="true" 
254        filterable="true"
255        exportable="true"
256      />
257      <tbl:columndef 
258        id="stackTrace"
259        property="stackTrace"
260        datatype="string"
261        title="Stack trace"
262        sortable="true" 
263        filterable="true"
264        exportable="true"
265      />
266      <tbl:columndef 
267        id="server"
268        property="server"
269        datatype="string"
270        title="Server"
271        sortable="true" 
272        filterable="true"
273        exportable="true"
274      />
275      <tbl:columndef 
276        id="estimatedExecutionTime"
277        property="estimatedExecutionTime"
278        datatype="int"
279        enumeration="<%=execTime%>"
280        title="Execution time"
281        tooltip="An estimation of the execution time of the plugin"
282        sortable="true" 
283        filterable="true"
284        exportable="true"
285      />
286      <tbl:columndef 
287        id="percentComplete"
288        property="percentComplete"
289        datatype="int"
290        title="Percent complete"
291        sortable="true" 
292        filterable="true"
293        exportable="true"
294      />
295      <tbl:columndef 
296        id="created" 
297        property="created"
298        datatype="date" 
299        title="Created" 
300        sortable="true" 
301        filterable="true" 
302        exportable="true"
303        formatter="<%=dateTimeFormatter%>"
304      />
305      <tbl:columndef 
306        id="started" 
307        property="started"
308        datatype="date" 
309        title="Started" 
310        sortable="true" 
311        filterable="true" 
312        exportable="true"
313        formatter="<%=dateTimeFormatter%>"
314      />
315      <tbl:columndef 
316        id="ended" 
317        property="ended"
318        datatype="date" 
319        title="Ended" 
320        sortable="true" 
321        filterable="true" 
322        exportable="true"
323        formatter="<%=dateTimeFormatter%>"
324      />
325      <tbl:columndef
326        id="pluginType"
327        property="pluginDefinition.mainType"
328        datatype="int"
329        title="Type"
330        enumeration="<%=pluginTypes%>"
331        sortable="true" 
332        filterable="true"
333        exportable="true"
334      />
335      <tbl:columndef 
336        id="experiment"
337        property="experiment.name"
338        datatype="string"
339        title="Experiment"
340        sortable="true" 
341        filterable="true"
342        exportable="true"
343      />
344      <tbl:columndef 
345        id="plugin"
346        property="pluginDefinition.name"
347        datatype="string"
348        title="Plugin"
349        sortable="true" 
350        filterable="true"
351        exportable="true"
352      />
353      <tbl:columndef 
354        id="configuration"
355        property="pluginConfiguration.name"
356        datatype="string"
357        title="Configuration"
358        sortable="true" 
359        filterable="true"
360        exportable="true"
361      />
362      <tbl:columndef 
363        id="description"
364        property="description"
365        datatype="string"
366        title="Description" 
367        sortable="true" 
368        filterable="true" 
369        exportable="true"
370      />
371      <tbl:columndef
372        id="permission"
373        title="Permission"
374      />
375      <tbl:toolbar
376        visible="<%=mode.hasToolbar()%>"
377        >
378        <tbl:button 
379          image="delete.gif"
380          onclick="deleteItems()" 
381          title="Delete" 
382          tooltip="Delete the selected items" 
383        />
384        <tbl:button 
385          image="restore.gif"
386          onclick="restoreItems()" 
387          title="Restore" 
388          tooltip="Restore the selected (deleted) items"
389        />
390        <tbl:button 
391          image="take_ownership.png"
392          onclick="takeOwnership()" 
393          title="Take ownership&hellip;"
394          tooltip="Take ownership of the selected items"
395          visible="<%=sc.hasPermission(Permission.SET_OWNER, Item.JOB)%>"
396        />
397        <tbl:button 
398          image="columns.gif" 
399          onclick="configureColumns()" 
400          title="Columns&hellip;" 
401          tooltip="Show, hide and re-order columns" 
402        />
403        <tbl:button 
404          image="import.gif" 
405          onclick="runPlugin('ImportItems')" 
406          title="Import&hellip;" 
407          tooltip="Import data" 
408          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
409        />
410        <tbl:button 
411          image="export.gif" 
412          onclick="runPlugin('ExportItems')" 
413          title="Export&hellip;" 
414          tooltip="Export data" 
415          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
416        />
417        <tbl:button 
418          image="runplugin.gif" 
419          onclick="runPlugin('RunListPlugin')" 
420          title="Run plugin&hellip;" 
421          tooltip="Run a plugin" 
422          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
423        />
424      </tbl:toolbar>
425      <tbl:navigator
426        page="<%=cc.getPage()%>" 
427        rowsperpage="<%=cc.getRowsPerPage()%>" 
428        totalrows="<%=jobs == null ? 0 : jobs.getTotalCount()%>" 
429        visible="<%=mode.hasNavigator()%>"
430      />
431      <tbl:data>
432        <tbl:columns>
433        <tbl:presetselector 
434          clazz="columnheader"
435          colspan="3"
436          onchange="presetOnChange()"
437        />
438        </tbl:columns>
439
440        <tr>
441          <tbl:header 
442            clazz="index"
443            >&nbsp;</tbl:header>
444          <tbl:header 
445            clazz="check" 
446            visible="<%=mode.hasCheck()%>"
447            ><base:icon 
448              image="check_uncheck.gif" 
449              tooltip="Check/uncheck all" 
450              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
451            /></tbl:header>
452          <tbl:header 
453            clazz="check" 
454            visible="<%=mode.hasRadio()%>"
455            >&nbsp;</tbl:header>
456          <tbl:header 
457            clazz="icons" 
458            visible="<%=mode.hasIcons()%>"
459            >&nbsp;</tbl:header>
460          <tbl:propertyfilter />
461        </tr>
462         
463          <tbl:rows>
464          <%
465          int index = cc.getPage()*cc.getRowsPerPage();
466          int selectedItemId = cc.getId();
467          if (jobs != null)
468          {
469            String tooltip = mode.isSelectionMode() ?
470              "Select this item" : "View this item";
471            while (jobs.hasNext())
472            {
473              Job item = jobs.next();
474              int itemId = item.getId();
475              String name = HTML.encodeTags(item.getName());
476              index++;
477              numListed++;
478              PluginDefinition plugin = null;
479              boolean readPlugin = true;
480              try
481              {
482                plugin = item.getPluginDefinition();
483              }
484              catch (PermissionDeniedException ex)
485              {
486                readPlugin = false;
487              }
488              %>
489              <tbl:row>
490                <tbl:header 
491                  clazz="index"
492                  ><%=index%></tbl:header>
493                <tbl:header 
494                  clazz="check" 
495                  visible="<%=mode.hasCheck()%>"
496                  ><input 
497                    type="checkbox" 
498                    name="<%=itemId%>" 
499                    value="<%=itemId%>" 
500                    title="<%=name%>" 
501                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
502                  ></tbl:header>
503                <tbl:header 
504                  clazz="check" 
505                  visible="<%=mode.hasRadio()%>"
506                  ><input 
507                    type="radio" 
508                    name="item_id" 
509                    value="<%=itemId%>" 
510                    title="<%=name%>" 
511                    <%=selectedItemId == itemId ? "checked" : ""%>
512                  ></tbl:header>
513                <tbl:header 
514                  clazz="icons" 
515                  visible="<%=mode.hasIcons()%>"
516                  ><base:icon 
517                    image="deleted.gif" 
518                    tooltip="This item has been scheduled for deletion" 
519                    visible="<%=item.isRemoved()%>"
520                  />&nbsp;</tbl:header>
521                <tbl:cell column="name"><div class="link" onclick="itemOnClick(event, <%=itemId%>)" 
522                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
523                <tbl:cell column="owner"
524                  ><base:propertyvalue 
525                    item="<%=item%>" 
526                    property="owner"
527                    enableEditLink="<%=mode.hasEditLink()%>" 
528                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
529                  /></tbl:cell>
530                <tbl:cell column="priority"><%=item.getPriority()%></tbl:cell>
531                <tbl:cell column="status"><%=item.getStatus()%></tbl:cell>
532                <tbl:cell column="statusMessage"><%=HTML.encodeTags(item.getStatusMessage())%></tbl:cell>
533                <tbl:cell column="stackTrace"><%=HTML.encodeTags(item.getStackTrace())%></tbl:cell>
534                <tbl:cell column="server"><%=HTML.encodeTags(item.getServer())%></tbl:cell>
535                <tbl:cell column="estimatedExecutionTime"><%=item.getEstimatedExecutionTime()%></tbl:cell>
536                <tbl:cell column="percentComplete">
537                  <table border=0 cellspacing=0 cellpadding=0>
538                  <tr>
539                  <td width="100">
540                    <table width="100" class="progressbar" border=0 cellspacing=0 cellpadding=0>
541                    <tr>
542                      <%
543                      int percent = item.getPercentComplete();
544                      if (percent > 0) 
545                      {
546                        %>
547                        <td width="<%=percent%>%" class="done">&nbsp;</td>
548                        <% 
549                      }
550                      if (percent < 100) 
551                      { 
552                        %>
553                        <td width="<%=100-percent%>%" class="remain">&nbsp;</td>
554                        <%
555                      }
556                      %>
557                    </tr>
558                    </table>
559                  </td>
560                  <td>&nbsp;<%=percent%>%</td>
561                  </tr>
562                  </table>
563                </tbl:cell>
564                <tbl:cell column="created" value="<%=item.getCreated()%>" />
565                <tbl:cell column="started" value="<%=item.getStarted()%>" />
566                <tbl:cell column="ended" value="<%=item.getEnded()%>" />
567                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
568                <tbl:cell column="pluginType">
569                  <%
570                  if (!readPlugin)
571                  {
572                    %>
573                    <i>- denied -</i>
574                    <%
575                  }
576                  else if (plugin == null)
577                  {
578                    %>
579                    <i>- none -</i>
580                    <%
581                  }
582                  else
583                  {
584                    %>
585                    <%=plugin.getMainType()%>
586                    <%
587                  }
588                  %>
589                </tbl:cell>
590                <tbl:cell column="experiment"
591                  ><base:propertyvalue 
592                    item="<%=item%>" 
593                    property="experiment"
594                    enableEditLink="<%=mode.hasEditLink()%>" 
595                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
596                  /></tbl:cell>
597                <tbl:cell column="plugin">
598                  <%
599                  if (!readPlugin)
600                  {
601                    %>
602                    <i>- denied -</i>
603                    <%
604                  }
605                  else if (plugin == null)
606                  {
607                    %>
608                    <i>- none -</i>
609                    <%
610                  }
611                  else
612                  {
613                    %>
614                    <%=HTML.encodeTags(plugin.getName())%>
615                    <%
616                  }
617                  %>
618                </tbl:cell>
619                <tbl:cell column="configuration"
620                  ><base:propertyvalue 
621                    item="<%=item%>" 
622                    property="pluginConfiguration"
623                    enableEditLink="<%=mode.hasEditLink()%>" 
624                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
625                  /></tbl:cell>
626                  <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
627              </tbl:row>
628              <%
629              }
630            }
631          %>
632          </tbl:rows>
633      </tbl:data>
634      <%
635      if (numListed == 0)
636      {
637        %>
638        <tbl:panel><%=jobs == null || jobs.getTotalCount() == 0 ? "No jobs were found" : "No jobs on this page. Please select another page!" %></tbl:panel>
639        <%
640      }
641      else
642      {
643        %>
644        <tbl:navigator
645          page="<%=cc.getPage()%>" 
646          rowsperpage="<%=cc.getRowsPerPage()%>" 
647          totalrows="<%=jobs == null ? 0 : jobs.getTotalCount()%>" 
648          visible="<%=mode.hasNavigator()%>"
649          locked="true"
650        />
651        <%
652      }
653      %>
654    </tbl:table>
655    <base:buttongroup align="center" clazz="fixedatbottom">
656      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
657      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
658      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
659    </base:buttongroup>
660    <br><br><br>
661  </base:body>
662  </base:page>
663  <%
664}
665finally
666{
667  if (jobs != null) jobs.close();
668  if (dc != null) dc.close();
669}
670%>
Note: See TracBrowser for help on using the repository browser.