source: trunk/www/biomaterials/events/list_events.jsp @ 6604

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

References #1890: Improve skinnability of BASE

Updated table listings with some new css classes to make it easier to modify background color.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.2 KB
Line 
1<%-- $Id: list_events.jsp 6604 2014-11-18 10:39:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell
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.ItemContext"
31  import="net.sf.basedb.core.BioMaterialEvent"
32  import="net.sf.basedb.core.BioPlateEvent"
33  import="net.sf.basedb.core.BioPlateEventParticipant"
34  import="net.sf.basedb.core.BioPlate"
35  import="net.sf.basedb.core.MeasuredBioMaterial"
36  import="net.sf.basedb.core.Quantity"
37  import="net.sf.basedb.core.Unit"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultIterator"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.PluginDefinition"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.core.query.Restrictions"
44  import="net.sf.basedb.core.query.Expressions"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.core.plugin.Plugin"
49  import="net.sf.basedb.util.Enumeration"
50  import="net.sf.basedb.util.units.UnitUtil"
51  import="net.sf.basedb.clients.web.Base"
52  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
53  import="net.sf.basedb.clients.web.ModeInfo"
54  import="net.sf.basedb.clients.web.PermissionUtil"
55  import="net.sf.basedb.clients.web.util.HTML"
56  import="net.sf.basedb.util.Values"
57  import="net.sf.basedb.util.formatter.Formatter"
58  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
59  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
60  import="net.sf.basedb.clients.web.extensions.JspContext"
61  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
62  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
63  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
64  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
65  import="java.util.List"
66  import="java.util.Map"
67  import="java.util.Date"
68%>
69<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
70<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
71<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
72<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
73<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
74<%!
75  private static final Item itemType = Item.BIOMATERIALEVENT;
76  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
77%>
78<%
79final Item bioMaterialType = Item.valueOf(request.getParameter("biomaterial_type"));
80final int bioMaterialId = Values.getInt(request.getParameter("biomaterial_id"));
81final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
82final String ID = sc.getId();
83final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
84
85final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
86final String callback = request.getParameter("callback");
87final String title = mode.generateTitle("event", "events");
88final DbControl dc = sc.newDbControl();
89ItemResultIterator<BioMaterialEvent> events = null;
90try
91{
92  final MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
93  final BioMaterialEvent creationEvent = bioMaterial.getCreationEvent();
94  final boolean createPermission = bioMaterial.hasPermission(Permission.WRITE);
95  final boolean deletePermission = createPermission;
96
97  String viewPage = null;
98  String listName = null;
99  if (bioMaterialType == Item.SAMPLE)
100  {
101    listName = "Samples";
102    viewPage = "../samples/index.jsp";
103  }
104  else if (bioMaterialType == Item.EXTRACT)
105  {
106    listName = "Extracts";
107    viewPage = "../extracts/index.jsp";
108  }
109 
110  Unit microGram = UnitUtil.getUnit(dc, Quantity.MASS, "µg");
111  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
112  try
113  {
114    final ItemQuery<BioMaterialEvent> query = Base.getConfiguredQuery(dc, cc, true, bioMaterial.getEvents(), mode);
115    events = query.iterate(dc);
116  }
117  catch (Throwable t)
118  {
119    cc.setMessage(t.getMessage());
120    t.printStackTrace();
121  }
122  int numListed = 0;
123  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
124  Formatter<Number> numericFormatter = FormatterFactory.getNumberFormatter(sc);
125  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, bioMaterial);
126  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
127  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
128  %>
129  <base:page title="<%=title%>" type="<%=mode.getPageType()%>" id="list-page">
130  <base:head scripts="table.js,tabcontrol-2.js,~events.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
131    <ext:scripts context="<%=jspContext%>" />
132    <ext:stylesheets context="<%=jspContext%>" />
133  </base:head>
134 
135  <base:body>
136    <p:path><p:pathelement 
137      title="<%=listName%>" href="<%=viewPage+"?ID="+ID%>" 
138      /><p:pathelement title="<%=HTML.encodeTags(bioMaterial.getName())%>"
139      /></p:path>
140
141    <t:tabcontrol 
142      id="main" 
143      subclass="mastertabcontrol content"
144      active="events">
145    <t:tab id="properties" title="Properties" />
146    <t:tab id="annotations" title="Annotations &amp; parameters"
147      tooltip="View annotation values and protocol parameters" />
148   
149    <t:tab id="events" title="Events">
150    <tbl:table 
151      id="events" 
152      columns="<%=cc.getSetting("columns")%>"
153      sortby="<%=cc.getSortProperty()%>" 
154      direction="<%=cc.getSortDirection()%>"
155      action="index.jsp"
156      sc="<%=sc%>"
157      item="<%=itemType%>"
158      subclass="fulltable"
159      >
160      <tbl:hidden 
161        name="mode" 
162        value="<%=mode.getName()%>" 
163      />
164      <tbl:hidden 
165        name="biomaterial_id"
166        value="<%=String.valueOf(bioMaterialId)%>" 
167      />
168      <tbl:hidden 
169        name="biomaterial_type" 
170        value="<%=bioMaterialType.name()%>" 
171      />
172      <tbl:hidden 
173        name="callback" 
174        value="<%=callback%>" 
175        skip="<%=callback == null%>" 
176      />
177      <%
178      Enumeration<String, String> eventTypes = new Enumeration<String, String>();
179      for (BioMaterialEvent.Type et : BioMaterialEvent.Type.values())
180      {
181        eventTypes.add(Integer.toString(et.getValue()), HTML.encodeTags(et.toString()));
182      }
183      %>
184      <tbl:columndef 
185        id="type"
186        property="eventType"
187        datatype="int"
188        title="Type"
189        enumeration="<%=eventTypes%>"
190        sortable="true" 
191        filterable="true"
192        exportable="true"
193        show="always" 
194      />
195      <tbl:columndef 
196        id="id"
197        clazz="uniquecol"
198        property="id"
199        datatype="int"
200        title="ID"
201        sortable="true"
202        filterable="true"
203        exportable="true"
204      />
205      <tbl:columndef 
206        id="entryDate"
207        property="entryDate"
208        datatype="date"
209        title="Entry date"
210        sortable="true" 
211        filterable="true"
212        exportable="true"
213        formatter="<%=dateFormatter%>"
214      />
215      <tbl:columndef 
216        id="eventDate"
217        property="eventDate"
218        datatype="date"
219        title="Event date"
220        sortable="true" 
221        filterable="true"
222        exportable="true"
223        formatter="<%=dateFormatter%>"
224      />
225      <tbl:columndef 
226        id="quantity"
227        datatype="float"
228        title="Used quantity (µg)"
229        sortable="false" 
230        filterable="false"
231        exportable="false"
232        unit="<%=microGram%>"
233        formatter="<%=numericFormatter %>"
234      />
235      <tbl:columndef
236        id="bioPlateEvent"
237        property="bioPlateEventParticipant.event.name"
238        datatype="string"
239        title="Plate event"
240        sortable="true" 
241        filterable="true"
242        exportable="true"
243      />
244      <tbl:columndef 
245        id="protocol"
246        property="protocol.name"
247        datatype="string"
248        title="Protocol"
249        sortable="true" 
250        filterable="true"
251        exportable="true"
252      />
253      <tbl:columndef 
254        id="user"
255        property="user.name"
256        datatype="string"
257        title="User"
258        sortable="true" 
259        filterable="true"
260        exportable="true"
261      />
262      <tbl:columndef 
263        id="comment"
264        property="comment"
265        datatype="string"
266        title="Comment" 
267        sortable="true" 
268        filterable="true" 
269        exportable="true"
270      />
271      <tbl:columndef
272        id="permission"
273        title="Permission"
274      />
275      <tbl:columndef 
276        id="xt-columns" 
277        extensions="<%=columnsInvoker%>" 
278        jspcontext="<%=jspContext%>" 
279      />
280      <div class="panelgroup bg-filled-50 bottomborder">
281        <tbl:toolbar
282          visible="<%=mode.hasToolbar()%>"
283          subclass="bottomborder"
284          >
285          <tbl:button 
286            id="btnNewItem"
287            data-extra-url="<%="&biomaterial_type="+bioMaterialType.name()+"&biomaterial_id="+bioMaterialId%>"
288            disabled="<%=!createPermission%>" 
289            image="new.png" 
290            title="New&hellip;" 
291            tooltip="<%=createPermission ? "Create new event" : "You do not have permission to create events"%>" 
292          />
293          <tbl:button 
294            id="btnDeleteItems"
295            disabled="<%=!deletePermission%>" 
296            image="delete.png" 
297            title="Delete&hellip;"
298            data-confirm="1"
299            tooltip="<%=deletePermission ? "Delete the selected events" : "You do not have permission to delete events"%>" 
300          />
301          <tbl:button 
302            id="btnColumns"
303            image="columns.png" 
304            title="Columns&hellip;" 
305            tooltip="Show, hide and re-order columns" 
306          />
307          <tbl:button 
308            id="btnImport"
309            data-plugin-type="IMPORT"
310            image="import.png" 
311            title="Import&hellip;" 
312            tooltip="Import data" 
313            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
314          />
315          <tbl:button 
316            id="btnExport"
317            data-plugin-type="EXPORT"
318            image="export.png" 
319            title="Export&hellip;" 
320            tooltip="Export data" 
321            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
322          />
323          <tbl:button 
324            id="btnRunPlugin"
325            data-plugin-type="OTHER"
326            image="runplugin.png" 
327            title="Run plugin&hellip;" 
328            tooltip="Run a plugin" 
329            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
330          />
331          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
332            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
333        </tbl:toolbar>
334        <tbl:panel>
335          <tbl:presetselector />
336          <tbl:navigator
337            page="<%=cc.getPage()%>" 
338            rowsperpage="<%=cc.getRowsPerPage()%>" 
339            totalrows="<%=events == null ? 0 : events.getTotalCount()%>" 
340            visible="<%=mode.hasNavigator()%>"
341          />
342        </tbl:panel>
343      </div>
344      <tbl:data>
345        <tbl:headers>
346          <tbl:headerrow>
347            <tbl:header colspan="3" />
348            <tbl:columnheaders />
349          </tbl:headerrow>
350          <tbl:headerrow>
351            <tbl:header subclass="index" />
352            <tbl:header 
353              subclass="check" 
354              visible="<%=mode.hasCheck()%>"
355              ><base:icon 
356                id="check.uncheck"
357                image="check_uncheck.png" 
358                tooltip="Check/uncheck all" 
359                 
360              /></tbl:header>
361            <tbl:header 
362              subclass="check" 
363              visible="<%=mode.hasRadio()%>"
364              />
365            <tbl:header 
366              subclass="icons" 
367              visible="<%=mode.hasIcons()%>"
368              />
369            <tbl:propertyfilter />
370          </tbl:headerrow>
371        </tbl:headers>
372        <tbl:rows>
373          <%
374          if (cc.getMessage() != null)
375          {
376            %>
377            <tbl:panel subclass="bg-filled-50">
378              <div class="messagecontainer error"><%=cc.getMessage()%></div>
379            </tbl:panel>
380            <%
381            cc.setMessage(null);
382          }
383          int index = cc.getPage()*cc.getRowsPerPage();
384          int selectedItemId = cc.getId();
385          if (events != null)
386          {
387            while (events.hasNext())
388            {
389              BioMaterialEvent item = events.next();
390              BioMaterialEvent.Type eventType = item.getEventType();
391              int itemId = item.getId();
392              boolean writePermission = item.hasPermission(Permission.WRITE);
393              String tooltip = mode.isSelectionMode() ? 
394                "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
395              String name = "TODO";
396              index++;
397              numListed++;
398              %>
399              <tbl:row>
400                <tbl:header 
401                  clazz="index"
402                  ><%=index%></tbl:header>
403                <tbl:header 
404                  clazz="check" 
405                  visible="<%=mode.hasCheck()%>"
406                  ><input 
407                    type="checkbox" 
408                    name="<%=itemId%>" 
409                    value="<%=itemId%>" 
410                    title="TODO" 
411                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
412                  ></tbl:header>
413                <tbl:header 
414                  clazz="check" 
415                  visible="<%=mode.hasRadio()%>"
416                  ><input 
417                      type="radio" 
418                      name="item_id" 
419                      value="<%=itemId%>" 
420                      title="<%=name%>" 
421                      <%=selectedItemId == itemId ? "checked" : ""%>
422                    ></tbl:header>
423                <tbl:header 
424                  clazz="icons" 
425                  visible="<%=mode.hasIcons()%>"
426                  >&nbsp;</tbl:header>
427                <tbl:cell column="type">
428                  <%
429                  if (eventType == BioMaterialEvent.Type.OTHER)
430                  {
431                    %>
432                    <div
433                      class="link table-item"
434                      data-item-id="<%=itemId%>"
435                      data-no-edit="<%=writePermission ? 0 : 1 %>" 
436                      data-extra-url="&biomaterial_type=<%=bioMaterialType.name()%>&biomaterial_id=<%=bioMaterialId%>"
437                      tabindex="0"
438                      title="<%=tooltip%>"><%=eventType%></div>
439                    <%
440                  }
441                  else if (eventType == BioMaterialEvent.Type.CREATION)
442                  {
443                    if (item.equals(creationEvent))
444                    {
445                      %>
446                      <div
447                        class="link table-item"
448                        data-item-id="<%=itemId%>"
449                        data-no-edit="1" 
450                        data-extra-url="&biomaterial_type=<%=bioMaterialType.name()%>&biomaterial_id=<%=bioMaterialId%>"
451                        tabindex="0"
452                        title="View this item">Created</div>
453                      <%
454                    }
455                    else
456                    {
457                      MeasuredBioMaterial child = null;
458                      try
459                      {
460                        child = item.getBioMaterial();
461                      }
462                      catch (PermissionDeniedException ex)
463                      {}
464                      %>
465                      <div
466                        class="link table-item"
467                        data-item-id="<%=itemId%>"
468                        data-no-edit="1" 
469                        data-extra-url="&biomaterial_type=<%=bioMaterialType.name()%>&biomaterial_id=<%=bioMaterialId%>"
470                        tabindex="0"
471                        title="View this item">
472                        Created <%=child == null ? "child" : child.getType().toString().toLowerCase() %>: <base:propertyvalue 
473                            item="<%=item%>" 
474                            property="bioMaterial"
475                            enableEditLink="<%=false%>" 
476                            enablePropertyLink="<%=false%>"
477                          />
478                        </div>
479                      <%
480                    }
481                  }
482                  else if (eventType == BioMaterialEvent.Type.BIOASSAY)
483                  {
484                    %>
485                    <div
486                      class="link table-item"
487                      data-item-id="<%=itemId%>"
488                      data-no-edit="1" 
489                      data-extra-url="&biomaterial_type=<%=bioMaterialType.name()%>&biomaterial_id=<%=bioMaterialId%>"
490                      tabindex="0"
491                      title="View this item">
492                        Bioassay: <base:propertyvalue 
493                            item="<%=item%>" 
494                            property="physicalBioAssay"
495                            enableEditLink="<%=false%>" 
496                            enablePropertyLink="<%=false%>"
497                          />
498                    </div>
499                    <%
500                  }
501                  %>
502                </tbl:cell>
503                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
504                <tbl:cell column="eventDate" value="<%=item.getEventDate()%>" />
505                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
506                <tbl:cell column="quantity" value="<%=item.getUsedQuantity(bioMaterial)%>" />
507                <tbl:cell column="bioPlateEvent">
508                  <%
509                  try
510                  {
511                    BioPlateEventParticipant participant = item.getBioPlateEventParticipant();
512                    if (participant != null)
513                    {
514                      BioPlateEvent event = participant.getEvent();
515                      String extraUrl = "";
516                      try
517                      {
518                        extraUrl = "&bioplate_id=" + participant.getBioPlate().getId();
519                      }
520                      catch (PermissionDeniedException ex)
521                      {}
522                      boolean editLink = event.hasPermission(Permission.WRITE);
523                      if (mode.hasPropertyLink())
524                      {
525                        %>
526                        <span class="link auto-init"
527                          data-auto-init="item-link" 
528                          data-item-type="BIOPLATEEVENT"
529                          data-item-id="<%=event.getId()%>"
530                          data-no-edit="<%=editLink ? 0 : 1 %>"
531                          data-extra-url="<%=extraUrl %>"
532                          title="View this bioplate event <%=editLink? "(use CTRL, ALT or SHIFT to edit)" : ""%>"
533                        >
534                        <%=HTML.encodeTags(event.getName()) %>
535                        </span>
536                        <%
537                      }
538                      else
539                      {
540                        %>
541                        <%=HTML.encodeTags(event.getName()) %>
542                        <%
543                      }
544                    }
545                    else
546                    {
547                      %>
548                      <i>- none -</i>
549                      <%
550                    }
551                  }
552                  catch (PermissionDeniedException ex)
553                  {
554                    %>
555                    <i>- denied -</i>
556                    <%
557                  }
558                  %>
559                </tbl:cell>
560                <tbl:cell column="protocol"
561                  ><base:propertyvalue 
562                    item="<%=item%>" 
563                    property="protocol"
564                    enableEditLink="<%=mode.hasEditLink()%>" 
565                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
566                  /></tbl:cell>
567                <tbl:cell column="user"
568                  ><base:propertyvalue 
569                    item="<%=item%>" 
570                    property="user"
571                    enableEditLink="<%=mode.hasEditLink()%>" 
572                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
573                  /></tbl:cell>
574                <tbl:cell column="comment"><%=HTML.encodeTags(item.getComment())%></tbl:cell>
575                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
576                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
577                  <tbl:cell column="xt-columns" />
578                </tbl:xt-cells>
579              </tbl:row>
580              <%
581            }
582          }
583          if (numListed == 0)
584          {
585            %>
586            <tbl:panel subclass="bg-filled-50">
587              <div class="messagecontainer note">
588              <%=events == null || events.getTotalCount() == 0 ? "No events were found" : "No events on this page. Please select another page!" %>
589              </div>
590            </tbl:panel>
591            <%
592          }
593          %>
594          </tbl:rows>
595        </tbl:data>
596    </tbl:table>
597    <base:buttongroup subclass="dialogbuttons">
598      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
599      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
600      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
601    </base:buttongroup>
602    </t:tab>
603   
604    <t:tab id="overview" title="Overview" 
605      tooltip="Display a tree overview of related items" />
606    <t:tab id="history" title="Change history" 
607        tooltip="Displays a log of all modifications made to this item"
608        visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>" />
609    </t:tabcontrol>
610
611  </base:body>
612  </base:page>
613  <%
614}
615finally
616{
617  if (events != null) events.close();
618  if (dc != null) dc.close();
619}
620%>
Note: See TracBrowser for help on using the repository browser.