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.
@@ -9,7 +9,7 @@ module VORuby
9
9
 
10
10
  module VOTable
11
11
  class CHANDRAVOTable < VOTable
12
-
12
+
13
13
  # Our object's contructor
14
14
  # [_votable:_]
15
15
  # The VOTable object
@@ -18,7 +18,7 @@ module VORuby
18
18
  votable.definitions, votable.coosys, votable.params,
19
19
  votable.info, votable.resources)
20
20
  end
21
-
21
+
22
22
  # Find the column number(s) associated with a Name.
23
23
  # Returns a list of column positions.
24
24
  # [_res_:]
@@ -27,7 +27,7 @@ module VORuby
27
27
  # The resource from which to extract the table in question.
28
28
  def find_columns(name, res=0, tbl=0)
29
29
  columns = []
30
-
30
+
31
31
  col_count = 0
32
32
  fields = fields(res, tbl)
33
33
  if fields
@@ -40,14 +40,14 @@ module VORuby
40
40
  end
41
41
  return columns
42
42
  end
43
-
43
+
44
44
  # Find a field in CHANDRA configuration file given a key.
45
45
  # Returns a hash with the field's attributes
46
46
  # [_key_:]
47
47
  # The key indexing on field's attribute
48
48
  def find_field_in_conf_file(key)
49
49
  chandra_field = {'id'=> nil, 'name'=> nil, 'ucd'=> nil}
50
-
50
+
51
51
  if key != nil
52
52
  CHANDRA_ARCHIVE_CONFIG.each do |archive|
53
53
  archive['votable_fields'].each do |field|
@@ -62,347 +62,310 @@ module VORuby
62
62
  end
63
63
  return chandra_field
64
64
  end
65
-
65
+
66
66
  def image_access_reference_columns()
67
67
  access_key = find_field_in_conf_file('URL')['name']
68
-
68
+
69
69
  if find_columns(access_key).first != nil
70
70
  find_columns(access_key).first
71
71
  end
72
72
  end
73
-
73
+
74
74
  def image_ra_columns
75
75
  ra_key = find_field_in_conf_file('RA')['name']
76
-
76
+
77
77
  if find_columns(ra_key).first != nil
78
78
  find_columns(ra_key).first
79
79
  end
80
80
  end
81
-
81
+
82
82
  def image_dec_columns
83
83
  dec_key = find_field_in_conf_file('Dec')['name']
84
-
84
+
85
85
  if find_columns(dec_key).first != nil
86
86
  find_columns(dec_key).first
87
87
  end
88
88
  end
89
-
89
+
90
90
  def image_filter_columns
91
91
  #filter_key = find_field_in_conf_file('')['name']
92
-
92
+
93
93
  #if find_columns(filter_key).first != nil
94
94
  # find_columns(filter_key).first
95
95
  #end
96
96
  end
97
-
97
+
98
98
  def image_date_obs_columns
99
99
  #date_obs_key = find_field_in_conf_file('')['name']
100
-
100
+
101
101
  #if find_columns(date_obs_key).first != nil
102
102
  # find_columns(date_obs_key).first
103
103
  #end
104
104
  end
105
-
105
+
106
106
  def image_telescope_columns
107
107
  #telescope_key = find_field_in_conf_file('')['name']
108
-
108
+
109
109
  #if find_columns(telescope_key).first != nil
110
110
  # find_columns(telescope_key).first
111
111
  #end
112
112
  end
113
-
113
+
114
114
  def image_survey_columns
115
115
  survey_key = find_field_in_conf_file('Object')['name']
116
-
116
+
117
117
  if find_columns(survey_key).first != nil
118
118
  find_columns(survey_key).first
119
119
  end
120
120
  end
121
-
121
+
122
122
  def image_instrument_columns
123
123
  instrument_key = find_field_in_conf_file('Instrument')['name']
124
-
124
+
125
125
  if find_columns(instrument_key).first != nil
126
126
  find_columns(instrument_key).first
127
127
  end
128
128
  end
129
-
129
+
130
130
  def image_sky_columns
131
131
  #sky_key = find_field_in_conf_file('')['name']
132
-
132
+
133
133
  #if find_columns(sky_key).first != nil
134
134
  # find_columns(sky_key).first
135
135
  #end
136
136
  end
137
-
137
+
138
138
  def image_zeropoint_columns
139
139
  #zeropoint_key = find_field_in_conf_file('')['name']
140
-
140
+
141
141
  #if find_columns(zeropoint_key).first != nil
142
142
  # find_columns(zeropoint_key).first
143
143
  #end
144
144
  end
145
-
145
+
146
146
  def image_seeing_columns
147
147
  #seeing_key = find_field_in_conf_file('')['name']
148
-
148
+
149
149
  #if find_columns(seeing_key).first != nil
150
150
  # find_columns(seeing_key).first
151
151
  #end
152
152
  end
153
-
153
+
154
154
  def image_depth_columns
155
155
  #depth_key = find_field_in_conf_file('')['name']
156
-
156
+
157
157
  #if find_columns(depth_key).first != nil
158
158
  # find_columns(depth_key).first
159
159
  #end
160
160
  end
161
-
161
+
162
162
  def image_exptime_columns
163
163
  #exptime_key = find_field_in_conf_file('')['name']
164
-
164
+
165
165
  #if find_columns(exptime_key).first != nil
166
166
  # find_columns(exptime_key).first
167
167
  #end
168
168
  end
169
-
170
- # Create headers for HTML table
171
- # [_res_:]
172
- # The resource from which to extract the table in question.
173
- # [_tbl_:]
174
- # The table inside the resource from which to extract the rows in question.
175
- # [_infer_add_to_cart_ref_:]
176
- #
177
- # [_add_to_cart_header_value_:]
178
- #
179
- # [_infer_access_ref_:]
180
- # Link the access reference URL associated with a row.
181
- # [_access_ref_header_value_:]
182
- # For the access reference column, place this value in the header.
183
- # [_access_ref_col_:]
169
+
170
+ # Create the headers for HTML table
171
+ # [_access_ref_index_:]
184
172
  # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
185
- # [_header_class_:]
186
- # The class to assign the header of the HTML table.
187
- def create_headers(res, tbl,
188
- infer_add_to_cart_ref, add_to_cart_header_value,
189
- infer_access_ref, access_ref_header_value, access_ref_col,
190
- header_class, id=nil)
191
-
192
- headers = Array.new
193
- thead = "<thead class=\"#{header_class}\">\n"
194
-
195
- thead << "<tr>\n"
196
- if infer_add_to_cart_ref
197
- thead << "<th>#{add_to_cart_header_value}</th>\n"
198
- headers.push("<a href=\"javascript:void(0);\" onclick=\"siap.addAllRowsToCart('#{id}');\">*</a>")
199
- end
200
- if infer_access_ref
201
- thead << "<th>#{access_ref_header_value}</th>\n"
202
- headers.push('&nbsp;')
173
+ # [_options_:]
174
+ #
175
+ def create_headers(access_ref_index, options)
176
+ thead, thead_2row = create_header_cart_links(options)
177
+
178
+ if options[:infer_access_ref] and access_ref_index
179
+ thead << "<th>#{options[:access_ref_header_label]}</th>\n"
180
+ thead_2row.push('&nbsp;')
203
181
  end
182
+
204
183
  col_count = 0
205
- fields(res, tbl).each do |field|
184
+ fields(options[:res], options[:tbl]).each do |field|
206
185
  field_archive = find_field_in_conf_file(field.name())
207
186
  field_ucd = field_archive['ucd']
208
- if infer_access_ref and col_count == access_ref_col
209
- headers[1] = field_ucd if field_ucd != 'nil'
187
+ if options[:infer_access_ref] and col_count == access_ref_index
188
+ thead_2row[1] = field_ucd if field_ucd != 'nil'
210
189
  else
211
190
  thead << "<th>#{field_archive['name']}</th>\n"
212
191
  if field_ucd != 'nil'
213
- headers.push(field_ucd)
192
+ thead_2row.push(field_ucd)
214
193
  else
215
- headers.push('&nbsp;')
194
+ thead_2row.push('&nbsp')
216
195
  end
217
196
  end
218
197
  col_count += 1
219
198
  end
199
+
220
200
  thead << " </tr>\n"
221
-
201
+
222
202
  thead << "<tr>\n"
223
- headers.each do |h|
203
+ thead_2row.each do |h|
224
204
  thead << "<th>#{h}</th>\n"
225
205
  end
226
206
  thead << "</tr>\n"
227
-
207
+
228
208
  thead << "</thead>"
229
-
209
+
230
210
  return thead
231
211
  end
232
-
233
- def create_add_to_cart_link(link_ref, columns)
234
- access_ref_col = image_access_reference_columns()
235
- link_ref << '&resource=' + CGI.escape(columns[access_ref_col].value).to_s if access_ref_col
236
- ra_col = image_ra_columns()
237
- link_ref << '&rac=' + columns[ra_col].value.to_s if ra_col
238
- dec_col = image_dec_columns()
239
- link_ref << '&decc=' + columns[dec_col].value.to_s if dec_col
240
- filter_col = image_filter_columns()
241
- link_ref << '&filter=' + columns[filter_col].value.to_s if filter_col
242
- date_obs_col = image_date_obs_columns()
243
- link_ref << '&date_obs=' + columns[date_obs_col].value.to_s if date_obs_col
244
- teles_col = image_telescope_columns()
245
- link_ref << '&telescop=' + columns[teles_col].value.to_s if teles_col
246
- survey_col = image_survey_columns()
247
- link_ref << '&survey=' + columns[survey_col].value.to_s if survey_col
248
- instrum_col = image_instrument_columns()
249
- link_ref << '&instrument=' + columns[instrum_col].value.to_s if instrum_col
250
- sky_col = image_sky_columns()
251
- link_ref << '&sky=' + columns[sky_col].value.to_s if sky_col
252
- zerop_col = image_zeropoint_columns()
253
- link_ref << '&zeropoint=' + columns[zerop_col].value.to_s if zerop_col
254
- seeing_col = image_seeing_columns()
255
- link_ref << '&seeing=' + columns[seeing_col].value.to_s if seeing_col
256
- depth_col = image_depth_columns()
257
- link_ref << '&depth=' + columns[depth_col].value.to_s if depth_col
258
- exptime_col = image_exptime_columns()
259
- link_ref << '&exptime=' + columns[exptime_col].value.to_s if exptime_col
260
-
261
- return link_ref
212
+
213
+ # Creates the cart parameters
214
+ # [_cart_params:_]
215
+ #
216
+ # [_columns:_]
217
+ #
218
+ def create_item_cart_params(cart_params, columns)
219
+ link_ref_array = []
220
+
221
+ cart_params.each do |key, value|
222
+ link_ref_array.push("#{key}=#{value}")
223
+ end
224
+
225
+ access_ref_index = image_access_reference_columns()
226
+ link_ref_array.push("resource=#{CGI.escape(columns[access_ref_index].value).to_s}") if access_ref_index
227
+ ra_index = image_ra_columns()
228
+ link_ref_array.push("rac=#{columns[ra_index].value.to_s}") if ra_index
229
+ dec_index = image_dec_columns()
230
+ link_ref_array.push("decc=#{columns[dec_index].value.to_s}") if dec_index
231
+ filter_index = image_filter_columns()
232
+ link_ref_array.push("filter=#{columns[filter_index].value.to_s}") if filter_index
233
+ date_obs_index = image_date_obs_columns()
234
+ link_ref_array.push("date_obs=#{columns[date_obs_index].value.to_s}") if date_obs_index
235
+ teles_index = image_telescope_columns()
236
+ link_ref_array.push("telescop=#{columns[teles_index].value.to_s}") if teles_index
237
+ survey_index = image_survey_columns()
238
+ link_ref_array.push("survey=#{columns[survey_index].value.to_s}") if survey_index
239
+ instrum_index = image_instrument_columns()
240
+ link_ref_array.push("instrument=#{columns[instrum_index].value.to_s}") if instrum_index
241
+ sky_index = image_sky_columns()
242
+ link_ref_array.push("sky=#{columns[sky_index].value.to_s}") if sky_index
243
+ zerop_index = image_zeropoint_columns()
244
+ link_ref_array.push("zeropoint=#{columns[zerop_index].value.to_s}") if zerop_index
245
+ seeing_index = image_seeing_columns()
246
+ link_ref_array.push("seeing=#{columns[seeing_index].value.to_s}") if seeing_index
247
+ depth_index = image_depth_columns()
248
+ link_ref_array.push("depth=#{columns[depth_index].value.to_s}") if depth_index
249
+ exptime_index = image_exptime_columns()
250
+ link_ref_array.push("exptime=#{columns[exptime_index].value.to_s}") if exptime_index
251
+
252
+ return link_ref_array.join('&')
262
253
  end
263
-
254
+
264
255
  # Create body for HTML table
265
- # [_res_:]
266
- # The resource from which to extract the table in question.
267
- # [_tbl_:]
268
- # The table inside the resource from which to extract the rows in question.
269
- # [_infer_add_to_cart_ref_:]
270
- #
271
- # [_add_to_cart_link_value_:]
272
- #
273
- # [_add_to_cart_link_ref_:]
274
- #
275
- # [_infer_access_ref_:]
276
- # Link the access reference URL associated with a row.
277
- # [_access_ref_link_value_:]
278
- # For the access reference column, link this word.
279
- # [_access_ref_col_:]
256
+ # [_access_ref_index_:]
280
257
  # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
281
- # [_body_class_:]
282
- # The class to assign the body of the HTML table.
283
- # [_row_classes_:]
284
- # The class to assign the HTML table body rows.
285
- def create_body(res, tbl,
286
- infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref,
287
- infer_access_ref, access_ref_link_value, access_ref_col,
288
- body_class, row_classes)
289
-
290
- tbody = "<tbody class=\"#{body_class}\">\n"
258
+ # [_options_:]
259
+ #
260
+ def create_body(access_ref_index, options)
261
+ tbody = "<tbody class=\"#{options[:body_class]}\" align=\"center\">\n"
291
262
  row_count = 0
292
- rows(res, tbl).each do |tr|
293
- tbody << "<tr class=\"#{row_classes[row_count % 2]}\">\n"
294
-
295
- # Specially mark up the first column to link to the image.
296
- columns = tr.tds()
297
-
298
- if infer_add_to_cart_ref
299
- archive = add_to_cart_link_ref.slice(add_to_cart_link_ref.index('&archive='), add_to_cart_link_ref.length)
300
- archive = archive.slice('&archive='.length, archive.length)
301
- archive = archive.slice(0, archive.index('&')) if archive.index('&')
302
- link_id = 'add_' + archive.to_s + '_' + row_count.to_s
303
- url = create_add_to_cart_link(add_to_cart_link_ref, columns)
304
- js = "new Ajax.Request('#{url}', " +
305
- " {method: 'post', " +
306
- " onComplete: function(request){Element.hide('#{link_id}');}});"
307
- tbody << "<td><a id=\"#{link_id}\" href=\"javascript:void(0);\" " +
308
- "onclick=\"#{js};return false;\"" +
309
- ">#{add_to_cart_link_value}</a></td>\n"
310
- end
311
- if infer_access_ref
312
- link_ref = columns[access_ref_col].value
313
- tbody << "<td><a href=\"#{link_ref}\">#{access_ref_link_value}</a></td>\n"
314
- end
315
-
316
- col_count = 0
317
- columns.each do |td|
318
- tbody << "<td>#{td.value}</td>\n" if infer_access_ref and col_count != access_ref_col
319
- col_count += 1
263
+ rows_data = rows(options[:res], options[:tbl])
264
+ if rows_data
265
+ rows_data.each do |tr|
266
+ tbody << "<tr class=\"#{options[:row_classes][row_count % 2]}\">\n"
267
+
268
+ # Specially mark up the first column to link to the image.
269
+ columns = tr.tds()
270
+
271
+ if options[:infer_add_to_cart_ref] and access_ref_index
272
+ tbody << "<td><input type=\"checkbox\" " +
273
+ "id=\"checkbox_add_#{options[:cart_params][:archive]}_#{row_count.to_s}\" " +
274
+ "value=\"#{create_item_cart_params(options[:cart_params], columns)}\"/></td>\n"
275
+ end
276
+
277
+ if options[:infer_access_ref] and access_ref_index
278
+ tbody << "<td><a href=\"#{columns[access_ref_index].value}\">#{options[:access_ref_link_label]}</a></td>\n"
279
+ end
280
+
281
+ col_count = 0
282
+ #ra_index = image_ra_columns()
283
+ #dec_index = image_dec_columns()
284
+ columns.each do |td|
285
+ if col_count != access_ref_index
286
+ #if ra_index and col_count == ra_index
287
+ # tbody << "<td>#{convert_ra_to_degrees(td.value)}</td>\n"
288
+ #elsif dec_index and col_count == dec_index
289
+ # tbody << "<td>#{convert_dec_to_degrees(td.value)}</td>\n"
290
+ #else
291
+ tbody << "<td>#{td.value}</td>\n"
292
+ #end
293
+ end
294
+ col_count += 1
295
+ end
296
+
297
+ tbody << "</tr>\n"
298
+ row_count += 1
320
299
  end
321
- tbody << "</tr>\n"
322
- row_count += 1
323
300
  end
324
301
  tbody << "</tbody>"
325
-
302
+
326
303
  return tbody
327
304
  end
328
-
305
+
329
306
  # Convert the specified table in the specified resource into an HTML
330
307
  # table.
331
- # [_id_:]
332
- # The ID to assign to the HTML table as a whole.
333
- # [_add_to_cart_link_ref_:]
334
- #
335
- # [_res_:]
336
- # The resource from which to extract the table in question.
337
- # [_tbl_:]
338
- # The table inside the resource from which to extract the rows in question.
339
- # [_infer_add_to_cart_ref_:]
340
- #
341
- # [_add_to_cart_header_value_:]
342
- #
343
- # [_add_to_cart_link_value_:]
344
- #
345
- # [_infer_access_ref_:]
346
- # Link the access reference URL associated with a row.
347
- # [_access_ref_header_value_:]
348
- # For the access reference column, place this value in the header.
349
- # [_access_ref_link_value_:]
350
- # For the access reference column, link this word.
351
- # [_show_border_:]
352
- # The boolean value to show HTML table border
353
- # [_table_class_:]
354
- # The class to assign the HTML table as a whole.
355
- # [_header_class_:]
356
- # The class to assign the header of the HTML table.
357
- # [_body_class_:]
358
- # The class to assign the body of the HTML table.
359
- # [_row_classes_:]
360
- # The class to assign the HTML table body rows.
361
- def to_html(id=nil, add_to_cart_link_ref=nil, res=0, tbl=0,
362
- infer_add_to_cart_ref=true,
363
- add_to_cart_header_value='Add to Cart',
364
- add_to_cart_link_value='Add',
365
- infer_access_ref=true,
366
- access_ref_header_value='URL',
367
- access_ref_link_value='Retrieve',
368
- show_border=false,
369
- table_class='votable',
370
- header_class='header',
371
- body_class='body',
372
- row_classes=['row1', 'row2'])
308
+ # [_options_:]
309
+ # The options for this VOTable.
310
+ def to_html(options={})
311
+ # The ID to assign to the HTML table as a whole.
312
+ options[:id] = options[:id] || "#{votable}_#{Time.now.to_i}_#{rand(10000)}"
313
+
314
+ options[:infer_add_to_cart_ref] = true if options[:infer_add_to_cart_ref] == nil
315
+ options[:add_to_cart_header_label] = options[:add_to_cart_header_label] || 'Add to Cart'
316
+ options[:cart_params] = {} if options[:cart_params] == nil
317
+ #options[:add_to_cart_url] = options[:add_to_cart_url] || nil
318
+
319
+ options[:throbber_src] = options[:throbber_src] || '/images/general/indicator.gif'
320
+ options[:throbber_size] = options[:throbber_size] || '16x16'
321
+ options[:throbber_class] = options[:throbber_class] || 'throbber'
322
+ options[:throbber_id] = options[:throbber_id] || "#{options[:id]}_throbber_id"
323
+
324
+ options[:flash_notice_class] = options[:flash_notice_class] || 'flash_notice'
325
+ options[:flash_notice_id] = options[:flash_notice_id] || "#{options[:id]}_flash_notice_id"
326
+
327
+ # Link the access reference URL associated with a row.
328
+ options[:infer_access_ref] = true if options[:infer_access_ref] == nil
329
+ #options[:retrieve_link_ref] = options[:retrieve_link_ref] || nil
330
+ # For the access reference column, place this value in the header.
331
+ options[:access_ref_header_label] = options[:access_ref_header_label] || 'URL'
332
+ # For the access reference column, link this word.
333
+ options[:access_ref_link_label] = options[:access_ref_link_label] || 'Retrieve'
334
+ options[:ssl] = false if options[:ssl] == nil
335
+ #options[:resource_link] = options[:resource_link]
336
+
337
+ # The resource from which to extract the table in question.
338
+ options[:res] = options[:res] || 0
339
+ # The table inside the resource from which to extract the rows in question.
340
+ options[:tbl] = options[:tbl] || 0
341
+
342
+ # The boolean value to show HTML table border
343
+ options[:show_border] = false if options[:show_border] == nil
344
+ # The class to assign the HTML table as a whole.
345
+ options[:table_class] = options[:table_class] || 'votable'
346
+ # The class to assign the header of the HTML table.
347
+ options[:header_class] = options[:header_class] || 'header'
348
+ # The class to assign the body of the HTML table.
349
+ options[:body_class] = options[:body_class] || 'body'
350
+ # The class to assign the HTML table body rows.
351
+ options[:row_classes] = options[:row_classes] || ['row1', 'row2']
352
+
373
353
  begin
374
354
  # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
375
- access_ref_col = image_access_reference_columns()
376
-
377
- if access_ref_col
378
- # Create headers
379
- thead = create_headers(res, tbl,
380
- infer_add_to_cart_ref, add_to_cart_header_value,
381
- infer_access_ref, access_ref_header_value, access_ref_col,
382
- header_class, id)
383
-
384
- # Create body
385
- tbody = create_body(res, tbl,
386
- infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref,
387
- infer_access_ref, access_ref_link_value, access_ref_col,
388
- body_class, row_classes)
389
-
390
- return create_table(id, show_border, table_class, thead, tbody)
391
- else
392
- title = 'No Data'
393
- message = 'VOTable not contains data.'
394
- return create_message_table(table_class, header_class,
395
- body_class, row_classes, title, message)
396
- end
397
-
355
+ access_ref_index = image_access_reference_columns()
356
+
357
+ return create_votable(create_headers(access_ref_index, options),
358
+ create_body(access_ref_index, options),
359
+ options)
360
+
398
361
  rescue Exception => e
399
- title = 'Error'
400
- message = @resources[0].info[0].text().to_s()
401
- table = create_message_table(table_class, header_class,
402
- body_class, row_classes, title, message)
362
+ title = 'Error...'
363
+ message = "VORuby error: #{e.message}<br>#{e.backtrace}"
364
+ message << "<br>#{@resources[0].info[0].text().to_s()}" if @resources[0].info[0]
365
+ create_message(title, message, options)
403
366
  end
404
367
  end
405
-
368
+
406
369
  end
407
370
  end
408
371