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

Last change on this file since 6690 was 6690, checked in by Nicklas Nordborg, 8 years ago

References #1906: Display inherited annotations in list views

Implemented this for samples, extracts physical bioassays, derived bioassays and array (slide/batch/desing) list views

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