source: trunk/www/lims/arraybatches/list_batches.jsp @ 6604

Last change on this file since 6604 was 6604, checked in by Nicklas Nordborg, 9 years ago

References #1890: Improve skinnability of BASE

Updated table listings with some new css classes to make it easier to modify background color.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.2 KB
Line 
1<%-- $Id: list_batches.jsp 6604 2014-11-18 10:39:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell, 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.Item"
30  import="net.sf.basedb.core.ArrayBatch"
31  import="net.sf.basedb.core.ArraySlide"
32  import="net.sf.basedb.core.AnnotationType"
33  import="net.sf.basedb.core.AnnotationSet"
34  import="net.sf.basedb.core.Annotation"
35  import="net.sf.basedb.core.Nameable"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.Include"
38  import="net.sf.basedb.core.Type"
39  import="net.sf.basedb.core.ItemResultIterator"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.ItemContext"
42  import="net.sf.basedb.core.Permission"
43  import="net.sf.basedb.core.PluginDefinition"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.core.query.Restrictions"
46  import="net.sf.basedb.core.query.Expressions"
47  import="net.sf.basedb.core.query.Orders"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.core.plugin.Plugin"
50  import="net.sf.basedb.core.snapshot.AnnotationLoaderUtil"
51  import="net.sf.basedb.core.snapshot.AnnotationTypeFilter"
52  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
53  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
54  import="net.sf.basedb.core.snapshot.SnapshotManager"
55  import="net.sf.basedb.core.User"
56  import="net.sf.basedb.util.Enumeration"
57  import="net.sf.basedb.util.ShareableUtil"
58  import="net.sf.basedb.clients.web.Base"
59  import="net.sf.basedb.clients.web.ModeInfo"
60  import="net.sf.basedb.clients.web.PermissionUtil"
61  import="net.sf.basedb.clients.web.util.HTML"
62  import="net.sf.basedb.util.formatter.Formatter"
63  import="net.sf.basedb.util.Values"
64  import="net.sf.basedb.util.formatter.Formatter"
65  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
66  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
67  import="net.sf.basedb.clients.web.extensions.JspContext"
68  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
69  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
70  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
71  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
72  import="java.util.Date"
73  import="java.util.ArrayList"
74  import="java.util.Iterator"
75  import="java.util.List"
76  import="java.util.Map"
77%>
78<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
79<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
80<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
81<%!
82  private static final Item itemType = Item.ARRAYBATCH;
83  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
84%>
85<%
86final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
87final String ID = sc.getId();
88final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
89final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
90
91final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
92final String callback = request.getParameter("callback");
93final String title = mode.generateTitle("array batch", "array batches");
94final DbControl dc = sc.newDbControl();
95ItemResultIterator<ArrayBatch> batches = null;
96List<AnnotationLoaderUtil> annotationLoaders = new ArrayList<AnnotationLoaderUtil>();
97try
98{
99  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
100  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
101  SnapshotManager manager = new SnapshotManager();
102  for (AnnotationType at : annotationTypeQuery.list(dc))
103  {
104    annotationLoaders.add(new AnnotationLoaderUtil(dc, manager, at));
105  }
106
107  // Query for slide relatated to the current batch
108  final ItemQuery<ArraySlide> slideQuery = ArraySlide.getQuery();
109  slideQuery.include(cc.getInclude());
110  slideQuery.restrict(Restrictions.eq(Hql.property("arrayBatch"), Expressions.parameter("arrayBatch")));
111  slideQuery.order(Orders.asc(Hql.property("name"))); 
112  final boolean createSlidePermission = sc.hasPermission(Permission.CREATE, Item.ARRAYSLIDE);   
113
114  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
115  try
116  {
117    final ItemQuery<ArrayBatch> query = Base.getConfiguredQuery(dc, cc, true, ArrayBatch.getQuery(), mode);
118    batches = query.iterate(dc);
119  }
120  catch (Throwable t)
121  {
122    cc.setMessage(t.getMessage());
123    t.printStackTrace();
124  }
125  int numListed = 0;
126  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
127  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
128  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
129  %>
130  <base:page title="<%=title==null ? "Array batches" : title%>" type="<%=mode.getPageType()%>" id="list-page">
131  <base:head scripts="table.js,~batches.js" styles="table.css,toolbar.css">
132    <ext:scripts context="<%=jspContext%>" />
133    <ext:stylesheets context="<%=jspContext%>" />
134  </base:head>
135 
136  <base:body>
137    <h1><%=title==null ? "Array batches" : title%></h1>
138    <div class="content">
139    <tbl:table 
140      id="batches" 
141      columns="<%=cc.getSetting("columns")%>"
142      sortby="<%=cc.getSortProperty()%>" 
143      direction="<%=cc.getSortDirection()%>"
144      action="index.jsp"
145      sc="<%=sc%>"
146      item="<%=itemType%>"
147      subclass="fulltable"
148      >
149      <tbl:hidden 
150        name="mode" 
151        value="<%=mode.getName()%>" 
152      />
153      <tbl:hidden 
154        name="callback" 
155        value="<%=callback%>" 
156        skip="<%=callback == null%>" 
157      />
158      <tbl:columndef 
159        id="name"
160        property="name"
161        datatype="string"
162        title="Name"
163        sortable="true" 
164        filterable="true"
165        exportable="true"
166        show="always" 
167      />
168      <tbl:columndef 
169        id="id"
170        clazz="uniquecol"
171        property="id"
172        datatype="int"
173        title="ID"
174        sortable="true"
175        filterable="true"
176        exportable="true"
177      />
178      <tbl:columndef 
179        id="entryDate"
180        property="entryDate"
181        datatype="date"
182        title="Registered"
183        sortable="true" 
184        filterable="true"
185        exportable="true"
186        formatter="<%=dateFormatter%>"
187      />
188      <tbl:columndef 
189        id="arrayDesign"
190        property="arrayDesign.name"
191        datatype="string"
192        title="Array design"
193        sortable="true" 
194        filterable="true"
195        exportable="true"
196      />
197      <tbl:columndef 
198        id="printRobot"
199        property="printRobot.name"
200        datatype="string"
201        title="Print robot"
202        sortable="true" 
203        filterable="true"
204        exportable="true"
205      />
206      <tbl:columndef 
207        id="protocol"
208        property="protocol.name"
209        datatype="string"
210        title="Protocol"
211        sortable="true" 
212        filterable="true"
213        exportable="true"
214      />
215      <tbl:columndef
216        id="slides"
217        title="Slides"
218        property="&arraySlides(name)"
219        datatype="string"
220        filterable="true"
221      />
222      <tbl:columndef 
223        id="owner"
224        property="owner.name"
225        datatype="string"
226        title="Owner"
227        sortable="true" 
228        filterable="true"
229        exportable="true"
230      />
231      <tbl:columndef 
232        id="description"
233        property="description"
234        datatype="string"
235        title="Description" 
236        sortable="true" 
237        filterable="true" 
238        exportable="true"
239      />     
240      <%
241      for (AnnotationLoaderUtil loader : annotationLoaders)
242      {
243        AnnotationType at = loader.getAnnotationType();
244        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
245        Enumeration<String, String> annotationEnum = null;
246        if (at.isEnumeration())
247        {
248          annotationEnum = new Enumeration<String, String>();
249          List<?> values = at.getValues();
250          for (Object value : values)
251          {
252            String encoded = formatter.format(value);
253            annotationEnum.add(encoded, encoded);
254          }
255        }
256        %>
257        <tbl:columndef 
258          id="<%="at"+at.getId()%>"
259          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
260          property="<%="#"+at.getId()%>"
261          annotation="true"
262          datatype="<%=at.getValueType().getStringValue()%>"
263          enumeration="<%=annotationEnum%>"
264          smartenum="<%=at.getDisplayAsList() %>"
265          sortable="<%=at.getMultiplicity() == 1%>" 
266          filterable="true" 
267          exportable="true"
268          formatter="<%=formatter%>"
269          unit="<%=at.getDefaultUnit()%>"
270        />
271        <%
272      }
273      %>
274      <tbl:columndef
275        id="permission"
276        title="Permission"
277      />
278      <tbl:columndef
279        id="sharedTo"
280        title="Shared to"
281        filterable="true"
282        filterproperty="!sharedTo.name"
283        datatype="string"
284      />
285      <tbl:columndef 
286        id="xt-columns" 
287        extensions="<%=columnsInvoker%>" 
288        jspcontext="<%=jspContext%>" 
289      />
290      <div class="panelgroup bg-filled-50 bottomborder">
291        <tbl:toolbar
292          subclass="bottomborder"
293          visible="<%=mode.hasToolbar()%>"
294          >
295          <tbl:button 
296            id="btnNewItem"
297            disabled="<%=!createPermission%>" 
298            image="new.png" 
299            title="New&hellip;" 
300            tooltip="<%=createPermission ? "Create new array batche" : "You do not have permission to create array batches"%>" 
301          />
302          <tbl:button 
303            id="btnDeleteItems"
304            image="delete.png"
305            title="Delete" 
306            tooltip="Delete the selected items" 
307          />
308          <tbl:button 
309            id="btnRestoreItems"
310            image="restore.png"
311            title="Restore" 
312            tooltip="Restore the selected (deleted) items"
313          />
314          <tbl:button 
315            id="btnShareItems"
316            image="share.png"
317            title="Share&hellip;" 
318            tooltip="Share the selected items"
319          />
320          <tbl:button 
321            id="btnSetOwner"
322            image="take_ownership.png"
323            title="Set owner&hellip;"
324            tooltip="Change owner of the selected items"
325          />
326          <tbl:button 
327            id="btnColumns"
328            image="columns.png" 
329            title="Columns&hellip;" 
330            tooltip="Show, hide and re-order columns" 
331          />
332          <tbl:button 
333            id="btnImport"
334            data-plugin-type="IMPORT"
335            image="import.png" 
336            title="Import&hellip;" 
337            tooltip="Import data" 
338            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
339          />
340          <tbl:button 
341            id="btnExport"
342            data-plugin-type="EXPORT"
343            image="export.png" 
344            title="Export&hellip;" 
345            tooltip="Export data" 
346            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
347          />
348          <tbl:button 
349            id="btnRunPlugin"
350            data-plugin-type="OTHER"
351            image="runplugin.png" 
352            title="Run plugin&hellip;" 
353            tooltip="Run a plugin" 
354            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
355          />
356          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
357            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
358        </tbl:toolbar>
359        <tbl:panel>
360          <tbl:presetselector />
361          <tbl:navigator
362            page="<%=cc.getPage()%>" 
363            rowsperpage="<%=cc.getRowsPerPage()%>" 
364            totalrows="<%=batches == null ? 0 : batches.getTotalCount()%>" 
365            visible="<%=mode.hasNavigator()%>"
366          />
367        </tbl:panel>
368      </div>
369      <tbl:data>
370        <tbl:headers>
371          <tbl:headerrow>
372            <tbl:header colspan="3" />
373            <tbl:columnheaders />
374          </tbl:headerrow>
375          <tbl:headerrow>
376            <tbl:header subclass="index" />
377            <tbl:header 
378              subclass="check" 
379              visible="<%=mode.hasCheck()%>"
380              ><base:icon 
381                id="check.uncheck"
382                image="check_uncheck.png" 
383                tooltip="Check/uncheck all" 
384                 
385              /></tbl:header>
386            <tbl:header 
387              subclass="check" 
388              visible="<%=mode.hasRadio()%>"
389              />
390            <tbl:header 
391              subclass="icons" 
392              visible="<%=mode.hasIcons()%>"
393              />
394            <tbl:propertyfilter />
395          </tbl:headerrow>
396        </tbl:headers>
397        <tbl:rows>
398          <%
399          if (cc.getMessage() != null)
400          {
401            %>
402            <tbl:panel subclass="bg-filled-50">
403              <div class="messagecontainer error"><%=cc.getMessage()%></div>
404            </tbl:panel>
405            <%
406            cc.setMessage(null);
407          }
408          int index = cc.getPage()*cc.getRowsPerPage();
409          int selectedItemId = cc.getId();
410          if (batches != null)
411          { 
412            while (batches.hasNext())
413            {
414              ArrayBatch item = batches.next();
415              int itemId = item.getId();
416             
417             
418              boolean deletePermission = item.hasPermission(Permission.DELETE);
419              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
420              boolean usePermission = item.hasPermission(Permission.USE);
421              boolean writePermission = item.hasPermission(Permission.WRITE);
422              String tooltip = mode.isSelectionMode() ? 
423                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
424              String name = HTML.encodeTags(item.getName());
425              index++;
426              numListed++;
427              %>
428              <tbl:row>
429                <tbl:header 
430                  clazz="index"
431                  ><%=index%></tbl:header>
432                <tbl:header 
433                  clazz="check" 
434                  visible="<%=mode.hasCheck()%>"
435                  ><input 
436                    type="checkbox" 
437                    name="<%=itemId%>" 
438                    value="<%=itemId%>" 
439                    title="<%=name%>" 
440                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
441                  ></tbl:header>
442                <tbl:header 
443                  clazz="check" 
444                  visible="<%=mode.hasRadio()%>"
445                  ><input 
446                    type="radio" 
447                    name="item_id" 
448                    value="<%=itemId%>" 
449                    title="<%=name%>" 
450                    <%=selectedItemId == itemId ? "checked" : ""%>
451                  ></tbl:header>
452                <tbl:header 
453                  clazz="icons" 
454                  visible="<%=mode.hasIcons()%>"
455                  ><base:icon 
456                    image="deleted.png"
457                    id="<%="delete."+itemId %>"
458                    subclass="<%=deletePermission ? "table-delete-item" : null %>"
459                    data-item-id="<%=itemId%>"
460                    tooltip="This item has been scheduled for deletion" 
461                    visible="<%=item.isRemoved()%>"
462                  /><base:icon 
463                    image="shared.png" 
464                    id="<%="share."+itemId %>"
465                    subclass="<%=sharePermission ? "table-share-item" : null %>"
466                    data-item-id="<%=itemId%>"
467                    tooltip="This item is shared to other users, groups and/or projects" 
468                    visible="<%=item.isShared()%>"
469                  />&nbsp;</tbl:header>
470                <tbl:cell column="name"><div
471                  class="link table-item"
472                  data-item-id="<%=itemId%>"
473                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
474                  tabindex="0"
475                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
476                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
477                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
478                <tbl:cell column="arrayDesign"
479                  ><base:propertyvalue 
480                    item="<%=item%>" 
481                    property="arrayDesign"
482                    enableEditLink="<%=mode.hasEditLink()%>" 
483                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
484                  /></tbl:cell>
485                <tbl:cell column="printRobot"
486                  ><base:propertyvalue 
487                    item="<%=item%>" 
488                    property="printRobot"
489                    enableEditLink="<%=mode.hasEditLink()%>" 
490                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
491                  /></tbl:cell>
492                <tbl:cell column="protocol"
493                  ><base:propertyvalue 
494                    item="<%=item%>" 
495                    property="protocol"
496                    enableEditLink="<%=mode.hasEditLink()%>" 
497                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
498                  /></tbl:cell>
499                <tbl:cell column="slides">
500                  <%
501                  slideQuery.setParameter("arrayBatch", itemId, Type.INT);
502                  try
503                  {
504                    %>
505                    <%=slideQuery.count(dc)%>
506                    <%
507                  }
508                  catch (Throwable t)
509                  {
510                    %>
511                    <div class="error"><%=t.getMessage()%></div>
512                    <%
513                  }
514                  %>
515                  <base:icon
516                    image="add.png" 
517                    subclass="link auto-init"
518                    data-auto-init="new-slide"
519                    data-item-id="<%=itemId %>"
520                    tooltip="Create new slide" 
521                    visible="<%=mode.hasEditLink() && createSlidePermission && usePermission %>"
522                  />
523                  <base:icon
524                    image="new_wizard.png" 
525                    subclass="link auto-init"
526                    data-auto-init="new-slide-wizard"
527                    data-item-id="<%=itemId %>"
528                    tooltip="Create multiple new slides using a wizard" 
529                    visible="<%=mode.hasEditLink() && createSlidePermission && usePermission %>"
530                  />
531                </tbl:cell>
532                <tbl:cell column="owner"
533                  ><base:propertyvalue 
534                    item="<%=item%>" 
535                    property="owner"
536                    enableEditLink="<%=mode.hasEditLink()%>" 
537                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
538                  /></tbl:cell>
539                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>               
540                <%
541                if (item.isAnnotated())
542                {
543                  AnnotationSetSnapshot snapshot = manager.getSnapshot(dc, item.getAnnotationSet().getId());
544                  for (AnnotationLoaderUtil loader : annotationLoaders)
545                  {
546                    if (loader.find(snapshot))
547                    {
548                      %>
549                      <tbl:cell 
550                        column="<%="at"+loader.getId()%>"
551                        ><tbl:cellvalue 
552                          list="<%=loader.getValues()%>"
553                          suffix="<%=loader.getUnitSymbol()%>"
554                      /></tbl:cell>
555                      <%
556                    }
557                  }
558                }
559                %>
560                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
561                <tbl:cell column="sharedTo">
562                  <%
563                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
564                  while(sharees.hasNext())
565                  {
566                    Nameable n = sharees.next();
567                    if (mode.hasPropertyLink())
568                    {
569                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
570                    }
571                    else
572                    {
573                      out.write(HTML.encodeTags(n.getName()));
574                    }
575                    out.write(sharees.hasNext() ? ", " : "");
576                  }
577                  %>
578                </tbl:cell>
579                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
580                  <tbl:cell column="xt-columns" />
581                </tbl:xt-cells>
582              </tbl:row>
583              <%
584              }
585            }
586          if (numListed == 0)
587          {
588            %>
589            <tbl:panel subclass="bg-filled-50">
590              <div class="messagecontainer note">
591              <%=batches == null || batches.getTotalCount() == 0 ? "No array batches were found" : "No array batches on this page. Please select another page!" %>
592              </div>
593            </tbl:panel>
594            <%
595          }
596          %>
597        </tbl:rows>
598      </tbl:data>
599    </tbl:table>
600    </div>
601   
602    <base:buttongroup subclass="dialogbuttons">
603      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
604      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
605      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
606    </base:buttongroup>
607   
608  </base:body>
609  </base:page>
610  <%
611}
612finally
613{
614  if (batches != null) batches.close();
615  if (dc != null) dc.close();
616}
617%>
Note: See TracBrowser for help on using the repository browser.