lib/voruby/votables/votable.rb in voruby-1.1 vs lib/voruby/votables/votable.rb in voruby-1.1.1

- old
+ new

@@ -11,128 +11,128 @@ # wouldn't construct this object directly, but rather use something like # VOTable::TreeParsedVOTable to do so from an XML file. class VOTable attr_accessor :description, :definitions, :coosys, :params, :info, :resources, :id, :version - + # [_id_:] # The VOTable's ID attribute. # [_version_:] # The VOTable version. # [_description_:] - # The VOTable DESCRIPTION element (type: VOTABLE::META::Description). + # The VOTable DESCRIPTION element (type: Meta::Description). # [_definitions_:] - # The VOTable DEFINITIONS element (type: VOTABLE::META::Definitions). + # The VOTable DEFINITIONS element (type: Meta::Definitions). # [_coosys_:] # The coordinate system (COOSYS) definitions for the the VOTable - # (type: VOTABLE::META::CooSys). + # (type: Meta::CooSys). # [_params_:] - # The PARAM elements for the VOTable (type: VOTABLE::META::Param). + # The PARAM elements for the VOTable (type: Meta::Param). # [_info_:] - # The INFO elements for the VOTable (type: VOTABLE::META::Info). + # The INFO elements for the VOTable (type: Meta::Info). # [_resources_:] - # The RESOURCE elements for the VOTable (type: VOTABLE::META::Resource). + # The RESOURCE elements for the VOTable (type: Meta::Resource). def initialize(id=nil, version='1.1', description=nil, definitions=nil, coosys=[], params=[], info=[], resources=[]) - + @id = id @version = version - + Misc::TypeCheck.new(description, Meta::Description).check() @description = description - + Misc::TypeCheck.new(definitions, Meta::Definitions).check() @definitions = definitions - + coosys.each{ |sys| Misc::TypeCheck.new(sys, Meta::CooSys).check() } @coosys = coosys - + params.each{ |param| Misc::TypeCheck.new(param, Meta::Param).check() } @params = params - + info.each{ |inf| Misc::TypeCheck.new(inf, Meta::Info).check() } @info = info - + resources.each{ |res| Misc::TypeCheck.new(res, Meta::Resource).check() } @resources = resources end - + # Get the compact string representation of the VOTable. def to_s coosys = @coosys.each{|x| x.to_s}.join('|') params = @params.each{|x| x.to_s}.join('|') info = @info.each{|x| x.to_s}.join('|') resources = @resources.each{|x| x.to_s}.join('|') - + return "{id=#{@id};version=#{@version};" + "description=#{@description};definitions=#{@definitions};" + "coosys=#{coosys};params=#{params};info=#{info};" + "resources=#{resources}}" end - + # A convenience method for accessing the fields of a votable, # rather than having to iterate through each resource and table # manually. - # Returns a list of VOTABLE::META::Field objects. + # Returns a list of Meta::Field objects. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def fields(res=0, tbl=0) @resources[res].tables()[tbl].fields() if @resources[res] end - + # A convenience method for determining the number of columns in # a votable. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def number_of_fields(res=0, tbl=0) return fields(res, tbl).length() || [] end - + # A convenience method for accessing the row data of a votable. - # Returns a list of VOTABLE::DATA::TR objects. + # Returns a list of Data::TR objects. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def rows(res=0, tbl=0) - @resources[res].tables()[tbl].data().format().trs() + @resources[res].tables()[tbl].data().format().trs() if @resources[res].tables()[tbl].data() end - + # A convenience method for determining the number of data rows # in a votable. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def number_of_rows(res=0, tbl=0) return rows(res, tbl).length() end - + # Find the main positional right ascension and declination # fields in a votable using UCDs. This should work for both # version 1 and 1+ UCDs. # Returns a hash with the keys "ra" and "dec". # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def main_positional_fields(res=0, tbl=0) main_pos = {} - + field_count = 0 fields(res, tbl).each do |field| if field.ucd() != nil ucd = field.ucd() # Determine if the UCD is of intereset. @@ -144,22 +144,22 @@ end field_count = field_count + 1 end return main_pos end - + # Find positional fields in a votable using UCDs. This should work # for both version 1 and 1+ UCDs. # Returns a hash of the positions of the fields and their - # corresponding VOTABLE::META::Field object. + # corresponding Meta::Field object. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def positional_fields(res=0, tbl=0) pos = {} - + field_count = 0 fields(res, tbl).each do |field| if field.ucd() != nil ucd = field.ucd() # Determine if the UCD is of interest @@ -169,23 +169,23 @@ end field_count = field_count + 1 end return pos end - + # Find the date of observation fields in a votable using UCDs. # This should work for both version 1 and 1+ UCDs, including # experimental (e.g. VOX) ones. # Returns a hash of the positions of the fields and their - # corresponding VOTABLE::META::Field object. + # corresponding Meta::Field object. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def date_of_observation_fields(res=0, tbl=0) date_obs = {} - + field_count = 0 fields(res, tbl).each do |field| if field.ucd() != nil ucd = field.ucd() dt = field.datatype() @@ -197,15 +197,15 @@ end field_count = field_count + 1 end return date_obs end - + # Find time fields in a votable using UCDs. This should work # for both version 1 and 1+ UCDs, including experimental (e.g. VOX) ones. # Returns a hash of the positions of the fields and their - # corresponding VOTABLE::META::Field object. + # corresponding Meta::Field object. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def time_fields(res=0, tbl=0) @@ -220,20 +220,20 @@ end field_count = field_count + 1 end return times end - + # Find the column number(s) associated with a UCD. # Returns a list of column positions. # [_res_:] # The resource from which to extract the table in question. # [_tbl_:] # The resource from which to extract the table in question. def find_columns(ucd, res=0, tbl=0) columns = [] - + col_count = 0 fields = fields(res, tbl) if fields fields.each do |field| if field.ucd() != nil @@ -243,11 +243,11 @@ col_count += 1 end end return columns end - + # Find the column number(s) associated with the # VOX:imageAccessReference UCD. # Returns a list of column positions. def image_access_reference_columns # The following is correct @@ -257,374 +257,431 @@ find_columns('VOX:Image_AccessReference').first else find_columns('DATA_LINK').first end end - + def image_ra_columns if find_columns('POS_EQ_RA_MAIN').first != nil find_columns('POS_EQ_RA_MAIN').first elsif find_columns('pos.eq.ra;meta.main').first != nil find_columns('pos.eq.ra;meta.main').first end end - + def image_dec_columns if find_columns('POS_EQ_DEC_MAIN').first != nil find_columns('POS_EQ_DEC_MAIN').first elsif find_columns('pos.eq.dec;meta.main').first != nil find_columns('pos.eq.dec;meta.main').first end end - + def image_filter_columns if find_columns('VOX:BandPass_ID').first != nil find_columns('VOX:BandPass_ID').first elsif find_columns('instr.filter').first != nil find_columns('instr.filter').first end end - + def image_date_obs_columns if find_columns('time.obs.start').first != nil find_columns('time.obs.start').first end end - + def image_telescope_columns if find_columns('instr.tel').first != nil find_columns('instr.tel').first end end - + def image_survey_columns if find_columns('VOX:Image_Title').first != nil find_columns('VOX:Image_Title').first elsif find_columns('ID_SURVEY').first != nil find_columns('ID_SURVEY').first end end - + def image_instrument_columns if find_columns('VOX:INST_ID').first != nil find_columns('VOX:INST_ID').first elsif find_columns('INST_ID').first != nil find_columns('INST_ID').first elsif find_columns('instr').first != nil find_columns('instr').first end end - + def image_sky_columns if find_columns('instr.skyLevel').first != nil find_columns('instr.skyLevel').first end end - + def image_zeropoint_columns if find_columns('arith.zp;phot').first != nil find_columns('arith.zp;phot').first end end - + def image_seeing_columns if find_columns('instr.obsty.seeing').first != nil find_columns('instr.obsty.seeing').first end end - + def image_depth_columns #if find_columns('').first != nil # find_columns('').first #end end - + def image_exptime_columns if find_columns('time.expo').first != nil find_columns('time.expo').first end end - - # Create headers for HTML table - # [_res_:] - # The resource from which to extract the table in question. - # [_tbl_:] - # The table inside the resource from which to extract the rows in question. - # [_infer_add_to_cart_ref_:] - # - # [_add_to_cart_header_value_:] + + # Creates the header for the cart links + # [_options_:] # - # [_infer_access_ref_:] - # Link the access reference URL associated with a row. - # [_access_ref_header_value_:] - # For the access reference column, place this value in the header. - # [_access_ref_col_:] - # A valid SIA VOTable will only ever have one VOX:Image_AccessReference. - # [_header_class_:] - # The class to assign the header of the HTML table. - def create_headers(res, tbl, - infer_add_to_cart_ref, add_to_cart_header_value, - infer_access_ref, access_ref_header_value, access_ref_col, - header_class, id=nil) - - headers = Array.new - thead = "<thead class=\"#{header_class}\">\n" - + def create_header_cart_links(options) + thead_2row = Array.new + thead = "<thead class=\"#{options[:header_class]}\">\n" + thead << "<tr>\n" - if infer_add_to_cart_ref - thead << "<th>#{add_to_cart_header_value}</th>\n" - headers.push("<a href=\"javascript:void(0);\" onclick=\"siap.addAllRowsToCart('#{id}');\">*</a>") + + if options[:infer_add_to_cart_ref] + js = "function addSelectedRowsToCart(){" + + " tbody = $$('#' + '#{options[:id]}' + ' tbody').first();" + + " $A(tbody.rows).each(function(row){" + + " checkbox = row.cells[0].childNodes[0];" + + " if(checkbox.checked){" + + " new Ajax.Request(" + + " '#{options[:add_to_cart_url]}?' + checkbox.value," + + " {method: 'post', " + + " onLoading: function(request){" + + " $('#{options[:throbber_id]}').style.display = 'inline';" + + " $('#{options[:flash_notice_id]}').innerHTML = 'Adding selected rows to cart...';" + + " }.bind(this), " + + " onComplete: function(request){" + + " $('#{options[:throbber_id]}').style.display = 'none';" + + " $('#{options[:flash_notice_id]}').innerHTML = 'Selected rows added to cart.';" + + " }.bind(this)" + + " });" + + " }" + + " });" + js << " new #{options[:on_complete]};" if options[:on_complete] + js << "}" + thead << "<th><a href=\"javascript:void(0);\" onclick=\"new #{js};return false;\">#{options[:add_to_cart_header_label]}</a></th>\n" + + js = "function selectAllRows(){" + + " tbody = $$('#' + '#{options[:id]}' + ' tbody').first();" + + " $A(tbody.rows).each(function(row){" + + " checkbox = row.cells[0].childNodes[0];" + + " if(!checkbox.checked){" + + " checkbox.checked = true;" + + " }" + + " });" + + "}" + buttons_text = "&nbsp;<a href=\"javascript:void(0);\" title=\"Select all rows\" onclick=\"new #{js};return false;\">+</a>&nbsp;" + + js = "function deselectAllRows(){" + + " tbody = $$('#' + '#{options[:id]}' + ' tbody').first();" + + " $A(tbody.rows).each(function(row){" + + " checkbox = row.cells[0].childNodes[0];" + + " if(checkbox.checked){" + + " checkbox.checked = false;" + + " }" + + " });" + + "}" + buttons_text << "&nbsp;<a href=\"javascript:void(0);\" title=\"Deselect all rows\" onclick=\"new #{js};return false;\">-</a>&nbsp;" + thead_2row.push(buttons_text) end - if infer_access_ref - thead << "<th>#{access_ref_header_value}</th>\n" - headers.push('&nbsp;') + + return [thead, thead_2row] + end + + # Create the headers for HTML table + # [_access_ref_index_:] + # A valid SIA VOTable will only ever have one VOX:Image_AccessReference. + # [_options_:] + # + def create_headers(access_ref_index, options) + thead, thead_2row = create_header_cart_links(options) + + if options[:infer_access_ref] and access_ref_index + thead << "<th>#{options[:access_ref_header_label]}</th>\n" + thead_2row.push('&nbsp;') end + col_count = 0 - fields(res, tbl).each do |field| - if infer_access_ref and col_count == access_ref_col - headers[1] = field.ucd.value + fields(options[:res], options[:tbl]).each do |field| + ucd_value = '&nbsp;' + ucd_value = field.ucd.value if field.ucd + if options[:infer_access_ref] and access_ref_index and col_count == access_ref_index + thead_2row[1] = ucd_value else thead << "<th>#{field.name}</th>\n" - headers.push(field.ucd.value) + thead_2row.push(ucd_value) end col_count += 1 end + thead << " </tr>\n" - + thead << "<tr>\n" - headers.each do |h| + thead_2row.each do |h| thead << "<th>#{h}</th>\n" end thead << "</tr>\n" - + thead << "</thead>" - + return thead end - - def create_add_to_cart_link(link_ref, columns) - access_ref_col = image_access_reference_columns() - link_ref << '&resource=' + CGI.escape(columns[access_ref_col].value).to_s if access_ref_col - ra_col = image_ra_columns() - link_ref << '&rac=' + columns[ra_col].value.to_s if ra_col - dec_col = image_dec_columns() - link_ref << '&decc=' + columns[dec_col].value.to_s if dec_col - filter_col = image_filter_columns() - link_ref << '&filter=' + columns[filter_col].value.to_s if filter_col - date_obs_col = image_date_obs_columns() - link_ref << '&date_obs=' + columns[date_obs_col].value.to_s if date_obs_col - teles_col = image_telescope_columns() - link_ref << '&telescop=' + columns[teles_col].value.to_s if teles_col - survey_col = image_survey_columns() - link_ref << '&survey=' + columns[survey_col].value.to_s if survey_col - instrum_col = image_instrument_columns() - link_ref << '&instrument=' + columns[instrum_col].value.to_s if instrum_col - sky_col = image_sky_columns() - link_ref << '&sky=' + columns[sky_col].value.to_s if sky_col - zerop_col = image_zeropoint_columns() - link_ref << '&zeropoint=' + columns[zerop_col].value.to_s if zerop_col - seeing_col = image_seeing_columns() - link_ref << '&seeing=' + columns[seeing_col].value.to_s if seeing_col - depth_col = image_depth_columns() - link_ref << '&depth=' + columns[depth_col].value.to_s if depth_col - exptime_col = image_exptime_columns() - link_ref << '&exptime=' + columns[exptime_col].value.to_s if exptime_col - - return link_ref + + # Convert hms of right ascension to decimal degrees. + # [_ra:_] + # + def convert_ra_to_degrees(ra) + hours, min, sec = ra.split(':') + degrees = (hours.to_f() * 15.0) + + (min.to_f() * 15.0 / 60.0) + + (sec.to_f() * 15.0 / (60.0 * 60.0)) end - - # Create body for HTML table - # [_res_:] - # The resource from which to extract the table in question. - # [_tbl_:] - # The table inside the resource from which to extract the rows in question. - # [_infer_add_to_cart_ref_:] + + # Convert dms of declination to degrees + # [_dec:_] # - # [_add_to_cart_link_value_:] + def convert_dec_to_degrees(dec) + degree, arcmin, arcsec = dec.split(':') + degree_f = degree.to_f() + arcmin_f = (arcmin.to_f() / 60.0) + arcsec_f = (arcsec.to_f() / (60.0 * 60.0)) + return (degree_f - arcmin_f - arcsec_f) if degree_f < 0 + return degree_f + arcmin_f + arcsec_f + end + + # Creates the cart parameters + # [_cart_params:_] + # + # [_columns:_] # - # [_add_to_cart_link_ref_:] - # - # [_infer_access_ref_:] - # Link the access reference URL associated with a row. - # [_access_ref_link_value_:] - # For the access reference column, link this word. - # [_access_ref_col_:] + def create_item_cart_params(cart_params, columns) + link_ref_array = [] + + cart_params.each do |key, value| + link_ref_array.push("#{key}=#{value}") + end + + access_ref_index = image_access_reference_columns() + link_ref_array.push("resource=#{CGI.escape(columns[access_ref_index].value).to_s}") if access_ref_index + ra_index = image_ra_columns() + link_ref_array.push("rac=#{columns[ra_index].value.to_s}") if ra_index + dec_index = image_dec_columns() + link_ref_array.push("decc=#{columns[dec_index].value.to_s}") if dec_index + filter_index = image_filter_columns() + link_ref_array.push("filter=#{columns[filter_index].value.to_s}") if filter_index + date_obs_index = image_date_obs_columns() + link_ref_array.push("date_obs=#{columns[date_obs_index].value.to_s}") if date_obs_index + teles_index = image_telescope_columns() + link_ref_array.push("telescop=#{columns[teles_index].value.to_s}") if teles_index + survey_index = image_survey_columns() + link_ref_array.push("survey=#{columns[survey_index].value.to_s}") if survey_index + instrum_index = image_instrument_columns() + link_ref_array.push("instrument=#{columns[instrum_index].value.to_s}") if instrum_index + sky_index = image_sky_columns() + link_ref_array.push("sky=#{columns[sky_index].value.to_s}") if sky_index + zerop_index = image_zeropoint_columns() + link_ref_array.push("zeropoint=#{columns[zerop_index].value.to_s}") if zerop_index + seeing_index = image_seeing_columns() + link_ref_array.push("seeing=#{columns[seeing_index].value.to_s}") if seeing_index + depth_index = image_depth_columns() + link_ref_array.push("depth=#{columns[depth_index].value.to_s}") if depth_index + exptime_index = image_exptime_columns() + link_ref_array.push("exptime=#{columns[exptime_index].value.to_s}") if exptime_index + + return link_ref_array.join('&') + end + + # Create body for HTML table + # [_access_ref_index_:] # A valid SIA VOTable will only ever have one VOX:Image_AccessReference. - # [_body_class_:] - # The class to assign the body of the HTML table. - # [_row_classes_:] - # The class to assign the HTML table body rows. - def create_body(res, tbl, - infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref, - infer_access_ref, access_ref_link_value, access_ref_col, - body_class, row_classes) - - tbody = "<tbody class=\"#{body_class}\">\n" + # [_options_:] + # + def create_body(access_ref_index, options) + tbody = "<tbody class=\"#{options[:body_class]}\" align=\"center\">\n" row_count = 0 - rows(res, tbl).each do |tr| - tbody << "<tr class=\"#{row_classes[row_count % 2]}\">\n" - - # Specially mark up the first column to link to the image. - columns = tr.tds() - - if infer_add_to_cart_ref - archive = add_to_cart_link_ref.slice(add_to_cart_link_ref.index('&archive='), add_to_cart_link_ref.length) - archive = archive.slice('&archive='.length, archive.length) - archive = archive.slice(0, archive.index('&')) if archive.index('&') - link_id = 'add_' + archive.to_s + '_' + row_count.to_s - url = create_add_to_cart_link(add_to_cart_link_ref, columns) - js = "new Ajax.Request('#{url}', " + - " {method: 'post', " + - " onComplete: function(request){Element.hide('#{link_id}');}});" - tbody << "<td><a id=\"#{link_id}\" href=\"javascript:void(0);\" " + - "onclick=\"#{js};return false;\"" + - ">#{add_to_cart_link_value}</a></td>\n" + rows_data = rows(options[:res], options[:tbl]) + if rows_data + rows_data.each do |tr| + tbody << "<tr class=\"#{options[:row_classes][row_count % 2]}\">\n" + + # Specially mark up the first column to link to the image. + columns = tr.tds() + + if options[:infer_add_to_cart_ref] and access_ref_index + tbody << "<td><input type=\"checkbox\" " + + "id=\"checkbox_add_#{options[:cart_params][:archive]}_#{row_count.to_s}\" " + + "value=\"#{create_item_cart_params(options[:cart_params], columns)}\"/></td>\n" + end + + if options[:infer_access_ref] and access_ref_index + tbody << "<td><a href=\"#{columns[access_ref_index].value}\">#{options[:access_ref_link_label]}</a></td>\n" + end + + col_count = 0 + #ra_index = image_ra_columns() + #dec_index = image_dec_columns() + columns.each do |td| + if col_count != access_ref_index + #if ra_index and col_count == ra_index + # tbody << "<td>#{convert_ra_to_degrees(td.value)}</td>\n" + #elsif dec_index and col_count == dec_index + # tbody << "<td>#{convert_dec_to_degrees(td.value)}</td>\n" + #else + tbody << "<td>#{td.value}</td>\n" + #end + end + col_count += 1 + end + + tbody << "</tr>\n" + row_count += 1 end - if infer_access_ref - link_ref = columns[access_ref_col].value - tbody << "<td><a href=\"#{link_ref}\">#{access_ref_link_value}</a></td>\n" - end - - col_count = 0 - columns.each do |td| - tbody << "<td>#{td.value}</td>\n" if infer_access_ref and col_count != access_ref_col - col_count += 1 - end - tbody << "</tr>\n" - row_count += 1 end tbody << "</tbody>" - + return tbody end - + # Create table for HTML VOTable - # [_id_:] - # The ID to assign to the HTML table as a whole. - # [_show_border_:] - # The boolean value to show HTML table border. - # [_table_class_:] - # The class to assign the HTML table as a whole. # [_thead_:] # The class to assign the HTML table thead. # [_tbody_:] # The class to assign the HTML table tbody. - def create_table(id, show_border, table_class, thead, tbody) - table = "<table class=\"#{table_class}\"" - table << " id=\"#{id}\"" if id - table << " border=\"1\"" if show_border - table << " width=\"100%\">\n" - table << "#{thead}\n#{tbody}\n</table>" - return table + # [_options_:] + # The options for this VOTable. + def create_votable(thead, tbody, options) + votable = "<img class=\"#{options[:throbber_class]}\" " + + " id=\"#{options[:throbber_id]}\" " + + " src=\"#{options[:throbber_src]}\" " + + " size=\"#{options[:throbber_size]}\"/>&nbsp;" + + "<span class=\"#{options[:flash_notice_class]}\" " + + " id=\"#{options[:flash_notice_id]}\"></span><br>\n" + votable << "<table class=\"#{options[:table_class]}\"" + votable << " id=\"#{options[:id]}\"" if options[:id] + votable << " border=\"1\"" if options[:show_border] + votable << " width=\"100%\">\n" + votable << "#{thead}\n#{tbody}\n</table>" + + return votable end - + # Convert the specified table in the specified resource into an HTML # table. - # [_id_:] - # The ID to assign to the HTML table as a whole. - # [_add_to_cart_link_ref_:] - # - # [_res_:] - # The resource from which to extract the table in question. - # [_tbl_:] - # The table inside the resource from which to extract the rows in question. - # [_infer_add_to_cart_ref_:] - # - # [_add_to_cart_header_value_:] - # - # [_add_to_cart_link_value_:] - # - # [_infer_access_ref_:] - # Link the access reference URL associated with a row. - # [_access_ref_header_value_:] - # For the access reference column, place this value in the header. - # [_access_ref_link_value_:] - # For the access reference column, link this word. - # [_show_border_:] - # The boolean value to show HTML table border - # [_table_class_:] - # The class to assign the HTML table as a whole. - # [_header_class_:] - # The class to assign the header of the HTML table. - # [_body_class_:] - # The class to assign the body of the HTML table. - # [_row_classes_:] - # The class to assign the HTML table body rows. - def to_html(id=nil, add_to_cart_link_ref=nil, res=0, tbl=0, - infer_add_to_cart_ref=true, - add_to_cart_header_value='Add to Cart', - add_to_cart_link_value='Add', - infer_access_ref=true, - access_ref_header_value='URL', - access_ref_link_value='Retrieve', - show_border=false, - table_class='votable', - header_class='header', - body_class='body', - row_classes=['row1', 'row2']) - begin - # A valid SIA VOTable will only ever have one VOX:Image_AccessReference. - access_ref_col = image_access_reference_columns() - - if access_ref_col - # Create headers - thead = create_headers(res, tbl, - infer_add_to_cart_ref, add_to_cart_header_value, - infer_access_ref, access_ref_header_value, access_ref_col, - header_class, id) + # [_options_:] + # The options for this VOTable. + def to_html(options={}) + # The ID to assign to the HTML table as a whole. + options[:id] = options[:id] || "#{votable}_#{Time.now.to_i}_#{rand(10000)}" - # Create body - tbody = create_body(res, tbl, - infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref, - infer_access_ref, access_ref_link_value, access_ref_col, - body_class, row_classes) + options[:infer_add_to_cart_ref] = true if options[:infer_add_to_cart_ref] == nil + options[:add_to_cart_header_label] = options[:add_to_cart_header_label] || 'Add to Cart' + options[:cart_params] = {} if options[:cart_params] == nil + #options[:add_to_cart_url] = options[:add_to_cart_url] || nil - return create_table(id, show_border, table_class, thead, tbody) - else - title = 'No Data' - message = 'VOTable not contains data.' - return create_message_table(table_class, header_class, - body_class, row_classes, title, message) - end - + options[:throbber_src] = options[:throbber_src] || '/images/general/indicator.gif' + options[:throbber_size] = options[:throbber_size] || '16x16' + options[:throbber_class] = options[:throbber_class] || 'throbber' + options[:throbber_id] = options[:throbber_id] || "#{options[:id]}_throbber_id" + + options[:flash_notice_class] = options[:flash_notice_class] || 'flash_notice' + options[:flash_notice_id] = options[:flash_notice_id] || "#{options[:id]}_flash_notice_id" + + # Link the access reference URL associated with a row. + options[:infer_access_ref] = true if options[:infer_access_ref] == nil + #options[:retrieve_link_ref] = options[:retrieve_link_ref] || nil + # For the access reference column, place this value in the header. + options[:access_ref_header_label] = options[:access_ref_header_label] || 'URL' + # For the access reference column, link this word. + options[:access_ref_link_label] = options[:access_ref_link_label] || 'Retrieve' + options[:ssl] = false if options[:ssl] == nil + #options[:resource_link] = options[:resource_link] + + # The resource from which to extract the table in question. + options[:res] = options[:res] || 0 + # The table inside the resource from which to extract the rows in question. + options[:tbl] = options[:tbl] || 0 + + # The boolean value to show HTML table border + options[:show_border] = false if options[:show_border] == nil + # The class to assign the HTML table as a whole. + options[:table_class] = options[:table_class] || 'votable' + # The class to assign the header of the HTML table. + options[:header_class] = options[:header_class] || 'header' + # The class to assign the body of the HTML table. + options[:body_class] = options[:body_class] || 'body' + # The class to assign the HTML table body rows. + options[:row_classes] = options[:row_classes] || ['row1', 'row2'] + + begin + # A valid SIA VOTable will only ever have one VOX:Image_AccessReference. + access_ref_index = image_access_reference_columns() + + return create_votable(create_headers(access_ref_index, options), + create_body(access_ref_index, options), + options) + rescue Exception => e - title = 'Error' - message = e.backtrace#@resources[0].info[0].text().to_s() - table = create_message_table(table_class, header_class, - body_class, row_classes, title, message) + title = 'Error...' + message = "VORuby error: #{e.message}<br>#{e.backtrace}" + message << "<br>#{@resources[0].info[0].text().to_s()}" if @resources[0].info[0] + create_message(title, message, options) end end - - def create_message_table(table_class, header_class, body_class, - row_classes, title, message) - table = "<table class=\"#{table_class}\" width=\"100%\">\n" - - table << " <thead class=\"#{header_class}\">\n" - table << " <tr>\n" - table << " <th>#{title}</th>\n" - table << " </tr>\n" - table << " </thead>\n" - - table << " <tbody class=\"#{body_class}\">\n" - table << " <tr class=\"#{row_classes[0]}\">\n" - table << " <td align=\"center\"><label>VOTable message: #{message}" + - "</label></td>\n" - table << " </tr>\n" - table << " </tbody>\n" - - table << "</table>" - + + # Creates a message + # [_title_:] + # + # [_message_:] + # + # [_options_:] + # The options for this VOTable. + def create_message(title, message, options) + table = "<table class=\"#{options[:table_class]}\" width=\"100%\">\n" + + " <thead class=\"#{options[:header_class]}\">\n" + + " <tr>\n" + + " <th>#{title}</th>\n" + + " </tr>\n" + + " </thead>\n" + + " <tbody class=\"#{options[:body_class]}\">\n" + + " <tr class=\"#{options[:row_classes][0]}\">\n" + + " <td align=\"center\"><label>VOTable message: #{message}</label></td>\n" + + " </tr>\n" + + " </tbody>\n" + + "</table>" + return table end - + + # + # [_attributes_:] + # + # [_name_:] + # def self._find_attr_value(attributes, name) attributes.each do |qname, value| return value if qname.name == name end - + return nil end end end - + end -end \ No newline at end of file +end