galaxy-dev
Threads by month
- ----- 2025 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- 10008 discussions

20 Oct '09
details: http://www.bx.psu.edu/hg/galaxy/rev/cbe28b41fb9d
changeset: 2887:cbe28b41fb9d
user: Ross Lazarus <ross.lazarus(a)gmail.com>
date: Thu Oct 15 10:48:38 2009 -0400
description:
rename composite files and rewrite the html links if base_name changed in the upload form - this should probably happen in the upload logic
1 file(s) affected in this change:
lib/galaxy/datatypes/genetics.py
diffs (63 lines):
diff -r 79fe45b43b4e -r cbe28b41fb9d lib/galaxy/datatypes/genetics.py
--- a/lib/galaxy/datatypes/genetics.py Thu Oct 15 07:54:10 2009 -0400
+++ b/lib/galaxy/datatypes/genetics.py Thu Oct 15 10:48:38 2009 -0400
@@ -238,6 +238,59 @@
rval.append( '<li><a href="%s" type="application/binary">%s</a>%s' % ( composite_name, composite_name, opt_text ) )
rval.append( '</ul></div></html>' )
return "\n".join( rval )
+
+ def regenerate_primary_file(self,dataset):
+ """cannot do this until we are setting metadata
+ """
+ def fix(oldpath,newbase):
+ old,e = os.path.splitext(oldpath)
+ head,rest = os.path.split(old)
+ newpath = os.path.join(head,newbase)
+ newpath = '%s%s' % (newpath,e)
+ shutil.move(oldpath,newpath)
+ return newpath
+ bn = dataset.metadata.base_name
+ efp = dataset.extra_files_path
+ flist = os.listdir(efp)
+ proper_base = bn
+ rval = ['<html><head><title>Files for Composite Dataset %s</title></head><p/>Comprises the following files:<p/><ul>' % (bn)]
+ for i,fname in enumerate(flist):
+ newpath = fix(os.path.join(efp,fname),proper_base)
+ sfname = os.path.split(newpath)[-1]
+ rval.append( '<li><a href="%s">%s</a>' % ( sfname, sfname ) )
+ rval.append( '</ul></html>' )
+ f = file(dataset.file_name,'w')
+ f.write("\n".join( rval ))
+ f.write('\n')
+ f.close()
+
+ def set_meta( self, dataset, **kwd ):
+
+ """
+ NOTE we apply the tabular machinary to the phenodata extracted
+ from a BioC eSet or affybatch.
+
+ """
+ try:
+ flist = os.listdir(dataset.extra_files_path)
+ except:
+ gal_Log.debug('@@@rgenetics set_meta failed - no dataset?')
+ return
+ bn = None
+ for f in flist:
+ n = os.path.splitext(f)[0]
+ if not bn:
+ bn = n
+ dataset.metadata.base_name = bn
+ if not bn:
+ bn = '?'
+ self.regenerate_primary_file(dataset)
+ if not dataset.info:
+ dataset.info = 'Galaxy genotype datatype object'
+ if not dataset.blurb:
+ dataset.blurb = 'Composite file - Rgenetics Galaxy toolkit'
+ return True
+
class SNPMatrix(Rgenetics):
"""fake class to distinguish different species of Rgenetics data collections
1
0
details: http://www.bx.psu.edu/hg/galaxy/rev/79fe45b43b4e
changeset: 2886:79fe45b43b4e
user: Ross Lazarus <ross.lazarus(a)gmail.com>
date: Thu Oct 15 07:54:10 2009 -0400
description:
remove debug and clean up genetics.py
1 file(s) affected in this change:
lib/galaxy/datatypes/genetics.py
diffs (504 lines):
diff -r 7f5489d7c3d8 -r 79fe45b43b4e lib/galaxy/datatypes/genetics.py
--- a/lib/galaxy/datatypes/genetics.py Wed Oct 14 18:43:38 2009 -0400
+++ b/lib/galaxy/datatypes/genetics.py Thu Oct 15 07:54:10 2009 -0400
@@ -1,463 +1,3 @@
-<<<<<<< local
-"""
-rgenetics datatypes
-Use at your peril
-Ross Lazarus
-for the rgenetics and galaxy projects
-
-genome graphs datatypes derived from Interval datatypes
-genome graphs datasets have a header row with appropriate columnames
-The first column is always the marker - eg columname = rs, first row= rs12345 if the rows are snps
-subsequent row values are all numeric ! Will fail if any non numeric (eg '+' or 'NA') values
-ross lazarus for rgenetics
-august 20 2007
-"""
-
-import logging, os, sys, time, tempfile, shutil
-import data
-from galaxy import util
-from cgi import escape
-import urllib
-from galaxy.web import url_for
-from galaxy.datatypes import metadata
-from galaxy.datatypes.metadata import MetadataElement
-from galaxy.datatypes.data import Text
-from galaxy.datatypes.tabular import Tabular
-from galaxy.datatypes.images import Html
-
-log = logging.getLogger(__name__)
-
-
-
-class GenomeGraphs( Tabular ):
- """Tab delimited data containing a marker id and any number of numeric values"""
-
- """Add metadata elements"""
- MetadataElement( name="markerCol", default=1, desc="Marker ID column", param=metadata.ColumnParameter )
- MetadataElement( name="columns", default=3, desc="Number of columns", readonly=True )
- MetadataElement( name="column_types", default=[], desc="Column types", readonly=True, visible=False )
- file_ext = 'gg'
-
- def __init__(self, **kwd):
- """Initialize gg datatype, by adding UCSC display apps"""
- Tabular.__init__(self, **kwd)
- self.add_display_app ( 'ucsc', 'Genome Graph', 'as_ucsc_display_file', 'ucsc_links' )
-
- def set_peek( self, dataset ):
- """Set the peek and blurb text"""
- if not dataset.dataset.purged:
- dataset.peek = data.get_file_peek( dataset.file_name )
- dataset.blurb = util.commaify( str( data.get_line_count( dataset.file_name ) ) ) + " rows"
- #i don't think set_meta should not be called here, it should be called separately
- self.set_meta( dataset )
- else:
- dataset.peek = 'file does not exist'
- dataset.blurb = 'file purged from disk'
-
- def get_estimated_display_viewport( self, dataset ):
- """Return a chrom, start, stop tuple for viewing a file."""
- raise notImplemented
-
- def as_ucsc_display_file( self, dataset, **kwd ):
- """Returns file"""
- return file(dataset.file_name,'r')
-
- def ucsc_links( self, dataset, type, app, base_url ):
- """ from the ever-helpful angie hinrichs angie(a)soe.ucsc.edu
- a genome graphs call looks like this
- http://genome.ucsc.edu/cgi-bin/hgGenome?clade=mammal&org=Human&db=hg18&hgGe…
- &hgGenome_dataSetDescription=test&hgGenome_formatType=best%20guess&hgGenome_markerType=best%20guess
- &hgGenome_columnLabels=best%20guess&hgGenome_maxVal=&hgGenome_labelVals=
- &hgGenome_maxGapToFill=25000000&hgGenome_uploadFile=http://galaxy.esphealth.org/datasets/333/display/index
- &hgGenome_doSubmitUpload=submit
- Galaxy gives this for an interval file
- http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr1:1-1000&hgt.cu…
- http%3A%2F%2Fgalaxy.esphealth.org%2Fdisplay_as%3Fid%3D339%26display_app%3Ducsc
- """
- ret_val = []
- ggtail = '&hgGenome_doSubmitUpload=submit'
- if not dataset.dbkey:
- dataset.dbkey = 'hg18' # punt!
- if dataset.has_data:
- for site_name, site_url in util.get_ucsc_by_build(dataset.dbkey):
- if site_name in app.config.ucsc_display_sites:
- site_url = site_url.replace('/hgTracks?','/hgGenome?') # for genome graphs
- display_url = urllib.quote_plus( "%s%s/display_as?id=%i&display_app=%s" % (base_url, url_for( controller='root' ), dataset.id, type))
- sl = ["%sdb=%s" % (site_url,dataset.dbkey ),]
- sl.append("&hgGenome_dataSetName=%s&hgGenome_dataSetDescription=%s" % (dataset.name, 'GalaxyGG_data'))
- sl.append("&hgGenome_formatType=best%20guess&hgGenome_markerType=best%20guess")
- sl.append("&hgGenome_columnLabels=first%20row&hgGenome_maxVal=&hgGenome_labelVals=")
- sl.append("&hgGenome_maxGapToFill=25000000&hgGenome_uploadFile=%%s")
- sl.append(ggtail)
- s = urllib.quote_plus( ''.join(sl) )
- link = '%s?redirect_url=%s&display_url=%s' % ( internal_url, s, display_url )
- ret_val.append( (site_name, link) )
- return ret_val
-
- def validate( self, dataset ):
- """Validate a gg file - all numeric after header row"""
- errors = list()
- infile = open(dataset.file_name, "r")
- header= infile.next() # header
- for i,row in enumerate(infile):
- ll = row.strip().split('\t')
- badvals = []
- for j,x in enumerate(ll):
- try:
- x = float(x)
- except:
- badval.append('col%d:%s' % (j+1,x))
- if len(badvals) > 0:
- errors.append('row %d, %s' % (' '.join(badvals)))
- return errors
-
- def repair_methods( self, dataset ):
- """Return options for removing errors along with a description"""
- return [("lines","Remove erroneous lines")]
-
-
-class rgTabList(Tabular):
- """ for sampleid and for featureid lists of exclusions or inclusions in the clean tool
- featureid subsets on statistical criteria -> specialized display such as gg
- """
- file_ext = "rgTList"
-
-
- def __init__(self, **kwd):
- """Initialize featurelistt datatype"""
- Tabular.__init__( self, **kwd )
- self.column_names = []
-
- def make_html_table( self, dataset, skipchars=[] ):
- """Create HTML table, used for displaying peek"""
- out = ['<table cellspacing="0" cellpadding="3">']
- comments = []
- try:
- # Generate column header
- out.append( '<tr>' )
- for i, name in enumerate( self.column_names ):
- out.append( '<th>%s.%s</th>' % ( str( i+1 ), name ) )
- if dataset.metadata.columns - len( self.column_names ) > 0:
- for i in range( len( self.column_names ), dataset.metadata.columns ):
- out.append( '<th>%s</th>' % str( i+1 ) )
- out.append( '</tr>' )
- out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) )
- out.append( '</table>' )
- out = "".join( out )
- except Exception, exc:
- out = "Can't create peek %s" % exc
- return out
-
-class rgSampleList(rgTabList):
- """ for sampleid exclusions or inclusions in the clean tool
- output from QC eg excess het, gender error, ibd pair member,eigen outlier,excess mendel errors,...
- since they can be uploaded, should be flexible
- but they are persistent at least
- same infrastructure for expression?
- """
- file_ext = "rgSList"
-
- def __init__(self, **kwd):
- """Initialize samplelist datatype"""
- rgTabList.__init__( self, **kwd )
- self.column_names[0] = 'FID'
- self.column_names[1] = 'IID'
- # this is what Plink wants as at 2009
-
-
-class rgFeatureList( rgTabList ):
- """ for featureid lists of exclusions or inclusions in the clean tool
- output from QC eg low maf, high missingness, bad hwe in controls, excess mendel errors,...
- featureid subsets on statistical criteria -> specialized display such as gg
- same infrastructure for expression?
- """
- file_ext = "rgFList"
-
- def __init__(self, **kwd):
- """Initialize featurelist datatype"""
- rgTabList.__init__( self, **kwd )
- for i,s in enumerate(['#FeatureId', 'Chr', 'Genpos', 'Mappos']):
- self.column_names[i] = s
-
-
-
-class Rgenetics(Html):
- """class to use for rgenetics"""
- """Add metadata elements"""
- MetadataElement( name="base_name", desc="base name for all transformed versions of this genetic dataset", default="galaxy", readonly=True, set_in_upload=True)
-
- file_ext="html"
- composite_type = 'auto_primary_file'
- allow_datatype_change = False
-
- def missing_meta( self, dataset=None, **kwargs):
- """Checks for empty meta values"""
- for key, value in dataset.metadata.items():
- if not value:
- return True
- return False
-
- def generate_primary_file( self, dataset = None ):
- rval = ['<html><head><title>Files for Composite Dataset (%s)</title></head><p/>This composite dataset is composed of the following files:<p/><ul>' % ( self.file_ext ) ]
- for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
- opt_text = ''
- if composite_file.optional:
- opt_text = ' (optional)'
- rval.append( '<li><a href="%s">%s</a>%s' % ( composite_name, composite_name, opt_text ) )
- rval.append( '</ul></html>' )
- return "\n".join( rval )
-
-class SNPMatrix(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="snpmatrix"
-
- def set_peek( self, dataset ):
- if not dataset.dataset.purged:
- dataset.peek = "Binary RGenetics file"
- dataset.blurb = data.nice_size( dataset.get_size() )
- else:
- dataset.peek = 'file does not exist'
- dataset.blurb = 'file purged from disk'
-
-
-class Lped(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="lped"
-
- def __init__( self, **kwd ):
- Rgenetics.__init__( self, **kwd )
- self.add_composite_file( '%s.ped', description = 'Pedigree File', substitute_name_with_metadata = 'base_name', is_binary = True )
- self.add_composite_file( '%s.map', description = 'Map File', substitute_name_with_metadata = 'base_name', is_binary = True )
-
-
-class Pphe(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="pphe"
-
- def __init__( self, **kwd ):
- Rgenetics.__init__( self, **kwd )
- self.add_composite_file( '%s.pphe', description = 'Plink Phenotype File', substitute_name_with_metadata = 'base_name' )
-
-
-class Lmap(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="lmap"
-
-class Fphe(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="fphe"
-
- def __init__( self, **kwd ):
- Rgenetics.__init__( self, **kwd )
- self.add_composite_file( '%s.fphe', description = 'FBAT Phenotype File', substitute_name_with_metadata = 'base_name' )
-
-class Phe(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="phe"
-
- def __init__( self, **kwd ):
- Rgenetics.__init__( self, **kwd )
- self.add_composite_file( '%s.phe', description = 'Phenotype File', substitute_name_with_metadata = 'base_name' )
-
-
-
-class Fped(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="fped"
-
- def __init__( self, **kwd ):
- Rgenetics.__init__( self, **kwd )
- self.add_composite_file( '%s.fped', description = 'FBAT format pedfile', substitute_name_with_metadata = 'base_name' )
-
-
-class Pbed(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="pbed"
-
- def __init__( self, **kwd ):
- Rgenetics.__init__( self, **kwd )
- self.add_composite_file( '%s.bim', substitute_name_with_metadata = 'base_name', is_binary = True )
- self.add_composite_file( '%s.bed', substitute_name_with_metadata = 'base_name', is_binary = True )
- self.add_composite_file( '%s.fam', substitute_name_with_metadata = 'base_name', is_binary = True )
-
-class Eigenstratgeno(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="eigenstratgeno"
-
- def __init__( self, **kwd ):
- Rgenetics.__init__( self, **kwd )
- self.add_composite_file( '%s.eigenstratgeno', substitute_name_with_metadata = 'base_name', is_binary = True )
- self.add_composite_file( '%s.ind', substitute_name_with_metadata = 'base_name', is_binary = True )
- self.add_composite_file( '%s.map', substitute_name_with_metadata = 'base_name', is_binary = True )
-
-
-
-class Eigenstratpca(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="eigenstratpca"
-
-class Snptest(Rgenetics):
- """fake class to distinguish different species of Rgenetics data collections
- """
- file_ext="snptest"
-
-class RexpBase( Html ):
- """base class for BioC data structures in Galaxy
- must be constructed with the pheno data in place since that
- goes into the metadata for each instance"""
-
- """Add metadata elements"""
- MetadataElement( name="columns", default=0, desc="Number of columns", readonly=True, visible=False )
- MetadataElement( name="column_names", default=[], desc="Column names", readonly=True,visible=True )
- MetadataElement( name="base_name",
- desc="base name for all transformed versions of this genetic dataset", readonly=True, default='galaxy', set_in_upload=True)
- ### Do we really need these below? can we rely on dataset.extra_files_path: os.path.join( dataset.extra_files_path, '%s.phenodata' % dataset.metadata.base_name ) ?
- ### Do these have a different purpose? Ross will need to clarify
- ### Uploading these datatypes will not work until this is sorted out (set_peek fails)...
- MetadataElement( name="pheno_path",
- desc="Path to phenotype data for this experiment", readonly=True)
- MetadataElement( name="pheno",
- desc="Phenotype data for this experiment", readonly=True)
-
- file_ext = None
-
- is_binary = True
-
- allow_datatype_change = False
-
- composite_type = 'basic'
-
- def __init__( self, **kwd ):
- Html.__init__( self, **kwd )
- self.add_composite_file( '%s.phenodata', substitute_name_with_metadata = 'base_name', is_binary = True )
- self.metadata.pheno_path = '%s.phenodata' % (self.metadata.base_name)
-
- def missing_meta( self, dataset=None, **kwargs):
- """Checks for empty meta values"""
- for key, value in dataset.metadata.items():
- if not value:
- return True
- return False
-
- def get_pheno(self,dataset):
- """expects a .pheno file in the extra_files_dir - ugh
- note that R is wierd and does not include the row.name in
- the header. why?"""
- p = file(dataset.metadata.pheno_path,'r').readlines() #this fails
- head = p[0].strip().split('\t')
- head.insert(0,'ChipFileName') # fix R write.table b0rken-ness
- p[0] = '\t'.join(head)
- p = '\n'.join(p)
- return p
-
- def set_peek( self, dataset ):
- """expects a .pheno file in the extra_files_dir - ugh
- note that R is wierd and does not include the row.name in
- the header. why?"""
- p = self.get_pheno(dataset)
- dataset.peek = p[:20]
- dataset.info = p[0]
- dataset.blurb = 'R loadable BioC expression object for the Rexpression Galaxy toolkit'
-
- # stolen from Tabular
- # class Tabular( data.Text ):
- """Tab delimited data"""
-
- """Add metadata elements"""
- def init_meta( self, dataset, copy_from=None ):
- if copy_from:
- dataset.metadata = copy_from.metadata
-
- def set_readonly_meta( self, dataset, **kwd ):
- """Resets the values of readonly metadata elements."""
- RexpBase.set_meta( self, dataset )
-
- def set_meta( self, dataset, **kwd ):
-
- """
- NOTE we apply the tabular machinary to the phenodata extracted
- from a BioC eSet or affybatch.
-
- """
- if not dataset.peek:
- dataset.set_peek()
- pk = dataset.get_pheno # read the basename.phenodata in the extra_files_path
- ###this is probably not the best source, can we just access the raw data directly?
- if pk:
- p = pk.split('\n')
- h = p[0].strip().split('\t') # hope is header
- h = [escape(x) for x in h]
- dataset.metadata.column_names = h
- dataset.metadata.columns = len(h)
- else:
- dataset.metadata.column_names = []
- dataset.metadata.columns = 0
-
- def make_html_table( self, dataset):
- """Create HTML table, used for displaying peek"""
- out = ['<table cellspacing="0" cellpadding="3">',]
- try:
- # Generate column header
- pk = dataset.peek
- p = pk.split('\n')
- for i,row in enumerate(p):
- lrow = row.strip().split('\t')
- if i == 0:
- orow = ['<th>%s</th>' % escape(x) for x in lrow]
- orow.insert(0,'<tr>')
- orow.append('</tr>')
- else:
- orow = ['<td>%s</td>' % escape(x) for x in lrow]
- orow.insert(0,'<tr>')
- orow.append('</tr>')
- out.append(''.join(orow))
- out.append( '</table>' )
- out = "\n".join( out )
- except Exception, exc:
- out = "Can't create peek %s" % str( exc )
- return out
-
- def display_peek( self, dataset ):
- """Returns formatted html of peek"""
- if not dataset.peek:
- dataset.set_peek()
- return self.make_html_table( dataset )
-
- def get_mime(self):
- """Returns the mime type of the datatype"""
- return 'application/gzip'
-
-
-class AffyBatch( RexpBase ):
- """derived class for BioC data structures in Galaxy """
- file_ext = "affybatch"
-
-
-class ESet( RexpBase ):
- """derived class for BioC data structures in Galaxy """
- file_ext = "eset"
-
-
-class MAList( RexpBase ):
- """derived class for BioC data structures in Galaxy """
- file_ext = "malist"
-
-
-if __name__ == '__main__':
- import doctest, sys
- doctest.testmod(sys.modules[__name__])
-
-=======
"""
rgenetics datatypes
Use at your peril
@@ -957,7 +497,6 @@
p = file(pp,'r').readlines()
except:
p = ['##failed to find %s' % pp,]
- gal_Log.debug('@@@rexpression set_peek, dataset.name=%s,\npp=%s,\np=%s' % (dataset.name,pp,p[:3]))
dataset.peek = ''.join(p[:5])
dataset.blurb = 'Galaxy Rexpression composite file'
else:
@@ -972,7 +511,6 @@
p = file(pp,'r').readlines()
except:
p = ['##failed to find %s' % pp]
- gal_Log.debug('@@@rexpression get_peek, dataset.file_name=%s,\npp=%s,\np=%s' % (dataset.file_name,pp,p[:3]))
return ''.join(p[:5])
def get_file_peek(self,filename):
@@ -996,7 +534,6 @@
sfname = os.path.split(fname)[-1]
rval.append( '<li><a href="%s">%s</a>' % ( sfname, sfname ) )
rval.append( '</ul></html>' )
- gal_Log.debug('rexpression regenerate primary file, writing %s' % rval)
f = file(dataset.file_name,'w')
f.write("\n".join( rval ))
f.write('\n')
@@ -1054,7 +591,6 @@
dataset.info = 'Galaxy Expression datatype object'
if not dataset.blurb:
dataset.blurb = 'R loadable BioC expression object for the Rexpression Galaxy toolkit'
- gal_Log.debug('@@@rexpression set_meta on dsn=%s, pf=%s, peek=%s' % (dataset.file_name,''.join(pf[:5]),dataset.peek))
return True
def make_html_table( self, pp='nothing supplied from peek\n'):
@@ -1125,4 +661,3 @@
doctest.testmod(sys.modules[__name__])
->>>>>>> other
1
0

20 Oct '09
details: http://www.bx.psu.edu/hg/galaxy/rev/c2d042ba8cd0
changeset: 2884:c2d042ba8cd0
user: Ross Lazarus <ross.lazarus(a)gmail.com>
date: Wed Oct 14 15:47:58 2009 -0400
description:
adding three LGPL ECMA script helpers for rgGRR interactive SVG.
4 file(s) affected in this change:
lib/galaxy/datatypes/genetics.py
static/scripts/checkbox_and_radiobutton.js
static/scripts/helper_functions.js
static/scripts/timer.js
diffs (1724 lines):
diff -r 878ca31a4995 -r c2d042ba8cd0 lib/galaxy/datatypes/genetics.py
--- a/lib/galaxy/datatypes/genetics.py Wed Oct 14 09:33:56 2009 -0400
+++ b/lib/galaxy/datatypes/genetics.py Wed Oct 14 15:47:58 2009 -0400
@@ -1,3 +1,463 @@
+<<<<<<< local
+"""
+rgenetics datatypes
+Use at your peril
+Ross Lazarus
+for the rgenetics and galaxy projects
+
+genome graphs datatypes derived from Interval datatypes
+genome graphs datasets have a header row with appropriate columnames
+The first column is always the marker - eg columname = rs, first row= rs12345 if the rows are snps
+subsequent row values are all numeric ! Will fail if any non numeric (eg '+' or 'NA') values
+ross lazarus for rgenetics
+august 20 2007
+"""
+
+import logging, os, sys, time, tempfile, shutil
+import data
+from galaxy import util
+from cgi import escape
+import urllib
+from galaxy.web import url_for
+from galaxy.datatypes import metadata
+from galaxy.datatypes.metadata import MetadataElement
+from galaxy.datatypes.data import Text
+from galaxy.datatypes.tabular import Tabular
+from galaxy.datatypes.images import Html
+
+log = logging.getLogger(__name__)
+
+
+
+class GenomeGraphs( Tabular ):
+ """Tab delimited data containing a marker id and any number of numeric values"""
+
+ """Add metadata elements"""
+ MetadataElement( name="markerCol", default=1, desc="Marker ID column", param=metadata.ColumnParameter )
+ MetadataElement( name="columns", default=3, desc="Number of columns", readonly=True )
+ MetadataElement( name="column_types", default=[], desc="Column types", readonly=True, visible=False )
+ file_ext = 'gg'
+
+ def __init__(self, **kwd):
+ """Initialize gg datatype, by adding UCSC display apps"""
+ Tabular.__init__(self, **kwd)
+ self.add_display_app ( 'ucsc', 'Genome Graph', 'as_ucsc_display_file', 'ucsc_links' )
+
+ def set_peek( self, dataset ):
+ """Set the peek and blurb text"""
+ if not dataset.dataset.purged:
+ dataset.peek = data.get_file_peek( dataset.file_name )
+ dataset.blurb = util.commaify( str( data.get_line_count( dataset.file_name ) ) ) + " rows"
+ #i don't think set_meta should not be called here, it should be called separately
+ self.set_meta( dataset )
+ else:
+ dataset.peek = 'file does not exist'
+ dataset.blurb = 'file purged from disk'
+
+ def get_estimated_display_viewport( self, dataset ):
+ """Return a chrom, start, stop tuple for viewing a file."""
+ raise notImplemented
+
+ def as_ucsc_display_file( self, dataset, **kwd ):
+ """Returns file"""
+ return file(dataset.file_name,'r')
+
+ def ucsc_links( self, dataset, type, app, base_url ):
+ """ from the ever-helpful angie hinrichs angie(a)soe.ucsc.edu
+ a genome graphs call looks like this
+ http://genome.ucsc.edu/cgi-bin/hgGenome?clade=mammal&org=Human&db=hg18&hgGe…
+ &hgGenome_dataSetDescription=test&hgGenome_formatType=best%20guess&hgGenome_markerType=best%20guess
+ &hgGenome_columnLabels=best%20guess&hgGenome_maxVal=&hgGenome_labelVals=
+ &hgGenome_maxGapToFill=25000000&hgGenome_uploadFile=http://galaxy.esphealth.org/datasets/333/display/index
+ &hgGenome_doSubmitUpload=submit
+ Galaxy gives this for an interval file
+ http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr1:1-1000&hgt.cu…
+ http%3A%2F%2Fgalaxy.esphealth.org%2Fdisplay_as%3Fid%3D339%26display_app%3Ducsc
+ """
+ ret_val = []
+ ggtail = '&hgGenome_doSubmitUpload=submit'
+ if not dataset.dbkey:
+ dataset.dbkey = 'hg18' # punt!
+ if dataset.has_data:
+ for site_name, site_url in util.get_ucsc_by_build(dataset.dbkey):
+ if site_name in app.config.ucsc_display_sites:
+ site_url = site_url.replace('/hgTracks?','/hgGenome?') # for genome graphs
+ display_url = urllib.quote_plus( "%s%s/display_as?id=%i&display_app=%s" % (base_url, url_for( controller='root' ), dataset.id, type))
+ sl = ["%sdb=%s" % (site_url,dataset.dbkey ),]
+ sl.append("&hgGenome_dataSetName=%s&hgGenome_dataSetDescription=%s" % (dataset.name, 'GalaxyGG_data'))
+ sl.append("&hgGenome_formatType=best%20guess&hgGenome_markerType=best%20guess")
+ sl.append("&hgGenome_columnLabels=first%20row&hgGenome_maxVal=&hgGenome_labelVals=")
+ sl.append("&hgGenome_maxGapToFill=25000000&hgGenome_uploadFile=%%s")
+ sl.append(ggtail)
+ s = urllib.quote_plus( ''.join(sl) )
+ link = '%s?redirect_url=%s&display_url=%s' % ( internal_url, s, display_url )
+ ret_val.append( (site_name, link) )
+ return ret_val
+
+ def validate( self, dataset ):
+ """Validate a gg file - all numeric after header row"""
+ errors = list()
+ infile = open(dataset.file_name, "r")
+ header= infile.next() # header
+ for i,row in enumerate(infile):
+ ll = row.strip().split('\t')
+ badvals = []
+ for j,x in enumerate(ll):
+ try:
+ x = float(x)
+ except:
+ badval.append('col%d:%s' % (j+1,x))
+ if len(badvals) > 0:
+ errors.append('row %d, %s' % (' '.join(badvals)))
+ return errors
+
+ def repair_methods( self, dataset ):
+ """Return options for removing errors along with a description"""
+ return [("lines","Remove erroneous lines")]
+
+
+class rgTabList(Tabular):
+ """ for sampleid and for featureid lists of exclusions or inclusions in the clean tool
+ featureid subsets on statistical criteria -> specialized display such as gg
+ """
+ file_ext = "rgTList"
+
+
+ def __init__(self, **kwd):
+ """Initialize featurelistt datatype"""
+ Tabular.__init__( self, **kwd )
+ self.column_names = []
+
+ def make_html_table( self, dataset, skipchars=[] ):
+ """Create HTML table, used for displaying peek"""
+ out = ['<table cellspacing="0" cellpadding="3">']
+ comments = []
+ try:
+ # Generate column header
+ out.append( '<tr>' )
+ for i, name in enumerate( self.column_names ):
+ out.append( '<th>%s.%s</th>' % ( str( i+1 ), name ) )
+ if dataset.metadata.columns - len( self.column_names ) > 0:
+ for i in range( len( self.column_names ), dataset.metadata.columns ):
+ out.append( '<th>%s</th>' % str( i+1 ) )
+ out.append( '</tr>' )
+ out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) )
+ out.append( '</table>' )
+ out = "".join( out )
+ except Exception, exc:
+ out = "Can't create peek %s" % exc
+ return out
+
+class rgSampleList(rgTabList):
+ """ for sampleid exclusions or inclusions in the clean tool
+ output from QC eg excess het, gender error, ibd pair member,eigen outlier,excess mendel errors,...
+ since they can be uploaded, should be flexible
+ but they are persistent at least
+ same infrastructure for expression?
+ """
+ file_ext = "rgSList"
+
+ def __init__(self, **kwd):
+ """Initialize samplelist datatype"""
+ rgTabList.__init__( self, **kwd )
+ self.column_names[0] = 'FID'
+ self.column_names[1] = 'IID'
+ # this is what Plink wants as at 2009
+
+
+class rgFeatureList( rgTabList ):
+ """ for featureid lists of exclusions or inclusions in the clean tool
+ output from QC eg low maf, high missingness, bad hwe in controls, excess mendel errors,...
+ featureid subsets on statistical criteria -> specialized display such as gg
+ same infrastructure for expression?
+ """
+ file_ext = "rgFList"
+
+ def __init__(self, **kwd):
+ """Initialize featurelist datatype"""
+ rgTabList.__init__( self, **kwd )
+ for i,s in enumerate(['#FeatureId', 'Chr', 'Genpos', 'Mappos']):
+ self.column_names[i] = s
+
+
+
+class Rgenetics(Html):
+ """class to use for rgenetics"""
+ """Add metadata elements"""
+ MetadataElement( name="base_name", desc="base name for all transformed versions of this genetic dataset", default="galaxy", readonly=True, set_in_upload=True)
+
+ file_ext="html"
+ composite_type = 'auto_primary_file'
+ allow_datatype_change = False
+
+ def missing_meta( self, dataset=None, **kwargs):
+ """Checks for empty meta values"""
+ for key, value in dataset.metadata.items():
+ if not value:
+ return True
+ return False
+
+ def generate_primary_file( self, dataset = None ):
+ rval = ['<html><head><title>Files for Composite Dataset (%s)</title></head><p/>This composite dataset is composed of the following files:<p/><ul>' % ( self.file_ext ) ]
+ for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
+ opt_text = ''
+ if composite_file.optional:
+ opt_text = ' (optional)'
+ rval.append( '<li><a href="%s">%s</a>%s' % ( composite_name, composite_name, opt_text ) )
+ rval.append( '</ul></html>' )
+ return "\n".join( rval )
+
+class SNPMatrix(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="snpmatrix"
+
+ def set_peek( self, dataset ):
+ if not dataset.dataset.purged:
+ dataset.peek = "Binary RGenetics file"
+ dataset.blurb = data.nice_size( dataset.get_size() )
+ else:
+ dataset.peek = 'file does not exist'
+ dataset.blurb = 'file purged from disk'
+
+
+class Lped(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="lped"
+
+ def __init__( self, **kwd ):
+ Rgenetics.__init__( self, **kwd )
+ self.add_composite_file( '%s.ped', description = 'Pedigree File', substitute_name_with_metadata = 'base_name', is_binary = True )
+ self.add_composite_file( '%s.map', description = 'Map File', substitute_name_with_metadata = 'base_name', is_binary = True )
+
+
+class Pphe(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="pphe"
+
+ def __init__( self, **kwd ):
+ Rgenetics.__init__( self, **kwd )
+ self.add_composite_file( '%s.pphe', description = 'Plink Phenotype File', substitute_name_with_metadata = 'base_name' )
+
+
+class Lmap(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="lmap"
+
+class Fphe(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="fphe"
+
+ def __init__( self, **kwd ):
+ Rgenetics.__init__( self, **kwd )
+ self.add_composite_file( '%s.fphe', description = 'FBAT Phenotype File', substitute_name_with_metadata = 'base_name' )
+
+class Phe(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="phe"
+
+ def __init__( self, **kwd ):
+ Rgenetics.__init__( self, **kwd )
+ self.add_composite_file( '%s.phe', description = 'Phenotype File', substitute_name_with_metadata = 'base_name' )
+
+
+
+class Fped(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="fped"
+
+ def __init__( self, **kwd ):
+ Rgenetics.__init__( self, **kwd )
+ self.add_composite_file( '%s.fped', description = 'FBAT format pedfile', substitute_name_with_metadata = 'base_name' )
+
+
+class Pbed(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="pbed"
+
+ def __init__( self, **kwd ):
+ Rgenetics.__init__( self, **kwd )
+ self.add_composite_file( '%s.bim', substitute_name_with_metadata = 'base_name', is_binary = True )
+ self.add_composite_file( '%s.bed', substitute_name_with_metadata = 'base_name', is_binary = True )
+ self.add_composite_file( '%s.fam', substitute_name_with_metadata = 'base_name', is_binary = True )
+
+class Eigenstratgeno(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="eigenstratgeno"
+
+ def __init__( self, **kwd ):
+ Rgenetics.__init__( self, **kwd )
+ self.add_composite_file( '%s.eigenstratgeno', substitute_name_with_metadata = 'base_name', is_binary = True )
+ self.add_composite_file( '%s.ind', substitute_name_with_metadata = 'base_name', is_binary = True )
+ self.add_composite_file( '%s.map', substitute_name_with_metadata = 'base_name', is_binary = True )
+
+
+
+class Eigenstratpca(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="eigenstratpca"
+
+class Snptest(Rgenetics):
+ """fake class to distinguish different species of Rgenetics data collections
+ """
+ file_ext="snptest"
+
+class RexpBase( Html ):
+ """base class for BioC data structures in Galaxy
+ must be constructed with the pheno data in place since that
+ goes into the metadata for each instance"""
+
+ """Add metadata elements"""
+ MetadataElement( name="columns", default=0, desc="Number of columns", readonly=True, visible=False )
+ MetadataElement( name="column_names", default=[], desc="Column names", readonly=True,visible=True )
+ MetadataElement( name="base_name",
+ desc="base name for all transformed versions of this genetic dataset", readonly=True, default='galaxy', set_in_upload=True)
+ ### Do we really need these below? can we rely on dataset.extra_files_path: os.path.join( dataset.extra_files_path, '%s.phenodata' % dataset.metadata.base_name ) ?
+ ### Do these have a different purpose? Ross will need to clarify
+ ### Uploading these datatypes will not work until this is sorted out (set_peek fails)...
+ MetadataElement( name="pheno_path",
+ desc="Path to phenotype data for this experiment", readonly=True)
+ MetadataElement( name="pheno",
+ desc="Phenotype data for this experiment", readonly=True)
+
+ file_ext = None
+
+ is_binary = True
+
+ allow_datatype_change = False
+
+ composite_type = 'basic'
+
+ def __init__( self, **kwd ):
+ Html.__init__( self, **kwd )
+ self.add_composite_file( '%s.phenodata', substitute_name_with_metadata = 'base_name', is_binary = True )
+ self.metadata.pheno_path = '%s.phenodata' % (self.metadata.base_name)
+
+ def missing_meta( self, dataset=None, **kwargs):
+ """Checks for empty meta values"""
+ for key, value in dataset.metadata.items():
+ if not value:
+ return True
+ return False
+
+ def get_pheno(self,dataset):
+ """expects a .pheno file in the extra_files_dir - ugh
+ note that R is wierd and does not include the row.name in
+ the header. why?"""
+ p = file(dataset.metadata.pheno_path,'r').readlines() #this fails
+ head = p[0].strip().split('\t')
+ head.insert(0,'ChipFileName') # fix R write.table b0rken-ness
+ p[0] = '\t'.join(head)
+ p = '\n'.join(p)
+ return p
+
+ def set_peek( self, dataset ):
+ """expects a .pheno file in the extra_files_dir - ugh
+ note that R is wierd and does not include the row.name in
+ the header. why?"""
+ p = self.get_pheno(dataset)
+ dataset.peek = p[:20]
+ dataset.info = p[0]
+ dataset.blurb = 'R loadable BioC expression object for the Rexpression Galaxy toolkit'
+
+ # stolen from Tabular
+ # class Tabular( data.Text ):
+ """Tab delimited data"""
+
+ """Add metadata elements"""
+ def init_meta( self, dataset, copy_from=None ):
+ if copy_from:
+ dataset.metadata = copy_from.metadata
+
+ def set_readonly_meta( self, dataset, **kwd ):
+ """Resets the values of readonly metadata elements."""
+ RexpBase.set_meta( self, dataset )
+
+ def set_meta( self, dataset, **kwd ):
+
+ """
+ NOTE we apply the tabular machinary to the phenodata extracted
+ from a BioC eSet or affybatch.
+
+ """
+ if not dataset.peek:
+ dataset.set_peek()
+ pk = dataset.get_pheno # read the basename.phenodata in the extra_files_path
+ ###this is probably not the best source, can we just access the raw data directly?
+ if pk:
+ p = pk.split('\n')
+ h = p[0].strip().split('\t') # hope is header
+ h = [escape(x) for x in h]
+ dataset.metadata.column_names = h
+ dataset.metadata.columns = len(h)
+ else:
+ dataset.metadata.column_names = []
+ dataset.metadata.columns = 0
+
+ def make_html_table( self, dataset):
+ """Create HTML table, used for displaying peek"""
+ out = ['<table cellspacing="0" cellpadding="3">',]
+ try:
+ # Generate column header
+ pk = dataset.peek
+ p = pk.split('\n')
+ for i,row in enumerate(p):
+ lrow = row.strip().split('\t')
+ if i == 0:
+ orow = ['<th>%s</th>' % escape(x) for x in lrow]
+ orow.insert(0,'<tr>')
+ orow.append('</tr>')
+ else:
+ orow = ['<td>%s</td>' % escape(x) for x in lrow]
+ orow.insert(0,'<tr>')
+ orow.append('</tr>')
+ out.append(''.join(orow))
+ out.append( '</table>' )
+ out = "\n".join( out )
+ except Exception, exc:
+ out = "Can't create peek %s" % str( exc )
+ return out
+
+ def display_peek( self, dataset ):
+ """Returns formatted html of peek"""
+ if not dataset.peek:
+ dataset.set_peek()
+ return self.make_html_table( dataset )
+
+ def get_mime(self):
+ """Returns the mime type of the datatype"""
+ return 'application/gzip'
+
+
+class AffyBatch( RexpBase ):
+ """derived class for BioC data structures in Galaxy """
+ file_ext = "affybatch"
+
+
+class ESet( RexpBase ):
+ """derived class for BioC data structures in Galaxy """
+ file_ext = "eset"
+
+
+class MAList( RexpBase ):
+ """derived class for BioC data structures in Galaxy """
+ file_ext = "malist"
+
+
+if __name__ == '__main__':
+ import doctest, sys
+ doctest.testmod(sys.modules[__name__])
+
+=======
"""
rgenetics datatypes
Use at your peril
@@ -665,3 +1125,4 @@
doctest.testmod(sys.modules[__name__])
+>>>>>>> other
diff -r 878ca31a4995 -r c2d042ba8cd0 static/scripts/checkbox_and_radiobutton.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/checkbox_and_radiobutton.js Wed Oct 14 15:47:58 2009 -0400
@@ -0,0 +1,347 @@
+/*
+Scripts to create interactive checkboxes and radio buttons in SVG using ECMA script
+Copyright (C) <2007> <Andreas Neumann>
+Version 1.1.3, 2007-08-09
+neumann(a)karto.baug.ethz.ch
+http://www.carto.net/
+http://www.carto.net/neumann/
+
+Credits:
+* Guy Morton for providing a fix to let users toggle checkboxes by clicking on text labels
+* Bruce Rindahl for providing the bugfix described in version 1.1.2
+* Simon Shutter for providing a fix for the ASV in IE crash when reloading the SVG file after calling the .remove() method on a checkbox
+
+----
+
+Documentation: http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/
+
+----
+
+current version: 1.1.3
+
+version history:
+1.0 (2006-03-13)
+initial version
+
+1.1 (2006-07-11)
+text labels are now clickable (thanks to Guy Morton)
+added method .moveTo() to move checkbox to a different location
+introduced new constructor parameter labelYOffset to allow more flexible placement of the text label
+
+1.1.1 (2007-02-06)
+added cursor pointer to the text label and use element representing the checkBox
+
+1.1.2 (2007-04-19)
+bug fix: this.selectedIndex was not correctly initialized in method addCheckBox of the radioButtonGroup object
+
+1.1.3 (2007-08-09)
+bug fix: the method .remove() was slightly modified (using removeEventListener) for avoiding a crash related to the method after reloading the SVG file
+
+-------
+
+
+This ECMA script library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library (lesser_gpl.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+----
+
+original document site: http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/
+Please contact the author in case you want to use code or ideas commercially.
+If you use this code, please include this copyright header, the included full
+LGPL 2.1 text and read the terms provided in the LGPL 2.1 license
+(http://www.gnu.org/copyleft/lesser.txt)
+
+-------------------------------
+
+Please report bugs and send improvements to neumann(a)karto.baug.ethz.ch
+If you use this control, please link to the original (http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/)
+somewhere in the source-code-comment or the "about" of your project and give credits, thanks!
+
+*/
+
+function checkBox(id,parentNode,x,y,checkboxId,checkcrossId,checkedStatus,labelText,textStyles,labelDistance,labelYOffset,radioButtonGroup,functionToCall) {
+ var nrArguments = 13;
+ var createCheckbox= true;
+ if (arguments.length == nrArguments) {
+ this.id = id; //an internal id, this id is not used in the SVG Dom tree
+ this.parentNode = parentNode; //the parentNode, string or nodeReference
+ this.x = x; //the center of the checkBox
+ this.y = y; //the center of the checkBox
+ this.checkboxId = checkboxId; //the id of the checkbox symbol (background)
+ this.checkcrossId = checkcrossId; //the id of the checkbox symbol (foreground), pointer-events should be set to "none"
+ this.checkedStatus = checkedStatus; //a status variable (true|false), indicates if checkbox is on or off
+ this.labelText = labelText; //the text of the checkbox label to be displayed, use undefined or empty string if you don't need a label text
+ this.textStyles = textStyles; //an array of literals containing the text settings
+ if (!this.textStyles["font-size"]) {
+ this.textStyles["font-size"] = 12;
+ }
+ this.labelDistance = labelDistance; //a distance defined from the center of the checkbox to the left of the text of the label
+ this.labelYOffset = labelYOffset; //a y offset value for the text label in relation to the checkbox symbol center
+ this.radioButtonGroup = radioButtonGroup; //a reference to a radio button group, if this is a standalone checkBox, just use the parameter undefined
+ this.functionToCall = functionToCall; //the function to call after triggering checkBox
+ this.exists = true; //status that indicates if checkbox exists or not, is set to false after method .remove() was called
+ this.label = undefined; //later a reference to the label text node
+ }
+ else {
+ createCheckbox = false;
+ alert("Error in checkbox ("+id+"): wrong nr of arguments! You have to pass over "+nrArguments+" parameters.");
+ }
+ if (createCheckbox) {
+ //timer stuff
+ this.timer = new Timer(this); //a Timer instance for calling the functionToCall
+ if (this.radioButtonGroup) {
+ this.timerMs = 0;
+ }
+ else {
+ this.timerMs = 200; //a constant of this object that is used in conjunction with the timer - functionToCall is called after 200 ms
+ }
+ //create checkbox
+ this.createCheckBox();
+ }
+ else {
+ alert("Could not create checkbox with id '"+id+"' due to errors in the constructor parameters");
+ }
+}
+
+//this method creates all necessary checkbox geometry
+checkBox.prototype.createCheckBox = function() {
+ if (typeof(this.parentNode) == "string") {
+ this.parentNode = document.getElementById(this.parentNode);
+ }
+ //create checkbox
+ this.checkBox = document.createElementNS(svgNS,"use");
+ this.checkBox.setAttributeNS(null,"x",this.x);
+ this.checkBox.setAttributeNS(null,"y",this.y);
+ this.checkBox.setAttributeNS(xlinkNS,"href","#"+this.checkboxId);
+ this.checkBox.addEventListener("click",this,false);
+ this.checkBox.setAttributeNS(null,"cursor","pointer");
+ this.parentNode.appendChild(this.checkBox);
+ //create checkcross
+ this.checkCross = document.createElementNS(svgNS,"use");
+ this.checkCross.setAttributeNS(null,"x",this.x);
+ this.checkCross.setAttributeNS(null,"y",this.y);
+ this.checkCross.setAttributeNS(xlinkNS,"href","#"+this.checkcrossId);
+ this.parentNode.appendChild(this.checkCross);
+ if (this.checkedStatus == false) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ }
+ //create label, if any
+ if (this.labelText) {
+ if (this.labelText.length > 0) {
+ this.label = document.createElementNS(svgNS,"text");
+ for (var attrib in this.textStyles) {
+ var value = this.textStyles[attrib];
+ if (attrib == "font-size") {
+ value += "px";
+ }
+ this.label.setAttributeNS(null,attrib,value);
+ }
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.labelYOffset));
+ this.label.setAttributeNS(null,"cursor","pointer");
+ var labelTextNode = document.createTextNode(this.labelText);
+ this.label.appendChild(labelTextNode);
+ this.label.setAttributeNS(null,"pointer-events","all");
+ this.label.addEventListener("click",this,false);
+ this.parentNode.appendChild(this.label);
+ }
+ }
+ if (this.radioButtonGroup) {
+ this.radioButtonGroup.addCheckBox(this);
+ }
+}
+
+checkBox.prototype.handleEvent = function(evt) {
+ if (evt.type == "click") {
+ if (this.checkedStatus == true) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ this.checkedStatus = false;
+ }
+ else {
+ this.checkCross.setAttributeNS(null,"display","inline");
+ this.checkedStatus = true;
+ }
+ }
+ this.timer.setTimeout("fireFunction",this.timerMs);
+}
+
+checkBox.prototype.fireFunction = function() {
+ if (this.radioButtonGroup) {
+ this.radioButtonGroup.selectById(this.id,true);
+ }
+ else {
+ if (typeof(this.functionToCall) == "function") {
+ this.functionToCall(this.id,this.checkedStatus,this.labelText);
+ }
+ if (typeof(this.functionToCall) == "object") {
+ this.functionToCall.checkBoxChanged(this.id,this.checkedStatus,this.labelText);
+ }
+ if (typeof(this.functionToCall) == undefined) {
+ return;
+ }
+ }
+}
+
+checkBox.prototype.check = function(FireFunction) {
+ this.checkCross.setAttributeNS(null,"display","inherit");
+ this.checkedStatus = true;
+ if (FireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+}
+
+checkBox.prototype.uncheck = function(FireFunction) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ this.checkedStatus = false;
+ if (FireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+}
+
+//move checkbox to a different position
+checkBox.prototype.moveTo = function(moveX,moveY) {
+ this.x = moveX;
+ this.y = moveY;
+ //move checkbox
+ this.checkBox.setAttributeNS(null,"x",this.x);
+ this.checkBox.setAttributeNS(null,"y",this.y);
+ //move checkcross
+ this.checkCross.setAttributeNS(null,"x",this.x);
+ this.checkCross.setAttributeNS(null,"y",this.y);
+ //move text label
+ if (this.labelText) {
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.labelYOffset));
+ }
+}
+
+checkBox.prototype.remove = function(FireFunction) {
+ this.checkBox.removeEventListener("click",this,false);
+ this.parentNode.removeChild(this.checkBox);
+ this.parentNode.removeChild(this.checkCross);
+ if (this.label) {
+ this.parentNode.removeChild(this.label);
+ }
+ this.exists = false;
+}
+
+checkBox.prototype.setLabelText = function(labelText) {
+ this.labelText = labelText
+ if (this.label) {
+ this.label.firstChild.nodeValue = labelText;
+ }
+ else {
+ if (this.labelText.length > 0) {
+ this.label = document.createElementNS(svgNS,"text");
+ for (var attrib in this.textStyles) {
+ value = this.textStyles[attrib];
+ if (attrib == "font-size") {
+ value += "px";
+ }
+ this.label.setAttributeNS(null,attrib,value);
+ }
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.textStyles["font-size"] * 0.3));
+ var labelTextNode = document.createTextNode(this.labelText);
+ this.label.appendChild(labelTextNode);
+ this.parentNode.appendChild(this.label);
+ }
+ }
+}
+
+/* start of the radioButtonGroup object */
+
+function radioButtonGroup(id,functionToCall) {
+ var nrArguments = 2;
+ if (arguments.length == nrArguments) {
+ this.id = id;
+ if (typeof(functionToCall) == "function" || typeof(functionToCall) == "object" || typeof(functionToCall) == undefined) {
+ this.functionToCall = functionToCall;
+ }
+ else {
+ alert("Error in radiobutton with ("+id+"): argument functionToCall is not of type 'function', 'object' or undefined!");
+ }
+ this.checkBoxes = new Array(); //this array will hold checkbox objects
+ this.selectedId = undefined; //holds the id of the active radio button
+ this.selectedIndex = undefined; //holds the index of the active radio button
+ //timer stuff
+ this.timer = new Timer(this); //a Timer instance for calling the functionToCall
+ this.timerMs = 200; //a constant of this object that is used in conjunction with the timer - functionToCall is called after 200 ms
+ }
+ else {
+ alert("Error in radiobutton with ("+id+"): wrong nr of arguments! You have to pass over "+nrArguments+" parameters.");
+ }
+}
+
+radioButtonGroup.prototype.addCheckBox = function(checkBoxObj) {
+ this.checkBoxes.push(checkBoxObj);
+ if (checkBoxObj.checkedStatus) {
+ this.selectedId = checkBoxObj.id;
+ this.selectedIndex = this.checkBoxes.length - 1;
+ }
+}
+
+//change radio button selection by id
+radioButtonGroup.prototype.selectById = function(cbId,fireFunction) {
+ var found = false;
+ for (var i=0;i<this.checkBoxes.length;i++) {
+ if (this.checkBoxes[i].id == cbId) {
+ this.selectedId = cbId;
+ this.selectedIndex = i;
+ if (this.checkBoxes[i].checkedStatus == false) {
+ this.checkBoxes[i].check(false);
+ }
+ found = true;
+ }
+ else {
+ this.checkBoxes[i].uncheck(false);
+ }
+ }
+ if (found) {
+ if (fireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+ }
+ else {
+ alert("Error in radiobutton with ("+this.id+"): could not find checkbox with id '"+cbId+"'");
+ }
+}
+
+//change radio button selection by label name
+radioButtonGroup.prototype.selectByLabelname = function(labelName,fireFunction) {
+ var id = -1;
+ for (var i=0;i<this.checkBoxes.length;i++) {
+ if (this.checkBoxes[i].labelText == labelName) {
+ id = this.checkBoxes[i].id;
+ }
+ }
+ if (id == -1) {
+ alert("Error in radiobutton with ("+this.id+"): could not find checkbox with label '"+labelName+"'");
+ }
+ else {
+ this.selectById(id,fireFunction);
+ }
+}
+
+radioButtonGroup.prototype.fireFunction = function() {
+ if (typeof(this.functionToCall) == "function") {
+ this.functionToCall(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText);
+ }
+ if (typeof(this.functionToCall) == "object") {
+ this.functionToCall.radioButtonChanged(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText);
+ }
+ if (typeof(this.functionToCall) == undefined) {
+ return;
+ }
+}
\ No newline at end of file
diff -r 878ca31a4995 -r c2d042ba8cd0 static/scripts/helper_functions.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/helper_functions.js Wed Oct 14 15:47:58 2009 -0400
@@ -0,0 +1,817 @@
+/**
+ * @fileoverview
+ *
+ * ECMAScript <a href="http://www.carto.net/papers/svg/resources/helper_functions.html">helper functions</a>, main purpose is to serve in SVG mapping or other SVG based web applications
+ *
+ * This ECMA script library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library (http://www.carto.net/papers/svg/resources/lesser_gpl.txt) if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Please report bugs and send improvements to neumann(a)karto.baug.ethz.ch
+ * If you use these scripts, please link to the original (http://www.carto.net/papers/svg/resources/helper_functions.html)
+ * somewhere in the source-code-comment or the "about" of your project and give credits, thanks!
+ *
+ * See <a href="js_docs_out/overview-summary-helper_functions.js.html">documentation</a>.
+ *
+ * @author Andreas Neumann a.neumann(a)carto.net
+ * @copyright LGPL 2.1 <a href="http://www.gnu.org/copyleft/lesser.txt">Gnu LGPL 2.1</a>
+ * @credits Bruce Rindahl, numerous people on svgdevelopers(a)yahoogroups.com
+ */
+
+//global variables necessary to create elements in these namespaces, do not delete them!!!!
+
+/**
+ * This variable is a shortcut to the full URL of the SVG namespace
+ * @final
+ * @type String
+ */
+var svgNS = "http://www.w3.org/2000/svg";
+
+/**
+ * This variable is a shortcut to the full URL of the XLink namespace
+ * @final
+ * @type String
+ */
+var xlinkNS = "http://www.w3.org/1999/xlink";
+
+/**
+ * This variable is a shortcut to the full URL of the attrib namespace
+ * @final
+ * @type String
+ */
+var cartoNS = "http://www.carto.net/attrib";
+
+/**
+ * This variable is a alias to the full URL of the attrib namespace
+ * @final
+ * @type String
+ */
+var attribNS = "http://www.carto.net/attrib";
+
+/**
+ * This variable is a alias to the full URL of the Batik extension namespace
+ * @final
+ * @type String
+ */
+var batikNS = "http://xml.apache.org/batik/ext";
+
+/**
+ * Returns the polar direction from a given vector
+ * @param {Number} xdiff the x-part of the vector
+ * @param {Number} ydiff the y-part of the vector
+ * @return direction the direction in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toRectX
+ * @see #toRectY
+ */
+function toPolarDir(xdiff,ydiff) {
+ var direction = (Math.atan2(ydiff,xdiff));
+ return(direction);
+}
+
+/**
+ * Returns the polar distance from a given vector
+ * @param {Number} xdiff the x-part of the vector
+ * @param {Number} ydiff the y-part of the vector
+ * @return distance the distance
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDir
+ * @see #toRectX
+ * @see #toRectY
+ */
+function toPolarDist(xdiff,ydiff) {
+ var distance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
+ return(distance);
+}
+
+/**
+ * Returns the x-part of a vector from a given direction and distance
+ * @param {Number} direction the direction (in radians)
+ * @param {Number} distance the distance
+ * @return x the x-part of the vector
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toPolarDir
+ * @see #toRectY
+ */
+function toRectX(direction,distance) {
+ var x = distance * Math.cos(direction);
+ return(x);
+}
+
+/**
+ * Returns the y-part of the vector from a given direction and distance
+ * @param {Number} direction the direction (in radians)
+ * @param {Number} distance the distance
+ * @return y the y-part of the vector
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toPolarDir
+ * @see #toRectX
+ */
+function toRectY(direction,distance) {
+ y = distance * Math.sin(direction);
+ return(y);
+}
+
+/**
+ * Converts degrees to radians
+ * @param {Number} deg the degree value
+ * @return rad the radians value
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #RadToDeg
+ */
+function DegToRad(deg) {
+ return (deg / 180.0 * Math.PI);
+}
+
+/**
+ * Converts radians to degrees
+ * @param {Number} rad the radians value
+ * @return deg the degree value
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #DegToRad
+ */
+function RadToDeg(rad) {
+ return (rad / Math.PI * 180.0);
+}
+
+/**
+ * Converts decimal degrees to degrees, minutes, seconds
+ * @param {Number} dd the decimal degree value
+ * @return degrees the degree values in the following notation: {deg:degrees,min:minutes,sec:seconds}
+ * @type literal
+ * @version 1.0 (2007-04-30)
+ * @see #dms2dd
+ */
+function dd2dms(dd) {
+ var minutes = (Math.abs(dd) - Math.floor(Math.abs(dd))) * 60;
+ var seconds = (minutes - Math.floor(minutes)) * 60;
+ var minutes = Math.floor(minutes);
+ if (dd >= 0) {
+ var degrees = Math.floor(dd);
+ }
+ else {
+ var degrees = Math.ceil(dd);
+ }
+ return {deg:degrees,min:minutes,sec:seconds};
+}
+
+/**
+ * Converts degrees, minutes and seconds to decimal degrees
+ * @param {Number} deg the degree value
+ * @param {Number} min the minute value
+ * @param {Number} sec the second value
+ * @return deg the decimal degree values
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #dd2dms
+ */
+function dms2dd(deg,min,sec) {
+ if (deg < 0) {
+ return deg - (min / 60) - (sec / 3600);
+ }
+ else {
+ return deg + (min / 60) + (sec / 3600);
+ }
+}
+
+/**
+ * log function, missing in the standard Math object
+ * @param {Number} x the value where the log function should be applied to
+ * @param {Number} b the base value for the log function
+ * @return logResult the result of the log function
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function log(x,b) {
+ if(b==null) b=Math.E;
+ return Math.log(x)/Math.log(b);
+}
+
+/**
+ * interpolates a value (e.g. elevation) bilinearly based on the position within a cell with 4 corner values
+ * @param {Number} za the value at the upper left corner of the cell
+ * @param {Number} zb the value at the upper right corner of the cell
+ * @param {Number} zc the value at the lower right corner of the cell
+ * @param {Number} zd the value at the lower left corner of the cell
+ * @param {Number} xpos the x position of the point where a new value should be interpolated
+ * @param {Number} ypos the y position of the point where a new value should be interpolated
+ * @param {Number} ax the x position of the lower left corner of the cell
+ * @param {Number} ay the y position of the lower left corner of the cell
+ * @param {Number} cellsize the size of the cell
+ * @return interpol_value the result of the bilinear interpolation function
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function intBilinear(za,zb,zc,zd,xpos,ypos,ax,ay,cellsize) { //bilinear interpolation function
+ var e = (xpos - ax) / cellsize;
+ var f = (ypos - ay) / cellsize;
+
+ //calculation of weights
+ var wa = (1 - e) * (1 - f);
+ var wb = e * (1 - f);
+ var wc = e * f;
+ var wd = f * (1 - e);
+
+ var interpol_value = wa * zc + wb * zd + wc * za + wd * zb;
+ return interpol_value;
+}
+
+/**
+ * tests if a given point is left or right of a given line
+ * @param {Number} pointx the x position of the given point
+ * @param {Number} pointy the y position of the given point
+ * @param {Number} linex1 the x position of line's start point
+ * @param {Number} liney1 the y position of line's start point
+ * @param {Number} linex2 the x position of line's end point
+ * @param {Number} liney2 the y position of line's end point
+ * @return leftof the result of the leftOfTest, 1 means leftOf, 0 means rightOf
+ * @type Number (integer, 0|1)
+ * @version 1.0 (2007-04-30)
+ */
+function leftOfTest(pointx,pointy,linex1,liney1,linex2,liney2) {
+ var result = (liney1 - pointy) * (linex2 - linex1) - (linex1 - pointx) * (liney2 - liney1);
+ if (result < 0) {
+ var leftof = 1; //case left of
+ }
+ else {
+ var leftof = 0; //case left of
+ }
+ return leftof;
+}
+
+/**
+ * calculates the distance between a given point and a given line
+ * @param {Number} pointx the x position of the given point
+ * @param {Number} pointy the y position of the given point
+ * @param {Number} linex1 the x position of line's start point
+ * @param {Number} liney1 the y position of line's start point
+ * @param {Number} linex2 the x position of line's end point
+ * @param {Number} liney2 the y position of line's end point
+ * @return distance the result of the leftOfTest, 1 means leftOf, 0 means rightOf
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function distFromLine(xpoint,ypoint,linex1,liney1,linex2,liney2) {
+ var dx = linex2 - linex1;
+ var dy = liney2 - liney1;
+ var distance = (dy * (xpoint - linex1) - dx * (ypoint - liney1)) / Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
+ return distance;
+}
+
+/**
+ * calculates the angle between two vectors (lines)
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return angle the angle in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect2/i.html#Winkel">Mathe Online (Winkel)</a>
+ */
+function angleBetwTwoLines(ax,ay,bx,by) {
+ var angle = Math.acos((ax * bx + ay * by) / (Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2)) * Math.sqrt(Math.pow(bx,2) + Math.pow(by,2))));
+ return angle;
+}
+
+/**
+ * calculates the bisector vector for two given vectors
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return c the resulting vector as an Array, c[0] is the x part of the vector, c[1] is the y part
+ * @type Array
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale">Mathe Online (Winkelsymmetrale)</a>
+ * see #calcBisectorAngle
+ * */
+function calcBisectorVector(ax,ay,bx,by) {
+ var betraga = Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2));
+ var betragb = Math.sqrt(Math.pow(bx,2) + Math.pow(by,2));
+ var c = new Array();
+ c[0] = ax / betraga + bx / betragb;
+ c[1] = ay / betraga + by / betragb;
+ return c;
+}
+
+/**
+ * calculates the bisector angle for two given vectors
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return angle the bisector angle in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale">Mathe Online (Winkelsymmetrale)</a>
+ * see #calcBisectorVector
+ * */
+function calcBisectorAngle(ax,ay,bx,by) {
+ var betraga = Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2));
+ var betragb = Math.sqrt(Math.pow(bx,2) + Math.pow(by,2));
+ var c1 = ax / betraga + bx / betragb;
+ var c2 = ay / betraga + by / betragb;
+ var angle = toPolarDir(c1,c2);
+ return angle;
+}
+
+/**
+ * calculates the intersection point of two given lines
+ * @param {Number} line1x1 the x the start point of line 1
+ * @param {Number} line1y1 the y the start point of line 1
+ * @param {Number} line1x2 the x the end point of line 1
+ * @param {Number} line1y2 the y the end point of line 1
+ * @return interSectPoint the intersection point, interSectPoint.x contains x-part, interSectPoint.y the y-part of the resulting coordinate
+ * @type Object
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/">P. Bourke</a>
+ */
+function intersect2lines(line1x1,line1y1,line1x2,line1y2,line2x1,line2y1,line2x2,line2y2) {
+ var interSectPoint = new Object();
+ var denominator = (line2y2 - line2y1)*(line1x2 - line1x1) - (line2x2 - line2x1)*(line1y2 - line1y1);
+ if (denominator == 0) {
+ alert("lines are parallel");
+ }
+ else {
+ var ua = ((line2x2 - line2x1)*(line1y1 - line2y1) - (line2y2 - line2y1)*(line1x1 - line2x1)) / denominator;
+ var ub = ((line1x2 - line1x1)*(line1y1 - line2y1) - (line1y2 - line1y1)*(line1x1 - line2x1)) / denominator;
+ }
+ interSectPoint["x"] = line1x1 + ua * (line1x2 - line1x1);
+ interSectPoint["y"] = line1y1 + ua * (line1y2 - line1y1);
+ return interSectPoint;
+}
+
+/**
+ * reformats a given number to a string by adding separators at every third digit
+ * @param {String|Number} inputNumber the input number, can be of type number or string
+ * @param {String} separator the separator, e.g. ' or ,
+ * @return newString the intersection point, interSectPoint.x contains x-part, interSectPoint.y the y-part of the resulting coordinate
+ * @type String
+ * @version 1.0 (2007-04-30)
+ */
+function formatNumberString(inputNumber,separator) {
+ //check if of type string, if number, convert it to string
+ if (typeof(inputNumber) == "Number") {
+ var myTempString = inputNumber.toString();
+ }
+ else {
+ var myTempString = inputNumber;
+ }
+ var newString="";
+ //if it contains a comma, it will be split
+ var splitResults = myTempString.split(".");
+ var myCounter = splitResults[0].length;
+ if (myCounter > 3) {
+ while(myCounter > 0) {
+ if (myCounter > 3) {
+ newString = separator + splitResults[0].substr(myCounter - 3,3) + newString;
+ }
+ else {
+ newString = splitResults[0].substr(0,myCounter) + newString;
+ }
+ myCounter -= 3;
+ }
+ }
+ else {
+ newString = splitResults[0];
+ }
+ //concatenate if it contains a comma
+ if (splitResults[1]) {
+ newString = newString + "." + splitResults[1];
+ }
+ return newString;
+}
+
+/**
+ * writes a status text message out to a SVG text element's first child
+ * @param {String} statusText the text message to be displayed
+ * @version 1.0 (2007-04-30)
+ */
+ function statusChange(statusText) {
+ document.getElementById("statusText").firstChild.nodeValue = "Statusbar: " + statusText;
+}
+
+/**
+ * scales an SVG element, requires that the element has an x and y attribute (e.g. circle, ellipse, use element, etc.)
+ * @param {dom::Event} evt the evt object that triggered the scaling
+ * @param {Number} factor the scaling factor
+ * @version 1.0 (2007-04-30)
+ */
+function scaleObject(evt,factor) {
+ //reference to the currently selected object
+ var element = evt.currentTarget;
+ var myX = element.getAttributeNS(null,"x");
+ var myY = element.getAttributeNS(null,"y");
+ var newtransform = "scale(" + factor + ") translate(" + (myX * 1 / factor - myX) + " " + (myY * 1 / factor - myY) +")";
+ element.setAttributeNS(null,'transform', newtransform);
+}
+
+/**
+ * returns the transformation matrix (ctm) for the given node up to the root element
+ * the basic use case is to provide a wrapper function for the missing SVGLocatable.getTransformToElement method (missing in ASV3)
+ * @param {svg::SVGTransformable} node the node reference for the SVGElement the ctm is queried
+ * @return CTM the current transformation matrix from the given node to the root element
+ * @type svg::SVGMatrix
+ * @version 1.0 (2007-05-01)
+ * @credits <a href="http://www.kevlindev.com/tutorials/basics/transformations/toUserSpace/index…">Kevin Lindsey (toUserSpace)</a>
+ * @see #getTransformToElement
+ */
+function getTransformToRootElement(node) {
+ try {
+ //this part is for fully conformant players (like Opera, Batik, Firefox, Safari ...)
+ var CTM = node.getTransformToElement(document.documentElement);
+ }
+ catch (ex) {
+ //this part is for ASV3 or other non-conformant players
+ // Initialize our CTM the node's Current Transformation Matrix
+ var CTM = node.getCTM();
+ // Work our way through the ancestor nodes stopping at the SVG Document
+ while ( ( node = node.parentNode ) != document ) {
+ // Multiply the new CTM to the one with what we have accumulated so far
+ CTM = node.getCTM().multiply(CTM);
+ }
+ }
+ return CTM;
+}
+
+/**
+ * returns the transformation matrix (ctm) for the given dom::Node up to a different dom::Node
+ * the basic use case is to provide a wrapper function for the missing SVGLocatable.getTransformToElement method (missing in ASV3)
+ * @param {svg::SVGTransformable} node the node reference for the element the where the ctm should be calculated from
+ * @param {svg::SVGTransformable} targetNode the target node reference for the element the ctm should be calculated to
+ * @return CTM the current transformation matrix from the given node to the target element
+ * @type svg::SVGMatrix
+ * @version 1.0 (2007-05-01)
+ * @credits <a href="http://www.kevlindev.com/tutorials/basics/transformations/toUserSpace/index…">Kevin Lindsey (toUserSpace)</a>
+ * @see #getTransformToRootElement
+ */
+function getTransformToElement(node,targetNode) {
+ try {
+ //this part is for fully conformant players
+ var CTM = node.getTransformToElement(targetNode);
+ }
+ catch (ex) {
+ //this part is for ASV3 or other non-conformant players
+ // Initialize our CTM the node's Current Transformation Matrix
+ var CTM = node.getCTM();
+ // Work our way through the ancestor nodes stopping at the SVG Document
+ while ( ( node = node.parentNode ) != targetNode ) {
+ // Multiply the new CTM to the one with what we have accumulated so far
+ CTM = node.getCTM().multiply(CTM);
+ }
+ }
+ return CTM;
+}
+
+/**
+ * converts HSV to RGB values
+ * @param {Number} hue the hue value (between 0 and 360)
+ * @param {Number} sat the saturation value (between 0 and 1)
+ * @param {Number} val the value value (between 0 and 1)
+ * @return rgbArr the rgb values (associative array or object, the keys are: red,green,blue), all values are scaled between 0 and 255
+ * @type Object
+ * @version 1.0 (2007-05-01)
+ * @see #rgb2hsv
+ */
+function hsv2rgb(hue,sat,val) {
+ var rgbArr = new Object();
+ if ( sat == 0) {
+ rgbArr["red"] = Math.round(val * 255);
+ rgbArr["green"] = Math.round(val * 255);
+ rgbArr["blue"] = Math.round(val * 255);
+ }
+ else {
+ var h = hue / 60;
+ var i = Math.floor(h);
+ var f = h - i;
+ if (i % 2 == 0) {
+ f = 1 - f;
+ }
+ var m = val * (1 - sat);
+ var n = val * (1 - sat * f);
+ switch(i) {
+ case 0:
+ rgbArr["red"] = val;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = m;
+ break;
+ case 1:
+ rgbArr["red"] = n;
+ rgbArr["green"] = val;
+ rgbArr["blue"] = m;
+ break;
+ case 2:
+ rgbArr["red"] = m;
+ rgbArr["green"] = val;
+ rgbArr["blue"] = n;
+ break;
+ case 3:
+ rgbArr["red"] = m;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = val;
+ break;
+ case 4:
+ rgbArr["red"] = n;
+ rgbArr["green"] = m;
+ rgbArr["blue"] = val;
+ break;
+ case 5:
+ rgbArr["red"] = val;
+ rgbArr["green"] = m;
+ rgbArr["blue"] = n;
+ break;
+ case 6:
+ rgbArr["red"] = val;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = m;
+ break;
+ }
+ rgbArr["red"] = Math.round(rgbArr["red"] * 255);
+ rgbArr["green"] = Math.round(rgbArr["green"] * 255);
+ rgbArr["blue"] = Math.round(rgbArr["blue"] * 255);
+ }
+ return rgbArr;
+}
+
+/**
+ * converts RGB to HSV values
+ * @param {Number} red the hue value (between 0 and 255)
+ * @param {Number} green the saturation value (between 0 and 255)
+ * @param {Number} blue the value value (between 0 and 255)
+ * @return hsvArr the hsv values (associative array or object, the keys are: hue (0-360),sat (0-1),val (0-1))
+ * @type Object
+ * @version 1.0 (2007-05-01)
+ * @see #hsv2rgb
+ */
+function rgb2hsv(red,green,blue) {
+ var hsvArr = new Object();
+ red = red / 255;
+ green = green / 255;
+ blue = blue / 255;
+ myMax = Math.max(red, Math.max(green,blue));
+ myMin = Math.min(red, Math.min(green,blue));
+ v = myMax;
+ if (myMax > 0) {
+ s = (myMax - myMin) / myMax;
+ }
+ else {
+ s = 0;
+ }
+ if (s > 0) {
+ myDiff = myMax - myMin;
+ rc = (myMax - red) / myDiff;
+ gc = (myMax - green) / myDiff;
+ bc = (myMax - blue) / myDiff;
+ if (red == myMax) {
+ h = (bc - gc) / 6;
+ }
+ if (green == myMax) {
+ h = (2 + rc - bc) / 6;
+ }
+ if (blue == myMax) {
+ h = (4 + gc - rc) / 6;
+ }
+ }
+ else {
+ h = 0;
+ }
+ if (h < 0) {
+ h += 1;
+ }
+ hsvArr["hue"] = Math.round(h * 360);
+ hsvArr["sat"] = s;
+ hsvArr["val"] = v;
+ return hsvArr;
+}
+
+/**
+ * populates an array such that it can be addressed by both a key or an index nr,
+ * note that both Arrays need to be of the same length
+ * @param {Array} arrayKeys the array containing the keys
+ * @param {Array} arrayValues the array containing the values
+ * @return returnArray the resulting array containing both associative values and also a regular indexed array
+ * @type Array
+ * @version 1.0 (2007-05-01)
+ */
+function arrayPopulate(arrayKeys,arrayValues) {
+ var returnArray = new Array();
+ if (arrayKeys.length != arrayValues.length) {
+ alert("error: arrays do not have the same length!");
+ }
+ else {
+ for (i=0;i<arrayKeys.length;i++) {
+ returnArray[arrayKeys[i]] = arrayValues[i];
+ }
+ }
+ return returnArray;
+}
+
+/**
+ * Wrapper object for network requests, uses getURL or XMLHttpRequest depending on availability
+ * The callBackFunction receives a XML or text node representing the rootElement
+ * of the fragment received or the return text, depending on the returnFormat.
+ * See also the following <a href="http://www.carto.net/papers/svg/network_requests/">documentation</a>.
+ * @class this is a wrapper object to provide network request functionality (get|post)
+ * @param {String} url the URL/IRI of the network resource to be called
+ * @param {Function|Object} callBackFunction the callBack function or object that is called after the data was received, in case of an object, the method 'receiveData' is called; both the function and the object's 'receiveData' method get 2 return parameters: 'node.firstChild'|text (the root element of the XML or text resource), this.additionalParams (if defined)
+ * @param {String} returnFormat the return format, either 'xml' or 'json' (or text)
+ * @param {String} method the method of the network request, either 'get' or 'post'
+ * @param {String|Undefined} postText the String containing the post text (optional) or Undefined (if not a 'post' request)
+ * @param {Object|Array|String|Number|Undefined} additionalParams additional parameters that will be passed to the callBackFunction or object (optional) or Undefined
+ * @return a new getData instance
+ * @type getData
+ * @constructor
+ * @version 1.0 (2007-02-23)
+ */
+function getData(url,callBackFunction,returnFormat,method,postText,additionalParams) {
+ this.url = url;
+ this.callBackFunction = callBackFunction;
+ this.returnFormat = returnFormat;
+ this.method = method;
+ this.additionalParams = additionalParams;
+ if (method != "get" && method != "post") {
+ alert("Error in network request: parameter 'method' must be 'get' or 'post'");
+ }
+ this.postText = postText;
+ this.xmlRequest = null; //@private reference to the XMLHttpRequest object
+}
+
+/**
+ * triggers the network request defined in the constructor
+ */
+getData.prototype.getData = function() {
+ //call getURL() if available
+ if (window.getURL) {
+ if (this.method == "get") {
+ getURL(this.url,this);
+ }
+ if (this.method == "post") {
+ postURL(this.url,this.postText,this);
+ }
+ }
+ //or call XMLHttpRequest() if available
+ else if (window.XMLHttpRequest) {
+ var _this = this;
+ this.xmlRequest = new XMLHttpRequest();
+ if (this.method == "get") {
+ if (this.returnFormat == "xml") {
+ this.xmlRequest.overrideMimeType("text/xml");
+ }
+ this.xmlRequest.open("GET",this.url,true);
+ }
+ if (this.method == "post") {
+ this.xmlRequest.open("POST",this.url,true);
+ }
+ this.xmlRequest.onreadystatechange = function() {_this.handleEvent()};
+ if (this.method == "get") {
+ this.xmlRequest.send(null);
+ }
+ if (this.method == "post") {
+ //test if postText exists and is of type string
+ var reallyPost = true;
+ if (!this.postText) {
+ reallyPost = false;
+ alert("Error in network post request: missing parameter 'postText'!");
+ }
+ if (typeof(this.postText) != "string") {
+ reallyPost = false;
+ alert("Error in network post request: parameter 'postText' has to be of type 'string')");
+ }
+ if (reallyPost) {
+ this.xmlRequest.send(this.postText);
+ }
+ }
+ }
+ //write an error message if neither method is available
+ else {
+ alert("your browser/svg viewer neither supports window.getURL nor window.XMLHttpRequest!");
+ }
+}
+
+/**
+ * this is the callback method for the getURL() or postURL() case
+ * @private
+ */
+getData.prototype.operationComplete = function(data) {
+ //check if data has a success property
+ if (data.success) {
+ //parse content of the XML format to the variable "node"
+ if (this.returnFormat == "xml") {
+ //convert the text information to an XML node and get the first child
+ var node = parseXML(data.content,document);
+ //distinguish between a callback function and an object
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(node.firstChild,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(node.firstChild,this.additionalParams);
+ }
+ }
+ if (this.returnFormat == "json") {
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(data.content,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(data.content,this.additionalParams);
+ }
+ }
+ }
+ else {
+ alert("something went wrong with dynamic loading of geometry!");
+ }
+}
+
+/**
+ * this is the callback method for the XMLHttpRequest case
+ * @private
+ */
+getData.prototype.handleEvent = function() {
+ if (this.xmlRequest.readyState == 4) {
+ if (this.returnFormat == "xml") {
+ //we need to import the XML node first
+ var importedNode = document.importNode(this.xmlRequest.responseXML.documentElement,true);
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(importedNode,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(importedNode,this.additionalParams);
+ }
+ }
+ if (this.returnFormat == "json") {
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(this.xmlRequest.responseText,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(this.xmlRequest.responseText,this.additionalParams);
+ }
+ }
+ }
+}
+
+/**
+ * Serializes an XML node and returns a string representation. Wrapper function to hide implementation differences.
+ * This can be used for debugging purposes or to post data to a server or network resource.
+ * @param {dom::Node} node the DOM node reference
+ * @return textRepresentation the String representation of the XML node
+ * @type String
+ * @version 1.0 (2007-05-01)
+ * @see getData
+ */
+function serializeNode(node) {
+ if (typeof XMLSerializer != 'undefined') {
+ return new XMLSerializer().serializeToString(node);
+ }
+ else if (typeof node.xml != 'undefined') {
+ return node.xml;
+ }
+ else if (typeof printNode != 'undefined') {
+ return printNode(node);
+ }
+ else if (typeof Packages != 'undefined') {
+ try {
+ var stringWriter = new java.io.StringWriter();
+ Packages.org.apache.batik.dom.util.DOMUtilities.writeNode(node,stringWriter);
+ return stringWriter.toString();
+ }
+ catch (e) {
+ alert("Sorry, your SVG viewer does not support the printNode/serialize function.");
+ return '';
+ }
+ }
+ else {
+ alert("Sorry, your SVG viewer does not support the printNode/serialize function.");
+ return '';
+ }
+}
+
+/**
+ * Starts a SMIL animation element with the given id by triggering the '.beginElement()' method.
+ * This is a convenience (shortcut) function.
+ * @param {String} id a valid id of a valid SMIL animation element
+ * @version 1.0 (2007-05-01)
+ */
+//starts an animtion with the given id
+//this function is useful in combination with window.setTimeout()
+function startAnimation(id) {
+ document.getElementById(id).beginElement();
+}
diff -r 878ca31a4995 -r c2d042ba8cd0 static/scripts/timer.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/timer.js Wed Oct 14 15:47:58 2009 -0400
@@ -0,0 +1,74 @@
+// source/credits: "Algorithm": http://www.codingforums.com/showthread.php?s=&threadid=10531
+// The constructor should be called with
+// the parent object (optional, defaults to window).
+
+function Timer(){
+ this.obj = (arguments.length)?arguments[0]:window;
+ return this;
+}
+
+// The set functions should be called with:
+// - The name of the object method (as a string) (required)
+// - The millisecond delay (required)
+// - Any number of extra arguments, which will all be
+// passed to the method when it is evaluated.
+
+Timer.prototype.setInterval = function(func, msec){
+ var i = Timer.getNew();
+ var t = Timer.buildCall(this.obj, i, arguments);
+ Timer.set[i].timer = window.setInterval(t,msec);
+ return i;
+}
+Timer.prototype.setTimeout = function(func, msec){
+ var i = Timer.getNew();
+ Timer.buildCall(this.obj, i, arguments);
+ Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
+ return i;
+}
+
+// The clear functions should be called with
+// the return value from the equivalent set function.
+
+Timer.prototype.clearInterval = function(i){
+ if(!Timer.set[i]) return;
+ window.clearInterval(Timer.set[i].timer);
+ Timer.set[i] = null;
+}
+Timer.prototype.clearTimeout = function(i){
+ if(!Timer.set[i]) return;
+ window.clearTimeout(Timer.set[i].timer);
+ Timer.set[i] = null;
+}
+
+// Private data
+
+Timer.set = new Array();
+Timer.buildCall = function(obj, i, args){
+ var t = "";
+ Timer.set[i] = new Array();
+ if(obj != window){
+ Timer.set[i].obj = obj;
+ t = "Timer.set["+i+"].obj.";
+ }
+ t += args[0]+"(";
+ if(args.length > 2){
+ Timer.set[i][0] = args[2];
+ t += "Timer.set["+i+"][0]";
+ for(var j=1; (j+2)<args.length; j++){
+ Timer.set[i][j] = args[j+2];
+ t += ", Timer.set["+i+"]["+j+"]";
+ }}
+ t += ");";
+ Timer.set[i].call = t;
+ return t;
+}
+Timer.callOnce = function(i){
+ if(!Timer.set[i]) return;
+ eval(Timer.set[i].call);
+ Timer.set[i] = null;
+}
+Timer.getNew = function(){
+ var i = 0;
+ while(Timer.set[i]) i++;
+ return i;
+}
\ No newline at end of file
1
0
details: http://www.bx.psu.edu/hg/galaxy/rev/7f5489d7c3d8
changeset: 2885:7f5489d7c3d8
user: Kanwei Li <kanwei(a)gmail.com>
date: Wed Oct 14 18:43:38 2009 -0400
description:
pack the new scripts for rgenetics
3 file(s) affected in this change:
static/scripts/packed/checkbox_and_radiobutton.js
static/scripts/packed/helper_functions.js
static/scripts/packed/timer.js
diffs (18 lines):
diff -r c2d042ba8cd0 -r 7f5489d7c3d8 static/scripts/packed/checkbox_and_radiobutton.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/packed/checkbox_and_radiobutton.js Wed Oct 14 18:43:38 2009 -0400
@@ -0,0 +1,1 @@
+function checkBox(d,g,m,j,n,l,c,f,k,b,h,o,a){var e=13;var i=true;if(arguments.length==e){this.id=d;this.parentNode=g;this.x=m;this.y=j;this.checkboxId=n;this.checkcrossId=l;this.checkedStatus=c;this.labelText=f;this.textStyles=k;if(!this.textStyles["font-size"]){this.textStyles["font-size"]=12}this.labelDistance=b;this.labelYOffset=h;this.radioButtonGroup=o;this.functionToCall=a;this.exists=true;this.label=undefined}else{i=false;alert("Error in checkbox ("+d+"): wrong nr of arguments! You have to pass over "+e+" parameters.")}if(i){this.timer=new Timer(this);if(this.radioButtonGroup){this.timerMs=0}else{this.timerMs=200}this.createCheckBox()}else{alert("Could not create checkbox with id '"+d+"' due to errors in the constructor parameters")}}checkBox.prototype.createCheckBox=function(){if(typeof(this.parentNode)=="string"){this.parentNode=document.getElementById(this.parentNode)}this.checkBox=document.createElementNS(svgNS,"use");this.checkBox.setAttributeNS(null,"x",this.x);
this.checkBox.setAttributeNS(null,"y",this.y);this.checkBox.setAttributeNS(xlinkNS,"href","#"+this.checkboxId);this.checkBox.addEventListener("click",this,false);this.checkBox.setAttributeNS(null,"cursor","pointer");this.parentNode.appendChild(this.checkBox);this.checkCross=document.createElementNS(svgNS,"use");this.checkCross.setAttributeNS(null,"x",this.x);this.checkCross.setAttributeNS(null,"y",this.y);this.checkCross.setAttributeNS(xlinkNS,"href","#"+this.checkcrossId);this.parentNode.appendChild(this.checkCross);if(this.checkedStatus==false){this.checkCross.setAttributeNS(null,"display","none")}if(this.labelText){if(this.labelText.length>0){this.label=document.createElementNS(svgNS,"text");for(var b in this.textStyles){var a=this.textStyles[b];if(b=="font-size"){a+="px"}this.label.setAttributeNS(null,b,a)}this.label.setAttributeNS(null,"x",(this.x+this.labelDistance));this.label.setAttributeNS(null,"y",(this.y+this.labelYOffset));this.label.setAttributeNS(null,"cursor",
"pointer");var c=document.createTextNode(this.labelText);this.label.appendChild(c);this.label.setAttributeNS(null,"pointer-events","all");this.label.addEventListener("click",this,false);this.parentNode.appendChild(this.label)}}if(this.radioButtonGroup){this.radioButtonGroup.addCheckBox(this)}};checkBox.prototype.handleEvent=function(a){if(a.type=="click"){if(this.checkedStatus==true){this.checkCross.setAttributeNS(null,"display","none");this.checkedStatus=false}else{this.checkCross.setAttributeNS(null,"display","inline");this.checkedStatus=true}}this.timer.setTimeout("fireFunction",this.timerMs)};checkBox.prototype.fireFunction=function(){if(this.radioButtonGroup){this.radioButtonGroup.selectById(this.id,true)}else{if(typeof(this.functionToCall)=="function"){this.functionToCall(this.id,this.checkedStatus,this.labelText)}if(typeof(this.functionToCall)=="object"){this.functionToCall.checkBoxChanged(this.id,this.checkedStatus,this.labelText)}if(typeof(this.functionToCall)==unde
fined){return}}};checkBox.prototype.check=function(a){this.checkCross.setAttributeNS(null,"display","inherit");this.checkedStatus=true;if(a){this.timer.setTimeout("fireFunction",this.timerMs)}};checkBox.prototype.uncheck=function(a){this.checkCross.setAttributeNS(null,"display","none");this.checkedStatus=false;if(a){this.timer.setTimeout("fireFunction",this.timerMs)}};checkBox.prototype.moveTo=function(b,a){this.x=b;this.y=a;this.checkBox.setAttributeNS(null,"x",this.x);this.checkBox.setAttributeNS(null,"y",this.y);this.checkCross.setAttributeNS(null,"x",this.x);this.checkCross.setAttributeNS(null,"y",this.y);if(this.labelText){this.label.setAttributeNS(null,"x",(this.x+this.labelDistance));this.label.setAttributeNS(null,"y",(this.y+this.labelYOffset))}};checkBox.prototype.remove=function(a){this.checkBox.removeEventListener("click",this,false);this.parentNode.removeChild(this.checkBox);this.parentNode.removeChild(this.checkCross);if(this.label){this.parentNode.removeChild(t
his.label)}this.exists=false};checkBox.prototype.setLabelText=function(a){this.labelText=a;if(this.label){this.label.firstChild.nodeValue=a}else{if(this.labelText.length>0){this.label=document.createElementNS(svgNS,"text");for(var b in this.textStyles){value=this.textStyles[b];if(b=="font-size"){value+="px"}this.label.setAttributeNS(null,b,value)}this.label.setAttributeNS(null,"x",(this.x+this.labelDistance));this.label.setAttributeNS(null,"y",(this.y+this.textStyles["font-size"]*0.3));var c=document.createTextNode(this.labelText);this.label.appendChild(c);this.parentNode.appendChild(this.label)}}};function radioButtonGroup(c,a){var b=2;if(arguments.length==b){this.id=c;if(typeof(a)=="function"||typeof(a)=="object"||typeof(a)==undefined){this.functionToCall=a}else{alert("Error in radiobutton with ("+c+"): argument functionToCall is not of type 'function', 'object' or undefined!")}this.checkBoxes=new Array();this.selectedId=undefined;this.selectedIndex=undefined;this.timer=ne
w Timer(this);this.timerMs=200}else{alert("Error in radiobutton with ("+c+"): wrong nr of arguments! You have to pass over "+b+" parameters.")}}radioButtonGroup.prototype.addCheckBox=function(a){this.checkBoxes.push(a);if(a.checkedStatus){this.selectedId=a.id;this.selectedIndex=this.checkBoxes.length-1}};radioButtonGroup.prototype.selectById=function(c,a){var d=false;for(var b=0;b<this.checkBoxes.length;b++){if(this.checkBoxes[b].id==c){this.selectedId=c;this.selectedIndex=b;if(this.checkBoxes[b].checkedStatus==false){this.checkBoxes[b].check(false)}d=true}else{this.checkBoxes[b].uncheck(false)}}if(d){if(a){this.timer.setTimeout("fireFunction",this.timerMs)}}else{alert("Error in radiobutton with ("+this.id+"): could not find checkbox with id '"+c+"'")}};radioButtonGroup.prototype.selectByLabelname=function(a,b){var d=-1;for(var c=0;c<this.checkBoxes.length;c++){if(this.checkBoxes[c].labelText==a){d=this.checkBoxes[c].id}}if(d==-1){alert("Error in radiobutton with ("+this.id+
"): could not find checkbox with label '"+a+"'")}else{this.selectById(d,b)}};radioButtonGroup.prototype.fireFunction=function(){if(typeof(this.functionToCall)=="function"){this.functionToCall(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText)}if(typeof(this.functionToCall)=="object"){this.functionToCall.radioButtonChanged(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText)}if(typeof(this.functionToCall)==undefined){return}};
\ No newline at end of file
diff -r c2d042ba8cd0 -r 7f5489d7c3d8 static/scripts/packed/helper_functions.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/packed/helper_functions.js Wed Oct 14 18:43:38 2009 -0400
@@ -0,0 +1,1 @@
+var svgNS="http://www.w3.org/2000/svg";var xlinkNS="http://www.w3.org/1999/xlink";var cartoNS="http://www.carto.net/attrib";var attribNS="http://www.carto.net/attrib";var batikNS="http://xml.apache.org/batik/ext";function toPolarDir(a,c){var b=(Math.atan2(c,a));return(b)}function toPolarDist(a,b){var c=Math.sqrt(a*a+b*b);return(c)}function toRectX(b,c){var a=c*Math.cos(b);return(a)}function toRectY(a,b){y=b*Math.sin(a);return(y)}function DegToRad(a){return(a/180*Math.PI)}function RadToDeg(a){return(a/Math.PI*180)}function dd2dms(a){var b=(Math.abs(a)-Math.floor(Math.abs(a)))*60;var d=(b-Math.floor(b))*60;var b=Math.floor(b);if(a>=0){var c=Math.floor(a)}else{var c=Math.ceil(a)}return{deg:c,min:b,sec:d}}function dms2dd(c,a,b){if(c<0){return c-(a/60)-(b/3600)}else{return c+(a/60)+(b/3600)}}function log(c,a){if(a==null){a=Math.E}return Math.log(c)/Math.log(a)}function intBilinear(m,k,g,c,o,b,a,u,t){var q=(o-a)/t;var p=(b-u)/t;var n=(1-q)*(1-p);var l=q*(1-p);var j=q*p;var d=p*(1-
q);var r=n*g+l*c+j*m+d*k;return r}function leftOfTest(b,j,d,g,c,f){var a=(g-j)*(c-d)-(d-b)*(f-g);if(a<0){var e=1}else{var e=0}return e}function distFromLine(e,f,d,a,c,j){var k=c-d;var g=j-a;var b=(g*(e-d)-k*(f-a))/Math.sqrt(Math.pow(k,2)+Math.pow(g,2));return b}function angleBetwTwoLines(b,a,e,c){var d=Math.acos((b*e+a*c)/(Math.sqrt(Math.pow(b,2)+Math.pow(a,2))*Math.sqrt(Math.pow(e,2)+Math.pow(c,2))));return d}function calcBisectorVector(b,a,g,e){var f=Math.sqrt(Math.pow(b,2)+Math.pow(a,2));var d=Math.sqrt(Math.pow(g,2)+Math.pow(e,2));var j=new Array();j[0]=b/f+g/d;j[1]=a/f+e/d;return j}function calcBisectorAngle(a,k,j,g){var c=Math.sqrt(Math.pow(a,2)+Math.pow(k,2));var b=Math.sqrt(Math.pow(j,2)+Math.pow(g,2));var f=a/c+j/b;var e=k/c+g/b;var d=toPolarDir(f,e);return d}function intersect2lines(l,f,k,e,n,j,m,g){var c=new Object();var d=(g-j)*(k-l)-(m-n)*(e-f);if(d==0){alert("lines are parallel")}else{var b=((m-n)*(f-j)-(g-j)*(l-n))/d;var a=((k-l)*(f-j)-(e-f)*(l-n))/d}c.x=l+b*(
k-l);c.y=f+b*(e-f);return c}function formatNumberString(a,e){if(typeof(a)=="Number"){var c=a.toString()}else{var c=a}var b="";var d=c.split(".");var f=d[0].length;if(f>3){while(f>0){if(f>3){b=e+d[0].substr(f-3,3)+b}else{b=d[0].substr(0,f)+b}f-=3}}else{b=d[0]}if(d[1]){b=b+"."+d[1]}return b}function statusChange(a){document.getElementById("statusText").firstChild.nodeValue="Statusbar: "+a}function scaleObject(a,e){var d=a.currentTarget;var c=d.getAttributeNS(null,"x");var b=d.getAttributeNS(null,"y");var f="scale("+e+") translate("+(c*1/e-c)+" "+(b*1/e-b)+")";d.setAttributeNS(null,"transform",f)}function getTransformToRootElement(b){try{var c=b.getTransformToElement(document.documentElement)}catch(a){var c=b.getCTM();while((b=b.parentNode)!=document){c=b.getCTM().multiply(c)}}return c}function getTransformToElement(b,c){try{var d=b.getTransformToElement(c)}catch(a){var d=b.getCTM();while((b=b.parentNode)!=c){d=b.getCTM().multiply(d)}}return d}function hsv2rgb(j,c,b){var l=new
Object();if(c==0){l.red=Math.round(b*255);l.green=Math.round(b*255);l.blue=Math.round(b*255)}else{var g=j/60;var e=Math.floor(g);var k=g-e;if(e%2==0){k=1-k}var d=b*(1-c);var a=b*(1-c*k);switch(e){case 0:l.red=b;l.green=a;l.blue=d;break;case 1:l.red=a;l.green=b;l.blue=d;break;case 2:l.red=d;l.green=b;l.blue=a;break;case 3:l.red=d;l.green=a;l.blue=b;break;case 4:l.red=a;l.green=d;l.blue=b;break;case 5:l.red=b;l.green=d;l.blue=a;break;case 6:l.red=b;l.green=a;l.blue=d;break}l.red=Math.round(l.red*255);l.green=Math.round(l.green*255);l.blue=Math.round(l.blue*255)}return l}function rgb2hsv(c,b,a){var d=new Object();c=c/255;b=b/255;a=a/255;myMax=Math.max(c,Math.max(b,a));myMin=Math.min(c,Math.min(b,a));v=myMax;if(myMax>0){s=(myMax-myMin)/myMax}else{s=0}if(s>0){myDiff=myMax-myMin;rc=(myMax-c)/myDiff;gc=(myMax-b)/myDiff;bc=(myMax-a)/myDiff;if(c==myMax){h=(bc-gc)/6}if(b==myMax){h=(2+rc-bc)/6}if(a==myMax){h=(4+gc-rc)/6}}else{h=0}if(h<0){h+=1}d.hue=Math.round(h*360);d.sat=s;d.val=v;ret
urn d}function arrayPopulate(a,b){var c=new Array();if(a.length!=b.length){alert("error: arrays do not have the same length!")}else{for(i=0;i<a.length;i++){c[a[i]]=b[i]}}return c}function getData(d,c,e,f,b,a){this.url=d;this.callBackFunction=c;this.returnFormat=e;this.method=f;this.additionalParams=a;if(f!="get"&&f!="post"){alert("Error in network request: parameter 'method' must be 'get' or 'post'")}this.postText=b;this.xmlRequest=null}getData.prototype.getData=function(){if(window.getURL){if(this.method=="get"){getURL(this.url,this)}if(this.method=="post"){postURL(this.url,this.postText,this)}}else{if(window.XMLHttpRequest){var b=this;this.xmlRequest=new XMLHttpRequest();if(this.method=="get"){if(this.returnFormat=="xml"){this.xmlRequest.overrideMimeType("text/xml")}this.xmlRequest.open("GET",this.url,true)}if(this.method=="post"){this.xmlRequest.open("POST",this.url,true)}this.xmlRequest.onreadystatechange=function(){b.handleEvent()};if(this.method=="get"){this.xmlRequest
.send(null)}if(this.method=="post"){var a=true;if(!this.postText){a=false;alert("Error in network post request: missing parameter 'postText'!")}if(typeof(this.postText)!="string"){a=false;alert("Error in network post request: parameter 'postText' has to be of type 'string')")}if(a){this.xmlRequest.send(this.postText)}}}else{alert("your browser/svg viewer neither supports window.getURL nor window.XMLHttpRequest!")}}};getData.prototype.operationComplete=function(b){if(b.success){if(this.returnFormat=="xml"){var a=parseXML(b.content,document);if(typeof(this.callBackFunction)=="function"){this.callBackFunction(a.firstChild,this.additionalParams)}if(typeof(this.callBackFunction)=="object"){this.callBackFunction.receiveData(a.firstChild,this.additionalParams)}}if(this.returnFormat=="json"){if(typeof(this.callBackFunction)=="function"){this.callBackFunction(b.content,this.additionalParams)}if(typeof(this.callBackFunction)=="object"){this.callBackFunction.receiveData(b.content,this.
additionalParams)}}}else{alert("something went wrong with dynamic loading of geometry!")}};getData.prototype.handleEvent=function(){if(this.xmlRequest.readyState==4){if(this.returnFormat=="xml"){var a=document.importNode(this.xmlRequest.responseXML.documentElement,true);if(typeof(this.callBackFunction)=="function"){this.callBackFunction(a,this.additionalParams)}if(typeof(this.callBackFunction)=="object"){this.callBackFunction.receiveData(a,this.additionalParams)}}if(this.returnFormat=="json"){if(typeof(this.callBackFunction)=="function"){this.callBackFunction(this.xmlRequest.responseText,this.additionalParams)}if(typeof(this.callBackFunction)=="object"){this.callBackFunction.receiveData(this.xmlRequest.responseText,this.additionalParams)}}}};function serializeNode(b){if(typeof XMLSerializer!="undefined"){return new XMLSerializer().serializeToString(b)}else{if(typeof b.xml!="undefined"){return b.xml}else{if(typeof printNode!="undefined"){return printNode(b)}else{if(typeof Pac
kages!="undefined"){try{var a=new java.io.StringWriter();Packages.org.apache.batik.dom.util.DOMUtilities.writeNode(b,a);return a.toString()}catch(c){alert("Sorry, your SVG viewer does not support the printNode/serialize function.");return""}}else{alert("Sorry, your SVG viewer does not support the printNode/serialize function.");return""}}}}}function startAnimation(a){document.getElementById(a).beginElement()};
\ No newline at end of file
diff -r c2d042ba8cd0 -r 7f5489d7c3d8 static/scripts/packed/timer.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/packed/timer.js Wed Oct 14 18:43:38 2009 -0400
@@ -0,0 +1,1 @@
+function Timer(){this.obj=(arguments.length)?arguments[0]:window;return this}Timer.prototype.setInterval=function(c,d){var b=Timer.getNew();var a=Timer.buildCall(this.obj,b,arguments);Timer.set[b].timer=window.setInterval(a,d);return b};Timer.prototype.setTimeout=function(b,c){var a=Timer.getNew();Timer.buildCall(this.obj,a,arguments);Timer.set[a].timer=window.setTimeout("Timer.callOnce("+a+");",c);return a};Timer.prototype.clearInterval=function(a){if(!Timer.set[a]){return}window.clearInterval(Timer.set[a].timer);Timer.set[a]=null};Timer.prototype.clearTimeout=function(a){if(!Timer.set[a]){return}window.clearTimeout(Timer.set[a].timer);Timer.set[a]=null};Timer.set=new Array();Timer.buildCall=function(e,d,b){var c="";Timer.set[d]=new Array();if(e!=window){Timer.set[d].obj=e;c="Timer.set["+d+"].obj."}c+=b[0]+"(";if(b.length>2){Timer.set[d][0]=b[2];c+="Timer.set["+d+"][0]";for(var a=1;(a+2)<b.length;a++){Timer.set[d][a]=b[a+2];c+=", Timer.set["+d+"]["+a+"]"}}c+=");";Timer.set[
d].call=c;return c};Timer.callOnce=function(i){if(!Timer.set[i]){return}eval(Timer.set[i].call);Timer.set[i]=null};Timer.getNew=function(){var a=0;while(Timer.set[a]){a++}return a};
\ No newline at end of file
1
0
Hi,
I want to run a few of the interval operation tools on the command
line, however I am getting the following error:
Traceback (most recent call last):
File
"/home/swebb/galaxy/galaxy_dist/tools/new_operations/gops_join.py",
line 11, in <module>
from galaxy import eggs
ImportError: No module named galaxy
I assume I may need to alter some Environmental variables.
Any help appreciated.
Thanks
Shaun Webb
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
2
1
To whom it may concern,
Here is my test code.
********************************************************
<tests>
<test>
<param name="source" value="From current history" />
<param name="fasta_input" value="chr4.fas" ftype="fasta" />
<param name="organism" value="Arabidopsis thaliana (TAIR9)" />
<output name="output" file="tair9_test.txt" />
</test>
</tests>
********************************************************
And I am getting a failure result for my test.
The error message is
*******************************************************
Traceback (most recent call last):
File "/home/galaxy/galaxy-2.1.2009/test/functional/test_toolbox.py", line 114, in test_tool
self.do_it()
File "/home/galaxy/galaxy-2.1.2009/test/functional/test_toolbox.py", line 54, in do_it
self.verify_dataset_correctness( file )
File "/home/galaxy/galaxy-2.1.2009/test/base/twilltestcase.py", line 363, in verify_dataset_correctness
raise AssertionError( errmsg )
AssertionError: History item 3 different than expected, difference:
--- local_file
+++ history_data
@@ -1,0 +1,14 @@
*****************************************************
It will be great if you can suggest a way for me to solve the problem.
Many thanks in advance,
Vipin T S
2
2
Hello,
I'd like to request a small change:
to create a dedicated python file for user customizable datatypes -
something like "user_intervals.py" along side "intervals.py" (in /lib/galaxy/datatypes).
The reason is that we have our own custom types, with special column assignment.
So for example, I've added the following class to the bottom of "intervals.py":
=========
class Foobar ( Interval ):
"""Foobar results"""
"""Add metadata elements"""
MetadataElement( name="chromCol", default=2, desc="Chrom column", param=metadata.ColumnParameter )
MetadataElement( name="startCol", default=4, desc="Start column", param=metadata.ColumnParameter )
MetadataElement( name="endCol", default=5, desc="End column", param=metadata.ColumnParameter )
MetadataElement( name="strandCol", default=3, desc="Strand column", param=metadata.ColumnParameter )
MetadataElement( name="nameCol", default=1, desc="Name/Identifier column", param=metadata.ColumnParameter )
MetadataElement( name="columns", default=6, desc="Number of columns", readonly=True, visible=False )
===========
It's a simple text file containing intervals, but with different column assignment.
I also updated <datatypes_conf.xml>, and this way, if my tool outputs a "foobar" format - the columns assignment works perfectly.
The only problem is merging:
If the "intervals.py" file is changed in the main repository - automatic merging doesn't work cleanly. It needs to merge an old intervals.py (with my custom types) together with a new intervals.py (without my custom types).
Maybe I'm doing something wrong, but I always end up having to manually resolve the conflicts.
My suggestion is to have an empty "user_intervals.py" (or other datatypes, too), which will be monitored in the repository, but will not contain any Galaxy official types. That will keep a clear separation between galaxy types and user types.
If this is already possible somehow, please let me know.
Thanks!
gordon.
2
1

14 Oct '09
details: http://www.bx.psu.edu/hg/galaxy/rev/878ca31a4995
changeset: 2883:878ca31a4995
user: Greg Von Kuster <greg(a)bx.psu.edu>
date: Wed Oct 14 09:33:56 2009 -0400
description:
Remove a debug statement, slight cleanup.
3 file(s) affected in this change:
lib/galaxy/web/controllers/forms.py
lib/galaxy/web/controllers/library.py
lib/galaxy/web/controllers/library_admin.py
diffs (37 lines):
diff -r ca816e66ec69 -r 878ca31a4995 lib/galaxy/web/controllers/forms.py
--- a/lib/galaxy/web/controllers/forms.py Wed Oct 14 02:22:11 2009 -0400
+++ b/lib/galaxy/web/controllers/forms.py Wed Oct 14 09:33:56 2009 -0400
@@ -135,7 +135,6 @@
renaming fields, adding/deleting fields, changing fields attributes.
'''
params = util.Params( kwd )
- log.debug( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
try:
diff -r ca816e66ec69 -r 878ca31a4995 lib/galaxy/web/controllers/library.py
--- a/lib/galaxy/web/controllers/library.py Wed Oct 14 02:22:11 2009 -0400
+++ b/lib/galaxy/web/controllers/library.py Wed Oct 14 09:33:56 2009 -0400
@@ -114,7 +114,8 @@
created_ldda_ids = params.get( 'created_ldda_ids', '' )
hidden_folder_ids = util.listify( util.restore_text( params.get( 'hidden_folder_ids', '' ) ) )
if created_ldda_ids and not msg:
- msg = "%d datasets are now uploading in the background to the library '%s' ( each is selected ). Please do not navigate away from Galaxy or use the browser's \"stop\" or \"reload\" buttons (on this tab) until the upload(s) change from the \"uploading\" state." % ( len( created_ldda_ids.split(',') ), library.name )
+ msg = "%d datasets are now uploading in the background to the library '%s' ( each is selected ). " % ( len( created_ldda_ids.split(',') ), library.name )
+ msg += "Do not navigate away from Galaxy or use the browser's \"stop\" or \"reload\" buttons ( on this tab ) until the upload(s) change from the \"uploading\" state."
messagetype = "info"
return trans.fill_template( '/library/browse_library.mako',
library=library,
diff -r ca816e66ec69 -r 878ca31a4995 lib/galaxy/web/controllers/library_admin.py
--- a/lib/galaxy/web/controllers/library_admin.py Wed Oct 14 02:22:11 2009 -0400
+++ b/lib/galaxy/web/controllers/library_admin.py Wed Oct 14 09:33:56 2009 -0400
@@ -50,7 +50,8 @@
messagetype='error' ) )
created_ldda_ids = params.get( 'created_ldda_ids', '' )
if created_ldda_ids and not msg:
- msg = "%d datasets are now uploading in the background to the library '%s' ( each is selected ). Please do not navigate away from Galaxy or use the browser's \"stop\" or \"reload\" buttons (on this tab) until the upload(s) change from the \"uploading\" state." % ( len( created_ldda_ids.split(',') ), library.name )
+ msg = "%d datasets are now uploading in the background to the library '%s' ( each is selected ). " % ( len( created_ldda_ids.split( ',' ) ), library.name )
+ msg += "Do not navigate away from Galaxy or use the browser's \"stop\" or \"reload\" buttons ( on this tab ) until the upload(s) change from the \"uploading\" state."
messagetype = "info"
return trans.fill_template( '/admin/library/browse_library.mako',
library=library,
1
0
details: http://www.bx.psu.edu/hg/galaxy/rev/ca816e66ec69
changeset: 2882:ca816e66ec69
user: rc
date: Wed Oct 14 02:22:11 2009 -0400
description:
Forms & request controllers
- refactored to work on main
- cleanup
Added more functional tests
12 file(s) affected in this change:
lib/galaxy/model/__init__.py
lib/galaxy/web/controllers/forms.py
lib/galaxy/web/controllers/requests.py
lib/galaxy/web/controllers/requests_admin.py
lib/galaxy/web/framework/__init__.py
templates/admin/forms/edit_form.mako
templates/admin/forms/show_form_read_only.mako
templates/admin/requests/show_request.mako
templates/requests/show_request.mako
templates/user/address.mako
test/base/twilltestcase.py
test/functional/test_forms_and_requests.py
diffs (2308 lines):
diff -r b16a6d767e65 -r ca816e66ec69 lib/galaxy/model/__init__.py
--- a/lib/galaxy/model/__init__.py Tue Oct 13 18:15:06 2009 -0400
+++ b/lib/galaxy/model/__init__.py Wed Oct 14 02:22:11 2009 -0400
@@ -1090,11 +1090,12 @@
types = Bunch( REQUEST = 'Sequencing Request Form',
SAMPLE = 'Sequencing Sample Form',
LIBRARY_INFO_TEMPLATE = 'Library information template' )
- def __init__(self, name=None, desc=None, fields=[], current_form=None, form_type=None, layout=None):
+ def __init__(self, name=None, desc=None, fields=[],
+ form_definition_current=None, form_type=None, layout=None):
self.name = name
self.desc = desc
self.fields = fields
- self.form_definition_current = current_form
+ self.form_definition_current = form_definition_current
self.type = form_type
self.layout = layout
def fields_of_grid(self, layout_grid_name):
@@ -1263,20 +1264,26 @@
self.postal_code = postal_code
self.country = country
self.phone = phone
- def display(self):
- return self.name+'<br/>'+ \
- self.institution+'<br/>'+ \
- self.address+'<br/>'+ \
- self.city+' '+self.state+' '+self.postal_code+'<br/>'+ \
- self.country+'<br/>'+ \
- 'Phone: '+self.phone
def get_html(self):
- return self.name+'<br/>'+ \
- self.institution+'<br/>'+ \
- self.address+'<br/>'+ \
- self.city+' '+self.state+' '+self.postal_code+'<br/>'+ \
- self.country+'<br/>'+ \
- 'Phone: '+self.phone
+ html = ''
+ if self.name:
+ html = html + self.name
+ if self.institution:
+ html = html + '<br/>' + self.institution
+ if self.address:
+ html = html + '<br/>' + self.address
+ if self.city:
+ html = html + '<br/>' + self.city
+ if self.state:
+ html = html + ' ' + self.state
+ if self.postal_code:
+ html = html + ' ' + self.postal_code
+ if self.country:
+ html = html + '<br/>' + self.country
+ if self.phone:
+ html = html + '<br/>' + 'Phone: ' + self.phone
+ return html
+
class Page( object ):
def __init__( self ):
diff -r b16a6d767e65 -r ca816e66ec69 lib/galaxy/web/controllers/forms.py
--- a/lib/galaxy/web/controllers/forms.py Tue Oct 13 18:15:06 2009 -0400
+++ b/lib/galaxy/web/controllers/forms.py Wed Oct 14 02:22:11 2009 -0400
@@ -12,6 +12,14 @@
log = logging.getLogger( __name__ )
class Forms( BaseController ):
+ # Empty form field
+ empty_field = { 'label': '',
+ 'helptext': '',
+ 'visible': True,
+ 'required': False,
+ 'type': BaseField.form_field_types()[0],
+ 'selectlist': [],
+ 'layout': 'none' }
@web.expose
@web.require_admin
def index( self, trans, **kwd ):
@@ -84,19 +92,12 @@
action='edit',
form_id=fd.id,
add_field_button='Add field',
- num_fields=0,
name=fd.name,
description=fd.desc,
form_type_selectbox=fd.type ) )
- self.current_form = {}
- self.current_form[ 'name' ] = 'New Form'
- self.current_form[ 'desc' ] = ''
- self.current_form[ 'type' ] = params.get( 'form_type', 'none' )
- self.current_form[ 'layout' ] = [ 'Main' ]
- self.current_form[ 'fields' ] = []
- inputs = [ ( 'Name', TextField( 'name', 40, self.current_form[ 'name' ] ) ),
- ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ),
- ( 'Type', self.__form_types_widget(trans, selected=self.current_form['type']) ),
+ inputs = [ ( 'Name', TextField( 'name', 40, 'New Form' ) ),
+ ( 'Description', TextField( 'description', 40, '' ) ),
+ ( 'Type', self.__form_types_widget(trans, selected=params.get( 'form_type', 'none' )) ),
( 'Import from csv file (Optional)', FileField( 'file_data', 40, '' ) ) ]
return trans.fill_template( '/admin/forms/create_form.mako',
inputs=inputs,
@@ -134,102 +135,156 @@
renaming fields, adding/deleting fields, changing fields attributes.
'''
params = util.Params( kwd )
+ log.debug( kwd )
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
- form_id = params.get( 'form_id', None )
- if not form_id:
- msg = 'Invalid form id %s' % str( form_id )
- trans.response.send_redirect( web.url_for( controller='forms',
- action='manage',
- msg=msg,
- messagetype='error' ) )
- fd = trans.app.model.FormDefinition.get( int( params.form_id ) )
+ try:
+ fd = trans.app.model.FormDefinition.get( int( params.get( 'form_id', None ) ) )
+ except:
+ return trans.response.send_redirect( web.url_for( controller='forms',
+ action='manage',
+ msg='Invalid form',
+ messagetype='error' ) )
+ #
# Show the form for editing
+ #
if params.get( 'show_form', False ):
- self.__get_saved_form( fd )
- # The following two dicts store the unsaved select box options
- self.del_options = {}
- self.add_options = {}
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
- #Add a layout grid
+ current_form = self.__get_saved_form( fd )
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+ #
+ # Add a layout grid
+ #
elif params.get( 'add_layout_grid', False ):
- self.__update_current_form( trans, **kwd )
- self.__add_layout_grid()
+ current_form = self.__get_form( trans, **kwd )
+ current_form['layout'].append('')
# show the form again
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+ #
# Delete a layout grid
+ #
elif params.get( 'remove_layout_grid_button', False ):
- self.__update_current_form( trans, **kwd )
+ current_form = self.__get_form( trans, **kwd )
index = int( kwd[ 'remove_layout_grid_button' ].split( ' ' )[2] ) - 1
- self.__remove_layout_grid( index )
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
+ del current_form['layout'][index]
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+ #
+ # Add a field
+ #
+ elif params.get( 'add_field_button', False ):
+ current_form = self.__get_form( trans, **kwd )
+ current_form['fields'].append( self.empty_field )
+ # show the form again with one empty field
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+ #
# Delete a field
+ #
elif params.get( 'remove_button', False ):
- self.__update_current_form( trans, **kwd )
+ current_form = self.__get_form( trans, **kwd )
+ # find the index of the field to be removed from the remove button label
index = int( kwd[ 'remove_button' ].split( ' ' )[2] ) - 1
- self.__remove_field( index )
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
+ del current_form['fields'][index]
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+ #
# Save changes
+ #
elif params.get( 'save_changes_button', False ):
- self.__update_current_form( trans, **kwd )
- fd_new, msg = self.__save_form( trans, fd.form_definition_current.id, **kwd )
+ fd_new, msg = self.__save_form( trans, fdc_id=fd.form_definition_current.id, **kwd )
+ # if validation error encountered while saving the form, show the
+ # unsaved form, with the error message
if not fd_new:
- return self.__show( trans=trans, form=fd, msg=msg, messagetype='error', **kwd )
- else:
- fd = fd_new
+ current_form = self.__get_form( trans, **kwd )
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype='error', **kwd )
+ # everything went fine. form saved successfully. Show the saved form
+ fd = fd_new
+ current_form = self.__get_saved_form( fd )
msg = "The form '%s' has been updated with the changes." % fd.name
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
- #Add a field
- elif params.get( 'add_field_button', False ):
- self.__update_current_form( trans, **kwd )
- self.__add_field()
- # show the form again with one empty field
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+ #
# Show form read-only
+ #
elif params.get( 'read_only', False ):
return trans.fill_template( '/admin/forms/show_form_read_only.mako',
form=fd,
msg=msg,
messagetype=messagetype )
- # Refresh page, SelectField is selected/deselected as the type of a field
+ #
+ # Add SelectField option
+ #
+ elif 'Add' in kwd.values():
+ return self.__add_selectbox_option(trans, fd, msg, messagetype, **kwd)
+ #
+ # Remove SelectField option
+ #
+ elif 'Remove' in kwd.values():
+ return self.__remove_selectbox_option(trans, fd, msg, messagetype, **kwd)
+ #
+ # Refresh page
+ #
elif params.get( 'refresh', False ):
- self.__update_current_form( trans, **kwd )
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
- # Remove SelectField option
- elif params.get( 'select_box_options', False ) == 'remove':
- index = int( kwd[ 'field_index' ] )
- option = int( kwd[ 'option_index' ] )
- del self.current_form[ 'fields' ][ index ][ 'selectlist' ][ option ]
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
- # Add SelectField option
- elif params.get( 'select_box_options', False ) == 'add':
- index = int( kwd[ 'field_index' ] )
- self.current_form[ 'fields' ][ index ][ 'selectlist' ].append( '' )
- return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd )
- def __add_layout_grid(self):
- self.current_form['layout'].append('')
- def __remove_layout_grid(self, index):
- del self.current_form['layout'][index]
- def __remove_field(self, index):
- del self.current_form['fields'][index]
- def __add_field(self):
+ current_form = self.__get_form( trans, **kwd )
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+
+ def __add_selectbox_option( self, trans, fd, msg, messagetype, **kwd ):
'''
- add an empty field to the fields list
+ This method adds a selectbox option. The kwd dict searched for
+ the field index which needs to be removed
'''
- empty_field = { 'label': '',
- 'helptext': '',
- 'visible': True,
- 'required': False,
- 'type': BaseField.form_field_types()[0],
- 'selectlist': [],
- 'layout': 'none' }
- self.current_form['fields'].append(empty_field)
+ current_form = self.__get_form( trans, **kwd )
+ index = -1
+ for k, v in kwd.items():
+ if v == 'Add':
+ # extract the field index from the
+ # button name of format: 'addoption_<field>'
+ index = int(k.split('_')[1])
+ break
+ if index == -1:
+ # something wrong happened
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg='Error in adding selectfield option',
+ messagetype='error', **kwd )
+ # add an empty option
+ current_form[ 'fields' ][ index ][ 'selectlist' ].append( '' )
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+ def __remove_selectbox_option( self, trans, fd, msg, messagetype, **kwd ):
+ '''
+ This method removes a selectbox option. The kwd dict searched for
+ the field index and option index which needs to be removed
+ '''
+ current_form = self.__get_form( trans, **kwd )
+ option = -1
+ for k, v in kwd.items():
+ if v == 'Remove':
+ # extract the field & option indices from the
+ # button name of format: 'removeoption_<field>_<option>'
+ index = int(k.split('_')[1])
+ option = int(k.split('_')[2])
+ break
+ if option == -1:
+ # something wrong happened
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg='Error in removing selectfield option',
+ messagetype='error', **kwd )
+ # remove the option
+ del current_form[ 'fields' ][ index ][ 'selectlist' ][ option ]
+ return self.__show( trans=trans, form=fd, current_form=current_form,
+ msg=msg, messagetype=messagetype, **kwd )
+
+
def __get_field(self, index, **kwd):
+ '''
+ This method retrieves all the user-entered details of a field and
+ returns a dict.
+ '''
params = util.Params( kwd )
- #TODO: RC this needs to be handled so that it does not throw an exception.
- # To reproduce, create a new form, click the "add field" button, click the
- # browser back arrow, then click the "add field" button again.
- # You should never attempt to "restore_text()" on a None object...
name = util.restore_text( params.get( 'field_name_%i' % index, '' ) )
helptext = util.restore_text( params.get( 'field_helptext_%i' % index, '' ) )
required = params.get( 'field_required_%i' % index, False )
@@ -266,57 +321,54 @@
else:
return sb_options
def __get_saved_form(self, fd):
- self.current_form = {}
- self.current_form['name'] = fd.name
- self.current_form['desc'] = fd.desc
- self.current_form['type'] = fd.type
- self.current_form['layout'] = list(copy.deepcopy(fd.layout))
- self.current_form['fields'] = list(copy.deepcopy(fd.fields))
- def __validate_form(self, **kwd):
'''
- This method checks the following text inputs are filled out by the user
- - the name of form
- - name of all the fields
+ This retrieves the saved form and returns a dictionary containing the name,
+ desc, type, layout & fields of the form
'''
- params = util.Params( kwd )
- # form name
- if not util.restore_text( params.name ):
- return None, 'Form name must be filled.'
- # form type
- if util.restore_text( params.form_type_selectbox ) == 'none':
- return None, 'Form type must be selected.'
- # fields
-# for i in range( len(self.current_form['fields']) ):
-# if not util.restore_text(params.get( 'field_name_%i' % i, None )):
-# return None, "All the field label(s) must be completed."
- return True, ''
+ return dict(name = fd.name,
+ desc = fd.desc,
+ type = fd.type,
+ layout = list(copy.deepcopy(fd.layout)),
+ fields = list(copy.deepcopy(fd.fields)))
def __get_form(self, trans, **kwd):
+ '''
+ This method gets all the user-entered form details and returns a
+ dictionary containing the name, desc, type, layout & fields of the form
+ '''
params = util.Params( kwd )
name = util.restore_text( params.name )
desc = util.restore_text( params.description ) or ""
form_type = util.restore_text( params.form_type_selectbox )
+ # get the user entered layout grids
layout = []
- if form_type == trans.app.model.FormDefinition.types.SAMPLE:
- for index in range(len(self.current_form[ 'layout' ])):
- layout.append(params.get( 'grid_layout%i' % index, '' ))
+ index = 0
+ while True:
+ grid_name = util.restore_text( params.get( 'grid_layout%i' % index, '' ) )
+ if grid_name:
+ layout.append( grid_name )
+ index = index + 1
+ else:
+ break
+ # for csv file import
csv_file = params.get( 'file_data', '' )
+ fields = []
if csv_file == '':
- # set form fields
- fields = []
- for i in range( len(self.current_form['fields']) ):
- fields.append(self.__get_field(i, **kwd))
+ # get the user entered fields
+ index = 0
+ while True:
+ if params.get( 'field_name_%i' % index, False ):
+ fields.append( self.__get_field( index, **kwd ) )
+ index = index + 1
+ else:
+ break
fields = fields
else:
fields, layout = self.__import_fields(trans, csv_file, form_type)
- return name, desc, form_type, layout, fields
- def __update_current_form(self, trans, **kwd):
- name, desc, form_type, layout, fields = self.__get_form(trans, **kwd)
- self.current_form = {}
- self.current_form['name'] = name
- self.current_form['desc'] = desc
- self.current_form['type'] = form_type
- self.current_form['layout'] = layout
- self.current_form['fields'] = fields
+ return dict(name = name,
+ desc = desc,
+ type = form_type,
+ layout = layout,
+ fields = fields)
def __import_fields(self, trans, csv_file, form_type):
'''
@@ -356,7 +408,20 @@
**kwd))
self.__imported_from_file = True
return fields, list(layouts)
-
+ def __validate_form(self, **kwd):
+ '''
+ This method checks the following text inputs are filled out by the user
+ - the name of form
+ - form type
+ '''
+ params = util.Params( kwd )
+ # form name
+ if not util.restore_text( params.name ):
+ return None, 'Form name must be filled.'
+ # form type
+ if util.restore_text( params.form_type_selectbox ) == 'none':
+ return None, 'Form type must be selected.'
+ return True, ''
def __save_form(self, trans, fdc_id=None, **kwd):
'''
This method saves the current form
@@ -365,13 +430,18 @@
flag, msg = self.__validate_form(**kwd)
if not flag:
return None, msg
- name, desc, form_type, layout, fields = self.__get_form(trans, **kwd)
+ current_form = self.__get_form( trans, **kwd )
# validate fields
- for field in fields:
+ for field in current_form[ 'fields' ]:
if not field[ 'label' ]:
return None, "All the field label(s) must be completed."
- fd = trans.app.model.FormDefinition(name, desc, fields, current_form=None,
- form_type=form_type, layout=layout )
+ # create a new form definition
+ fd = trans.app.model.FormDefinition(name=current_form[ 'name' ],
+ desc=current_form[ 'desc' ],
+ fields=current_form[ 'fields' ],
+ form_definition_current=None,
+ form_type=current_form[ 'type' ],
+ layout=current_form[ 'layout' ] )
if fdc_id: # save changes to the existing form
# change the pointer in the form_definition_current table to point
# to this new record
@@ -467,7 +537,7 @@
def label(self):
return str(self.index)+'.'+self.label
- def __show( self, trans, form, msg='', messagetype='done', **kwd ):
+ def __show( self, trans, form, current_form, msg='', messagetype='done', **kwd ):
'''
This method displays the form and any of the changes made to it,
The empty_form param allows for this method to simulate clicking
@@ -476,18 +546,18 @@
'''
params = util.Params( kwd )
# name & description
- form_details = [ ( 'Name', TextField( 'name', 40, self.current_form[ 'name' ] ) ),
- ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ),
- ( 'Type', self.__form_types_widget(trans, selected=self.current_form['type']) ) ]
+ form_details = [ ( 'Name', TextField( 'name', 40, current_form[ 'name' ] ) ),
+ ( 'Description', TextField( 'description', 40, current_form[ 'desc' ] ) ),
+ ( 'Type', self.__form_types_widget(trans, selected=current_form[ 'type' ]) ) ]
form_layout = []
- if self.current_form['type'] == trans.app.model.FormDefinition.types.SAMPLE:
- for index, lg in enumerate(self.current_form['layout']):
+ if current_form[ 'type' ] == trans.app.model.FormDefinition.types.SAMPLE:
+ for index, lg in enumerate(current_form[ 'layout' ]):
form_layout.append( TextField( 'grid_layout%i' % index, 40, lg ))
# fields
field_details = []
- for index, field in enumerate( self.current_form[ 'fields' ] ):
- if self.current_form['type'] == trans.app.model.FormDefinition.types.SAMPLE:
- field_ui = self.FieldUI( self.current_form['layout'], index, field )
+ for index, field in enumerate( current_form[ 'fields' ] ):
+ if current_form['type'] == trans.app.model.FormDefinition.types.SAMPLE:
+ field_ui = self.FieldUI( current_form['layout'], index, field )
else:
field_ui = self.FieldUI( None, index, field )
field_details.append( field_ui.get() )
@@ -498,7 +568,7 @@
field_types=BaseField.form_field_types(),
msg=msg,
messagetype=messagetype,
- current_form_type=self.current_form['type'],
+ current_form_type=current_form[ 'type' ],
layout_grids=form_layout )
# Common methods for all components that use forms
diff -r b16a6d767e65 -r ca816e66ec69 lib/galaxy/web/controllers/requests.py
--- a/lib/galaxy/web/controllers/requests.py Tue Oct 13 18:15:06 2009 -0400
+++ b/lib/galaxy/web/controllers/requests.py Wed Oct 14 02:22:11 2009 -0400
@@ -115,20 +115,17 @@
status='error',
message="Invalid request ID",
**kwd) )
- self.current_samples = []
- self.edit_mode = False
+ current_samples = []
for s in request.samples:
- self.current_samples.append([s.name, s.values.content])
+ current_samples.append([s.name, s.values.content])
if add_sample:
- self.current_samples.append(['Sample_%i' % (len(self.current_samples)+1),['' for field in request.type.sample_form.fields]])
- self.details_state = 'Show request details'
+ current_samples.append(['Sample_%i' % (len(current_samples)+1),['' for field in request.type.sample_form.fields]])
return trans.fill_template( '/requests/show_request.mako',
request=request,
request_details=self.request_details(trans, id),
- current_samples = self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details='hide', edit_mode='False')
def request_details(self, trans, id):
'''
Shows the request details
@@ -186,25 +183,34 @@
value=request.values.content[index],
helptext=field['helptext']+' ('+req+')'))
return request_details
-
def __update_samples(self, request, **kwd):
+ '''
+ This method retrieves all the user entered sample information and
+ returns an list of all the samples and their field values
+ '''
params = util.Params( kwd )
- num_samples = len(self.current_samples)
- self.current_samples = []
+ current_samples = []
for s in request.samples:
- self.current_samples.append([s.name, s.values.content])
- for index in range(num_samples-len(request.samples)):
- sample_index = index + len(request.samples)
- sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
- sample_values = []
- for field_index in range(len(request.type.sample_form.fields)):
- sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
- self.current_samples.append([sample_name, sample_values])
-
- def __copy_sample(self):
+ current_samples.append([s.name, s.values.content])
+ index = len(request.samples)
+ while True:
+ if params.get( 'sample_%i_name' % index, '' ):
+ sample_index = index
+ sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
+ sample_values = []
+ for field_index in range(len(request.type.sample_form.fields)):
+ sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
+ current_samples.append([sample_name, sample_values])
+ index = index + 1
+ else:
+ break
+ details = params.get( 'details', 'hide' )
+ edit_mode = params.get( 'edit_mode', 'False' )
+ return current_samples, details, edit_mode
+ def __copy_sample(self, current_samples):
copy_list = SelectField('copy_sample')
copy_list.add_option('None', -1, selected=True)
- for i, s in enumerate(self.current_samples):
+ for i, s in enumerate(current_samples):
copy_list.add_option(s[0], i)
return copy_list
@web.expose
@@ -221,20 +227,22 @@
status='error',
message="Invalid request ID",
**kwd) )
+ # get the user entered sample details
+ current_samples, details, edit_mode = self.__update_samples( request, **kwd )
if params.get('import_samples_button', False) == 'Import samples':
try:
file_obj = params.get('file_data', '')
import csv
reader = csv.reader(file_obj.file)
for row in reader:
- self.current_samples.append([row[0], row[1:]])
+ current_samples.append([row[0], row[1:]])
return trans.fill_template( '/requests/show_request.mako',
request=request,
request_details=self.request_details(trans, request.id),
- current_samples=self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
+ current_samples=current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
except:
return trans.response.send_redirect( web.url_for( controller='requests',
action='list',
@@ -242,39 +250,35 @@
message='Error in importing samples file',
**kwd))
elif params.get('add_sample_button', False) == 'Add New':
- # save the all (saved+unsaved) sample info in 'current_samples'
- self.__update_samples(request, **kwd)
# add an empty or filled sample
# if the user has selected a sample no. to copy then copy the contents
# of the src sample to the new sample else an empty sample
src_sample_index = int(params.get( 'copy_sample', -1 ))
if src_sample_index == -1:
# empty sample
- self.current_samples.append(['Sample_%i' % (len(self.current_samples)+1),['' for field in request.type.sample_form.fields]])
+ current_samples.append(['Sample_%i' % (len(current_samples)+1),['' for field in request.type.sample_form.fields]])
else:
- self.current_samples.append([self.current_samples[src_sample_index][0]+'_%i' % (len(self.current_samples)+1),
- [val for val in self.current_samples[src_sample_index][1]]])
+ current_samples.append([current_samples[src_sample_index][0]+'_%i' % (len(current_samples)+1),
+ [val for val in current_samples[src_sample_index][1]]])
return trans.fill_template( '/requests/show_request.mako',
request=request,
request_details=self.request_details(trans, request.id),
- current_samples=self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
+ current_samples=current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
elif params.get('save_samples_button', False) == 'Save':
- # update current_samples
- self.__update_samples(request, **kwd)
# check for duplicate sample names
msg = ''
- for index in range(len(self.current_samples)-len(request.samples)):
+ for index in range(len(current_samples)-len(request.samples)):
sample_index = index + len(request.samples)
- sample_name = self.current_samples[sample_index][0]
+ sample_name = current_samples[sample_index][0]
if not sample_name.strip():
msg = 'Please enter the name of sample number %i' % sample_index
break
count = 0
- for i in range(len(self.current_samples)):
- if sample_name == self.current_samples[i][0]:
+ for i in range(len(current_samples)):
+ if sample_name == current_samples[i][0]:
count = count + 1
if count > 1:
msg = "This request has <b>%i</b> samples with the name <b>%s</b>.\nSamples belonging to a request must have unique names." % (count, sample_name)
@@ -283,12 +287,13 @@
return trans.fill_template( '/requests/show_request.mako',
request=request,
request_details=self.request_details(trans, request.id),
- current_samples = self.current_samples,
- sample_copy=self.__copy_sample(), details_state=self.details_state,
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details, edit_mode=edit_mode,
messagetype='error', msg=msg)
# save all the new/unsaved samples entered by the user
- if not self.edit_mode:
- for index in range(len(self.current_samples)-len(request.samples)):
+ if edit_mode == 'False':
+ for index in range(len(current_samples)-len(request.samples)):
sample_index = index + len(request.samples)
sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
sample_values = []
@@ -299,9 +304,9 @@
s = trans.app.model.Sample(sample_name, '', request, form_values)
s.flush()
else:
- for index in range(len(self.current_samples)):
+ for index in range(len(current_samples)):
sample_index = index
- sample_name = self.current_samples[sample_index][0]
+ sample_name = current_samples[sample_index][0]
new_sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
sample_values = []
for field_index in range(len(request.type.sample_form.fields)):
@@ -318,14 +323,14 @@
operation='show_request',
id=trans.security.encode_id(request.id)) )
elif params.get('edit_samples_button', False) == 'Edit samples':
- self.edit_mode = True
+ edit_mode = 'True'
return trans.fill_template( '/requests/show_request.mako',
request=request,
request_details=self.request_details(trans, request.id),
- current_samples=self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
+ current_samples=current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
elif params.get('cancel_changes_button', False) == 'Cancel':
return trans.response.send_redirect( web.url_for( controller='requests',
action='list',
@@ -340,21 +345,22 @@
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
request = trans.app.model.Request.get(int(params.get('request_id', 0)))
+ current_samples, details, edit_mode = self.__update_samples( request, **kwd )
sample_index = int(params.get('sample_id', 0))
- sample_name = self.current_samples[sample_index][0]
+ sample_name = current_samples[sample_index][0]
s = request.has_sample(sample_name)
if s:
s.delete()
s.flush()
request.flush()
- del self.current_samples[sample_index]
+ del current_samples[sample_index]
return trans.fill_template( '/requests/show_request.mako',
request=request,
request_details=self.request_details(trans, request.id),
- current_samples = self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
@web.expose
@web.require_login( "create/submit sequencing requests" )
@@ -363,17 +369,14 @@
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
request = trans.app.model.Request.get(int(params.get('request_id', 0)))
- if self.details_state == 'Show request details':
- self.details_state = 'Hide request details'
- elif self.details_state == 'Hide request details':
- self.details_state = 'Show request details'
+ current_samples, details, edit_mode = self.__update_samples( request, **kwd )
return trans.fill_template( '/requests/show_request.mako',
request=request,
request_details=self.request_details(trans, request.id),
- current_samples = self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
def __select_request_type(self, trans, rtid):
rt_ids = ['none']
for rt in trans.app.model.RequestType.query().all():
@@ -476,17 +479,22 @@
msg=msg,
messagetype=messagetype)
def __library_ui(self, trans, request=None, **kwd):
+ '''
+ This method creates the data library & folder selectbox for new &
+ editing requests. First we get a list of all the libraries accessible to
+ the current user and display it in a selectbox. If the user has select an
+ existing library then display all the accessible sub folders of the selected
+ data library.
+ '''
params = util.Params( kwd )
lib_id = params.get( 'library_id', 'none' )
- # if editing a request
selected_lib = None
+ # if editing a request and the user has already associated a library to
+ # this request, then set the selected_lib to the request.library
if request and lib_id == 'none':
if request.library:
lib_id = str(request.library.id)
selected_lib = request.library
- else:
- # new request
- selected_lib = None
# get all permitted libraries for this user
all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \
.order_by( trans.app.model.Library.name ).all()
@@ -497,15 +505,16 @@
can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
if can_show:
libraries[ library ] = hidden_folder_ids
+ # create data library selectbox with refresh on change enabled
lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()]
lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list )
- # fill up the options in the Library selectfield
- # first option
+ # fill up the options in the Library selectbox
+ # first option 'none' is the value for "Select one" option
if lib_id == 'none':
lib_list.add_option('Select one', 'none', selected=True)
else:
lib_list.add_option('Select one', 'none')
- # all the libraries available to the user
+ # add all the libraries available to the user to the library selectbox
for lib, hidden_folder_ids in libraries.items():
if str(lib.id) == lib_id:
lib_list.add_option(lib.name, lib.id, selected=True)
@@ -524,14 +533,21 @@
helptext='Data library where the resultant dataset will be stored.')
# show the folder widget only if the user has selected a valid library above
if selected_lib:
- # when editing a request
+ # when editing a request, either the user has already selected a subfolder or not
if request:
if request.folder:
current_fid = request.folder.id
- else:
- current_fid = request.library.root_folder.id
+ else:
+ # when a folder not yet associated with the request then the
+ # the current folder is set to the root_folder of the
+ # parent data library if present.
+ if request.library:
+ current_fid = request.library.root_folder.id
+ else:
+ current_fid = params.get( 'folder_id', 'none' )
else:
current_fid = params.get( 'folder_id', 'none' )
+ # create the folder selectbox
folder_list = SelectField( 'folder_id')
# first option
if lib_id == 'none':
@@ -543,6 +559,7 @@
selected_lib,
actions_to_check,
selected_hidden_folder_ids )
+ # add all the folders to the folder selectbox
for f in showable_folders:
if str(f.id) == str(current_fid):
folder_list.add_option(f.name, f.id, selected=True)
@@ -568,8 +585,6 @@
Validates the request entered by the user
'''
empty_fields = []
-# if not request.library:
-# empty_fields.append('Data library')
# check rest of the fields of the form
for index, field in enumerate(request.type.request_form.fields):
if field['required'] == 'required' and request.values.content[index] in ['', None]:
diff -r b16a6d767e65 -r ca816e66ec69 lib/galaxy/web/controllers/requests_admin.py
--- a/lib/galaxy/web/controllers/requests_admin.py Tue Oct 13 18:15:06 2009 -0400
+++ b/lib/galaxy/web/controllers/requests_admin.py Wed Oct 14 02:22:11 2009 -0400
@@ -10,6 +10,10 @@
from galaxy.web.controllers.forms import get_all_forms
log = logging.getLogger( __name__ )
+
+#
+# ---- Request Grid ------------------------------------------------------------
+#
class RequestsListGrid( grids.Grid ):
title = "Sequencing Requests"
@@ -60,6 +64,11 @@
else:
return query
+
+#
+# ---- Request Controller ------------------------------------------------------
+#
+
class Requests( BaseController ):
request_grid = RequestsListGrid()
@@ -67,6 +76,7 @@
@web.require_admin
def index( self, trans ):
return trans.fill_template( "/admin/requests/index.mako" )
+
@web.expose
@web.require_admin
def list( self, trans, **kwargs ):
@@ -104,51 +114,26 @@
self.request_grid.show_filter = kwargs.get('show_filter', trans.app.model.Request.states.SUBMITTED)
# Render the list view
return self.request_grid( trans, **kwargs )
- @web.expose
- @web.require_admin
- def edit(self, trans, **kwd):
- params = util.Params( kwd )
- msg = util.restore_text( params.get( 'msg', '' ) )
- messagetype = params.get( 'messagetype', 'done' )
+ def __show_request(self, trans, id, messagetype, msg):
try:
- request = trans.app.model.Request.get(int(params.get('request_id', None)))
+ request = trans.app.model.Request.get(id)
except:
return trans.response.send_redirect( web.url_for( controller='requests_admin',
action='list',
status='error',
message="Invalid request ID",
**kwd) )
- if params.get('show', False) == 'True':
- return self.__edit_request(trans, request.id, **kwd)
- elif params.get('save_changes_request_button', False) == 'Save changes' \
- or params.get('edit_samples_button', False) == 'Edit samples':
- request_type = trans.app.model.RequestType.get(int(params.select_request_type))
- if not util.restore_text(params.get('name', '')):
- msg = 'Please enter the <b>Name</b> of the request'
- kwd['messagetype'] = 'error'
- kwd['msg'] = msg
- kwd['show'] = 'True'
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='edit',
- **kwd) )
- request = self.__save_request(trans, request, **kwd)
- msg = 'The changes made to the request named %s has been saved' % request.name
- if params.get('save_changes_request_button', False) == 'Save changes':
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- message=msg ,
- status='done') )
- elif params.get('edit_samples_button', False) == 'Edit samples':
- new_kwd = {}
- new_kwd['request_id'] = request.id
- new_kwd['edit_samples_button'] = 'Edit samples'
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='show_request',
- msg=msg ,
- messagetype='done',
- **new_kwd) )
- elif params.get('refresh', False) == 'true':
- return self.__edit_request(trans, request.id, **kwd)
+ current_samples = []
+ for s in request.samples:
+ current_samples.append([s.name, s.values.content])
+ return trans.fill_template( '/admin/requests/show_request.mako',
+ request=request,
+ request_details=self.request_details(trans, id),
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details='hide', edit_mode='False',
+ msg=msg, messagetype=messagetype)
+
def __edit_request(self, trans, id, **kwd):
try:
request = trans.app.model.Request.get(id)
@@ -276,317 +261,10 @@
action='list',
show_filter=trans.app.model.Request.states.SUBMITTED,
**kwd) )
- @web.expose
- @web.require_admin
- def submit_request(self, trans, **kwd):
- params = util.Params( kwd )
- try:
- id = int(params.get('id', False))
- request = trans.app.model.Request.get(id)
- except:
- msg = "Invalid request ID"
- log.warn( msg )
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- status='error',
- message=msg,
- **kwd) )
- msg = self.__validate(trans, request)
- if msg:
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='edit',
- messagetype='error',
- msg=msg,
- request_id=request.id,
- show='True') )
- # get the new state
- new_state = request.type.states[0]
- for s in request.samples:
- event = trans.app.model.SampleEvent(s, new_state, 'Samples submitted to the system')
- event.flush()
- # change request's submitted field
- request.state = request.states.SUBMITTED
- request.flush()
- kwd['id'] = trans.security.encode_id(request.id)
- kwd['status'] = 'done'
- kwd['message'] = 'The request <b>%s</b> has been submitted.' % request.name
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- show_filter=trans.app.model.Request.states.SUBMITTED,
- **kwd) )
- def __copy_sample(self):
- copy_list = SelectField('copy_sample')
- copy_list.add_option('None', -1, selected=True)
- for i, s in enumerate(self.current_samples):
- copy_list.add_option(s[0], i)
- return copy_list
- def __update_samples(self, request, **kwd):
- params = util.Params( kwd )
- num_samples = len(self.current_samples)
- self.current_samples = []
- for s in request.samples:
- self.current_samples.append([s.name, s.values.content])
- for index in range(num_samples-len(request.samples)):
- sample_index = index + len(request.samples)
- sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
- sample_values = []
- for field_index in range(len(request.type.sample_form.fields)):
- sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
- self.current_samples.append([sample_name, sample_values])
- def __show_request(self, trans, id, messagetype, msg):
- try:
- request = trans.app.model.Request.get(id)
- except:
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- status='error',
- message="Invalid request ID",
- **kwd) )
- self.current_samples = []
- self.edit_mode = False
- for s in request.samples:
- self.current_samples.append([s.name, s.values.content])
- self.details_state = 'Show request details'
- return trans.fill_template( '/admin/requests/show_request.mako',
- request=request,
- request_details=self.request_details(trans, id),
- current_samples = self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode,
- msg=msg, messagetype=messagetype)
- @web.expose
- @web.require_admin
- def show_request(self, trans, **kwd):
- params = util.Params( kwd )
- msg = util.restore_text( params.get( 'msg', '' ) )
- messagetype = params.get( 'messagetype', 'done' )
- try:
- request = trans.app.model.Request.get(int(params.get('request_id', None)))
- except:
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- status='error',
- message="Invalid request ID",
- **kwd) )
- if params.get('import_samples_button', False) == 'Import samples':
- try:
- file_obj = params.get('file_data', '')
- import csv
- reader = csv.reader(file_obj.file)
- for row in reader:
- self.current_samples.append([row[0], row[1:]])
- return trans.fill_template( '/admin/requests/show_request.mako',
- request=request,
- request_details=self.request_details(trans, request.id),
- current_samples=self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
- except:
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- status='error',
- operation='show_request',
- id=trans.security.encode_id(request.id),
- message='Error in importing samples from the given file.',
- **kwd))
- elif params.get('add_sample_button', False) == 'Add New':
- # save the all (saved+unsaved) sample info in 'current_samples'
- self.__update_samples(request, **kwd)
- # add an empty or filled sample
- # if the user has selected a sample no. to copy then copy the contents
- # of the src sample to the new sample else an empty sample
- src_sample_index = int(params.get( 'copy_sample', -1 ))
- if src_sample_index == -1:
- # empty sample
- self.current_samples.append(['Sample_%i' % (len(self.current_samples)+1),['' for field in request.type.sample_form.fields]])
- else:
- self.current_samples.append([self.current_samples[src_sample_index][0]+'_%i' % (len(self.current_samples)+1),
- [val for val in self.current_samples[src_sample_index][1]]])
- return trans.fill_template( '/admin/requests/show_request.mako',
- request=request,
- request_details=self.request_details(trans, request.id),
- current_samples=self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
- elif params.get('save_samples_button', False) == 'Save':
- # update current_samples
- self.__update_samples(request, **kwd)
- # check for duplicate sample names
- msg = ''
- for index in range(len(self.current_samples)-len(request.samples)):
- sample_index = index + len(request.samples)
- sample_name = self.current_samples[sample_index][0]
- if not sample_name.strip():
- msg = 'Please enter the name of sample number %i' % sample_index
- break
- count = 0
- for i in range(len(self.current_samples)):
- if sample_name == self.current_samples[i][0]:
- count = count + 1
- if count > 1:
- msg = "This request has <b>%i</b> samples with the name <b>%s</b>.\nSamples belonging to a request must have unique names." % (count, sample_name)
- break
- if msg:
- return trans.fill_template( '/admin/requests/show_request.mako',
- request=request,
- request_details=self.request_details(trans, request.id),
- current_samples = self.current_samples,
- sample_copy=self.__copy_sample(), details_state=self.details_state,
- messagetype='error', msg=msg)
- # save all the new/unsaved samples entered by the user
- if not self.edit_mode:
- for index in range(len(self.current_samples)-len(request.samples)):
- sample_index = index + len(request.samples)
- sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
- sample_values = []
- for field_index in range(len(request.type.sample_form.fields)):
- sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
- form_values = trans.app.model.FormValues(request.type.sample_form, sample_values)
- form_values.flush()
- s = trans.app.model.Sample(sample_name, '', request, form_values)
- s.flush()
- else:
- for index in range(len(self.current_samples)):
- sample_index = index
- sample_name = self.current_samples[sample_index][0]
- new_sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
- sample_values = []
- for field_index in range(len(request.type.sample_form.fields)):
- sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
- sample = request.has_sample(sample_name)
- if sample:
- form_values = trans.app.model.FormValues.get(sample.values.id)
- form_values.content = sample_values
- form_values.flush()
- sample.name = new_sample_name
- sample.flush()
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- operation='show_request',
- id=trans.security.encode_id(request.id)) )
- elif params.get('edit_samples_button', False) == 'Edit samples':
- self.edit_mode = True
- return trans.fill_template( '/admin/requests/show_request.mako',
- request=request,
- request_details=self.request_details(trans, request.id),
- current_samples=self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
- elif params.get('cancel_changes_button', False) == 'Cancel':
- return trans.response.send_redirect( web.url_for( controller='requests_admin',
- action='list',
- operation='show_request',
- id=trans.security.encode_id(request.id)) )
-
- @web.expose
- @web.require_admin
- def delete_sample(self, trans, **kwd):
- params = util.Params( kwd )
- msg = util.restore_text( params.get( 'msg', '' ) )
- messagetype = params.get( 'messagetype', 'done' )
- request = trans.app.model.Request.get(int(params.get('request_id', 0)))
- sample_index = int(params.get('sample_id', 0))
- sample_name = self.current_samples[sample_index][0]
- s = request.has_sample(sample_name)
- if s:
- s.delete()
- s.flush()
- request.flush()
- del self.current_samples[sample_index]
- return trans.fill_template( '/admin/requests/show_request.mako',
- request=request,
- request_details=self.request_details(trans, request.id),
- current_samples = self.current_samples,
- sample_copy=self.__copy_sample(),
- details_state=self.details_state,
- edit_mode=self.edit_mode)
-
- @web.expose
- @web.require_admin
- def toggle_request_details(self, trans, **kwd):
- params = util.Params( kwd )
- msg = util.restore_text( params.get( 'msg', '' ) )
- messagetype = params.get( 'messagetype', 'done' )
- request = trans.app.model.Request.get(int(params.get('request_id', 0)))
- if self.details_state == 'Show request details':
- self.details_state = 'Hide request details'
- elif self.details_state == 'Hide request details':
- self.details_state = 'Show request details'
- copy_list = SelectField('copy_sample')
- copy_list.add_option('None', -1, selected=True)
- for i, s in enumerate(self.current_samples):
- copy_list.add_option(i+1, i)
- return trans.fill_template( '/admin/requests/show_request.mako',
- request=request,
- request_details=self.request_details(trans, request.id),
- current_samples = self.current_samples,
- sample_copy=copy_list, details_state=self.details_state)
- def request_details(self, trans, id):
- '''
- Shows the request details
- '''
- request = trans.app.model.Request.get(id)
- # list of widgets to be rendered on the request form
- request_details = []
- # main details
- request_details.append(dict(label='User',
- value=str(request.user.email),
- helptext=''))
- request_details.append(dict(label='Description',
- value=request.desc,
- helptext=''))
- request_details.append(dict(label='Type',
- value=request.type.name,
- helptext=''))
- request_details.append(dict(label='State',
- value=request.state,
- helptext=''))
- request_details.append(dict(label='Date created',
- value=request.create_time,
- helptext=''))
- # library associated
- if request.library:
- value=request.library.name
- else:
- value = None
- request_details.append(dict(label='Data library',
- value=value,
- helptext='Data library where the resultant dataset will be stored'))
- # folder associated
- if request.folder:
- value = request.folder.name
- else:
- value = None
- request_details.append( dict( label='Data library folder',
- value=value,
- helptext='Data library folder where the resultant dataset will be stored' ) )
-
- # form fields
- for index, field in enumerate(request.type.request_form.fields):
- if field['required']:
- req = 'Required'
- else:
- req = 'Optional'
- if field['type'] == 'AddressField':
- if request.values.content[index]:
- request_details.append(dict(label=field['label'],
- value=trans.app.model.UserAddress.get(int(request.values.content[index])).get_html(),
- helptext=field['helptext']+' ('+req+')'))
- else:
- request_details.append(dict(label=field['label'],
- value=None,
- helptext=field['helptext']+' ('+req+')'))
- else:
- request_details.append(dict(label=field['label'],
- value=request.values.content[index],
- helptext=field['helptext']+' ('+req+')'))
- return request_details
-
+#
+#---- Request Creation ----------------------------------------------------------
+#
def __select_request_type(self, trans, rtid):
rt_ids = ['none']
for rt in trans.app.model.RequestType.query().all():
@@ -723,21 +401,22 @@
return select_user
def __library_ui(self, trans, user, request=None, **kwd):
- """
- Return a list of libraries for which user has the permission
- to perform the LIBRARY_ADD action on any of it's folders
- """
+ '''
+ This method creates the data library & folder selectbox for new &
+ editing requests. First we get a list of all the libraries accessible to
+ the current user and display it in a selectbox. If the user has select an
+ existing library then display all the accessible sub folders of the selected
+ data library.
+ '''
params = util.Params( kwd )
lib_id = params.get( 'library_id', 'none' )
- # if editing a request
+ # if editing a request and the user has already associated a library to
+ # this request, then set the selected_lib to the request.library
selected_lib = None
if request and lib_id == 'none':
if request.library:
lib_id = str(request.library.id)
selected_lib = request.library
- else:
- # new request
- selected_lib = None
# if new request no user is selected initially, none of the libraries are
# listed in the selectfield
if not user:
@@ -759,10 +438,11 @@
can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
if can_show:
libraries[ library ] = hidden_folder_ids
- # create the selectfield
+ # create data library selectbox with refresh on change enabled
lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()]
lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list )
- # first option
+ # fill up the options in the Library selectbox
+ # first option 'none' is the value for "Select one" option
if lib_id == 'none':
lib_list.add_option('Select one', 'none', selected=True)
else:
@@ -784,15 +464,23 @@
lib_widget = dict(label='Data library',
widget=lib_list,
helptext='Data library where the resultant dataset will be stored.')
+ # show the folder widget only if the user has selected a valid library above
if selected_lib:
- # when editing a request
+ # when editing a request, either the user has already selected a subfolder or not
if request:
if request.folder:
current_fid = request.folder.id
- else:
- current_fid = request.library.root_folder.id
+ else:
+ # when a folder not yet associated with the request then the
+ # the current folder is set to the root_folder of the
+ # parent data library if present.
+ if request.library:
+ current_fid = request.library.root_folder.id
+ else:
+ current_fid = params.get( 'folder_id', 'none' )
else:
current_fid = params.get( 'folder_id', 'none' )
+ # create the folder selectbox
folder_list = SelectField( 'folder_id')
# first option
if lib_id == 'none':
@@ -828,9 +516,14 @@
'''
Validates the request entered by the user
'''
+ if not request.samples:
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ operation='show_request',
+ message='Please add one or more samples to this request before submitting.',
+ status='error',
+ id=trans.security.encode_id(request.id)) )
empty_fields = []
-# if not request.library:
-# empty_fields.append('Library')
# check rest of the fields of the form
for index, field in enumerate(request.type.request_form.fields):
if field['required'] == 'required' and request.values.content[index] in ['', None]:
@@ -909,6 +602,350 @@
request.folder = folder
request.flush()
return request
+
+
+#
+#---- Request Editing ----------------------------------------------------------
+#
+ @web.expose
+ @web.require_admin
+ def edit(self, trans, **kwd):
+ params = util.Params( kwd )
+ msg = util.restore_text( params.get( 'msg', '' ) )
+ messagetype = params.get( 'messagetype', 'done' )
+ try:
+ request = trans.app.model.Request.get(int(params.get('request_id', None)))
+ except:
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ status='error',
+ message="Invalid request ID",
+ **kwd) )
+ if params.get('show', False) == 'True':
+ return self.__edit_request(trans, request.id, **kwd)
+ elif params.get('save_changes_request_button', False) == 'Save changes' \
+ or params.get('edit_samples_button', False) == 'Edit samples':
+ request_type = trans.app.model.RequestType.get(int(params.select_request_type))
+ if not util.restore_text(params.get('name', '')):
+ msg = 'Please enter the <b>Name</b> of the request'
+ kwd['messagetype'] = 'error'
+ kwd['msg'] = msg
+ kwd['show'] = 'True'
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='edit',
+ **kwd) )
+ request = self.__save_request(trans, request, **kwd)
+ msg = 'The changes made to the request named %s has been saved' % request.name
+ if params.get('save_changes_request_button', False) == 'Save changes':
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ message=msg ,
+ status='done') )
+ elif params.get('edit_samples_button', False) == 'Edit samples':
+ new_kwd = {}
+ new_kwd['request_id'] = request.id
+ new_kwd['edit_samples_button'] = 'Edit samples'
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='show_request',
+ msg=msg ,
+ messagetype='done',
+ **new_kwd) )
+ elif params.get('refresh', False) == 'true':
+ return self.__edit_request(trans, request.id, **kwd)
+ @web.expose
+ @web.require_admin
+ def submit_request(self, trans, **kwd):
+ params = util.Params( kwd )
+ try:
+ id = int(params.get('id', False))
+ request = trans.app.model.Request.get(id)
+ except:
+ msg = "Invalid request ID"
+ log.warn( msg )
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ status='error',
+ message=msg,
+ **kwd) )
+ msg = self.__validate(trans, request)
+ if msg:
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='edit',
+ messagetype='error',
+ msg=msg,
+ request_id=request.id,
+ show='True') )
+ # get the new state
+ new_state = request.type.states[0]
+ for s in request.samples:
+ event = trans.app.model.SampleEvent(s, new_state, 'Samples submitted to the system')
+ event.flush()
+ # change request's submitted field
+ request.state = request.states.SUBMITTED
+ request.flush()
+ kwd['id'] = trans.security.encode_id(request.id)
+ kwd['status'] = 'done'
+ kwd['message'] = 'The request <b>%s</b> has been submitted.' % request.name
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ show_filter=trans.app.model.Request.states.SUBMITTED,
+ **kwd) )
+ def __update_samples(self, request, **kwd):
+ '''
+ This method retrieves all the user entered sample information and
+ returns an list of all the samples and their field values
+ '''
+ params = util.Params( kwd )
+ current_samples = []
+ for s in request.samples:
+ current_samples.append([s.name, s.values.content])
+ index = len(request.samples)
+ while True:
+ if params.get( 'sample_%i_name' % index, '' ):
+ sample_index = index
+ sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
+ sample_values = []
+ for field_index in range(len(request.type.sample_form.fields)):
+ sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
+ current_samples.append([sample_name, sample_values])
+ index = index + 1
+ else:
+ break
+ details = params.get( 'details', 'hide' )
+ edit_mode = params.get( 'edit_mode', 'False' )
+ return current_samples, details, edit_mode
+ def __copy_sample(self, current_samples):
+ copy_list = SelectField('copy_sample')
+ copy_list.add_option('None', -1, selected=True)
+ for i, s in enumerate(current_samples):
+ copy_list.add_option(s[0], i)
+ return copy_list
+ @web.expose
+ @web.require_login( "create/submit sequencing requests" )
+ def show_request(self, trans, **kwd):
+ params = util.Params( kwd )
+ msg = util.restore_text( params.get( 'msg', '' ) )
+ messagetype = params.get( 'messagetype', 'done' )
+ try:
+ request = trans.app.model.Request.get(int(params.get('request_id', None)))
+ except:
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ status='error',
+ message="Invalid request ID",
+ **kwd) )
+ # get the user entered sample details
+ current_samples, details, edit_mode = self.__update_samples( request, **kwd )
+ if params.get('import_samples_button', False) == 'Import samples':
+ try:
+ file_obj = params.get('file_data', '')
+ import csv
+ reader = csv.reader(file_obj.file)
+ for row in reader:
+ current_samples.append([row[0], row[1:]])
+ return trans.fill_template( '/admin/requests/show_request.mako',
+ request=request,
+ request_details=self.request_details(trans, request.id),
+ current_samples=current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
+ except:
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ status='error',
+ message='Error in importing samples file',
+ **kwd))
+ elif params.get('add_sample_button', False) == 'Add New':
+ # add an empty or filled sample
+ # if the user has selected a sample no. to copy then copy the contents
+ # of the src sample to the new sample else an empty sample
+ src_sample_index = int(params.get( 'copy_sample', -1 ))
+ if src_sample_index == -1:
+ # empty sample
+ current_samples.append(['Sample_%i' % (len(current_samples)+1),['' for field in request.type.sample_form.fields]])
+ else:
+ current_samples.append([current_samples[src_sample_index][0]+'_%i' % (len(current_samples)+1),
+ [val for val in current_samples[src_sample_index][1]]])
+ return trans.fill_template( '/admin/requests/show_request.mako',
+ request=request,
+ request_details=self.request_details(trans, request.id),
+ current_samples=current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
+ elif params.get('save_samples_button', False) == 'Save':
+ # check for duplicate sample names
+ msg = ''
+ for index in range(len(current_samples)-len(request.samples)):
+ sample_index = index + len(request.samples)
+ sample_name = current_samples[sample_index][0]
+ if not sample_name.strip():
+ msg = 'Please enter the name of sample number %i' % sample_index
+ break
+ count = 0
+ for i in range(len(current_samples)):
+ if sample_name == current_samples[i][0]:
+ count = count + 1
+ if count > 1:
+ msg = "This request has <b>%i</b> samples with the name <b>%s</b>.\nSamples belonging to a request must have unique names." % (count, sample_name)
+ break
+ if msg:
+ return trans.fill_template( '/admin/requests/show_request.mako',
+ request=request,
+ request_details=self.request_details(trans, request.id),
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details, edit_mode=edit_mode,
+ messagetype='error', msg=msg)
+ # save all the new/unsaved samples entered by the user
+ if edit_mode == 'False':
+ for index in range(len(current_samples)-len(request.samples)):
+ sample_index = index + len(request.samples)
+ sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
+ sample_values = []
+ for field_index in range(len(request.type.sample_form.fields)):
+ sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
+ form_values = trans.app.model.FormValues(request.type.sample_form, sample_values)
+ form_values.flush()
+ s = trans.app.model.Sample(sample_name, '', request, form_values)
+ s.flush()
+ else:
+ for index in range(len(current_samples)):
+ sample_index = index
+ sample_name = current_samples[sample_index][0]
+ new_sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) )
+ sample_values = []
+ for field_index in range(len(request.type.sample_form.fields)):
+ sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) ))
+ sample = request.has_sample(sample_name)
+ if sample:
+ form_values = trans.app.model.FormValues.get(sample.values.id)
+ form_values.content = sample_values
+ form_values.flush()
+ sample.name = new_sample_name
+ sample.flush()
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ operation='show_request',
+ id=trans.security.encode_id(request.id)) )
+ elif params.get('edit_samples_button', False) == 'Edit samples':
+ edit_mode = 'True'
+ return trans.fill_template( '/admin/requests/show_request.mako',
+ request=request,
+ request_details=self.request_details(trans, request.id),
+ current_samples=current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
+ elif params.get('cancel_changes_button', False) == 'Cancel':
+ return trans.response.send_redirect( web.url_for( controller='requests_admin',
+ action='list',
+ operation='show_request',
+ id=trans.security.encode_id(request.id)) )
+
+
+ @web.expose
+ @web.require_login( "create/submit sequencing requests" )
+ def delete_sample(self, trans, **kwd):
+ params = util.Params( kwd )
+ msg = util.restore_text( params.get( 'msg', '' ) )
+ messagetype = params.get( 'messagetype', 'done' )
+ request = trans.app.model.Request.get(int(params.get('request_id', 0)))
+ current_samples, details, edit_mode = self.__update_samples( request, **kwd )
+ sample_index = int(params.get('sample_id', 0))
+ sample_name = current_samples[sample_index][0]
+ s = request.has_sample(sample_name)
+ if s:
+ s.delete()
+ s.flush()
+ request.flush()
+ del current_samples[sample_index]
+ return trans.fill_template( '/admin/requests/show_request.mako',
+ request=request,
+ request_details=self.request_details(trans, request.id),
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
+
+ @web.expose
+ @web.require_login( "create/submit sequencing requests" )
+ def toggle_request_details(self, trans, **kwd):
+ params = util.Params( kwd )
+ msg = util.restore_text( params.get( 'msg', '' ) )
+ messagetype = params.get( 'messagetype', 'done' )
+ request = trans.app.model.Request.get(int(params.get('request_id', 0)))
+ current_samples, details, edit_mode = self.__update_samples( request, **kwd )
+ return trans.fill_template( '/admin/requests/show_request.mako',
+ request=request,
+ request_details=self.request_details(trans, request.id),
+ current_samples = current_samples,
+ sample_copy=self.__copy_sample(current_samples),
+ details=details,
+ edit_mode=edit_mode)
+ @web.expose
+ @web.require_admin
+ def request_details(self, trans, id):
+ '''
+ Shows the request details
+ '''
+ request = trans.app.model.Request.get(id)
+ # list of widgets to be rendered on the request form
+ request_details = []
+ # main details
+ request_details.append(dict(label='User',
+ value=str(request.user.email),
+ helptext=''))
+ request_details.append(dict(label='Description',
+ value=request.desc,
+ helptext=''))
+ request_details.append(dict(label='Type',
+ value=request.type.name,
+ helptext=''))
+ request_details.append(dict(label='State',
+ value=request.state,
+ helptext=''))
+ request_details.append(dict(label='Date created',
+ value=request.create_time,
+ helptext=''))
+ # library associated
+ if request.library:
+ value=request.library.name
+ else:
+ value = None
+ request_details.append(dict(label='Data library',
+ value=value,
+ helptext='Data library where the resultant dataset will be stored'))
+ # folder associated
+ if request.folder:
+ value = request.folder.name
+ else:
+ value = None
+ request_details.append( dict( label='Data library folder',
+ value=value,
+ helptext='Data library folder where the resultant dataset will be stored' ) )
+
+ # form fields
+ for index, field in enumerate(request.type.request_form.fields):
+ if field['required']:
+ req = 'Required'
+ else:
+ req = 'Optional'
+ if field['type'] == 'AddressField':
+ if request.values.content[index]:
+ request_details.append(dict(label=field['label'],
+ value=trans.app.model.UserAddress.get(int(request.values.content[index])).get_html(),
+ helptext=field['helptext']+' ('+req+')'))
+ else:
+ request_details.append(dict(label=field['label'],
+ value=None,
+ helptext=field['helptext']+' ('+req+')'))
+ else:
+ request_details.append(dict(label=field['label'],
+ value=request.values.content[index],
+ helptext=field['helptext']+' ('+req+')'))
+ return request_details
@web.expose
@web.require_admin
def bar_codes(self, trans, **kwd):
@@ -1086,7 +1123,9 @@
events_list=events_list,
sample=sample, widgets=widgets, title=title)
- # Request Type Stuff
+##
+#### Request Type Stuff ###################################################
+##
@web.expose
@web.require_admin
def manage_request_types( self, trans, **kwd ):
diff -r b16a6d767e65 -r ca816e66ec69 lib/galaxy/web/framework/__init__.py
--- a/lib/galaxy/web/framework/__init__.py Tue Oct 13 18:15:06 2009 -0400
+++ b/lib/galaxy/web/framework/__init__.py Wed Oct 14 02:22:11 2009 -0400
@@ -635,7 +635,7 @@
return None
def request_types(self):
- if self.app.model.RequestType.query().all():
+ if self.app.model.RequestType.query().filter_by(deleted=False).all():
return True
return False
diff -r b16a6d767e65 -r ca816e66ec69 templates/admin/forms/edit_form.mako
--- a/templates/admin/forms/edit_form.mako Tue Oct 13 18:15:06 2009 -0400
+++ b/templates/admin/forms/edit_form.mako Wed Oct 14 02:22:11 2009 -0400
@@ -36,16 +36,20 @@
<% options = field_attr[2] %>
<div class="repeat-group-item">
<div class="form-row">
- <label> Options</label>
- %for i, option in enumerate(options):
- <b> ${i+1}</b>
- ${option[1].get_html()}
- <a class="action-button" href="${h.url_for( controller='forms', action='edit', form_id=form.id, select_box_options='remove', field_index=index, option_index=i )}">Remove</a><br>
- %endfor
+ <label> Options</label>
+ %for i, option in enumerate(options):
+ <div class="form-row">
+ <b> ${i+1}</b>
+ ${option[1].get_html()}
+ ##<a class="action-button" href="${h.url_for( controller='forms', action='edit', form_id=form.id, select_box_options='remove', field_index=index, option_index=i )}">Remove</a><br>
+ <input type="submit" name="removeoption_${index}_${i}" value="Remove"/>
+ </div>
+ %endfor
+ <input type="hidden" name="field_index" value="${index}"/>
</div>
</div>
<div class="form-row">
- <a class="action-button" href="${h.url_for( controller='forms', action='edit', form_id=form.id, select_box_options='add', field_index=index )}">Add</a>
+ <input type="submit" name="addoption_${index}" value="Add"/>
</div>
%endif
%endif
@@ -81,7 +85,7 @@
<div class="toolForm">
<div class="toolFormTitle">Edit form definition "${form.name}"</div>
- <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='edit', form_id=form.id, num_fields=len(form.fields) )}" method="post" >
+ <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='edit', form_id=form.id )}" method="post" >
%for label, input in form_details:
<div class="form-row">
<label>${label}</label>
diff -r b16a6d767e65 -r ca816e66ec69 templates/admin/forms/show_form_read_only.mako
--- a/templates/admin/forms/show_form_read_only.mako Tue Oct 13 18:15:06 2009 -0400
+++ b/templates/admin/forms/show_form_read_only.mako Wed Oct 14 02:22:11 2009 -0400
@@ -63,9 +63,19 @@
<div class="toolForm">
%if form.desc:
- <div class="toolFormTitle">${form.name} - <i>${form.desc}</i></div>
+ <div class="toolFormTitle">${form.name} - <i>${form.desc}</i>
+ <a id="form-${form.id}-popup" class="popup-arrow" style="display: none;">▼</a>
+ <div popupmenu="form-${form.id}-popup">
+ <a class="action-button" href="${h.url_for( action='edit', form_id=form.id, show_form=True )}">Edit</a>
+ </div>
+ </div>
%else:
- <div class="toolFormTitle">${form.name}</div>
+ <div class="toolFormTitle">${form.name}
+ <a id="form-${form.id}-popup" class="popup-arrow" style="display: none;">▼</a>
+ <div popupmenu="form-${form.id}-popup">
+ <a class="action-button" href="${h.url_for( action='edit', form_id=form.id, show_form=True )}">Edit</a>
+ </div>
+ </div>
%endif
<form name="library" action="${h.url_for( controller='forms', action='manage' )}" method="post" >
%if form.type == trans.app.model.FormDefinition.types.SAMPLE:
@@ -77,58 +87,27 @@
%endfor
%endif
%else:
- <table class = "grid">
- <tbody>
- %for index, field in enumerate(form.fields):
- <tr>
- <td>
- <div class="form-row">
- <label>${1+index}. Label</label>
- <a>${field['label']}</a>
- %if field['type'] == 'SelectField':
- <a id="${field['label']}-popup" class="popup-arrow" style="display: none;">▼</a>
- %for option in field['selectlist']:
- <div popupmenu="${field['label']}-type-popup">
- <a class="action-button" href="" >${option}</a>
- </div>
- %endfor
- %endif
- </div>
- </td>
- <td>
- <div class="form-row">
- <label>Help text </label>
- %if not field['helptext']:
- <a><i>No helptext</i></a>
- %else:
- <a>${field['helptext']}</a>
- %endif
- </div>
- </td>
- <td>
- <div class="form-row">
- <label>Type:</label>
- <a>${field['type']}</a>
- %if field['type'] == 'SelectField':
- <a id="fieldtype-popup" class="popup-arrow" style="display: none;">▼</a>
- %for option in field['selectlist']:
- <div popupmenu="type-popup">
- <a class="action-button" href="" >${option}</a>
- </div>
- %endfor
- %endif
- </div>
- </td>
- <td>
- <div class="form-row">
- <label>Required?</label>
- <a>${field['required']}</a>
- </div>
- </td>
- </tr>
- %endfor
- </tbody>
- </table>
+ %for index, field in enumerate(form.fields):
+ <div class="form-row">
+ <label>${field['label']}</label>
+ %if field['helptext']:
+ <div class="toolParamHelp" style="clear: both;">
+ <i>${field['helptext']}</i>
+ </div>
+ %endif
+ <div>${field['required']}</div>
+ <i>Type: </i> ${field['type']}
+ %if field['type'] == 'SelectField':
+ <div>
+ <div><i>Options:</i></div>
+ %for option in field['selectlist']:
+ <div>${option}</div>
+ %endfor
+ </div>
+ %endif
+ </div>
+ <div style="clear: both"></div>
+ %endfor
%endif
</form>
</div>
diff -r b16a6d767e65 -r ca816e66ec69 templates/admin/requests/show_request.mako
--- a/templates/admin/requests/show_request.mako Tue Oct 13 18:15:06 2009 -0400
+++ b/templates/admin/requests/show_request.mako Wed Oct 14 02:22:11 2009 -0400
@@ -58,6 +58,8 @@
</select>
%elif field['type'] == 'CheckboxField':
<input type="checkbox" name="sample_${index}_field_${field_index}" value="Yes"/>
+ %elif field['type'] == 'NumberField':
+ <input type=int name="sample_${index}_field_${field_index}" value="${sample_values[field_index]}" size="7"/>
%endif
<div class="toolParamHelp" style="clear: both;">
<i>${'('+field['required']+')' }</i>
@@ -91,35 +93,41 @@
</%def>
<div class="toolForm">
- <div class="form-row">
- <a href="${h.url_for( controller='requests_admin', action='toggle_request_details', request_id=request.id )}">${details_state}</a>
- </div>
- %if details_state == "Hide request details":
- %for index, rd in enumerate(request_details):
+ <div class="form-row">
+ %if details == "show":
+ <a href="${h.url_for( controller='requests_admin', action='toggle_request_details', request_id=request.id, details="hide" )}">Hide request details</a>
+ </div>
+ %for index, rd in enumerate(request_details):
+ <div class="form-row">
+ <label>${rd['label']}</label>
+ %if not rd['value']:
+ <i>None</i>
+ %else:
+ %if rd['label'] == 'Data library':
+ %if rd['value']:
+ <a href="${h.url_for( controller='library', action='browse_library', obj_id=request.library.id )}">${rd['value']}</a>
+ %else:
+ <i>None</i>
+ %endif
+ %else:
+ ${rd['value']}
+ %endif
+ %endif
+ </div>
+ <div style="clear: both"></div>
+ %endfor
<div class="form-row">
- <label>${rd['label']}</label>
- %if not rd['value']:
- <i>None</i>
- %else:
- %if rd['label'] == 'Data library':
- <a href="${h.url_for( controller='library_admin', action='browse_library', obj_id=request.library.id )}">${rd['value']}</a>
- %else:
- ${rd['value']}
- %endif
- %endif
- </div>
- <div style="clear: both"></div>
- %endfor
- <div class="form-row">
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller='requests_admin', action='edit', show=True, request_id=request.id)}">
<span>Edit request details</span></a>
</li>
</ul>
+ </div>
</div>
+ %else:
+ <a href="${h.url_for( controller='requests_admin', action='toggle_request_details', request_id=request.id, details="show" )}">Show request details</a>
%endif
- </div>
</div>
<%def name="render_grid( grid_index, grid_name, fields_dict )">
@@ -151,13 +159,13 @@
request.refresh()
%>
%for sample_index, sample in enumerate(current_samples):
- %if edit_mode:
+ %if edit_mode == 'True':
<tr>
<td>${sample_index+1}</td>
${render_sample_form( sample_index, sample[0], sample[1], grid_index, fields_dict)}
<td>
%if request.unsubmitted() and grid_index == 0:
- <a class="action-button" href="${h.url_for( controller='requests', action='delete_sample', request_id=request.id, sample_id=sample_index)}">
+ <a class="action-button" href="${h.url_for( controller='requests_admin', action='delete_sample', request_id=request.id, sample_id=sample_index)}">
<img src="${h.url_for('/static/images/delete_icon.png')}" />
<span></span></a>
%endif
@@ -173,7 +181,7 @@
%endif
<td>
%if request.unsubmitted() and grid_index == 0:
- <a class="action-button" href="${h.url_for( controller='requests', action='delete_sample', request_id=request.id, sample_id=sample_index)}">
+ <a class="action-button" href="${h.url_for( controller='requests_admin', action='delete_sample', request_id=request.id, sample_id=sample_index)}">
<img src="${h.url_for('/static/images/delete_icon.png')}" />
<span></span></a>
%endif
@@ -201,7 +209,7 @@
<label>There are no samples.</label>
%endif
</div>
- %if not edit_mode:
+ %if edit_mode == 'False':
<table class="grid">
<tbody>
<tr>
@@ -238,7 +246,7 @@
<div style="clear: both"></div>
</div>
<div class="form-row">
- %if edit_mode:
+ %if edit_mode == 'True':
<input type="submit" name="save_samples_button" value="Save"/>
<input type="submit" name="cancel_changes_button" value="Cancel"/>
%elif request.unsubmitted():
diff -r b16a6d767e65 -r ca816e66ec69 templates/requests/show_request.mako
--- a/templates/requests/show_request.mako Tue Oct 13 18:15:06 2009 -0400
+++ b/templates/requests/show_request.mako Wed Oct 14 02:22:11 2009 -0400
@@ -92,41 +92,43 @@
</%def>
<div class="toolForm">
- <div class="form-row">
- <a href="${h.url_for( controller='requests', action='toggle_request_details', request_id=request.id )}">${details_state}</a>
- </div>
- %if details_state == "Hide request details":
- %for index, rd in enumerate(request_details):
- <div class="form-row">
- <label>${rd['label']}</label>
- %if not rd['value']:
- <i>None</i>
- %else:
- %if rd['label'] == 'Data library':
- %if rd['value']:
- <a href="${h.url_for( controller='library', action='browse_library', obj_id=request.library.id )}">${rd['value']}</a>
+ <div class="form-row">
+ %if details == "show":
+ <a href="${h.url_for( controller='requests', action='toggle_request_details', request_id=request.id, details="hide" )}">Hide request details</a>
+ </div>
+ %for index, rd in enumerate(request_details):
+ <div class="form-row">
+ <label>${rd['label']}</label>
+ %if not rd['value']:
+ <i>None</i>
+ %else:
+ %if rd['label'] == 'Data library':
+ %if rd['value']:
+ <a href="${h.url_for( controller='library', action='browse_library', obj_id=request.library.id )}">${rd['value']}</a>
+ %else:
+ <i>None</i>
+ %endif
%else:
- <i>None</i>
+ ${rd['value']}
%endif
- %else:
- ${rd['value']}
%endif
- %endif
- </div>
- <div style="clear: both"></div>
- %endfor
- %if request.unsubmitted():
- <div class="form-row">
- <ul class="manage-table-actions">
- <li>
- <a class="action-button" href="${h.url_for( controller='requests', action='edit', show=True, request_id=request.id)}">
- <span>Edit request details</span></a>
- </li>
- </ul>
- </div>
- %endif
+ </div>
+ <div style="clear: both"></div>
+ %endfor
+ %if request.unsubmitted():
+ <div class="form-row">
+ <ul class="manage-table-actions">
+ <li>
+ <a class="action-button" href="${h.url_for( controller='requests', action='edit', show=True, request_id=request.id)}">
+ <span>Edit request details</span></a>
+ </li>
+ </ul>
+ </div>
+ %endif
+ </div>
+ %else:
+ <a href="${h.url_for( controller='requests', action='toggle_request_details', request_id=request.id, details="show" )}">Show request details</a>
%endif
- </div>
</div>
<%def name="render_grid( grid_index, grid_name, fields_dict )">
@@ -158,7 +160,7 @@
request.refresh()
%>
%for sample_index, sample in enumerate(current_samples):
- %if edit_mode:
+ %if edit_mode == 'True':
<tr>
<td>${sample_index+1}</td>
${render_sample_form( sample_index, sample[0], sample[1], grid_index, fields_dict)}
@@ -194,7 +196,7 @@
<div class="toolForm">
##<div class="toolFormTitle">Samples (${len(request.samples)})</div>
- <form id="show_request" name="show_request" action="${h.url_for( controller='requests', action='show_request' )}" enctype="multipart/form-data" method="post" >
+ <form id="show_request" name="show_request" action="${h.url_for( controller='requests', action='show_request', edit_mode=edit_mode )}" enctype="multipart/form-data" method="post" >
<div class="form-row">
%if current_samples:
%if not request.type.sample_form.layout:
@@ -211,7 +213,7 @@
%endif
</div>
- %if request.unsubmitted() and not edit_mode:
+ %if request.unsubmitted() and edit_mode == 'False':
<table class="grid">
<tbody>
<tr>
@@ -251,7 +253,7 @@
</div>
<div class="form-row">
<input type="submit" name="save_samples_button" value="Save"/>
- %if edit_mode:
+ %if edit_mode == 'True':
<input type="submit" name="cancel_changes_button" value="Cancel"/>
%endif
</div>
diff -r b16a6d767e65 -r ca816e66ec69 templates/user/address.mako
--- a/templates/user/address.mako Tue Oct 13 18:15:06 2009 -0400
+++ b/templates/user/address.mako Wed Oct 14 02:22:11 2009 -0400
@@ -46,7 +46,7 @@
<td>
<div class="form-row">
<label>${address.desc}</label>
- ${address.display()}
+ ${address.get_html()}
</div>
<div class="form-row">
<ul class="manage-table-actions">
diff -r b16a6d767e65 -r ca816e66ec69 test/base/twilltestcase.py
--- a/test/base/twilltestcase.py Tue Oct 13 18:15:06 2009 -0400
+++ b/test/base/twilltestcase.py Wed Oct 14 02:22:11 2009 -0400
@@ -1059,8 +1059,15 @@
tc.fv( "1", field_name, field_contents )
tc.fv( "1", field_help_name, field_help_contents )
tc.submit( "save_changes_button" )
+ if num_fields:
check_str = "The form '%s' has been updated with the changes." % name
- self.check_page_for_string( check_str )
+ self.check_page_for_string( check_str )
+ else:
+ self.home()
+ self.visit_url( "%s/forms/manage" % self.url )
+ self.check_page_for_string( name )
+ self.check_page_for_string( desc )
+ self.check_page_for_string( formtype )
self.home()
def edit_form( self, form_id, form_name, new_form_name="Form One's Name (Renamed)", new_form_desc="This is Form One's description (Re-described)"):
"""
@@ -1074,7 +1081,7 @@
tc.submit( "save_changes_button" )
self.check_page_for_string( "The form '%s' has been updated with the changes." % new_form_name )
self.home()
- def form_add_field( self, form_id, form_name, field_index, fields):
+ def form_add_field( self, form_id, form_name, form_desc, form_type, field_index, fields):
"""
Add a new fields to the form definition
"""
@@ -1088,13 +1095,18 @@
tc.fv( "1", "field_helptext_%i" % index, field['desc'] )
tc.fv( "1", "field_type_%i" % index, field['type'] )
tc.fv( "1", "field_required_%i" % index, field['required'] )
-# if field['type'] == 'SelectField':
-# for option_index, option in enumerate(field['selectlist']):
-# self.visit_url( "%s/forms/edit?select_box_options=add&form_id=%i&field_index=%i" % \
-# (self.url, form_id, index))
-# #data = self.last_page()
-# #file( "rc.html", 'wb' ).write(data)
-# tc.fv( "1", "field_%i_option_%i" % (index, option_index), option )
+ if field['type'] == 'SelectField':
+ options = ''
+ for option_index, option in enumerate(field['selectlist']):
+ url_str = "%s/forms/edit?description=%s&form_id=%i&form_type_selectbox=%s&addoption_%i=Add&name=%s&field_name_%i=%s&field_helptext_%i=%s&field_type_%i=%s" % \
+ (self.url, form_desc.replace(" ", "+"), form_id, form_type.replace(" ", "+"),
+ index, form_name.replace(" ", "+"), index, field['name'].replace(" ", "+"),
+ index, field['desc'].replace(" ", "+"), index, field['type'])
+ self.visit_url( url_str + options )
+ data = self.last_page()
+ file( "rc.html", 'wb' ).write(data)
+ tc.fv( "1", "field_%i_option_%i" % (index, option_index), option )
+ options = options + "&field_%i_option_%i=%s" % (index, option_index, option)
tc.submit( "save_changes_button" )
check_str = "The form '%s' has been updated with the changes." % form_name
self.check_page_for_string( check_str )
@@ -1130,18 +1142,22 @@
self.check_page_for_string( "Request type <b>%s</b> has been created" % name )
def create_request( self, request_type_id, name, desc, library_id, folder_id, fields ):
self.home()
- self.visit_url( "%s/requests/new?create=True&select_request_type=%i" % (self.url, request_type_id) )
+ self.visit_url( "%s/requests/new?create=True&select_request_type=%i&library_id=%i" % ( self.url,
+ request_type_id,
+ library_id ) )
self.check_page_for_string( 'Add a new request' )
tc.fv( "1", "name", name )
tc.fv( "1", "desc", desc )
tc.fv( "1", "library_id", str(library_id) )
- #tc.fv( "1", "folder_id", str(folder_id) )
+ tc.fv( "1", "folder_id", str(folder_id) )
for index, field_value in enumerate(fields):
tc.fv( "1", "field_%i" % index, field_value )
tc.submit( "create_request_button" )
def create_request_admin( self, request_type_id, user_id, name, desc, library_id, fields ):
self.home()
- self.visit_url( "%s/requests_admin/new?create=True&select_request_type=%i" % (self.url, request_type_id) )
+ self.visit_url( "%s/requests_admin/new?create=True&select_request_type=%i&library_id=%i" % ( self.url,
+ request_type_id,
+ library_id ) )
self.check_page_for_string( 'Add a new request' )
tc.fv( "1", "select_user", str(user_id) )
tc.fv( "1", "name", name )
diff -r b16a6d767e65 -r ca816e66ec69 test/functional/test_forms_and_requests.py
--- a/test/functional/test_forms_and_requests.py Tue Oct 13 18:15:06 2009 -0400
+++ b/test/functional/test_forms_and_requests.py Wed Oct 14 02:22:11 2009 -0400
@@ -42,12 +42,7 @@
name = form_one_name
desc = "This is Form One's description"
formtype = galaxy.model.FormDefinition.types.REQUEST
- self.create_form( name=name, desc=desc, formtype=formtype )
- self.home()
- self.visit_page( 'forms/manage' )
- self.check_page_for_string( name )
- self.check_page_for_string( desc )
- self.check_page_for_string( formtype )
+ self.create_form( name=name, desc=desc, formtype=formtype, num_fields=0 )
# Get the form_definition object for later tests
form_one = galaxy.model.FormDefinition.filter( and_( galaxy.model.FormDefinition.table.c.name==name,
galaxy.model.FormDefinition.table.c.desc==desc,
@@ -66,24 +61,21 @@
"""Testing adding fields to a form definition"""
fields = [dict(name='Test field name one',
desc='Test field description one',
- type='TextField',
- required='required'),
+ type='SelectField',
+ required='optional',
+ selectlist=['option1', 'option2']),
dict(name='Test field name two',
desc='Test field description two',
type='AddressField',
- required='optional')]
+ required='optional'),
+ dict(name='Test field name three',
+ desc='Test field description three',
+ type='TextField',
+ required='required')]
form_one = get_latest_form(form_one_name)
- self.form_add_field(form_one.id, form_one.name, field_index=len(form_one.fields), fields=fields)
+ self.form_add_field(form_one.id, form_one.name, form_one.desc, form_one.type, field_index=len(form_one.fields), fields=fields)
form_one_latest = get_latest_form(form_one_name)
assert len(form_one_latest.fields) == len(form_one.fields)+len(fields)
-#This following test has been commented out as it is causing:
-#TwillException: multiple matches to "remove_button"
-# def test_010_remove_form_fields( self ):
-# """Testing removing fields from a form definition"""
-# form_one = get_latest_form(form_one_name)
-# self.form_remove_field( form_one.id, form_one.name, 'Test field name one' )
-# form_one_latest = get_latest_form(form_one_name)
-# assert len(form_one_latest.fields) == len(form_one.fields)-1
def test_015_create_sample_form( self ):
"""Testing creating another form (for samples)"""
global form_two_name
@@ -186,10 +178,10 @@
self.logout()
self.login( email='test1(a)bx.psu.edu' )
# set field values
- fields = ['field one value', 'field two value', str(user_address.id)]
+ fields = ['option1', str(user_address.id), 'field three value']
# create the request
request_name, request_desc = 'Request One', 'Request One Description'
- self.create_request(request_type.id, request_name, request_desc, library_one.id, folder_one.id, fields)
+ self.create_request(request_type.id, request_name, request_desc, library_one.id, 'none', fields)
self.check_page_for_string( request_name )
self.check_page_for_string( request_desc )
global request_one
@@ -208,8 +200,9 @@
for field_value in fields:
self.check_page_for_string( field_value )
# edit this request
- fields = ['field one value (edited)', 'field two value (edited)', str(user_address.id)]
- self.edit_request(request_one.id, request_one.name, request_one.name+' (Renamed)', request_one.desc+' (Re-described)', library_one.id, folder_one.id, fields)
+ fields = ['option2', str(user_address.id), 'field three value (edited)']
+ self.edit_request(request_one.id, request_one.name, request_one.name+' (Renamed)',
+ request_one.desc+' (Re-described)', library_one.id, folder_one.id, fields)
request_one.refresh()
self.check_page_for_string( request_name+' (Renamed)' )
self.check_page_for_string( request_desc+' (Re-described)' )
@@ -261,8 +254,8 @@
self.login( email='test(a)bx.psu.edu' )
request_name = "RequestTwo"
# simulate request creation
- url_str = '%s/requests_admin/new?create=True&create_request_button=Save&select_request_type=%i&select_user=%i&name=%s&library_id=%i&folder_id=%i&refresh=True&field_1=%s&field_2=%i' \
- % ( self.url, request_type.id, regular_user.id, request_name, library_one.id, library_one.root_folder.id, "field_1_value", user_address.id )
+ url_str = '%s/requests_admin/new?create=True&create_request_button=Save&select_request_type=%i&select_user=%i&name=%s&library_id=%i&folder_id=%i&refresh=True&field_2=%s&field_0=%s&field_1=%i' \
+ % ( self.url, request_type.id, regular_user.id, request_name, library_one.id, library_one.root_folder.id, "field_2_value", 'option1', user_address.id )
self.home()
self.visit_url( url_str )
self.check_page_for_string( "The new request named %s has been created" % request_name )
@@ -299,10 +292,3 @@
self.visit_url( '%s/requests_admin/list?show_filter=All' % self.url )
self.check_page_for_string( request_one.name )
self.check_page_for_string( request_two.name )
-
-
-
-
-
-
-
\ No newline at end of file
1
0

14 Oct '09
details: http://www.bx.psu.edu/hg/galaxy/rev/b16a6d767e65
changeset: 2881:b16a6d767e65
user: Greg Von Kuster <greg(a)bx.psu.edu>
date: Tue Oct 13 18:15:06 2009 -0400
description:
Add 2 rgenetics test files I missed for testing uploading composite data types.
2 file(s) affected in this change:
test-data/rgenetics.map
test-data/rgenetics.ped
diffs (108 lines):
diff -r 738085dcc542 -r b16a6d767e65 test-data/rgenetics.map
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/rgenetics.map Tue Oct 13 18:15:06 2009 -0400
@@ -0,0 +1,10 @@
+22 rs5992809 16.5965 16596539
+22 rs12168131 16.6573 16657262
+22 rs390041 16.6629 16662916
+22 rs437633 16.6697 16669684
+22 rs450960 16.6909 16690858
+22 rs450975 16.6909 16690887
+22 rs451740 16.6912 16691174
+22 rs8139723 16.6917 16691696
+22 rs405490 16.6922 16692175
+22 rs415170 16.6935 16693517
diff -r 738085dcc542 -r b16a6d767e65 test-data/rgenetics.ped
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/rgenetics.ped Tue Oct 13 18:15:06 2009 -0400
@@ -0,0 +1,90 @@
+CH18526 NA18526 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18524 NA18524 0 0 1 1 C C A A C C G G C C C C C C C C A A C C
+CH18529 NA18529 0 0 2 1 C C A A T C A G T C T C T C C C G A G C
+CH18558 NA18558 0 0 1 1 C C A A C C G G C C C C C C C C A A C C
+CH18532 NA18532 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18561 NA18561 0 0 1 1 C C A A C C G G T C C C T C C C G A G C
+CH18562 NA18562 0 0 1 1 C C G A T C A G T C C C T C C C G A G C
+CH18537 NA18537 0 0 2 2 C C A A T C A G C C C C C C C C A A C C
+CH18603 NA18603 0 0 1 2 C C G A T C A G C C C C C C C C A A C C
+CH18540 NA18540 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18605 NA18605 0 0 1 1 C C A A T T A A C C C C C C C C A A C C
+CH18542 NA18542 0 0 2 1 C C G A T C G G C C C C C C C C A A C C
+CH18545 NA18545 0 0 2 1 C C G A T C A G T C C C T C C C G A G C
+CH18572 NA18572 0 0 1 2 C C A A T C A G C C C C C C C C A A G C
+CH18547 NA18547 0 0 2 2 C C G A T C A G T C C C T C C C G A G C
+CH18609 NA18609 0 0 1 1 C C A A C C G G C C C C C C C C A A C C
+CH18550 NA18550 0 0 2 1 C C G G T T A A T C C C T C T C G A G C
+CH18608 NA18608 0 0 1 1 C C G A T C G G C C C C C C C C A A C C
+CH18552 NA18552 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18611 NA18611 0 0 1 1 C C G A T C A G T C C C T C C C G A G C
+CH18555 NA18555 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18564 NA18564 0 0 2 2 C C A A T C G G C C C C C C C C A A C C
+CH18566 NA18566 0 0 2 1 C C A A T C A G C C C C C C T C A A C C
+CH18563 NA18563 0 0 1 1 C C A A C C G G C C C C C C C C A A C C
+CH18570 NA18570 0 0 2 1 C C A A T C A G T C T C T C C C G A G C
+CH18612 NA18612 0 0 1 2 C C A A T C A A T C T C T C C C G A G C
+CH18571 NA18571 0 0 2 1 C C A A T C A G C C C C C C C C A A C C
+CH18620 NA18620 0 0 1 1 C C A A C C G G T C T C T C C C G A G C
+CH18621 NA18621 0 0 1 1 C C G G T T A A T C C C T C C C G A G C
+CH18594 NA18594 0 0 2 1 C C A A T T A A C C C C C C C C A A G C
+CH18622 NA18622 0 0 1 2 C C A A C C G G C C C C C C C C A A C C
+CH18573 NA18573 0 0 2 2 C C A A T C A G C C C C C C C C A A C C
+CH18623 NA18623 0 0 1 1 C C G A T C G G C C C C C C C C A A C C
+CH18576 NA18576 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18577 NA18577 0 0 2 1 C C A A T C A G C C C C C C C C A A G C
+CH18624 NA18624 0 0 1 1 C C A A T C A G C C C C C C C C A A C C
+CH18579 NA18579 0 0 2 1 C C A A T C A G T C T C T C T C G A G C
+CH18632 NA18632 0 0 1 2 C C A A C C G G C C C C C C C C A A C C
+CH18582 NA18582 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18633 NA18633 0 0 1 1 C C G A T C G G C C C C C C C C A A C C
+CH18635 NA18635 0 0 1 2 C C A A T C G G C C C C C C C C A A C C
+CH18592 NA18592 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+CH18636 NA18636 0 0 1 1 C C A A T C A A T C T C T C C C G A G C
+CH18593 NA18593 0 0 2 2 C C A A C C G G T C T C T C C C G A G C
+CH18637 NA18637 0 0 1 1 C C A A T C A G T C T C T C C C G A G C
+JA18942 NA18942 0 0 2 2 C C A A C C A G C C C C C C C C A A C C
+JA18940 NA18940 0 0 1 2 C C A A T C A G C C C C C C C C A A G C
+JA18951 NA18951 0 0 2 2 C C G A T C A G C C C C C C C C A A C C
+JA18943 NA18943 0 0 1 2 C C A A C C G G C C C C C C C C A A C C
+JA18947 NA18947 0 0 2 2 C C G A T T A A C C C C C C C C A A G C
+JA18944 NA18944 0 0 1 2 C C A A T C A G T C T C T C C C G A G C
+JA18945 NA18945 0 0 1 2 C C A A C C G G C C C C C C C C A A C C
+JA18949 NA18949 0 0 2 2 C C G A T C G G C C C C C C C C A A C C
+JA18948 NA18948 0 0 1 2 C C G A T C G G C C C C C C C C A A C C
+JA18952 NA18952 0 0 1 2 C C A A T C A G C C C C C C C C A A C C
+JA18956 NA18956 0 0 2 2 C C A A C C A G T C T C T C C C G A G C
+JA18964 NA18964 0 0 2 2 C C A A T T A A C C C C C C C C A A G C
+JA18953 NA18953 0 0 1 1 C C A A T C A G C C C C C C T C A A C C
+JA18968 NA18968 0 0 2 2 C C A A C C G G C C C C C C C C A A C C
+JA18959 NA18959 0 0 1 2 C C G A T C G G C C C C C C C C A A C C
+JA18969 NA18969 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+JA18960 NA18960 0 0 1 2 C C A A T C A G T C T C T C C C G A G C
+JA18961 NA18961 0 0 1 2 C C A A C C A G C C C C C C C C A A C C
+JA18972 NA18972 0 0 2 2 C C G A T T A A T T T C T T C C G G G G
+JA18965 NA18965 0 0 1 2 C C A A T T A A C C C C C C C C A A C C
+JA18973 NA18973 0 0 2 2 C C A A C C G G C C C C C C T C A A C C
+JA18966 NA18966 0 0 1 2 C C G A T C A G T C C C T C C C G A G C
+JA18975 NA18975 0 0 2 2 C C A A C C G G C C C C C C C C A A G C
+JA18967 NA18967 0 0 1 2 C C A A C C G G C C C C C C C C A A G C
+JA18976 NA18976 0 0 2 1 C C A A C C G G C C C C C C C C A A C C
+JA18978 NA18978 0 0 2 2 C C G A T C G G C C C C C C C C A A C C
+JA18970 NA18970 0 0 1 1 C C G G T T A A T T C C T T C C G G G G
+JA18980 NA18980 0 0 2 2 C C A A T C A G T C T C T C C C G A G C
+JA18995 NA18995 0 0 1 1 C C A A T T A A C C C C C C C C A A G G
+JA18981 NA18981 0 0 2 2 C C A A T C A G C C C C C C C C A A G C
+JA18971 NA18971 0 0 1 2 C C A A C C G G C C C C C C C C A A C C
+JA18974 NA18974 0 0 1 1 C C A A C C G G C C C C C C C C A A C C
+JA18987 NA18987 0 0 2 2 C C A A C C G G C C C C C C C C A A C C
+JA18990 NA18990 0 0 1 1 C C A A T C G G C C C C C C C C A A G C
+JA18991 NA18991 0 0 2 2 C C A A C C G G C C C C C C C C A A C C
+JA18994 NA18994 0 0 1 2 C C G A T C A G C C C C C C C C A A G C
+JA18992 NA18992 0 0 2 2 C C A A T C A G C C C C C C T C A A C C
+JA18997 NA18997 0 0 2 2 C C A A C C G G C C C C C C C C A A C C
+JA18998 NA18998 0 0 2 2 C C A A C C G G C C C C C C T C A A C C
+JA19000 NA19000 0 0 1 2 C C A A C C G G C C C C C C C C A A C C
+JA19005 NA19005 0 0 1 2 C C A A C C G G C C C C C C C C A A G C
+JA18999 NA18999 0 0 2 2 C C A A T C A G C C C C C C C C A A C C
+JA19007 NA19007 0 0 1 2 C C A A T C A G C C C C C C C C A A G C
+JA19003 NA19003 0 0 2 2 C C A A T C G G C C C C C C C C A A C C
+JA19012 NA19012 0 0 1 2 C C A A 0 0 G G C C C C C C 0 0 A A C C
1
0