comparison createHTML.sh @ 0:ac5f9272033b draft

first upload
author saskia-hiltemann
date Tue, 01 Jul 2014 11:42:23 -0400
parents
children 440f4aa3db97
comparison
equal deleted inserted replaced
-1:000000000000 0:ac5f9272033b
1 function makeIntroPage ( ){
2 echo "Creating Intro Page"
3 title="$1"
4 coverimage=$2
5 link=$3
6 htmlout=$4
7
8 echo -e "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
9 <html>
10 <head>
11 </head>
12 <body>
13 <!-- dummy intro page, since first page will not have any javascript/css features enabled unless specified in universe_wsgi.ini file, but subsequent pages will -->
14 <br/>
15 <br/>
16 <center>
17 <b><font size=\"15\"> iReport: ${title} </font></b><br/>
18 <br/>
19 <br/>
20 <a href=\"$link\"> Click here to view report </a> <br/><br/>
21 <a href=\"$link\"> <img src="$coverimage" width=\"50%\" alt=\"loading image..\"/> </a><br/><br/>
22 </center>
23 </body>
24 </html>" > $htmlout
25
26 }
27
28
29 function makeTabContent ( ){
30 tab=$1 #name of current tab
31 itemslist=$2 #list of all items
32 contentline="<br/>"
33 imgcount=0
34 #echo -e "\n Creating items. itemslist: $itemslist"
35
36 for item in $itemslist
37 do
38 #echo -e "\n -> item : $item"
39 item=${item/::/:emptycol:}
40 declare -a myarr=(`echo $item |sed 's/:/ /g'`)
41 #echo "break: ${myarr[3]}"
42 if [ ${myarr[0]} == $tab ]
43 then
44
45 ## add contents of text field to page####
46 if [ ${myarr[1]} == "text" ]
47 then
48 text=${myarr[2]}
49 ## allow some html formatting tags
50 text=${text//==lt==strong==gt==/<strong>} # search for strong tags
51 text=${text//==lt====slash==strong==gt==/<\/strong>} # search for strong tags
52 text=${text//==lt==em==gt==/<em>} # search for strong tags
53 text=${text//==lt====slash==em==gt==/<\/em>} # search for strong tags
54
55 text=${text//==lt==b==gt==/<strong>} # search for strong tags
56 text=${text//==lt====slash==b==gt==/<\/strong>} # search for strong tags
57 text=${text//==lt==i==gt==/<em>} # search for strong tags
58 text=${text//==lt====slash==i==gt==/<\/em>} # search for strong tags
59
60 text=${text//==lt==br==gt==/<br\/>} # search for strong tags
61 text=${text//==lt====br==slash==gt==/<br\/>} # search for strong tags
62 text=${text//==lt==h1==gt==/<h1>} # search for h1-h6 tags
63 text=${text//==lt==h2==gt==/<h2>} # search for h1-h6 tags
64 text=${text//==lt==h3==gt==/<h3>} # search for h1-h6 tags
65 text=${text//==lt==h4==gt==/<h4>} # search for h1-h6 tags
66 text=${text//==lt==h5==gt==/<h5>} # search for h1-h6 tags
67 text=${text//==lt==h6==gt==/<h6>} # search for h1-h6 tags
68 text=${text//==lt====slash==h1==gt==/<\/h1>} # search for h1-h6 closing tags
69 text=${text//==lt====slash==h2==gt==/<\/h2>} # search for h1-h6 closing tags
70 text=${text//==lt====slash==h3==gt==/<\/h3>} # search for h1-h6 closing tags
71 text=${text//==lt====slash==h4==gt==/<\/h4>} # search for h1-h6 closing tags
72 text=${text//==lt====slash==h5==gt==/<\/h5>} # search for h1-h6 closing tags
73 text=${text//==lt====slaxh==h6==gt==/<\/h6>} # search for h1-h6 closing tags
74
75 ## display everything else verbatim
76 text=${text//==space==/ }
77 text=${text//==colon==/:}
78 text=${text//==comma==/,}
79 text=${text//==slash==/\/}
80 text=${text//==lt==/&lt;}
81 text=${text//==gt==/&gt;}
82 text=${text//==apos==/&apos;}
83 text=${text//==quote==/&quot;}
84 text=${text//&&/&amp;}
85 text=${text//\\n/<br/>}
86 text=${text//\\t/&emsp;}
87 text=${text//\&r\&n/<br/>}
88 text=${text//\&r/<br/>}
89 text=${text//\&n/<br/>}
90 text=${text//\&c/:}
91 contentline="${contentline}${text}"
92 fi
93
94 ## add contents of a text file to page
95 if [ ${myarr[1]} == "textfile" ]
96 then
97 tfile=${myarr[2]}
98 fname=`basename ${tfile}`
99 fname=${fname%.*}
100 fname="${fname}.txt"
101 cp ${tfile} "${galaxypath}/${fname}"
102
103 #estimate height for iframe based on number oflines in the file
104 numlines=`wc -l ${tfile} | cut -d" " -f1`
105 minheight=$[$numlines*17]
106
107 contentline="${contentline}<iframe class=\"invisibleframe\" src=\"${fname}\" width=\"100%\" height=\"$minheight\"> </iframe>"
108 fi
109
110 ## add image file to page
111 if [ ${myarr[1]} == "image" ]
112 then
113 imgcount=$[$imgcount+1]
114 #restore file suffix for html
115 ftype=`file ${myarr[2]}`
116 zoomlevel=${myarr[4]}
117 zoomenable=${myarr[5]}
118 align=${myarr[6]}
119 #####echo "zoomenable:${zoomenable}, align:${align}"
120 if [[ $ftype == *JPEG* ]]
121 then
122 suffix=".jpg"
123 fi
124 if [[ $ftype == *SVG* ]]
125 then
126 suffix=".svg"
127 fi
128 if [[ $ftype == *PNG* ]]
129 then
130 suffix=".png"
131 fi
132
133 image=`basename ${myarr[2]}`
134 image=${image%.dat}
135 image="${image}${suffix}"
136 cp ${myarr[2]} ${galaxypath}/${image}
137
138 if [[ ${align} == "none" ]]
139 then
140 alignstring=""
141 alignstring2=""
142 else
143 alignstring="<div float=\"${align}\">"
144 alignstring2="</div>"
145
146 alignstring="align=\"${align}\""
147 alignstring2=""
148 fi
149
150
151 if [[ ${zoomlevel} -eq 0 ]]
152 then
153 widthstring=""
154 else
155 widthstring="width=\"${zoomlevel}\""
156 fi
157
158 if [[ ${zoomlevel} -eq 0 || ${zoomenable} == "N" ]]
159 then
160 contentline="${contentline}<span id=\"img${imgcount}\"> <img src=\"${image}\" ${alignstring} ${widthstring} alt=\"loading image..\"/></span>"
161 else
162 contentline="${contentline}<span class=\"zoomme\" id=\"img${imgcount}\"> <img src=\"${image}\" ${alignstring} ${widthstring} alt=\"loading image..\"/></span>"
163 fi
164
165 fi
166 if [ ${myarr[1]} == "table" ]
167 then
168 maxlines=50000
169 tsvfile_orig=${myarr[2]}
170 tsvfile="tablehead.tsv"
171 fname=`basename ${tsvfile_orig}`
172 fname=${fname%.*}
173 fancy=${myarr[4]}
174 makelinks=${myarr[5]}
175 #echo "\nmakelinks: $makelinks fancy: $fancy <br>"
176
177 #TODO client side database for large files. For now only display first section of file and add download link
178 numlines=`wc -l ${tsvfile_orig} |cut -d" " -f1`
179
180 head -${maxlines} ${tsvfile_orig} > tsvtmpfile
181
182 #remove any empty or header lines (lines starting with #, unless vcf file, then keep #CHROM line)
183 awk 'BEGIN{
184 FS="\t"
185 OFS="\t"
186 }{
187 if((index($0,"#")==1 && index($0,"#CHROM")!=1) || $0==""){
188 headerlines++
189 }
190 else print $0
191
192 }END{}' tsvtmpfile > ${tsvfile}
193
194 if [[ $makelinks == "Y" ]]
195 then
196 col=${myarr[6]}
197 prefix=${myarr[7]}
198 suffix=${myarr[8]}
199 suffix=${suffix/emptycol/}
200 suffix=${suffix/==quote==/&}
201 prefix=${prefix/emptycol/}
202 prefix=${prefix/==quote==/&}
203 prefix=${prefix/==colon==/:}
204 #echo "prefix: $prefix"
205
206 #edit the table to include links
207 awk 'BEGIN{
208 FS="\t"
209 OFS="\t"
210 url="'"$prefix"'"
211 url2="'"$suffix"'"
212 prefix="<a href=\42"
213 suffix="\42>"
214 col="'"$col"'"
215 end="</a>"
216 }{
217 if(FNR==1)
218 print $0
219 else{
220 $col=prefix""url""$col""url2""suffix""$col""end
221 print $0
222 }
223 }END{}' ${tsvfile} > ${tsvfile}2
224 #echo "converted file: "
225 #cat ${tsvfile}2
226 else
227 cp ${tsvfile} ${tsvfile}2
228 fi
229
230 if [ $fancy == "Y" ]
231 then
232 perl ${repositorypath}/tsv2html.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html
233 #contentline="${contentline}\n<div class=\"resizable\" id=\"iframe${iframecount}\"><iframe src=\"htmltable_${fname}.html\" style=\"max-width: 100%;vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe></div>"
234 #contentline="${contentline}\n<iframe class=\"resizable\" id=\"iframe${iframecount}\" src=\"htmltable_${fname}.html\" style=\"max-width: 100%;vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe>"
235 contentline="${contentline}\n<iframe class=\"invisibleframe fancyiframe\" src=\"htmltable_${fname}.html\" width=\"100%\" style=\"min-height: 300px; overflow-y: hidden; overflow-x: scroll\" ></iframe>"
236
237 iframecount=$[$iframecount+1]
238 else
239 perl ${repositorypath}/tsv2html_simple.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html
240 #contentline="${contentline}\n<iframe class=\"invisibleframe\" id=\"iframe${iframecount}\" style=\"max-width: 100%; vertical-align: top;\" src=\"htmltable_${fname}.html\" onload=\"resizeIframe(this)\"></iframe>"
241 contentline="${contentline}\n<iframe class=\"unfancyiframe invisibleframe\" src=\"htmltable_${fname}.html\" scrolling=\"no\" style=\"max-width: 100%; vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe>"
242 iframecount=$[$iframecount+1]
243 fi
244
245 if [[ $numlines -gt ${maxlines} ]]
246 then
247 tablename=`basename ${tsvfile_orig}`
248 cp ${tsvfile_orig} ${galaxypath}/$tablename
249 contentline="${contentline}<br/>\nLarge tables will be supported soon. The first ${maxlines} lines are shown here, and you can download the full file <a href=\"${tablename}\">here</a>."
250 fi
251 fi
252
253 if [[ ${myarr[1]} == "pdf" ]]
254 then
255 pdffile=${myarr[2]}
256 fname=`basename ${pdffile}`
257 fname=${fname%.dat}
258 pdfname="${fname}.pdf"
259 cp ${pdffile} "${galaxypath}/${pdfname}"
260
261 width=1000
262 height=800
263 #contentline="${contentline}<object data=\"${fname}\" type=\"application/pdf\" width=\"1000\" height=\"1000\"><p>It appears you have no PDF plugin for your browser. No biggie... you can <a href=\"${fname}\">click here to download the PDF file.</a></p></object>"
264 echo -e "<html><body><object data=\"${pdfname}\" type=\"application/pdf\" width=\"$width\" height=\"$height\"><embed src=\"${pdfname}\" type=\"application/pdf\" /><p>It appears you have no PDF plugin for your browser. No biggie... you can <a href=\"${pdfname}\">click here to download the PDF file.</a></p></object></body></html>" > "${galaxypath}/${fname}.html"
265 width=$[$width+10]
266 height=$[$height+10]
267 contentline="${contentline}<iframe src=\"${fname}.html\" width=\"${width}\" height=\"${height}\"></iframe>\n"
268
269 fi
270 ## link to a location on the web, open in new window
271 if [ ${myarr[1]} == "weblink" ]
272 then
273 url=${myarr[2]}
274 linktext=${myarr[4]}
275 url=${url/==colon==/:}
276 url=${url/==quote==/&}
277
278 contentline="${contentline}<a href=\"${url}\" target=\"_blank\">${linktext}</a>"
279 fi
280
281 ## link to a file in the history
282 if [ ${myarr[1]} == "link" ]
283 then
284 linkfile=${myarr[2]}
285 apiid=${myarr[4]}
286 isireport=${myarr[5]}
287 linkfilename=`basename ${linkfile}`
288 linktext=${myarr[6]}
289
290
291 #check for some basic filetypes
292 ftype=`file $linkfile`
293 if [[ $ftype == *HTML* ]]
294 then
295 linkfilename=${linkfilename%.dat}
296 linkfilename=${linkfilename}.html
297 fi
298 if [[ $ftype == *PNG* ]]
299 then
300 linkfilename=${linkfilename%.dat}
301 linkfilename=${linkfilename}.png
302 fi
303 if [[ $ftype == *SVG* ]]
304 then
305 linkfilename=${linkfilename%.dat}
306 linkfilename=${linkfilename}.svg
307 fi
308 if [[ $ftype == *JPEG* ]]
309 then
310 linkfilename=${linkfilename%.dat}
311 linkfilename=${linkfilename}.jpg
312 fi
313
314
315 if [[ ${isireport} == "Y" ]]
316 then
317 linkfilename="/datasets/${apiid}/display/"
318 else
319 cp ${linkfile} "${galaxypath}/${linkfilename}"
320 fi
321
322 contentline="${contentline}<a href=\"${linkfilename}\">${linktext}</a>"
323 fi
324
325 ## link to files in an archive in the history item
326 if [[ ${myarr[1]} == "links" ]]
327 then
328 #echo "making links:"
329 archive=${myarr[2]}
330 fname=`basename ${archive}`
331 fname=${fname%.dat}
332 ftype=`file $archive`
333 mkdir ${galaxypath}/archive_${fname}/
334
335 #echo "archive type: `file $archive`"
336 # decompress archive
337 if [[ $ftype == *Zip* ]]
338 then
339 #echo "detected zip file"
340 cp $archive ${galaxypath}/archive_${fname}/${fname}.zip
341 wd=`pwd`
342 cd ${galaxypath}/archive_${fname}/
343 unzip -q ${fname}.zip
344 rm ${fname}.zip
345 cd $wd
346 fi
347 if [[ $ftype == *tar* ]]
348 then
349 cp $archive ${galaxypath}/archive_${fname}/${fname}.tar
350 wd=`pwd`
351 cd ${galaxypath}/archive_${fname}/
352 tar xf ${fname}.tar
353 rm ${fname}.tar
354 cd $wd
355 fi
356 if [[ $ftype == *gzip* ]]
357 then
358 cp $archive ${galaxypath}/archive_${fname}/${fname}.gz
359 gunzip ${galaxypath}/archive_${fname}/${fname}.gz
360 #ls ${galaxypath}/archive_${fname}/
361
362 # check for tar.gz
363 ftype=`file ${galaxypath}/archive_${fname}/${fname}`
364 if [[ $ftype == *tar* ]]
365 then
366 # turns out it was tar.gz
367 rm -Rf ${galaxypath}/archive_${fname}/*
368 ls ${galaxypath}/archive_${fname}/
369 cp $archive ${galaxypath}/archive_${fname}/${fname}.tar.gz
370
371 wd=`pwd`
372 cd ${galaxypath}/archive_${fname}/
373 tar xzf ${fname}.tar.gz
374 cd $wd
375 fi
376 wait
377 rm -f ${galaxypath}/archive_${fname}/*.tar
378 rm -f ${galaxypath}/archive_${fname}/*.tar.gz
379 fi
380 if [[ $ftype == *bzip2* ]]
381 then
382 cp $archive ${galaxypath}/archive_${fname}/${fname}.gz
383 gunzip2 ${galaxypath}/archive_${fname}/${fname}.gz
384 fi
385
386
387
388 # add links to webpage
389 # separate line for each folder, files within folder on same line
390 for linkfile in `ls ${galaxypath}/archive_${fname}/ |sort -V`
391 do
392 #echo "<br/> ->making link to file: $linkfile "
393 if [ -d ${galaxypath}/archive_${fname}/$linkfile ] # if directory, add break, and list all contained files, max level 1 deep
394 then
395 #echo "<br/> ->is directory, entering: $linkfile "
396 #ls ${galaxypath}/archive_${fname}/$linkfile
397 contentline="${contentline}"
398 for linkfile2 in `ls ${galaxypath}/archive_${fname}/$linkfile | sort -V`
399 do
400 #echo "<br/> ->making link to file: ${galaxypath}/archive_${fname}/$linkfile2"
401 if [ -f ${galaxypath}/archive_${fname}/$linkfile/$linkfile2 ] # if directory, add break, and list all contained files, max level 1 deep
402 then
403 #echo "<br/> ->is file, making link: $linkfile "
404 label=`basename $linkfile2`
405 label=${label%.*}
406 contentline="${contentline}<a class=\"mylinks\" href=\"archive_${fname}/${linkfile}/${linkfile2}\">${label}</a>&nbsp;\n "
407 fi
408 done
409 elif [ -f ${galaxypath}/archive_${fname}/$linkfile ]
410 then
411 label=`basename ${galaxypath}/archive_${fname}/$linkfile`
412 label=${label%.*}
413 contentline="${contentline}<a class=\"mylinks\" href=\"archive_${fname}/${linkfile}\">$label</a>&nbsp;\n"
414 fi
415 done
416
417
418 fi
419
420 if [[ ${myarr[3]} == "Y" ]]
421 then
422 contentline="${contentline}<br/>"
423 fi
424 fi
425 done
426
427 echo "${contentline}"
428 }
429
430
431 createMainPage (){
432 page=$1
433 tabtitles=$2 #comma-separated list of tab titles
434 tabitems=$3
435 iframecount=1
436 minwidth=$4
437
438 echo "createMainPage: tabitems: $tabitems. tabtitles: $tabtitles"
439 # create correct number of tabs
440 count=0
441
442 tabtitles=${tabtitles//,/ }
443 tabtitles=${tabtitles//==colon==/:}
444 tabslist="<ul>\n"
445 mytabs=""
446 for title in $tabtitles
447 do
448 #create list of tabs
449
450 count=$[count+1]
451 title2=${title//_s_/ }
452 tabslist="${tabslist} <li><a href=\"#tabs-${count}\">${title2}</a></li>\n"
453
454 #create tabs with content
455 tabcontent=$(makeTabContent $title "$tabitems")
456 mytabs="${mytabs}\n<div id=\"tabs-${count}\">\n"
457 mytabs="${mytabs}${tabcontent}"
458 mytabs="${mytabs}\n</div>\n"
459 done
460 tabslist="${tabslist}</ul>"
461
462 #output the webpage
463 echo -e "<!doctype html>
464 <head>
465 <meta charset=\"utf-8\">
466 <title>jQuery UI Tabs - Default functionality</title>
467
468
469 <link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css\">
470 <link rel=\"stylesheet\" href=\"/resources/demos/style.css\">
471
472 <script src=\"//code.jquery.com/jquery-1.10.2.js\"></script>
473 <script src=\"//code.jquery.com/ui/1.10.4/jquery-ui.js\"></script>
474 <script type=\"text/javascript\" src=\"iframe-resizer/src/iframeResizer.js\"></script>
475 <script type=\"text/javascript\" src=\"jquery.zoom.js\"></script>
476 <script>
477 \$(function() {
478 \$( \"#tabs\" ).tabs();
479 });
480
481 \$(function() {
482 \$( \".resizable\" ).resizable();
483 });
484
485 \$(document).ready(function(){
486 \$('.zoomme').zoom();
487 \$('#ex2').zoom({ on:'grab' });
488 \$('#ex3').zoom({ on:'click' });
489 \$('#ex4').zoom({ on:'toggle' });
490 \$('.fancyiframe').iFrameResize({
491 heightCalculationMethod: 'max',
492 minHeight: 250,
493 scrolling: true,
494 checkOrigin: false,
495 bodyMargin: 15
496 });
497 \$('.unfancyiframe').iFrameResize({
498 heightCalculationMethod: 'max',
499 scrolling: false,
500 checkOrigin: false
501 });
502 });
503
504 </script>
505
506
507 <script language=\"javascript\" type=\"text/javascript\">
508 function resizeIframe(obj) {
509 oldheight=obj.style.height
510 oldwidth=obj.style.width
511 obj.style.height = obj.contentWindow.document.body.scrollHeight + 4 + 'px';
512 obj.style.width = obj.contentWindow.document.body.scrollWidth + 4 + 'px';
513
514 if(obj.style.height < 50){
515 obj.style.height=oldheight
516 }
517 }
518 </script>
519 <style type=\"text/css\">
520 body {
521 min-width: ${minwidth}px;
522 width: ${minwidth}px;
523 min-height: 100%;
524 }
525 .invisibleframe{
526 border: 0px;
527 overflow: hidden
528 }
529 .mylinks{
530 color: blue !important;
531 }
532 .mylinks:visited {
533 color: #551A8B !important;
534 }
535 </style>
536 <style >
537 .zoomme {
538 display: inline-block;
539 }
540 </style>
541
542
543 </head>
544 <body>
545
546 <div id=\"tabs\" style=\"display:inline-block; min-height:100%; min-width:${minwidth}px\">
547 $tabslist
548
549 $mytabs
550 </div>
551
552
553 </body>
554 </html>" > $page
555
556
557
558 }