source: trunk/www/lims/plates/wells/list_wells.jsp @ 4302

Last change on this file since 4302 was 4302, checked in by Nicklas Nordborg, 15 years ago

References #1016: Filter table using a reporter list

I think this should now be working, but I may have missed a list somewhere. Please test.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.0 KB
Line 
1<%-- $Id: list_wells.jsp 4302 2008-05-19 12:07:25Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Johan Enell, Jari Hakkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell, Nicklas Nordborg
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 2
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 this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330,
22  Boston, MA  02111-1307, USA.
23  ------------------------------------------------------------------
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.AnnotationType"
34  import="net.sf.basedb.core.AnnotationSet"
35  import="net.sf.basedb.core.Plate"
36  import="net.sf.basedb.core.Well"
37  import="net.sf.basedb.core.ReporterType"
38  import="net.sf.basedb.core.Reporter"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultIterator"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.Permission"
43  import="net.sf.basedb.core.PluginDefinition"
44  import="net.sf.basedb.core.ExtendedProperty"
45  import="net.sf.basedb.core.ExtendedProperties"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.query.Restrictions"
48  import="net.sf.basedb.core.query.Expressions"
49  import="net.sf.basedb.core.query.Orders"
50  import="net.sf.basedb.core.query.Hql"
51  import="net.sf.basedb.core.plugin.GuiContext"
52  import="net.sf.basedb.core.plugin.Plugin"
53  import="net.sf.basedb.core.data.ReporterData"
54  import="net.sf.basedb.util.Enumeration"
55  import="net.sf.basedb.clients.web.Base"
56  import="net.sf.basedb.clients.web.ModeInfo"
57  import="net.sf.basedb.clients.web.PermissionUtil"
58  import="net.sf.basedb.clients.web.util.HTML"
59  import="net.sf.basedb.util.Values"
60  import="net.sf.basedb.util.formatter.Formatter"
61  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
62  import="java.util.List"
63  import="java.util.Map"
64  import="java.util.Date"
65%>
66<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
67<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
68<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
69<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
70<%!
71  private static final Item itemType = Item.WELL;
72  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
73%>
74<%
75final int plateId = Values.getInt(request.getParameter("plate_id"));
76final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
77final String ID = sc.getId();
78final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
79
80final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
81final String callback = request.getParameter("callback");
82final String title = mode.generateTitle("well", "wells");
83final DbControl dc = sc.newDbControl();
84ItemResultIterator<Well> wells = null;
85ItemResultList<AnnotationType> annotationTypes = null;
86try
87{
88  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
89  annotationTypes = annotationTypeQuery.list(dc);
90  final Plate plate = Plate.getById(dc, plateId);
91  final boolean createPermission = plate.hasPermission(Permission.WRITE);
92  final boolean deletePermission = createPermission;
93
94  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
95  final ItemQuery<ReporterType> typeQuery = ReporterType.getQuery();
96  typeQuery.order(Orders.asc(Hql.property("name")));
97  typeQuery.setCacheResult(true);
98  List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData");
99  Formatter<Date> dateFormatter = FormatterFactory.getDateTimeFormatter(sc);
100 
101  try
102  {
103    final ItemQuery<Well> query = Base.getConfiguredQuery(dc, cc, true, plate.getWells(), mode);
104    query.join(Hql.leftJoin(null, "reporter", "rpt", null, false));
105    if (!"row".equals(cc.getSortProperty())) query.order(Orders.asc(Hql.property("row")));
106    if (!"column".equals(cc.getSortProperty())) query.order(Orders.asc(Hql.property("column")));
107    wells = query.iterate(dc);
108  }
109  catch (Throwable t)
110  {
111    cc.setMessage(t.getMessage());
112  }
113  int numListed = 0;
114  %>
115  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
116  <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css">
117    <script language="JavaScript">
118    var submitPage = 'index.jsp';
119    var formId = 'wells';
120    function editItem(itemId)
121    {
122      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
123    }
124    function viewItem(itemId)
125    {
126      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
127    }
128    function itemOnClick(evt, itemId)
129    {
130      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
131    }
132    function configureColumns()
133    {
134      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
135    }
136    function runPlugin(cmd)
137    {
138      Table.submitToPopup(formId, cmd, 540, 460);
139    }
140    function returnSelected()
141    {
142      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
143      window.close();
144    }
145    function presetOnChange()
146    {
147      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
148    }
149    function switchTab(tabControlId, tabId)
150    {
151      if (tabId == 'properties' || tabId == 'annotations')
152      {
153        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=plateId%>&tab='+tabId;
154      }
155      else if (tabId == 'events')
156      {
157        location.href = '../events/index.jsp?ID=<%=ID%>&plate_id=<%=plateId%>';
158      }
159      else
160      {
161        TabControl.setActiveTab(tabControlId, tabId);
162      }
163    }
164    </script>
165  </base:head>
166 
167  <base:body>
168    <p>
169    <p:path>
170      <p:pathelement title="Plates" href="<%="../index.jsp?ID="+ID%>" />
171      <p:pathelement title="<%=HTML.encodeTags(plate.getName())%>" />
172    </p:path>
173
174    <t:tabcontrol id="main" active="wells" switch="switchTab">
175    <t:tab id="properties" title="Properties" />
176    <t:tab id="annotations" title="Annotations" />
177    <t:tab id="events" title="Events" />
178   
179    <t:tab id="wells" title="Wells">
180   
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="wells" 
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="plate_id" 
207        value="<%=String.valueOf(plateId)%>" 
208      />
209      <tbl:hidden 
210        name="callback" 
211        value="<%=callback%>" 
212        skip="<%=callback == null%>" 
213      />
214      <tbl:columndef 
215        id="row"
216        property="row"
217        datatype="int"
218        title="Row"
219        sortable="true" 
220        filterable="true"
221        exportable="true"
222        show="always" 
223      />
224      <tbl:columndef 
225        id="column"
226        property="column"
227        datatype="int"
228        title="Column"
229        sortable="true" 
230        filterable="true"
231        exportable="true"
232        show="always" 
233      />
234      <tbl:columndef 
235        id="parent"
236        title="Parent"
237      />
238      <tbl:columndef
239        id="reporterList"
240        property="$rpt.£reporterListScores"
241        datatype="int"
242        title="[Rep] Reporter list"
243        filterable="true"
244        enumeration="<%=Base.getReporterListsEnum(dc)%>"
245        multiple="false"
246      />
247      <tbl:columndef 
248        id="reporter.name"
249        property="reporter.name"
250        datatype="string"
251        title="[Rep] Name"
252        sortable="true" 
253        filterable="true"
254        exportable="true"
255      />
256      <tbl:columndef 
257        id="reporter.externalId"
258        property="reporter.externalId"
259        datatype="string"
260        title="[Rep] ID"
261        sortable="true" 
262        filterable="true"
263        exportable="true"
264      />
265      <tbl:columndef 
266        id="reporter.symbol"
267        property="reporter.symbol"
268        datatype="string"
269        title="[Rep] Gene symbol"
270        sortable="true" 
271        filterable="true"
272        exportable="true"
273      />
274      <tbl:columndef 
275        id="reporter.description"
276        property="reporter.description"
277        datatype="string"
278        title="[Rep] Description" 
279        sortable="true" 
280        filterable="true" 
281        exportable="true"
282      />
283      <tbl:columndef 
284        id="reporter.lastUpdate"
285        property="reporter.lastUpdate"
286        datatype="date"
287        title="[Rep] Last update" 
288        sortable="true" 
289        filterable="true" 
290        exportable="true"
291        formatter="<%=dateFormatter%>"
292      />
293      <%
294      Enumeration<String, String> types = new Enumeration<String, String>();
295      ItemResultList<ReporterType> reporterTypes = typeQuery.list(dc);
296      types.add("", "- none -");
297      for (ReporterType rt : reporterTypes)
298      {
299        types.add(Integer.toString(rt.getId()), HTML.encodeTags(rt.getName()));
300      }
301      %>
302      <tbl:columndef 
303        id="reporter.reporterType"
304        property="reporter.reporterType"
305        sortproperty="reporter.reporterType.name"
306        exportproperty="reporter.reporterType.name"
307        datatype="int"
308        enumeration="<%=types%>"
309        title="[Rep] Type"
310        sortable="true" 
311        filterable="true"
312        exportable="true"
313      />
314      <%
315      if (reporterProperties != null)
316      {
317        for (ExtendedProperty ep : reporterProperties)
318        {
319          String name = ep.getName();
320          %>
321          <tbl:columndef
322            id="<%="reporter."+name%>"
323            property="<%="reporter."+name%>"
324            datatype="<%=ep.getType().getStringValue()%>"
325            title="<%="[Rep] "+HTML.encodeTags(ep.getTitle())%>"
326            sortable="true"
327            filterable="true"
328            exportable="true"
329            formatter="<%=FormatterFactory.getExtendedPropertyFormatter(sc, ep)%>"
330          />
331          <%
332        }
333      }
334      %>
335      <%
336      for (AnnotationType at : annotationTypes)
337      {
338        Enumeration<String, String> annotationEnum = null;
339        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
340        if (at.isEnumeration())
341        {
342          annotationEnum = new Enumeration<String, String>();
343          List<?> values = at.getValues();
344          for (Object value : values)
345          {
346            String encoded = formatter.format(value);
347            annotationEnum.add(encoded, encoded);
348          }
349        }
350        %>
351        <tbl:columndef 
352          id="<%="at"+at.getId()%>"
353          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
354          property="<%="#"+at.getId()%>"
355          annotation="true"
356          datatype="<%=at.getValueType().getStringValue()%>"
357          enumeration="<%=annotationEnum%>"
358          sortable="false" 
359          filterable="true" 
360          exportable="true"
361          formatter="<%=formatter%>"
362        />
363        <%
364      }
365      %>
366      <tbl:columndef
367        id="permission"
368        title="Permission"
369      />
370      <tbl:toolbar
371        visible="<%=mode.hasToolbar()%>"
372        >
373        <tbl:button 
374          image="columns.gif" 
375          onclick="configureColumns()" 
376          title="Columns&hellip;" 
377          tooltip="Show, hide and re-order columns" 
378        />
379        <tbl:button 
380          image="import.gif" 
381          onclick="runPlugin('ImportItems')" 
382          title="Import&hellip;" 
383          tooltip="Import data" 
384          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
385        />
386        <tbl:button 
387          image="export.gif" 
388          onclick="runPlugin('ExportItems')" 
389          title="Export&hellip;" 
390          tooltip="Export data" 
391          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
392        />
393        <tbl:button 
394          image="runplugin.gif" 
395          onclick="runPlugin('RunListPlugin')" 
396          title="Run plugin&hellip;" 
397          tooltip="Run a plugin" 
398          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
399        />
400      </tbl:toolbar>
401      <tbl:navigator
402        page="<%=cc.getPage()%>" 
403        rowsperpage="<%=cc.getRowsPerPage()%>" 
404        totalrows="<%=wells == null ? 0 : wells.getTotalCount()%>" 
405        visible="<%=mode.hasNavigator()%>"
406      />
407      <tbl:data>
408        <tbl:columns>
409        <tbl:presetselector 
410          clazz="columnheader"
411          colspan="3"
412          onchange="presetOnChange()"
413        />
414        </tbl:columns>
415         
416        <tr>
417          <tbl:header 
418            clazz="index"
419            >&nbsp;</tbl:header>
420          <tbl:header 
421            clazz="check" 
422            visible="<%=mode.hasCheck()%>"
423            ><base:icon 
424              image="check_uncheck.gif" 
425              tooltip="Check/uncheck all" 
426              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
427            /></tbl:header>
428          <tbl:header 
429            clazz="check" 
430            visible="<%=mode.hasRadio()%>"
431            />
432          <tbl:header 
433            clazz="icons" 
434            visible="<%=mode.hasIcons()%>"
435            >&nbsp;</tbl:header>
436          <tbl:propertyfilter />
437        </tr>
438   
439          <tbl:rows>
440          <%
441          int index = cc.getPage()*cc.getRowsPerPage();
442          int selectedItemId = cc.getId();
443          if (wells != null)
444          {           
445            while (wells.hasNext())
446            {
447              Well item = wells.next();
448              int itemId = item.getId();
449              boolean writePermission = item.hasPermission(Permission.WRITE);
450              String tooltip = mode.isSelectionMode() ? 
451                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : ""); 
452              index++;
453              numListed++;
454              %>
455              <tbl:row>
456                <tbl:header 
457                  clazz="index"
458                  ><%=index%></tbl:header>
459                <tbl:header 
460                  clazz="check" 
461                  visible="<%=mode.hasCheck()%>"
462                  ><input 
463                      type="checkbox" 
464                      name="<%=itemId%>" 
465                      value="<%=itemId%>" 
466                      title="TODO" 
467                      <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
468                    ></tbl:header>
469                <tbl:header 
470                  clazz="check" 
471                  visible="<%=mode.hasRadio()%>"
472                  ><input 
473                      type="radio" 
474                      name="item_id" 
475                      value="<%=itemId%>" 
476                      title="TODO" 
477                      <%=selectedItemId == itemId ? "checked" : ""%>
478                    ></tbl:header>
479                <tbl:header 
480                  clazz="icons" 
481                  visible="<%=mode.hasIcons()%>"
482                  >&nbsp;</tbl:header>
483                <tbl:cell column="row"><div class="link" 
484                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
485                  title="<%=tooltip%>"><%=item.getRow()%></div></tbl:cell>
486                <tbl:cell column="column"><%=item.getColumn()%></tbl:cell>
487                <tbl:cell column="parent">
488                  <%
489                  try
490                  {
491                    Well parent = item.getParent();
492                    if (parent == null)
493                    {
494                      %>
495                      <i>- none -</i>
496                      <%
497                    }
498                    else
499                    {
500                      %>
501                      <%=Base.getLink(ID, 
502                        parent.getPlate().getName() + " [" + parent.getRow() + ", " + parent.getColumn() + "]", 
503                        Item.WELL, parent.getId(), true)%>
504                      <%
505                    }
506                  }
507                  catch (PermissionDeniedException ex)
508                  {
509                    %>
510                    <i>- denied -</i>
511                    <%
512                  }
513                  %>
514                </tbl:cell>
515                <%
516                ReporterData reporter = item.getReporter();
517                if (reporter == null)
518                {
519                  %>
520                  <tbl:cell column="reporter.name"><i>- none -</i></tbl:cell>
521                  <tbl:cell column="reporter.externalId"><i>- none -</i></tbl:cell>
522                  <%
523                }
524                else
525                {
526                  %>
527                  <tbl:cell column="reporter.name"><%=Base.getLink(ID, reporter.getName(), Item.REPORTER, reporter.getId(), true)%></tbl:cell>
528                  <tbl:cell column="reporter.externalId"><%=HTML.encodeTags(reporter.getExternalId())%></tbl:cell>
529                  <tbl:cell column="reporter.symbol"><%=HTML.encodeTags(reporter.getSymbol())%></tbl:cell>
530                  <tbl:cell column="reporter.description"><%=HTML.encodeTags(reporter.getDescription())%></tbl:cell>
531                  <tbl:cell column="reporter.lastUpdate" value="<%=reporter.getLastUpdate()%>" />
532                  <tbl:cell column="reporter.reporterType"
533                    ><base:propertyvalue 
534                      dbcontrol="<%=dc%>" 
535                      item="<%=reporter%>" 
536                      property="reporterType"
537                      enableEditLink="<%=mode.hasEditLink()%>" 
538                      enablePropertyLink="<%=mode.hasPropertyLink()%>"
539                    /></tbl:cell>
540                  <%
541                  if (reporterProperties != null)
542                  {
543                    for (ExtendedProperty ep : reporterProperties)
544                    {
545                      String name = ep.getName();
546                      %>
547                      <tbl:cell column="<%="reporter."+name%>"><tbl:cellvalue value="<%=reporter.getExtended(name)%>" /></tbl:cell>
548                      <%
549                    }
550                  }
551                }
552                AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
553                if (as != null)
554                {
555                  for (AnnotationType at : annotationTypes)
556                  {
557                    if (as.hasAnnotation(at))
558                    {
559                      %>
560                      <tbl:cell column="<%="at"+at.getId()%>"
561                        ><tbl:cellvalue 
562                        list="<%=as.getAnnotation(at).getValues()%>" 
563                      /></tbl:cell>
564                      <%
565                    }
566                  }
567                }
568                %>
569                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
570              </tbl:row>
571              <%
572            }
573          }
574          %>
575          </tbl:rows>
576        </tbl:data>
577      <%
578      if (numListed == 0)
579      {
580        %>
581        <tbl:panel><%=wells == null || wells.getTotalCount() == 0 ? "No wells were found" : "No wells on this page. Please select another page!" %></tbl:panel>
582        <%
583      }
584      else
585      {
586        %>
587        <tbl:navigator
588          page="<%=cc.getPage()%>" 
589          rowsperpage="<%=cc.getRowsPerPage()%>" 
590          totalrows="<%=wells == null ? 0 : wells.getTotalCount()%>" 
591          visible="<%=mode.hasNavigator()%>"
592          locked="true"
593        />
594        <%
595      }
596      %>
597    </tbl:table>
598    <base:buttongroup align="center">
599      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
600      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
601      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
602    </base:buttongroup>
603 
604    </t:tab>
605    </t:tabcontrol>
606
607 
608  </base:body>
609  </base:page>
610  <%
611}
612finally
613{
614  if (wells != null) wells.close();
615  if (dc != null) dc.close();
616}
617%>
Note: See TracBrowser for help on using the repository browser.