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

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

References #1015: Add reporter list from tables that list reporters/reporter info

It is now possible to create reporter lists from features, wells and raw data, eg. all DataQuery?-based item types. Creating the lists using queries from the dynamic database needs a different solution.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.4 KB
Line 
1<%-- $Id: list_wells.jsp 4305 2008-05-21 11:11:20Z 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    function newReporterList()
165    {
166      Table.submitToPopup(formId, 'CreateReporterList', 540, 400);
167    }
168    </script>
169  </base:head>
170 
171  <base:body>
172    <p>
173    <p:path>
174      <p:pathelement title="Plates" href="<%="../index.jsp?ID="+ID%>" />
175      <p:pathelement title="<%=HTML.encodeTags(plate.getName())%>" />
176    </p:path>
177
178    <t:tabcontrol id="main" active="wells" switch="switchTab">
179    <t:tab id="properties" title="Properties" />
180    <t:tab id="annotations" title="Annotations" />
181    <t:tab id="events" title="Events" />
182   
183    <t:tab id="wells" title="Wells">
184   
185    <%
186    if (cc.getMessage() != null)
187    {
188      %>
189      <div class="error"><%=cc.getMessage()%></div>
190      <%
191      cc.setMessage(null);
192    }
193    %>
194    <tbl:table 
195      id="wells" 
196      clazz="itemlist" 
197      columns="<%=cc.getSetting("columns")%>"
198      sortby="<%=cc.getSortProperty()%>" 
199      direction="<%=cc.getSortDirection()%>"
200      title="<%=title%>"
201      action="index.jsp"
202      sc="<%=sc%>"
203      item="<%=itemType%>"
204      >
205      <tbl:hidden 
206        name="mode" 
207        value="<%=mode.getName()%>" 
208      />
209      <tbl:hidden 
210        name="plate_id" 
211        value="<%=String.valueOf(plateId)%>" 
212      />
213      <tbl:hidden 
214        name="callback" 
215        value="<%=callback%>" 
216        skip="<%=callback == null%>" 
217      />
218      <tbl:columndef 
219        id="row"
220        property="row"
221        datatype="int"
222        title="Row"
223        sortable="true" 
224        filterable="true"
225        exportable="true"
226        show="always" 
227      />
228      <tbl:columndef 
229        id="column"
230        property="column"
231        datatype="int"
232        title="Column"
233        sortable="true" 
234        filterable="true"
235        exportable="true"
236        show="always" 
237      />
238      <tbl:columndef 
239        id="parent"
240        title="Parent"
241      />
242      <tbl:columndef
243        id="reporterList"
244        property="$rpt.£reporterListScores"
245        datatype="int"
246        title="[Rep] Reporter list"
247        filterable="true"
248        enumeration="<%=Base.getReporterListsEnum(dc)%>"
249        multiple="false"
250      />
251      <tbl:columndef 
252        id="reporter.name"
253        property="reporter.name"
254        datatype="string"
255        title="[Rep] Name"
256        sortable="true" 
257        filterable="true"
258        exportable="true"
259      />
260      <tbl:columndef 
261        id="reporter.externalId"
262        property="reporter.externalId"
263        datatype="string"
264        title="[Rep] ID"
265        sortable="true" 
266        filterable="true"
267        exportable="true"
268      />
269      <tbl:columndef 
270        id="reporter.symbol"
271        property="reporter.symbol"
272        datatype="string"
273        title="[Rep] Gene symbol"
274        sortable="true" 
275        filterable="true"
276        exportable="true"
277      />
278      <tbl:columndef 
279        id="reporter.description"
280        property="reporter.description"
281        datatype="string"
282        title="[Rep] Description" 
283        sortable="true" 
284        filterable="true" 
285        exportable="true"
286      />
287      <tbl:columndef 
288        id="reporter.lastUpdate"
289        property="reporter.lastUpdate"
290        datatype="date"
291        title="[Rep] Last update" 
292        sortable="true" 
293        filterable="true" 
294        exportable="true"
295        formatter="<%=dateFormatter%>"
296      />
297      <%
298      Enumeration<String, String> types = new Enumeration<String, String>();
299      ItemResultList<ReporterType> reporterTypes = typeQuery.list(dc);
300      types.add("", "- none -");
301      for (ReporterType rt : reporterTypes)
302      {
303        types.add(Integer.toString(rt.getId()), HTML.encodeTags(rt.getName()));
304      }
305      %>
306      <tbl:columndef 
307        id="reporter.reporterType"
308        property="reporter.reporterType"
309        sortproperty="reporter.reporterType.name"
310        exportproperty="reporter.reporterType.name"
311        datatype="int"
312        enumeration="<%=types%>"
313        title="[Rep] Type"
314        sortable="true" 
315        filterable="true"
316        exportable="true"
317      />
318      <%
319      if (reporterProperties != null)
320      {
321        for (ExtendedProperty ep : reporterProperties)
322        {
323          String name = ep.getName();
324          %>
325          <tbl:columndef
326            id="<%="reporter."+name%>"
327            property="<%="reporter."+name%>"
328            datatype="<%=ep.getType().getStringValue()%>"
329            title="<%="[Rep] "+HTML.encodeTags(ep.getTitle())%>"
330            sortable="true"
331            filterable="true"
332            exportable="true"
333            formatter="<%=FormatterFactory.getExtendedPropertyFormatter(sc, ep)%>"
334          />
335          <%
336        }
337      }
338      %>
339      <%
340      for (AnnotationType at : annotationTypes)
341      {
342        Enumeration<String, String> annotationEnum = null;
343        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
344        if (at.isEnumeration())
345        {
346          annotationEnum = new Enumeration<String, String>();
347          List<?> values = at.getValues();
348          for (Object value : values)
349          {
350            String encoded = formatter.format(value);
351            annotationEnum.add(encoded, encoded);
352          }
353        }
354        %>
355        <tbl:columndef 
356          id="<%="at"+at.getId()%>"
357          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
358          property="<%="#"+at.getId()%>"
359          annotation="true"
360          datatype="<%=at.getValueType().getStringValue()%>"
361          enumeration="<%=annotationEnum%>"
362          sortable="false" 
363          filterable="true" 
364          exportable="true"
365          formatter="<%=formatter%>"
366        />
367        <%
368      }
369      %>
370      <tbl:columndef
371        id="permission"
372        title="Permission"
373      />
374      <tbl:toolbar
375        visible="<%=mode.hasToolbar()%>"
376        >
377        <tbl:button 
378          image="columns.gif" 
379          onclick="configureColumns()" 
380          title="Columns&hellip;" 
381          tooltip="Show, hide and re-order columns" 
382        />
383        <tbl:button
384          image="add.png"
385          onclick="newReporterList()"
386          title="New reporter list&hellip;"
387          tooltip="Create a new reporter list from matching wells"
388          visible="<%=sc.hasPermission(Permission.CREATE, Item.REPORTERLIST)%>"
389        />
390        <tbl:button 
391          image="import.gif" 
392          onclick="runPlugin('ImportItems')" 
393          title="Import&hellip;" 
394          tooltip="Import data" 
395          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
396        />
397        <tbl:button 
398          image="export.gif" 
399          onclick="runPlugin('ExportItems')" 
400          title="Export&hellip;" 
401          tooltip="Export data" 
402          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
403        />
404        <tbl:button 
405          image="runplugin.gif" 
406          onclick="runPlugin('RunListPlugin')" 
407          title="Run plugin&hellip;" 
408          tooltip="Run a plugin" 
409          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
410        />
411      </tbl:toolbar>
412      <tbl:navigator
413        page="<%=cc.getPage()%>" 
414        rowsperpage="<%=cc.getRowsPerPage()%>" 
415        totalrows="<%=wells == null ? 0 : wells.getTotalCount()%>" 
416        visible="<%=mode.hasNavigator()%>"
417      />
418      <tbl:data>
419        <tbl:columns>
420        <tbl:presetselector 
421          clazz="columnheader"
422          colspan="3"
423          onchange="presetOnChange()"
424        />
425        </tbl:columns>
426         
427        <tr>
428          <tbl:header 
429            clazz="index"
430            >&nbsp;</tbl:header>
431          <tbl:header 
432            clazz="check" 
433            visible="<%=mode.hasCheck()%>"
434            ><base:icon 
435              image="check_uncheck.gif" 
436              tooltip="Check/uncheck all" 
437              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
438            /></tbl:header>
439          <tbl:header 
440            clazz="check" 
441            visible="<%=mode.hasRadio()%>"
442            />
443          <tbl:header 
444            clazz="icons" 
445            visible="<%=mode.hasIcons()%>"
446            >&nbsp;</tbl:header>
447          <tbl:propertyfilter />
448        </tr>
449   
450          <tbl:rows>
451          <%
452          int index = cc.getPage()*cc.getRowsPerPage();
453          int selectedItemId = cc.getId();
454          if (wells != null)
455          {           
456            while (wells.hasNext())
457            {
458              Well item = wells.next();
459              int itemId = item.getId();
460              boolean writePermission = item.hasPermission(Permission.WRITE);
461              String tooltip = mode.isSelectionMode() ? 
462                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : ""); 
463              index++;
464              numListed++;
465              %>
466              <tbl:row>
467                <tbl:header 
468                  clazz="index"
469                  ><%=index%></tbl:header>
470                <tbl:header 
471                  clazz="check" 
472                  visible="<%=mode.hasCheck()%>"
473                  ><input 
474                      type="checkbox" 
475                      name="<%=itemId%>" 
476                      value="<%=itemId%>" 
477                      title="TODO" 
478                      <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
479                    ></tbl:header>
480                <tbl:header 
481                  clazz="check" 
482                  visible="<%=mode.hasRadio()%>"
483                  ><input 
484                      type="radio" 
485                      name="item_id" 
486                      value="<%=itemId%>" 
487                      title="TODO" 
488                      <%=selectedItemId == itemId ? "checked" : ""%>
489                    ></tbl:header>
490                <tbl:header 
491                  clazz="icons" 
492                  visible="<%=mode.hasIcons()%>"
493                  >&nbsp;</tbl:header>
494                <tbl:cell column="row"><div class="link" 
495                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
496                  title="<%=tooltip%>"><%=item.getRow()%></div></tbl:cell>
497                <tbl:cell column="column"><%=item.getColumn()%></tbl:cell>
498                <tbl:cell column="parent">
499                  <%
500                  try
501                  {
502                    Well parent = item.getParent();
503                    if (parent == null)
504                    {
505                      %>
506                      <i>- none -</i>
507                      <%
508                    }
509                    else
510                    {
511                      %>
512                      <%=Base.getLink(ID, 
513                        parent.getPlate().getName() + " [" + parent.getRow() + ", " + parent.getColumn() + "]", 
514                        Item.WELL, parent.getId(), true)%>
515                      <%
516                    }
517                  }
518                  catch (PermissionDeniedException ex)
519                  {
520                    %>
521                    <i>- denied -</i>
522                    <%
523                  }
524                  %>
525                </tbl:cell>
526                <%
527                ReporterData reporter = item.getReporter();
528                if (reporter == null)
529                {
530                  %>
531                  <tbl:cell column="reporter.name"><i>- none -</i></tbl:cell>
532                  <tbl:cell column="reporter.externalId"><i>- none -</i></tbl:cell>
533                  <%
534                }
535                else
536                {
537                  %>
538                  <tbl:cell column="reporter.name"><%=Base.getLink(ID, reporter.getName(), Item.REPORTER, reporter.getId(), true)%></tbl:cell>
539                  <tbl:cell column="reporter.externalId"><%=HTML.encodeTags(reporter.getExternalId())%></tbl:cell>
540                  <tbl:cell column="reporter.symbol"><%=HTML.encodeTags(reporter.getSymbol())%></tbl:cell>
541                  <tbl:cell column="reporter.description"><%=HTML.encodeTags(reporter.getDescription())%></tbl:cell>
542                  <tbl:cell column="reporter.lastUpdate" value="<%=reporter.getLastUpdate()%>" />
543                  <tbl:cell column="reporter.reporterType"
544                    ><base:propertyvalue 
545                      dbcontrol="<%=dc%>" 
546                      item="<%=reporter%>" 
547                      property="reporterType"
548                      enableEditLink="<%=mode.hasEditLink()%>" 
549                      enablePropertyLink="<%=mode.hasPropertyLink()%>"
550                    /></tbl:cell>
551                  <%
552                  if (reporterProperties != null)
553                  {
554                    for (ExtendedProperty ep : reporterProperties)
555                    {
556                      String name = ep.getName();
557                      %>
558                      <tbl:cell column="<%="reporter."+name%>"><tbl:cellvalue value="<%=reporter.getExtended(name)%>" /></tbl:cell>
559                      <%
560                    }
561                  }
562                }
563                AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
564                if (as != null)
565                {
566                  for (AnnotationType at : annotationTypes)
567                  {
568                    if (as.hasAnnotation(at))
569                    {
570                      %>
571                      <tbl:cell column="<%="at"+at.getId()%>"
572                        ><tbl:cellvalue 
573                        list="<%=as.getAnnotation(at).getValues()%>" 
574                      /></tbl:cell>
575                      <%
576                    }
577                  }
578                }
579                %>
580                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
581              </tbl:row>
582              <%
583            }
584          }
585          %>
586          </tbl:rows>
587        </tbl:data>
588      <%
589      if (numListed == 0)
590      {
591        %>
592        <tbl:panel><%=wells == null || wells.getTotalCount() == 0 ? "No wells were found" : "No wells on this page. Please select another page!" %></tbl:panel>
593        <%
594      }
595      else
596      {
597        %>
598        <tbl:navigator
599          page="<%=cc.getPage()%>" 
600          rowsperpage="<%=cc.getRowsPerPage()%>" 
601          totalrows="<%=wells == null ? 0 : wells.getTotalCount()%>" 
602          visible="<%=mode.hasNavigator()%>"
603          locked="true"
604        />
605        <%
606      }
607      %>
608    </tbl:table>
609    <base:buttongroup align="center">
610      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
611      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
612      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
613    </base:buttongroup>
614 
615    </t:tab>
616    </t:tabcontrol>
617
618 
619  </base:body>
620  </base:page>
621  <%
622}
623finally
624{
625  if (wells != null) wells.close();
626  if (dc != null) dc.close();
627}
628%>
Note: See TracBrowser for help on using the repository browser.