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