1 | <%@ page import="dbnp.studycapturing.EventGroup" %> |
---|
2 | <%@ page import="dbnp.studycapturing.RelTime" %> |
---|
3 | <g:if test="${studyList*.eventGroups?.flatten()?.size()==0}"> |
---|
4 | No event groups in this study |
---|
5 | </g:if> |
---|
6 | <g:else> |
---|
7 | <% |
---|
8 | // Determine a union of the event templates for all different |
---|
9 | // eventgroups in all studies, in order to show a proper list. |
---|
10 | // We want every field to appear just once, |
---|
11 | // so the list is filtered for unique values |
---|
12 | def showTemplates = studyList*.giveAllEventTemplates()?.flatten().unique() |
---|
13 | |
---|
14 | def showProperties = [:]; |
---|
15 | def allEvents = studyList*.events.flatten() + studyList*.samplingEvents.flatten(); |
---|
16 | def eventColumns = 0; |
---|
17 | |
---|
18 | showTemplates.each { template -> |
---|
19 | // We want to show all properties only once. If the properties are never filled |
---|
20 | // we shouldn't show them at all. |
---|
21 | def showFields = [] |
---|
22 | template.fields.each { field -> |
---|
23 | if( field.isFilledInList( allEvents.findAll { it.template == template } ) ) { |
---|
24 | showFields << field; |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | showProperties[ template.name ] = showFields; |
---|
29 | |
---|
30 | // Compute the total number of columns under 'Events' (the +1 is |
---|
31 | // because of the 'start time' column) |
---|
32 | eventColumns += [ 1, showFields.size() + 1 ].max(); |
---|
33 | } |
---|
34 | |
---|
35 | %> |
---|
36 | <table> |
---|
37 | <thead> |
---|
38 | <tr> |
---|
39 | <g:if test="${multipleStudies}"> |
---|
40 | <th></th> |
---|
41 | </g:if> |
---|
42 | <th>Name</th> |
---|
43 | <th colspan="${eventColumns}">Events</th> |
---|
44 | <th>Subjects</th> |
---|
45 | </tr> |
---|
46 | <tr> |
---|
47 | <g:if test="${multipleStudies}"> |
---|
48 | <th></th> |
---|
49 | </g:if> |
---|
50 | <th></th> |
---|
51 | <g:each in="${showTemplates}" var="eventTemplate"> |
---|
52 | <th colspan="${[1, showProperties[ eventTemplate.name ].size() + 1 ].max()}">${eventTemplate.name}</th> |
---|
53 | </g:each> |
---|
54 | <th></th> |
---|
55 | </tr> |
---|
56 | <tr class="templateFields"> |
---|
57 | <g:if test="${multipleStudies}"> |
---|
58 | <th></th> |
---|
59 | </g:if> |
---|
60 | <th></th> |
---|
61 | <g:each in="${showTemplates}" var="eventTemplate"> |
---|
62 | <th>start time</th> |
---|
63 | <g:if test="${showProperties[ eventTemplate.name ].size() > 0}"> |
---|
64 | <g:each in="${showProperties[ eventTemplate.name ]}" var="field"> |
---|
65 | <th>${field.name}</th> |
---|
66 | </g:each> |
---|
67 | </g:if> |
---|
68 | </g:each> |
---|
69 | <th></th> |
---|
70 | </tr> |
---|
71 | </thead> |
---|
72 | |
---|
73 | <g:set var="i" value="${1}" /> |
---|
74 | |
---|
75 | <g:each in="${studyList}" var="studyInstance"> |
---|
76 | <% |
---|
77 | // Sort the groups by name |
---|
78 | def sortedEventGroups = studyInstance.eventGroups.sort( { a, b -> |
---|
79 | return a.name <=> b.name; |
---|
80 | } as Comparator ); |
---|
81 | |
---|
82 | // Determine the number of rows per group (depending on the max |
---|
83 | // number of events per template in a group) |
---|
84 | def maxNumberEventsPerTemplate = [:]; |
---|
85 | def rowsPerStudy = 0; |
---|
86 | sortedEventGroups.each { group -> |
---|
87 | def max = 1; |
---|
88 | showTemplates.each { template -> |
---|
89 | def num = ( group.events + group.samplingEvents ).findAll { it.template == template }.size(); |
---|
90 | if( num > max ) |
---|
91 | max = num; |
---|
92 | } |
---|
93 | maxNumberEventsPerTemplate[group.name] = max; |
---|
94 | rowsPerStudy += max; |
---|
95 | } |
---|
96 | |
---|
97 | def orphans = studyInstance.getOrphanEvents(); |
---|
98 | if( orphans?.size() > 0 ) { |
---|
99 | sortedEventGroups.add( new EventGroup( |
---|
100 | id: -1, |
---|
101 | name: 'No group', |
---|
102 | events: orphans, |
---|
103 | subjects: [] |
---|
104 | )); |
---|
105 | } |
---|
106 | %> |
---|
107 | <g:each in="${sortedEventGroups}" var="eventGroup" status="j"> |
---|
108 | <g:set var="n" value="${1}" /> |
---|
109 | <g:while test="${n <= maxNumberEventsPerTemplate[ eventGroup.name ]}"> |
---|
110 | |
---|
111 | <tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> |
---|
112 | <g:if test="${n == 1}"> |
---|
113 | <g:if test="${multipleStudies && j==0}"> |
---|
114 | <td class="studytitle" rowspan="${rowsPerStudy}"> |
---|
115 | ${studyInstance.title} |
---|
116 | </td> |
---|
117 | </g:if> |
---|
118 | <td rowspan="${maxNumberEventsPerTemplate[ eventGroup.name ]}">${eventGroup.name}</td> |
---|
119 | </g:if> |
---|
120 | |
---|
121 | <g:each in="${showTemplates}" var="currentEventTemplate"> |
---|
122 | <g:if test="${showProperties[ currentEventTemplate.name ].size() == 0}"> |
---|
123 | <td> </td> |
---|
124 | </g:if> |
---|
125 | <g:else> |
---|
126 | <% |
---|
127 | def templateEvents = (eventGroup.events + eventGroup.samplingEvents).findAll { it.template == currentEventTemplate }.sort { a, b -> a.startTime <=> b.startTime }.asType(List) |
---|
128 | def event = templateEvents.size() >= n ? templateEvents[ n - 1 ] : null; |
---|
129 | %> |
---|
130 | <td class="templateFieldValue"><g:if test="${event}">${new RelTime( event.startTime ).toString()}</g:if></td> |
---|
131 | <g:each in="${showProperties[ currentEventTemplate.name ]}" var="field"> |
---|
132 | <td class="templateFieldValue"><wizard:showTemplateField field="${field}" entity="${event}" /></td> |
---|
133 | </g:each> |
---|
134 | </g:else> |
---|
135 | </g:each> |
---|
136 | |
---|
137 | <g:if test="${n == 1}"> |
---|
138 | <% sortedGroupSubjects = eventGroup.subjects.sort( { a, b -> a.name <=> b.name } as Comparator ) %> |
---|
139 | |
---|
140 | <td rowspan="${maxNumberEventsPerTemplate[ eventGroup.name ]}" title="${sortedGroupSubjects.name.join( ', ' )}"> |
---|
141 | <g:if test="${eventGroup.subjects.size()==0}"> |
---|
142 | - |
---|
143 | </g:if> |
---|
144 | <g:else> |
---|
145 | <g:each in="${eventGroup.subjects.species.unique()}" var="currentSpecies" status="k"> |
---|
146 | <g:if test="${k > 0}">,</g:if> |
---|
147 | <%=eventGroup.subjects.findAll { return it.species == currentSpecies; }.size() %> |
---|
148 | ${currentSpecies} |
---|
149 | </g:each> |
---|
150 | </g:else> |
---|
151 | </td> |
---|
152 | </g:if> |
---|
153 | </tr> |
---|
154 | |
---|
155 | |
---|
156 | <g:set var="n" value="${n+1}" /> |
---|
157 | </g:while> |
---|
158 | |
---|
159 | <g:set var="i" value="${i + 1}" /> |
---|
160 | </g:each> |
---|
161 | |
---|
162 | </g:each> |
---|
163 | |
---|
164 | </table> |
---|
165 | </g:else> |
---|