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