source: trunk/www/views/reporterlists/reporters/list_reporters.jsp @ 6699

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

References #1912: Add more filter rows in list pages

Fixes a problem with using non-unique id for the 'Add filter row' icon when used on pages that has multiple lists. This caused the icon to not work or add rows to the incorrect list.

The add/remove icons are now based on class names instead which means we can target each icon within the table context it is defined in.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 16.3 KB
Line 
1<%-- $Id: list_reporters.jsp 6699 2015-01-30 10:32:48Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Johan Enell, 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 modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13 
14  BASE is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  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.SystemItems"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.ItemResultList"
34  import="net.sf.basedb.core.ReporterList"
35  import="net.sf.basedb.core.ReporterType"
36  import="net.sf.basedb.core.ReporterScore"
37  import="net.sf.basedb.core.PluginDefinition"
38  import="net.sf.basedb.core.data.ReporterData"
39  import="net.sf.basedb.core.ReporterScoreQuery"
40  import="net.sf.basedb.core.ReporterScoreResultIterator"
41  import="net.sf.basedb.core.ExtendedProperty"
42  import="net.sf.basedb.core.ExtendedProperties"
43  import="net.sf.basedb.core.Permission"
44  import="net.sf.basedb.core.query.Orders"
45  import="net.sf.basedb.core.query.Hql"
46  import="net.sf.basedb.core.plugin.GuiContext"
47  import="net.sf.basedb.core.plugin.Plugin"
48  import="net.sf.basedb.util.Enumeration"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.ModeInfo"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.Values"
53  import="net.sf.basedb.util.formatter.Formatter"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
56  import="net.sf.basedb.clients.web.extensions.JspContext"
57  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
58  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
59  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
60  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
61  import="java.util.Date"
62  import="java.util.Map"
63  import="java.util.List"
64%>
65<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
66<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
67<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
68<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
69<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
70<%!
71  private static final Item itemType = Item.REPORTERSCORE;
72  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
73%>
74<%
75final int reporterListId = Values.getInt(request.getParameter("reporterlist_id"));
76final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
77final String ID = sc.getId();
78
79final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
80
81final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
82final String callback = request.getParameter("callback");
83final String title = mode.generateTitle("reporter", "reporters");
84final DbControl dc = sc.newDbControl();
85ReporterScoreResultIterator reporters = null;
86ItemResultList<ReporterType> reporterTypes = null;
87try
88{
89  final ReporterList reporterList = ReporterList.getById(dc, reporterListId);
90  final boolean createPermission = reporterList.hasPermission(Permission.WRITE);
91  final boolean writePermission = createPermission;
92  final boolean deletePermission = createPermission;
93
94  final ReporterScoreQuery query = reporterList.getReporterScores();
95  query.join(Hql.innerJoin(null, "reporter", "rpt", true));
96  final ItemQuery<ReporterType> typeQuery = ReporterType.getQuery();
97  typeQuery.order(Orders.asc(Hql.property("name")));
98  typeQuery.setCacheResult(true);
99  List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData");
100  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
101
102  try
103  {
104    cc.configureQuery(dc, query, true);
105    reporters = query.iterate(dc);
106  }
107  catch (Throwable t)
108  {
109    cc.setMessage(t.getMessage());
110    t.printStackTrace();
111  }
112  int numListed = 0;
113  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
114  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
115  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, reporterList);
116  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
117  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
118  %>
119  <base:page title="<%=title%>" type="<%=mode.getPageType()%>" id="list-page">
120  <base:head scripts="table.js,tabcontrol-2.js,~reporters.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
121    <ext:scripts context="<%=jspContext%>" />
122    <ext:stylesheets context="<%=jspContext%>" />
123  </base:head>
124 
125  <base:body>
126    <p:path><p:pathelement 
127      title="Reporter lists" href="<%="../index.jsp?ID="+ID%>" 
128      /><p:pathelement title="<%=HTML.encodeTags(reporterList.getName())%>" 
129      /></p:path>
130 
131    <t:tabcontrol 
132      id="main" 
133      subclass="mastertabcontrol content"
134      active="reporters">
135    <t:tab id="properties" title="Properties" />
136   
137    <t:tab id="reporters" title="Reporters">
138    <tbl:table 
139      id="reporters" 
140      columns="<%=cc.getSetting("columns")%>"
141      sortby="<%=cc.getSortProperty()%>" 
142      direction="<%=cc.getSortDirection()%>"
143      action="index.jsp"
144      sc="<%=sc%>"
145      item="<%=itemType%>"
146      filterrows="<%=cc.getFilterRows()%>"
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:hidden 
159        name="reporterlist_id" 
160        value="<%=String.valueOf(reporterListId)%>" 
161      />
162      <tbl:columndef 
163        id="externalId"
164        clazz="uniquecol"
165        property="reporter.externalId"
166        datatype="string"
167        title="External ID"
168        sortable="true" 
169        filterable="true"
170        exportable="true"
171      />
172      <tbl:columndef 
173        id="name"
174        property="reporter.name"
175        datatype="string"
176        title="Name"
177        sortable="true" 
178        filterable="true"
179        exportable="true"
180        show="always" 
181      />
182      <tbl:columndef 
183        id="id"
184        clazz="uniquecol"
185        property="reporter.id"
186        datatype="int"
187        title="ID"
188        sortable="true"
189        filterable="true"
190        exportable="true"
191      />
192      <tbl:columndef 
193        id="score"
194        property="score"
195        datatype="float"
196        title="Score"
197        sortable="true" 
198        filterable="true"
199        exportable="true"
200      />
201      <tbl:columndef 
202        id="symbol"
203        property="reporter.symbol"
204        datatype="string"
205        title="Gene symbol"
206        sortable="true" 
207        filterable="true"
208        exportable="true"
209      />
210      <tbl:columndef 
211        id="description"
212        property="reporter.description"
213        datatype="string"
214        title="Description" 
215        sortable="true" 
216        filterable="true" 
217        exportable="true"
218      />
219      <tbl:columndef
220        id="reporterList"
221        property="$rpt.£reporterListScores"
222        datatype="int"
223        title="Reporter list"
224        filterable="true"
225        enumeration="<%=Base.getReporterListsEnum(dc)%>"
226        multiple="false"
227      />
228      <tbl:columndef 
229        id="entryDate"
230        property="reporter.entryDate"
231        datatype="date"
232        title="Registered"
233        sortable="true" 
234        filterable="true"
235        exportable="true"
236        formatter="<%=dateFormatter%>"
237      />
238      <tbl:columndef 
239        id="lastUpdate"
240        property="reporter.lastUpdate"
241        datatype="timestamp"
242        title="Last update" 
243        sortable="true" 
244        filterable="true" 
245        exportable="true"
246        formatter="<%=dateTimeFormatter%>"
247      />
248      <%
249      if (reporterProperties != null)
250      {
251        for (ExtendedProperty ep : reporterProperties)
252        {
253          String name = ep.getName();
254          %>
255          <tbl:columndef
256            id="<%=name%>"
257            property="<%="reporter."+name%>"
258            datatype="<%=ep.getType().getStringValue()%>"
259            title="<%=HTML.encodeTags(ep.getTitle())%>"
260            sortable="true"
261            filterable="true"
262            exportable="true"
263            formatter="<%=FormatterFactory.getExtendedPropertyFormatter(sc, ep)%>"
264          />
265          <%
266        }
267      }
268      Enumeration<String, String> types = new Enumeration<String, String>();
269      reporterTypes = typeQuery.list(dc);
270      types.add("", "- none -");
271      for (ReporterType rt : reporterTypes)
272      {
273        types.add(Integer.toString(rt.getId()), HTML.encodeTags(rt.getName()));
274      }
275      %>
276      <tbl:columndef 
277        id="reporterType"
278        property="reporter.reporterType"
279        sortproperty="reporter.reporterType.name"
280        exportproperty="reporter.reporterType.name:string"
281        datatype="int"
282        enumeration="<%=types%>"
283        title="Type"
284        sortable="true" 
285        filterable="true"
286        exportable="true"
287      />
288      <tbl:columndef 
289        id="xt-columns" 
290        extensions="<%=columnsInvoker%>" 
291        jspcontext="<%=jspContext%>" 
292      />
293      <div class="panelgroup bg-filled-50 bottomborder">
294        <tbl:toolbar
295          subclass="bottomborder"
296          visible="<%=mode.hasToolbar()%>"
297          >
298          <tbl:button 
299            id="btnAddReporters"
300            disabled="<%=!writePermission%>" 
301            image="add.png" 
302            title="Add&hellip;" 
303            tooltip="<%=writePermission ? "Add reporters to this list" : "You do not have permission to add reporters" %>" 
304          />
305          <tbl:button 
306            id="btnRemoveReporters"
307            disabled="<%=!deletePermission%>" 
308            image="delete.png" 
309            title="Remove&hellip;" 
310            tooltip="<%=deletePermission ? "Remove the selected items from this list" : "You do not have permission to remove reporters" %>" 
311          />
312          <tbl:button 
313            id="btnColumns"
314            image="columns.png" 
315            title="Columns&hellip;" 
316            tooltip="Show, hide and re-order columns" 
317          />
318          <tbl:button 
319            id="btnImport"
320            data-plugin-type="IMPORT"
321            image="import.png" 
322            title="Import&hellip;" 
323            tooltip="Import data" 
324            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
325          />
326          <tbl:button 
327            id="btnExport"
328            data-plugin-type="EXPORT"
329            image="export.png" 
330            title="Export&hellip;" 
331            tooltip="Export data" 
332            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
333          />
334          <tbl:button 
335            id="btnRunPlugin"
336            data-plugin-type="OTHER"
337            image="runplugin.png" 
338            title="Run plugin&hellip;" 
339            tooltip="Run a plugin" 
340            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
341          />
342          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
343            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
344        </tbl:toolbar>
345        <tbl:panel>
346          <tbl:presetselector />
347          <tbl:navigator
348            page="<%=cc.getPage()%>" 
349            rowsperpage="<%=cc.getRowsPerPage()%>" 
350            totalrows="<%=reporters == null ? 0 : reporters.getTotalCount()%>" 
351            visible="<%=mode.hasNavigator()%>"
352          />
353        </tbl:panel>
354      </div>
355      <tbl:data>
356        <tbl:headers>
357          <tbl:headerrow>
358            <tbl:header colspan="3" />
359            <tbl:columnheaders />
360          </tbl:headerrow>
361          <%
362          int numFilters = cc.getNumPropertyFilters();
363          int numRows = cc.getFilterRows();
364          for (int filterNo = 0; filterNo < numRows; filterNo++)
365          {
366            boolean lastRow = filterNo == numRows-1;
367            %>
368            <tbl:headerrow>
369              <tbl:header subclass="index" />
370              <tbl:header 
371                subclass="check" 
372                visible="<%=mode.hasCheck()%>"
373                ><base:icon 
374                  id="check.uncheck"
375                  image="check_uncheck.png" 
376                  tooltip="Check/uncheck all" 
377                  visible="<%=lastRow%>"
378                /></tbl:header>
379              <tbl:header 
380                subclass="check" 
381                visible="<%=mode.hasRadio()%>"
382                />
383              <tbl:header 
384                subclass="icons" 
385                visible="<%=mode.hasIcons()%>"
386                >
387                <base:icon
388                  subclass="link table-filter-row-action"
389                  image="add.png"
390                  tooltip="Add extra filter row"
391                  visible="<%=lastRow%>"
392                /><base:icon
393                  subclass="link table-filter-row-action"
394                  image="remove.png"
395                  tooltip="Remove this filter row"
396                  visible="<%=numRows > 1 || numFilters > 0 %>"
397                  data-remove-row="<%=filterNo%>"
398                />
399              </tbl:header>
400              <tbl:propertyfilter row="<%=filterNo%>" />
401            </tbl:headerrow>
402            <%
403          }
404          %>
405        </tbl:headers>
406        <tbl:rows>
407          <%
408          if (cc.getMessage() != null)
409          {
410            %>
411            <tbl:panel subclass="bg-filled-50">
412              <div class="messagecontainer error"><%=cc.getMessage()%></div>
413            </tbl:panel>
414            <%
415            cc.setMessage(null);
416          }
417          int index = cc.getPage()*cc.getRowsPerPage();
418          int selectedItemId = cc.getId();
419          if (reporters != null)
420          {           
421            while (reporters.hasNext())
422            {
423              ReporterScore score = reporters.next();
424              ReporterData item = score.getReporter();
425              int itemId = item.getId();
426              String name = HTML.encodeTags(item.getName());
427              String tooltip = mode.isSelectionMode() ?
428                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
429              index++;
430              numListed++;
431              %>
432              <tbl:row>
433                <tbl:header 
434                  clazz="index"
435                  ><%=index%></tbl:header>
436                <tbl:header 
437                  clazz="check" 
438                  visible="<%=mode.hasCheck()%>"
439                  ><input 
440                    type="checkbox" 
441                    name="<%=itemId%>" 
442                    value="<%=itemId%>" 
443                    title="<%=name%>" 
444                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
445                  ></tbl:header>
446                <tbl:header 
447                  clazz="check" 
448                  visible="<%=mode.hasRadio()%>"
449                  ><input 
450                    type="radio" 
451                    name="item_id" 
452                    value="<%=itemId%>" 
453                    title="<%=name%>" 
454                    <%=selectedItemId == itemId ? "checked" : ""%>
455                  ></tbl:header>
456                <tbl:header 
457                  clazz="icons" 
458                  visible="<%=mode.hasIcons()%>"
459                  >&nbsp;</tbl:header>
460                <tbl:cell column="name"><div
461                  class="link table-item"
462                  data-item-id="<%=itemId%>"
463                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
464                  tabindex="0"
465                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
466                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
467                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
468                <tbl:cell column="score"><%=Values.formatNumber(score.getScore(), 2)%></tbl:cell>
469                <tbl:cell column="symbol"><%=HTML.encodeTags(item.getSymbol())%></tbl:cell>
470                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
471                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
472                <tbl:cell column="lastUpdate" value="<%=item.getLastUpdate()%>" />
473                <tbl:cell column="reporterType"><base:propertyvalue dbcontrol="<%=dc%>" item="<%=item%>" property="reporterType.name" /></tbl:cell>
474                <%
475                if (reporterProperties != null)
476                {
477                  for (ExtendedProperty ep : reporterProperties)
478                  {
479                    name = ep.getName();
480                    %>
481                    <tbl:cell column="<%=name%>"><tbl:cellvalue value="<%=item.getExtended(name)%>" /></tbl:cell>
482                    <%
483                  }
484                }
485                %>
486                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
487                  <tbl:cell column="xt-columns" />
488                </tbl:xt-cells>
489              </tbl:row>
490              <%
491            }
492          }
493          if (numListed == 0)
494          {
495            %>
496            <tbl:panel subclass="bg-filled-50">
497              <div class="messagecontainer note">
498              <%=reporters == null || reporters.getTotalCount() == 0 ? "No reporters were found" : "No reporters on this page. Please select another page!" %>
499              </div>
500            </tbl:panel>
501            <%
502          }
503          %>
504          </tbl:rows>
505      </tbl:data>
506    </tbl:table>
507    </t:tab>
508    </t:tabcontrol>
509
510    <base:buttongroup subclass="dialogbuttons">
511      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
512      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
513      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
514    </base:buttongroup>
515
516  </base:body>
517  </base:page>
518  <%
519}
520finally
521{
522  if (reporters != null) reporters.close();
523  if (dc != null) dc.close();
524}
525%>
Note: See TracBrowser for help on using the repository browser.