source: extensions/net.sf.basedb.labenv/trunk/resources/reports/labenvironmentdatabaseexport.jsp @ 2341

Last change on this file since 2341 was 2341, checked in by olle, 9 years ago

Refs #529. JSP files labsensorinfo.jsp, labenvironmentdatabaseexport.jsp, and labenvironmentdatabasestatistics.jsp in resources/reports/ updated to set link for header text "LabEnv" to the same JSP page, as currently the lab environment extension doesn't have a common index page.

File size: 12.3 KB
Line 
1<%@ page
2  pageEncoding="UTF-8"
3  session="false"
4  import="net.sf.basedb.core.Application"
5  import="net.sf.basedb.core.User"
6  import="net.sf.basedb.core.DbControl"
7  import="net.sf.basedb.core.SessionControl"
8  import="net.sf.basedb.clients.web.Base"
9  import="net.sf.basedb.clients.web.util.HTML"
10  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
11  import="net.sf.basedb.util.Values"
12  import="net.sf.basedb.util.formatter.DateFormatter"
13  import="java.util.Calendar"
14  import="java.util.Locale"
15  import="java.text.SimpleDateFormat"
16%>
17<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
18<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
19<%
20final SessionControl sc = Base.getExistingSessionControl(request, true);
21final String ID = sc.getId();
22final float scale = Base.getScale(sc);
23final String home = ExtensionsControl.getHomeUrl("net.sf.basedb.labenv");
24DbControl dc = null;
25try
26{
27  dc = sc.newDbControl();
28  final User user = User.getById(dc, sc.getLoggedInUserId());
29%>
30<base:page type="default" >
31<base:head scripts="ajax.js" styles="path.css">
32  <link rel="stylesheet" type="text/css" href="../css/reggie.css">
33  <script language="JavaScript" src="../reggie.js" type="text/javascript" charset="UTF-8"></script>
34
35<script language="JavaScript">
36
37window.onload = function()
38{
39  // Create lab sensor menu from configuration data
40  createSensorMenu();
41};
42
43function createSensorMenu()
44{
45  // Get lab sensor configurations dynamically from server data
46  var frm = document.forms['labenv'];
47  var labSensorConfigList = getLabSensorConfigList();
48  if (labSensorConfigList != null)
49  {
50    // Construct lab sensor menu from JSON data
51    var sensorSelect = document.getElementById('sensorSelectId');
52    for (var i=0; i < labSensorConfigList.length; i++)
53    {
54      // Get URL and name for lab sensor number 'i'
55      var labSensorConfig = labSensorConfigList[i];
56      var sensorUrl = labSensorConfig['url'];
57      var sensorName = labSensorConfig['name'];
58      // Create and add new option element to select menu
59      var optionEl = document.createElement('option');
60      optionEl.setAttribute('value',sensorUrl);
61      optionEl.innerHTML = sensorName;
62      sensorSelect.appendChild(optionEl);
63    }
64  }
65}
66
67function getLabSensorConfigList()
68{
69  // Get lab sensor configurations JSON object with AJAX
70  var frm = document.forms['labenv'];
71  var request = Ajax.getXmlHttpRequest();
72  var url = '../../labenv.jar/LabEnvironment.servlet?ID=<%=ID%>&cmd=GetLabSensorConfigList';
73  request.open("GET", url, false); 
74  request.send(null);
75 
76  //if (debug) Main.debug(request.responseText);
77  //Main.debug(request.responseText);
78
79  var response = JSON.parse(request.responseText);
80  if (response.status != 'ok')
81  {
82    setFatalError(response.message);
83    return false;
84  }
85 
86  // Get sensor configurations information from the AJAX response
87  var labSensorConfigList = response.labSensorConfigList;
88
89  return labSensorConfigList;
90}
91
92function goExport(preview)
93{
94  var frm = document.forms['labenv'];
95  var url = '../../labenv.jar/LabEnvironment.servlet?ID=<%=ID%>&cmd=LabEnvironmentDatabaseQuery';
96  if (frm.sensorSelect.value != null) url += '&sensorurl='+frm.sensorSelect.value;
97  var sensorUrlText = frm.sensorSelect[frm.sensorSelect.selectedIndex].text;
98  url += '&sensorname='+sensorUrlText;
99  url += '&fdate='+frm.fromDate.value;
100  url += '&ftime='+frm.fromTime.value;
101  url += '&tdate='+frm.toDate.value;
102  url += '&ttime='+frm.toTime.value;
103  if (frm.displayIndexSelect.value != null) url += '&displayindex='+frm.displayIndexSelect.value;
104  url += '&returntype=export';
105  if (preview) 
106  {
107    var previewTitle = document.getElementById('previewTitle');
108    var previewList = document.getElementById('previewList');
109   
110    Main.hide('previewWrapper');
111    previewTitle.innerHTML = 'Working...';
112    previewList.innerHTML = '';
113   
114    url += '&preview=1';
115    var request = Ajax.getXmlHttpRequest();
116   
117    try
118    {
119      showLoadingAnimation('Working...');
120      request.open("GET", url, false); 
121      request.send(null);
122    }
123    finally
124    {
125      hideLoadingAnimation();
126    }
127
128    if (request.status != 200)
129    {
130      Main.openPopup('', 'ErrorWindow', 800, 600);
131      Main.getWindow('ErrorWindow').document.write(request.responseText);
132    }
133    else
134    {
135      var allLines = request.responseText.split('\n');
136      var numCases = allLines.length - 2; // First line is a header line
137      var numSpecimen = 0;
138      var numNoSpecimen = 0;
139     
140      var html = '<tr><th>'+allLines[0].replace(/\t/g, '</th><th>')+'</th></tr>';
141      // Check second column for the 'Subtype' value
142      var numNoConsent = 0;
143      var numMissingConsent = 0;
144      for (var i = 1 ; i <= numCases; i++)
145      {
146        var line = allLines[i];
147        var cols = line.split(/\t/);
148        var sampleSubtype = cols[1];
149        if (sampleSubtype == 'Specimen')
150        {
151          numSpecimen++;
152        }
153        else if (sampleSubtype == 'NoSpecimen')
154        {
155          numNoSpecimen++;
156        }
157        var rowClass = '';
158        html += '<tr class="'+rowClass+'"><td>'+cols.join('</td><td>')+'</td></tr>';
159      }
160
161      //var sensorUrlText = frm.sensorSelect[frm.sensorSelect.selectedIndex].text;
162      previewTitle.innerHTML = 'Sensor - ' + sensorUrlText;
163      previewList.innerHTML = '<table>'+html+'</table>';
164      Main.show('previewWrapper');
165    }
166  }
167  else
168  {
169    window.location = url;   
170  }
171 
172}
173
174function fromDateTimeOnChange()
175{
176  var frm = document.forms['labenv'];
177  var todaysDate = new Date();
178  fromDateIsValid = false;
179  setInputStatus('fromDate', '', '');
180 
181  var fromDate = frm.fromDate.value;
182  var fromTime = frm.fromTime.value;
183 
184  if (fromDate != '' || fromTime != '')
185  {
186    // Auto-fill the date if it's only given with 4(MMdd) or 6(yyMMdd) digits.
187    fromDate = autoFillDate(fromDate);
188    frm.fromDate.value = fromDate;
189
190    fromTime = autoFillTime(fromTime);
191    frm.fromTime.value = fromTime;
192   
193    if (!Dates.isDate(fromDate, 'yyyyMMdd'))
194    {
195      setInputStatus('fromDate', 'Not a valid date', 'invalid');
196      return;
197    }   
198   
199    if (!Dates.isDate(fromDate + ' ' + fromTime, 'yyyyMMdd HHmm'))
200    {
201      if (fromDate != '') setInputStatus('fromDate', 'Not a valid time (if time unknown, also leave date field blank)', 'invalid');
202      return;
203    }
204    setInputStatus('fromDate', '', 'valid');
205  }
206  fromDateIsValid = true;
207  toDateTimeOnChange();
208}
209
210function toDateTimeOnChange()
211{
212  var frm = document.forms['labenv'];
213  var todaysDate = new Date();
214  toDateIsValid = false;
215  setInputStatus('toDate', '', '');
216 
217  var toDate = frm.toDate.value;
218  var toTime = frm.toTime.value;
219 
220  if (toDate != '' || toTime != '')
221  {
222    // Auto-fill the date if it's only given with 4(MMdd) or 6(yyMMdd) digits.
223    toDate = autoFillDate(toDate);
224    frm.toDate.value = toDate;
225
226    toTime = autoFillTime(toTime);
227    frm.toTime.value = toTime;
228   
229    if (!Dates.isDate(toDate, 'yyyyMMdd'))
230    {
231      setInputStatus('toDate', 'Not a valid date', 'invalid');
232      return;
233    }   
234   
235    if (!Dates.isDate(toDate + ' ' + toTime, 'yyyyMMdd HHmm'))
236    {
237      if (toDate != '') setInputStatus('toDate', 'Not a valid time (if time unknown, also leave date field blank)', 'invalid');
238      return;
239    }
240    setInputStatus('toDate', '', 'valid');
241  }
242  toDateIsValid = true;
243}
244
245</script>
246<style>
247
248.fullyear
249{
250  font-weight: bold;
251}
252
253#previewWrapper
254{
255  position: absolute;
256  //top: 11em;
257  top: 15em;
258  bottom: 1em;
259  left: 20px;
260  width: 950px;
261  overflow: visible;
262}
263
264#previewList
265{
266  position: absolute;
267  top: 1.5em;
268  bottom: 0px;
269  width: 950px;
270  overflow: auto;
271  white-space: pre;
272  font-family: monospace;
273  border: 1px dotted #A0A0A0;
274  border-radius: 4px;
275  background: #E8E8E8;
276  padding: 0.25em;
277}
278
279#previewTitle
280{
281  font-weight: bold;
282}
283
284#previewList th
285{
286  border-bottom: 1px dotted #A0A0A0;
287}
288
289#previewList td, #previewList th
290{
291  text-align: left;
292  padding-right: 2em;
293  vertical-align: bottom;
294}
295
296.consent-warning
297{
298  color: #A00000;
299  background-color: #F8F8E8;
300}
301
302.consent-warning td:last-child
303{
304  background-image: url('../images/warning_small.png');
305  background-position: 95% 50%;
306  background-repeat: no-repeat;
307}
308
309</style>
310</base:head>
311<base:body >
312
313  <p:path><p:pathelement 
314    title="LabEnv" href="<%="./labenvironmentdatabaseexport.jsp?ID="+ID%>" 
315    /><p:pathelement title="Lab environment database export" 
316    /></p:path>
317
318  <div class="content">
319  <%
320  if (sc.getActiveProjectId() == 0)
321  {
322    %>
323    <div class="messagecontainer note" style="width: 950px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
324      No project has been selected. You may proceed with the export but
325      it may no include all items.
326    </div>
327    <%
328  }
329  %>
330  <form name="labenv" onsubmit="return false;">
331 
332  <!-- 1. Select lab sensor -->
333  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
334  <tr>
335    <td rowspan="3" class="stepno">1</td>
336    <td class="steptitle">Select lab sensor(s) and time period</td>
337  </tr>
338  <tr>
339    <td class="stepfields">
340      <table border="0" cellspacing="0" cellpadding="0" width="100%">
341      <tr>
342        <td class="prompt">Sensor</td>
343        <td class="input">
344          <select id="sensorSelectId" name="sensorSelect">
345            <option value="all">All</option>
346          </select>
347        </td>
348        <td class="status" id="sensorSelect.status"></td>
349        <td class="help"><span id="time.message" class="message" style="display: none;"></span></td>
350      </tr>     
351      <tr id="fromDateTimeSection" valign="top">
352        <td class="prompt">From</td>
353        <td class="input">Date <input type="text" name="fromDate" value="" size="12" maxlength="10" 
354            onkeypress="focusOnEnter(event, 'fromTime')" onblur="fromDateTimeOnChange()">
355          Time <input type="text" name="fromTime" value="" size="6" maxlength="4" 
356            onkeypress="focusOnEnter(event, 'fromDate')" onblur="fromDateTimeOnChange()"></td>
357        <td class="status" id="fromDateTime.status"></td>
358        <td class="help"><span id="fromDateTime.message" class="message" style="display: none;"></span>Start date+time (YYYYMMDD, HHMM) Blank fields give data from start</td>
359      </tr>
360      <tr id="toDateTimeSection" valign="top">
361        <td class="prompt">To</td>
362        <td class="input">Date <input type="text" name="toDate" value="" size="12" maxlength="10"
363            onkeypress="focusOnEnter(event, 'toTime')" onblur="toDateTimeOnChange()">
364          Time <input type="text" name="toTime" value="" size="6" maxlength="4"
365            onkeypress="focusOnEnter(event, 'toTime')" onblur="toDateTimeOnChange()"></td>
366        <td class="status" id="toDateTime.status"></td>
367        <td class="help"><span id="toDateTime.message" class="message" style="display: none;"></span>End date+time (YYYYMMDD, HHMM) Blank fields give data to end</td>
368      </tr>
369      <tr id="displayIndexSection" valign="top">
370        <td class="prompt">Display index values</td>
371        <td class="input">
372          <select id="displayIndexSelectId" name="displayIndexSelect">
373            <option value="true">Yes</option>
374            <option value="false" selected="yes">No</option>
375          </select>
376        </td>
377        <td class="status" id="displayIndex.status"></td>
378        <td class="help"><span id="displayIndex.message" class="message" style="display: none;"></span>Select if database indices should be displayed</td>
379      </tr>
380      </table>
381    </td>
382  </tr>
383  </table>
384
385  <div class="messagecontainer error" id="errorMessage" style="display: none; width: 950px; margin-left: 20px; margin-bottom: 0px;"></div>
386
387  <div id="done" class="success" style="display: none; width: 950px; margin-left: 20px; margin-top: 20px;"></div>
388
389  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
390  <tr>
391<!--
392    <td><base:button id="gopreview" title="Preview" image="<%=home+"/images/export.png"%>" onclick="goExport(true)"/></td>
393    <td><base:button id="goexport" title="Download" image="<%=home+"/images/download.png"%>" onclick="goExport(false)"/></td>
394-->
395    <td><base:button id="gopreview" title="Preview" image="<%="export.png"%>" onclick="goExport(true)"/></td>
396    <td><base:button id="goexport" title="Download" image="<%="download.png"%>" onclick="goExport(false)"/></td>
397  </tr>
398  </table>
399  </form>
400 
401  <div class="loading" id="loading" style="display: none;"><table><tr><td><img src="../images/loading.gif"></td><td id="loading.msg">Please wait...</td></tr></table></div>
402 
403  <div id="previewWrapper" style="display: none;">
404    <div>
405      <span id="previewTitle">Preview</span>
406      <span id="previewWarning"></span>
407    </div>
408    <div id="previewList"></div>
409  </div>
410 
411  </div>
412 
413</base:body>
414</base:page>
415<%
416}
417finally
418{
419  if (dc != null) dc.close();
420}
421%>
Note: See TracBrowser for help on using the repository browser.