voruby 1.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,75 +13,75 @@ module VORuby
13
13
  class VOTable
14
14
  attr_accessor :description, :definitions, :coosys, :params, :info, :resources,
15
15
  :id, :version
16
-
16
+
17
17
  # [_id_:]
18
18
  # The VOTable's ID attribute.
19
19
  # [_version_:]
20
20
  # The VOTable version.
21
21
  # [_description_:]
22
- # The VOTable DESCRIPTION element (type: VOTABLE::META::Description).
22
+ # The VOTable DESCRIPTION element (type: Meta::Description).
23
23
  # [_definitions_:]
24
- # The VOTable DEFINITIONS element (type: VOTABLE::META::Definitions).
24
+ # The VOTable DEFINITIONS element (type: Meta::Definitions).
25
25
  # [_coosys_:]
26
26
  # The coordinate system (COOSYS) definitions for the the VOTable
27
- # (type: VOTABLE::META::CooSys).
27
+ # (type: Meta::CooSys).
28
28
  # [_params_:]
29
- # The PARAM elements for the VOTable (type: VOTABLE::META::Param).
29
+ # The PARAM elements for the VOTable (type: Meta::Param).
30
30
  # [_info_:]
31
- # The INFO elements for the VOTable (type: VOTABLE::META::Info).
31
+ # The INFO elements for the VOTable (type: Meta::Info).
32
32
  # [_resources_:]
33
- # The RESOURCE elements for the VOTable (type: VOTABLE::META::Resource).
33
+ # The RESOURCE elements for the VOTable (type: Meta::Resource).
34
34
  def initialize(id=nil, version='1.1', description=nil,
35
35
  definitions=nil, coosys=[],
36
36
  params=[], info=[], resources=[])
37
-
37
+
38
38
  @id = id
39
39
  @version = version
40
-
40
+
41
41
  Misc::TypeCheck.new(description, Meta::Description).check()
42
42
  @description = description
43
-
43
+
44
44
  Misc::TypeCheck.new(definitions, Meta::Definitions).check()
45
45
  @definitions = definitions
46
-
46
+
47
47
  coosys.each{ |sys|
48
48
  Misc::TypeCheck.new(sys, Meta::CooSys).check()
49
49
  }
50
50
  @coosys = coosys
51
-
51
+
52
52
  params.each{ |param|
53
53
  Misc::TypeCheck.new(param, Meta::Param).check()
54
54
  }
55
55
  @params = params
56
-
56
+
57
57
  info.each{ |inf|
58
58
  Misc::TypeCheck.new(inf, Meta::Info).check()
59
59
  }
60
60
  @info = info
61
-
61
+
62
62
  resources.each{ |res|
63
63
  Misc::TypeCheck.new(res, Meta::Resource).check()
64
64
  }
65
65
  @resources = resources
66
66
  end
67
-
67
+
68
68
  # Get the compact string representation of the VOTable.
69
69
  def to_s
70
70
  coosys = @coosys.each{|x| x.to_s}.join('|')
71
71
  params = @params.each{|x| x.to_s}.join('|')
72
72
  info = @info.each{|x| x.to_s}.join('|')
73
73
  resources = @resources.each{|x| x.to_s}.join('|')
74
-
74
+
75
75
  return "{id=#{@id};version=#{@version};" +
76
76
  "description=#{@description};definitions=#{@definitions};" +
77
77
  "coosys=#{coosys};params=#{params};info=#{info};" +
78
78
  "resources=#{resources}}"
79
79
  end
80
-
80
+
81
81
  # A convenience method for accessing the fields of a votable,
82
82
  # rather than having to iterate through each resource and table
83
83
  # manually.
84
- # Returns a list of VOTABLE::META::Field objects.
84
+ # Returns a list of Meta::Field objects.
85
85
  # [_res_:]
86
86
  # The resource from which to extract the table in question.
87
87
  # [_tbl_:]
@@ -89,7 +89,7 @@ module VORuby
89
89
  def fields(res=0, tbl=0)
90
90
  @resources[res].tables()[tbl].fields() if @resources[res]
91
91
  end
92
-
92
+
93
93
  # A convenience method for determining the number of columns in
94
94
  # a votable.
95
95
  # [_res_:]
@@ -99,17 +99,17 @@ module VORuby
99
99
  def number_of_fields(res=0, tbl=0)
100
100
  return fields(res, tbl).length() || []
101
101
  end
102
-
102
+
103
103
  # A convenience method for accessing the row data of a votable.
104
- # Returns a list of VOTABLE::DATA::TR objects.
104
+ # Returns a list of Data::TR objects.
105
105
  # [_res_:]
106
106
  # The resource from which to extract the table in question.
107
107
  # [_tbl_:]
108
108
  # The resource from which to extract the table in question.
109
109
  def rows(res=0, tbl=0)
110
- @resources[res].tables()[tbl].data().format().trs()
110
+ @resources[res].tables()[tbl].data().format().trs() if @resources[res].tables()[tbl].data()
111
111
  end
112
-
112
+
113
113
  # A convenience method for determining the number of data rows
114
114
  # in a votable.
115
115
  # [_res_:]
@@ -119,7 +119,7 @@ module VORuby
119
119
  def number_of_rows(res=0, tbl=0)
120
120
  return rows(res, tbl).length()
121
121
  end
122
-
122
+
123
123
  # Find the main positional right ascension and declination
124
124
  # fields in a votable using UCDs. This should work for both
125
125
  # version 1 and 1+ UCDs.
@@ -130,7 +130,7 @@ module VORuby
130
130
  # The resource from which to extract the table in question.
131
131
  def main_positional_fields(res=0, tbl=0)
132
132
  main_pos = {}
133
-
133
+
134
134
  field_count = 0
135
135
  fields(res, tbl).each do |field|
136
136
  if field.ucd() != nil
@@ -146,18 +146,18 @@ module VORuby
146
146
  end
147
147
  return main_pos
148
148
  end
149
-
149
+
150
150
  # Find positional fields in a votable using UCDs. This should work
151
151
  # for both version 1 and 1+ UCDs.
152
152
  # Returns a hash of the positions of the fields and their
153
- # corresponding VOTABLE::META::Field object.
153
+ # corresponding Meta::Field object.
154
154
  # [_res_:]
155
155
  # The resource from which to extract the table in question.
156
156
  # [_tbl_:]
157
157
  # The resource from which to extract the table in question.
158
158
  def positional_fields(res=0, tbl=0)
159
159
  pos = {}
160
-
160
+
161
161
  field_count = 0
162
162
  fields(res, tbl).each do |field|
163
163
  if field.ucd() != nil
@@ -171,19 +171,19 @@ module VORuby
171
171
  end
172
172
  return pos
173
173
  end
174
-
174
+
175
175
  # Find the date of observation fields in a votable using UCDs.
176
176
  # This should work for both version 1 and 1+ UCDs, including
177
177
  # experimental (e.g. VOX) ones.
178
178
  # Returns a hash of the positions of the fields and their
179
- # corresponding VOTABLE::META::Field object.
179
+ # corresponding Meta::Field object.
180
180
  # [_res_:]
181
181
  # The resource from which to extract the table in question.
182
182
  # [_tbl_:]
183
183
  # The resource from which to extract the table in question.
184
184
  def date_of_observation_fields(res=0, tbl=0)
185
185
  date_obs = {}
186
-
186
+
187
187
  field_count = 0
188
188
  fields(res, tbl).each do |field|
189
189
  if field.ucd() != nil
@@ -199,11 +199,11 @@ module VORuby
199
199
  end
200
200
  return date_obs
201
201
  end
202
-
202
+
203
203
  # Find time fields in a votable using UCDs. This should work
204
204
  # for both version 1 and 1+ UCDs, including experimental (e.g. VOX) ones.
205
205
  # Returns a hash of the positions of the fields and their
206
- # corresponding VOTABLE::META::Field object.
206
+ # corresponding Meta::Field object.
207
207
  # [_res_:]
208
208
  # The resource from which to extract the table in question.
209
209
  # [_tbl_:]
@@ -222,7 +222,7 @@ module VORuby
222
222
  end
223
223
  return times
224
224
  end
225
-
225
+
226
226
  # Find the column number(s) associated with a UCD.
227
227
  # Returns a list of column positions.
228
228
  # [_res_:]
@@ -231,7 +231,7 @@ module VORuby
231
231
  # The resource from which to extract the table in question.
232
232
  def find_columns(ucd, res=0, tbl=0)
233
233
  columns = []
234
-
234
+
235
235
  col_count = 0
236
236
  fields = fields(res, tbl)
237
237
  if fields
@@ -245,7 +245,7 @@ module VORuby
245
245
  end
246
246
  return columns
247
247
  end
248
-
248
+
249
249
  # Find the column number(s) associated with the
250
250
  # VOX:imageAccessReference UCD.
251
251
  # Returns a list of column positions.
@@ -259,7 +259,7 @@ module VORuby
259
259
  find_columns('DATA_LINK').first
260
260
  end
261
261
  end
262
-
262
+
263
263
  def image_ra_columns
264
264
  if find_columns('POS_EQ_RA_MAIN').first != nil
265
265
  find_columns('POS_EQ_RA_MAIN').first
@@ -267,7 +267,7 @@ module VORuby
267
267
  find_columns('pos.eq.ra;meta.main').first
268
268
  end
269
269
  end
270
-
270
+
271
271
  def image_dec_columns
272
272
  if find_columns('POS_EQ_DEC_MAIN').first != nil
273
273
  find_columns('POS_EQ_DEC_MAIN').first
@@ -275,7 +275,7 @@ module VORuby
275
275
  find_columns('pos.eq.dec;meta.main').first
276
276
  end
277
277
  end
278
-
278
+
279
279
  def image_filter_columns
280
280
  if find_columns('VOX:BandPass_ID').first != nil
281
281
  find_columns('VOX:BandPass_ID').first
@@ -283,19 +283,19 @@ module VORuby
283
283
  find_columns('instr.filter').first
284
284
  end
285
285
  end
286
-
286
+
287
287
  def image_date_obs_columns
288
288
  if find_columns('time.obs.start').first != nil
289
289
  find_columns('time.obs.start').first
290
290
  end
291
291
  end
292
-
292
+
293
293
  def image_telescope_columns
294
294
  if find_columns('instr.tel').first != nil
295
295
  find_columns('instr.tel').first
296
296
  end
297
297
  end
298
-
298
+
299
299
  def image_survey_columns
300
300
  if find_columns('VOX:Image_Title').first != nil
301
301
  find_columns('VOX:Image_Title').first
@@ -303,7 +303,7 @@ module VORuby
303
303
  find_columns('ID_SURVEY').first
304
304
  end
305
305
  end
306
-
306
+
307
307
  def image_instrument_columns
308
308
  if find_columns('VOX:INST_ID').first != nil
309
309
  find_columns('VOX:INST_ID').first
@@ -313,318 +313,375 @@ module VORuby
313
313
  find_columns('instr').first
314
314
  end
315
315
  end
316
-
316
+
317
317
  def image_sky_columns
318
318
  if find_columns('instr.skyLevel').first != nil
319
319
  find_columns('instr.skyLevel').first
320
320
  end
321
321
  end
322
-
322
+
323
323
  def image_zeropoint_columns
324
324
  if find_columns('arith.zp;phot').first != nil
325
325
  find_columns('arith.zp;phot').first
326
326
  end
327
327
  end
328
-
328
+
329
329
  def image_seeing_columns
330
330
  if find_columns('instr.obsty.seeing').first != nil
331
331
  find_columns('instr.obsty.seeing').first
332
332
  end
333
333
  end
334
-
334
+
335
335
  def image_depth_columns
336
336
  #if find_columns('').first != nil
337
337
  # find_columns('').first
338
338
  #end
339
339
  end
340
-
340
+
341
341
  def image_exptime_columns
342
342
  if find_columns('time.expo').first != nil
343
343
  find_columns('time.expo').first
344
344
  end
345
345
  end
346
-
347
- # Create headers for HTML table
348
- # [_res_:]
349
- # The resource from which to extract the table in question.
350
- # [_tbl_:]
351
- # The table inside the resource from which to extract the rows in question.
352
- # [_infer_add_to_cart_ref_:]
353
- #
354
- # [_add_to_cart_header_value_:]
346
+
347
+ # Creates the header for the cart links
348
+ # [_options_:]
355
349
  #
356
- # [_infer_access_ref_:]
357
- # Link the access reference URL associated with a row.
358
- # [_access_ref_header_value_:]
359
- # For the access reference column, place this value in the header.
360
- # [_access_ref_col_:]
361
- # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
362
- # [_header_class_:]
363
- # The class to assign the header of the HTML table.
364
- def create_headers(res, tbl,
365
- infer_add_to_cart_ref, add_to_cart_header_value,
366
- infer_access_ref, access_ref_header_value, access_ref_col,
367
- header_class, id=nil)
368
-
369
- headers = Array.new
370
- thead = "<thead class=\"#{header_class}\">\n"
371
-
350
+ def create_header_cart_links(options)
351
+ thead_2row = Array.new
352
+ thead = "<thead class=\"#{options[:header_class]}\">\n"
353
+
372
354
  thead << "<tr>\n"
373
- if infer_add_to_cart_ref
374
- thead << "<th>#{add_to_cart_header_value}</th>\n"
375
- headers.push("<a href=\"javascript:void(0);\" onclick=\"siap.addAllRowsToCart('#{id}');\">*</a>")
355
+
356
+ if options[:infer_add_to_cart_ref]
357
+ js = "function addSelectedRowsToCart(){" +
358
+ " tbody = $$('#' + '#{options[:id]}' + ' tbody').first();" +
359
+ " $A(tbody.rows).each(function(row){" +
360
+ " checkbox = row.cells[0].childNodes[0];" +
361
+ " if(checkbox.checked){" +
362
+ " new Ajax.Request(" +
363
+ " '#{options[:add_to_cart_url]}?' + checkbox.value," +
364
+ " {method: 'post', " +
365
+ " onLoading: function(request){" +
366
+ " $('#{options[:throbber_id]}').style.display = 'inline';" +
367
+ " $('#{options[:flash_notice_id]}').innerHTML = 'Adding selected rows to cart...';" +
368
+ " }.bind(this), " +
369
+ " onComplete: function(request){" +
370
+ " $('#{options[:throbber_id]}').style.display = 'none';" +
371
+ " $('#{options[:flash_notice_id]}').innerHTML = 'Selected rows added to cart.';" +
372
+ " }.bind(this)" +
373
+ " });" +
374
+ " }" +
375
+ " });"
376
+ js << " new #{options[:on_complete]};" if options[:on_complete]
377
+ js << "}"
378
+ thead << "<th><a href=\"javascript:void(0);\" onclick=\"new #{js};return false;\">#{options[:add_to_cart_header_label]}</a></th>\n"
379
+
380
+ js = "function selectAllRows(){" +
381
+ " tbody = $$('#' + '#{options[:id]}' + ' tbody').first();" +
382
+ " $A(tbody.rows).each(function(row){" +
383
+ " checkbox = row.cells[0].childNodes[0];" +
384
+ " if(!checkbox.checked){" +
385
+ " checkbox.checked = true;" +
386
+ " }" +
387
+ " });" +
388
+ "}"
389
+ buttons_text = "&nbsp;<a href=\"javascript:void(0);\" title=\"Select all rows\" onclick=\"new #{js};return false;\">+</a>&nbsp;"
390
+
391
+ js = "function deselectAllRows(){" +
392
+ " tbody = $$('#' + '#{options[:id]}' + ' tbody').first();" +
393
+ " $A(tbody.rows).each(function(row){" +
394
+ " checkbox = row.cells[0].childNodes[0];" +
395
+ " if(checkbox.checked){" +
396
+ " checkbox.checked = false;" +
397
+ " }" +
398
+ " });" +
399
+ "}"
400
+ buttons_text << "&nbsp;<a href=\"javascript:void(0);\" title=\"Deselect all rows\" onclick=\"new #{js};return false;\">-</a>&nbsp;"
401
+ thead_2row.push(buttons_text)
376
402
  end
377
- if infer_access_ref
378
- thead << "<th>#{access_ref_header_value}</th>\n"
379
- headers.push('&nbsp;')
403
+
404
+ return [thead, thead_2row]
405
+ end
406
+
407
+ # Create the headers for HTML table
408
+ # [_access_ref_index_:]
409
+ # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
410
+ # [_options_:]
411
+ #
412
+ def create_headers(access_ref_index, options)
413
+ thead, thead_2row = create_header_cart_links(options)
414
+
415
+ if options[:infer_access_ref] and access_ref_index
416
+ thead << "<th>#{options[:access_ref_header_label]}</th>\n"
417
+ thead_2row.push('&nbsp;')
380
418
  end
419
+
381
420
  col_count = 0
382
- fields(res, tbl).each do |field|
383
- if infer_access_ref and col_count == access_ref_col
384
- headers[1] = field.ucd.value
421
+ fields(options[:res], options[:tbl]).each do |field|
422
+ ucd_value = '&nbsp;'
423
+ ucd_value = field.ucd.value if field.ucd
424
+ if options[:infer_access_ref] and access_ref_index and col_count == access_ref_index
425
+ thead_2row[1] = ucd_value
385
426
  else
386
427
  thead << "<th>#{field.name}</th>\n"
387
- headers.push(field.ucd.value)
428
+ thead_2row.push(ucd_value)
388
429
  end
389
430
  col_count += 1
390
431
  end
432
+
391
433
  thead << " </tr>\n"
392
-
434
+
393
435
  thead << "<tr>\n"
394
- headers.each do |h|
436
+ thead_2row.each do |h|
395
437
  thead << "<th>#{h}</th>\n"
396
438
  end
397
439
  thead << "</tr>\n"
398
-
440
+
399
441
  thead << "</thead>"
400
-
442
+
401
443
  return thead
402
444
  end
403
-
404
- def create_add_to_cart_link(link_ref, columns)
405
- access_ref_col = image_access_reference_columns()
406
- link_ref << '&resource=' + CGI.escape(columns[access_ref_col].value).to_s if access_ref_col
407
- ra_col = image_ra_columns()
408
- link_ref << '&rac=' + columns[ra_col].value.to_s if ra_col
409
- dec_col = image_dec_columns()
410
- link_ref << '&decc=' + columns[dec_col].value.to_s if dec_col
411
- filter_col = image_filter_columns()
412
- link_ref << '&filter=' + columns[filter_col].value.to_s if filter_col
413
- date_obs_col = image_date_obs_columns()
414
- link_ref << '&date_obs=' + columns[date_obs_col].value.to_s if date_obs_col
415
- teles_col = image_telescope_columns()
416
- link_ref << '&telescop=' + columns[teles_col].value.to_s if teles_col
417
- survey_col = image_survey_columns()
418
- link_ref << '&survey=' + columns[survey_col].value.to_s if survey_col
419
- instrum_col = image_instrument_columns()
420
- link_ref << '&instrument=' + columns[instrum_col].value.to_s if instrum_col
421
- sky_col = image_sky_columns()
422
- link_ref << '&sky=' + columns[sky_col].value.to_s if sky_col
423
- zerop_col = image_zeropoint_columns()
424
- link_ref << '&zeropoint=' + columns[zerop_col].value.to_s if zerop_col
425
- seeing_col = image_seeing_columns()
426
- link_ref << '&seeing=' + columns[seeing_col].value.to_s if seeing_col
427
- depth_col = image_depth_columns()
428
- link_ref << '&depth=' + columns[depth_col].value.to_s if depth_col
429
- exptime_col = image_exptime_columns()
430
- link_ref << '&exptime=' + columns[exptime_col].value.to_s if exptime_col
431
-
432
- return link_ref
433
- end
434
-
435
- # Create body for HTML table
436
- # [_res_:]
437
- # The resource from which to extract the table in question.
438
- # [_tbl_:]
439
- # The table inside the resource from which to extract the rows in question.
440
- # [_infer_add_to_cart_ref_:]
445
+
446
+ # Convert hms of right ascension to decimal degrees.
447
+ # [_ra:_]
441
448
  #
442
- # [_add_to_cart_link_value_:]
449
+ def convert_ra_to_degrees(ra)
450
+ hours, min, sec = ra.split(':')
451
+ degrees = (hours.to_f() * 15.0) +
452
+ (min.to_f() * 15.0 / 60.0) +
453
+ (sec.to_f() * 15.0 / (60.0 * 60.0))
454
+ end
455
+
456
+ # Convert dms of declination to degrees
457
+ # [_dec:_]
443
458
  #
444
- # [_add_to_cart_link_ref_:]
459
+ def convert_dec_to_degrees(dec)
460
+ degree, arcmin, arcsec = dec.split(':')
461
+ degree_f = degree.to_f()
462
+ arcmin_f = (arcmin.to_f() / 60.0)
463
+ arcsec_f = (arcsec.to_f() / (60.0 * 60.0))
464
+ return (degree_f - arcmin_f - arcsec_f) if degree_f < 0
465
+ return degree_f + arcmin_f + arcsec_f
466
+ end
467
+
468
+ # Creates the cart parameters
469
+ # [_cart_params:_]
470
+ #
471
+ # [_columns:_]
445
472
  #
446
- # [_infer_access_ref_:]
447
- # Link the access reference URL associated with a row.
448
- # [_access_ref_link_value_:]
449
- # For the access reference column, link this word.
450
- # [_access_ref_col_:]
473
+ def create_item_cart_params(cart_params, columns)
474
+ link_ref_array = []
475
+
476
+ cart_params.each do |key, value|
477
+ link_ref_array.push("#{key}=#{value}")
478
+ end
479
+
480
+ access_ref_index = image_access_reference_columns()
481
+ link_ref_array.push("resource=#{CGI.escape(columns[access_ref_index].value).to_s}") if access_ref_index
482
+ ra_index = image_ra_columns()
483
+ link_ref_array.push("rac=#{columns[ra_index].value.to_s}") if ra_index
484
+ dec_index = image_dec_columns()
485
+ link_ref_array.push("decc=#{columns[dec_index].value.to_s}") if dec_index
486
+ filter_index = image_filter_columns()
487
+ link_ref_array.push("filter=#{columns[filter_index].value.to_s}") if filter_index
488
+ date_obs_index = image_date_obs_columns()
489
+ link_ref_array.push("date_obs=#{columns[date_obs_index].value.to_s}") if date_obs_index
490
+ teles_index = image_telescope_columns()
491
+ link_ref_array.push("telescop=#{columns[teles_index].value.to_s}") if teles_index
492
+ survey_index = image_survey_columns()
493
+ link_ref_array.push("survey=#{columns[survey_index].value.to_s}") if survey_index
494
+ instrum_index = image_instrument_columns()
495
+ link_ref_array.push("instrument=#{columns[instrum_index].value.to_s}") if instrum_index
496
+ sky_index = image_sky_columns()
497
+ link_ref_array.push("sky=#{columns[sky_index].value.to_s}") if sky_index
498
+ zerop_index = image_zeropoint_columns()
499
+ link_ref_array.push("zeropoint=#{columns[zerop_index].value.to_s}") if zerop_index
500
+ seeing_index = image_seeing_columns()
501
+ link_ref_array.push("seeing=#{columns[seeing_index].value.to_s}") if seeing_index
502
+ depth_index = image_depth_columns()
503
+ link_ref_array.push("depth=#{columns[depth_index].value.to_s}") if depth_index
504
+ exptime_index = image_exptime_columns()
505
+ link_ref_array.push("exptime=#{columns[exptime_index].value.to_s}") if exptime_index
506
+
507
+ return link_ref_array.join('&')
508
+ end
509
+
510
+ # Create body for HTML table
511
+ # [_access_ref_index_:]
451
512
  # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
452
- # [_body_class_:]
453
- # The class to assign the body of the HTML table.
454
- # [_row_classes_:]
455
- # The class to assign the HTML table body rows.
456
- def create_body(res, tbl,
457
- infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref,
458
- infer_access_ref, access_ref_link_value, access_ref_col,
459
- body_class, row_classes)
460
-
461
- tbody = "<tbody class=\"#{body_class}\">\n"
513
+ # [_options_:]
514
+ #
515
+ def create_body(access_ref_index, options)
516
+ tbody = "<tbody class=\"#{options[:body_class]}\" align=\"center\">\n"
462
517
  row_count = 0
463
- rows(res, tbl).each do |tr|
464
- tbody << "<tr class=\"#{row_classes[row_count % 2]}\">\n"
465
-
466
- # Specially mark up the first column to link to the image.
467
- columns = tr.tds()
468
-
469
- if infer_add_to_cart_ref
470
- archive = add_to_cart_link_ref.slice(add_to_cart_link_ref.index('&archive='), add_to_cart_link_ref.length)
471
- archive = archive.slice('&archive='.length, archive.length)
472
- archive = archive.slice(0, archive.index('&')) if archive.index('&')
473
- link_id = 'add_' + archive.to_s + '_' + row_count.to_s
474
- url = create_add_to_cart_link(add_to_cart_link_ref, columns)
475
- js = "new Ajax.Request('#{url}', " +
476
- " {method: 'post', " +
477
- " onComplete: function(request){Element.hide('#{link_id}');}});"
478
- tbody << "<td><a id=\"#{link_id}\" href=\"javascript:void(0);\" " +
479
- "onclick=\"#{js};return false;\"" +
480
- ">#{add_to_cart_link_value}</a></td>\n"
481
- end
482
- if infer_access_ref
483
- link_ref = columns[access_ref_col].value
484
- tbody << "<td><a href=\"#{link_ref}\">#{access_ref_link_value}</a></td>\n"
485
- end
486
-
487
- col_count = 0
488
- columns.each do |td|
489
- tbody << "<td>#{td.value}</td>\n" if infer_access_ref and col_count != access_ref_col
490
- col_count += 1
518
+ rows_data = rows(options[:res], options[:tbl])
519
+ if rows_data
520
+ rows_data.each do |tr|
521
+ tbody << "<tr class=\"#{options[:row_classes][row_count % 2]}\">\n"
522
+
523
+ # Specially mark up the first column to link to the image.
524
+ columns = tr.tds()
525
+
526
+ if options[:infer_add_to_cart_ref] and access_ref_index
527
+ tbody << "<td><input type=\"checkbox\" " +
528
+ "id=\"checkbox_add_#{options[:cart_params][:archive]}_#{row_count.to_s}\" " +
529
+ "value=\"#{create_item_cart_params(options[:cart_params], columns)}\"/></td>\n"
530
+ end
531
+
532
+ if options[:infer_access_ref] and access_ref_index
533
+ tbody << "<td><a href=\"#{columns[access_ref_index].value}\">#{options[:access_ref_link_label]}</a></td>\n"
534
+ end
535
+
536
+ col_count = 0
537
+ #ra_index = image_ra_columns()
538
+ #dec_index = image_dec_columns()
539
+ columns.each do |td|
540
+ if col_count != access_ref_index
541
+ #if ra_index and col_count == ra_index
542
+ # tbody << "<td>#{convert_ra_to_degrees(td.value)}</td>\n"
543
+ #elsif dec_index and col_count == dec_index
544
+ # tbody << "<td>#{convert_dec_to_degrees(td.value)}</td>\n"
545
+ #else
546
+ tbody << "<td>#{td.value}</td>\n"
547
+ #end
548
+ end
549
+ col_count += 1
550
+ end
551
+
552
+ tbody << "</tr>\n"
553
+ row_count += 1
491
554
  end
492
- tbody << "</tr>\n"
493
- row_count += 1
494
555
  end
495
556
  tbody << "</tbody>"
496
-
557
+
497
558
  return tbody
498
559
  end
499
-
560
+
500
561
  # Create table for HTML VOTable
501
- # [_id_:]
502
- # The ID to assign to the HTML table as a whole.
503
- # [_show_border_:]
504
- # The boolean value to show HTML table border.
505
- # [_table_class_:]
506
- # The class to assign the HTML table as a whole.
507
562
  # [_thead_:]
508
563
  # The class to assign the HTML table thead.
509
564
  # [_tbody_:]
510
565
  # The class to assign the HTML table tbody.
511
- def create_table(id, show_border, table_class, thead, tbody)
512
- table = "<table class=\"#{table_class}\""
513
- table << " id=\"#{id}\"" if id
514
- table << " border=\"1\"" if show_border
515
- table << " width=\"100%\">\n"
516
- table << "#{thead}\n#{tbody}\n</table>"
517
- return table
566
+ # [_options_:]
567
+ # The options for this VOTable.
568
+ def create_votable(thead, tbody, options)
569
+ votable = "<img class=\"#{options[:throbber_class]}\" " +
570
+ " id=\"#{options[:throbber_id]}\" " +
571
+ " src=\"#{options[:throbber_src]}\" " +
572
+ " size=\"#{options[:throbber_size]}\"/>&nbsp;" +
573
+ "<span class=\"#{options[:flash_notice_class]}\" " +
574
+ " id=\"#{options[:flash_notice_id]}\"></span><br>\n"
575
+ votable << "<table class=\"#{options[:table_class]}\""
576
+ votable << " id=\"#{options[:id]}\"" if options[:id]
577
+ votable << " border=\"1\"" if options[:show_border]
578
+ votable << " width=\"100%\">\n"
579
+ votable << "#{thead}\n#{tbody}\n</table>"
580
+
581
+ return votable
518
582
  end
519
-
583
+
520
584
  # Convert the specified table in the specified resource into an HTML
521
585
  # table.
522
- # [_id_:]
523
- # The ID to assign to the HTML table as a whole.
524
- # [_add_to_cart_link_ref_:]
525
- #
526
- # [_res_:]
527
- # The resource from which to extract the table in question.
528
- # [_tbl_:]
529
- # The table inside the resource from which to extract the rows in question.
530
- # [_infer_add_to_cart_ref_:]
531
- #
532
- # [_add_to_cart_header_value_:]
533
- #
534
- # [_add_to_cart_link_value_:]
535
- #
536
- # [_infer_access_ref_:]
537
- # Link the access reference URL associated with a row.
538
- # [_access_ref_header_value_:]
539
- # For the access reference column, place this value in the header.
540
- # [_access_ref_link_value_:]
541
- # For the access reference column, link this word.
542
- # [_show_border_:]
543
- # The boolean value to show HTML table border
544
- # [_table_class_:]
545
- # The class to assign the HTML table as a whole.
546
- # [_header_class_:]
547
- # The class to assign the header of the HTML table.
548
- # [_body_class_:]
549
- # The class to assign the body of the HTML table.
550
- # [_row_classes_:]
551
- # The class to assign the HTML table body rows.
552
- def to_html(id=nil, add_to_cart_link_ref=nil, res=0, tbl=0,
553
- infer_add_to_cart_ref=true,
554
- add_to_cart_header_value='Add to Cart',
555
- add_to_cart_link_value='Add',
556
- infer_access_ref=true,
557
- access_ref_header_value='URL',
558
- access_ref_link_value='Retrieve',
559
- show_border=false,
560
- table_class='votable',
561
- header_class='header',
562
- body_class='body',
563
- row_classes=['row1', 'row2'])
586
+ # [_options_:]
587
+ # The options for this VOTable.
588
+ def to_html(options={})
589
+ # The ID to assign to the HTML table as a whole.
590
+ options[:id] = options[:id] || "#{votable}_#{Time.now.to_i}_#{rand(10000)}"
591
+
592
+ options[:infer_add_to_cart_ref] = true if options[:infer_add_to_cart_ref] == nil
593
+ options[:add_to_cart_header_label] = options[:add_to_cart_header_label] || 'Add to Cart'
594
+ options[:cart_params] = {} if options[:cart_params] == nil
595
+ #options[:add_to_cart_url] = options[:add_to_cart_url] || nil
596
+
597
+ options[:throbber_src] = options[:throbber_src] || '/images/general/indicator.gif'
598
+ options[:throbber_size] = options[:throbber_size] || '16x16'
599
+ options[:throbber_class] = options[:throbber_class] || 'throbber'
600
+ options[:throbber_id] = options[:throbber_id] || "#{options[:id]}_throbber_id"
601
+
602
+ options[:flash_notice_class] = options[:flash_notice_class] || 'flash_notice'
603
+ options[:flash_notice_id] = options[:flash_notice_id] || "#{options[:id]}_flash_notice_id"
604
+
605
+ # Link the access reference URL associated with a row.
606
+ options[:infer_access_ref] = true if options[:infer_access_ref] == nil
607
+ #options[:retrieve_link_ref] = options[:retrieve_link_ref] || nil
608
+ # For the access reference column, place this value in the header.
609
+ options[:access_ref_header_label] = options[:access_ref_header_label] || 'URL'
610
+ # For the access reference column, link this word.
611
+ options[:access_ref_link_label] = options[:access_ref_link_label] || 'Retrieve'
612
+ options[:ssl] = false if options[:ssl] == nil
613
+ #options[:resource_link] = options[:resource_link]
614
+
615
+ # The resource from which to extract the table in question.
616
+ options[:res] = options[:res] || 0
617
+ # The table inside the resource from which to extract the rows in question.
618
+ options[:tbl] = options[:tbl] || 0
619
+
620
+ # The boolean value to show HTML table border
621
+ options[:show_border] = false if options[:show_border] == nil
622
+ # The class to assign the HTML table as a whole.
623
+ options[:table_class] = options[:table_class] || 'votable'
624
+ # The class to assign the header of the HTML table.
625
+ options[:header_class] = options[:header_class] || 'header'
626
+ # The class to assign the body of the HTML table.
627
+ options[:body_class] = options[:body_class] || 'body'
628
+ # The class to assign the HTML table body rows.
629
+ options[:row_classes] = options[:row_classes] || ['row1', 'row2']
630
+
564
631
  begin
565
632
  # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
566
- access_ref_col = image_access_reference_columns()
567
-
568
- if access_ref_col
569
- # Create headers
570
- thead = create_headers(res, tbl,
571
- infer_add_to_cart_ref, add_to_cart_header_value,
572
- infer_access_ref, access_ref_header_value, access_ref_col,
573
- header_class, id)
574
-
575
- # Create body
576
- tbody = create_body(res, tbl,
577
- infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref,
578
- infer_access_ref, access_ref_link_value, access_ref_col,
579
- body_class, row_classes)
580
-
581
- return create_table(id, show_border, table_class, thead, tbody)
582
- else
583
- title = 'No Data'
584
- message = 'VOTable not contains data.'
585
- return create_message_table(table_class, header_class,
586
- body_class, row_classes, title, message)
587
- end
588
-
633
+ access_ref_index = image_access_reference_columns()
634
+
635
+ return create_votable(create_headers(access_ref_index, options),
636
+ create_body(access_ref_index, options),
637
+ options)
638
+
589
639
  rescue Exception => e
590
- title = 'Error'
591
- message = e.backtrace#@resources[0].info[0].text().to_s()
592
- table = create_message_table(table_class, header_class,
593
- body_class, row_classes, title, message)
640
+ title = 'Error...'
641
+ message = "VORuby error: #{e.message}<br>#{e.backtrace}"
642
+ message << "<br>#{@resources[0].info[0].text().to_s()}" if @resources[0].info[0]
643
+ create_message(title, message, options)
594
644
  end
595
645
  end
596
-
597
- def create_message_table(table_class, header_class, body_class,
598
- row_classes, title, message)
599
- table = "<table class=\"#{table_class}\" width=\"100%\">\n"
600
-
601
- table << " <thead class=\"#{header_class}\">\n"
602
- table << " <tr>\n"
603
- table << " <th>#{title}</th>\n"
604
- table << " </tr>\n"
605
- table << " </thead>\n"
606
-
607
- table << " <tbody class=\"#{body_class}\">\n"
608
- table << " <tr class=\"#{row_classes[0]}\">\n"
609
- table << " <td align=\"center\"><label>VOTable message: #{message}" +
610
- "</label></td>\n"
611
- table << " </tr>\n"
612
- table << " </tbody>\n"
613
-
614
- table << "</table>"
615
-
646
+
647
+ # Creates a message
648
+ # [_title_:]
649
+ #
650
+ # [_message_:]
651
+ #
652
+ # [_options_:]
653
+ # The options for this VOTable.
654
+ def create_message(title, message, options)
655
+ table = "<table class=\"#{options[:table_class]}\" width=\"100%\">\n" +
656
+ " <thead class=\"#{options[:header_class]}\">\n" +
657
+ " <tr>\n" +
658
+ " <th>#{title}</th>\n" +
659
+ " </tr>\n" +
660
+ " </thead>\n" +
661
+ " <tbody class=\"#{options[:body_class]}\">\n" +
662
+ " <tr class=\"#{options[:row_classes][0]}\">\n" +
663
+ " <td align=\"center\"><label>VOTable message: #{message}</label></td>\n" +
664
+ " </tr>\n" +
665
+ " </tbody>\n" +
666
+ "</table>"
667
+
616
668
  return table
617
669
  end
618
-
670
+
671
+ #
672
+ # [_attributes_:]
673
+ #
674
+ # [_name_:]
675
+ #
619
676
  def self._find_attr_value(attributes, name)
620
677
  attributes.each do |qname, value|
621
678
  return value if qname.name == name
622
679
  end
623
-
680
+
624
681
  return nil
625
682
  end
626
683
  end
627
684
  end
628
-
685
+
629
686
  end
630
- end
687
+ end