mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +08:00
Merge pull request #1003 from Zanz2/table_missing_scrollbar_sci1818
Table missing scrollbar [SCI-1818]
This commit is contained in:
commit
8f5dd3df38
1 changed files with 16 additions and 1 deletions
|
@ -39,25 +39,40 @@ module ProtocolsIoHelper
|
|||
I18n.t('protocols.protocols_io_import.too_long').length
|
||||
# The + 2 above (in title) is there because if the length was at the limit,
|
||||
# the cutter method had issues, this gives it some space
|
||||
|
||||
# below are default min table settings (minimum 5x5)
|
||||
PIO_TABLE_MIN_WIDTH = 5
|
||||
PIO_TABLE_MIN_HEIGHT = 5
|
||||
|
||||
def protocolsio_string_to_table_element(description_string)
|
||||
string_without_tables = string_html_table_remove(description_string)
|
||||
table_regex = %r{<table\b[^>]*>(.*?)<\/table>}m
|
||||
tr_regex = %r{<tr\b[^>]*>(.*?)<\/tr>}m
|
||||
td_regex = %r{<td\b[^>]*>(.*?)<\/td>}m
|
||||
tables = {}
|
||||
description_string.gsub! '<th>', '<td>'
|
||||
description_string.gsub! '</th>', '</td>'
|
||||
table_strings = description_string.scan(table_regex)
|
||||
table_strings.each_with_index do |table, table_counter|
|
||||
tables[table_counter.to_s] = {}
|
||||
tr_strings = table[0].scan(tr_regex)
|
||||
tr_number = table[0].scan(tr_regex).count
|
||||
diff = PIO_TABLE_MIN_HEIGHT - tr_number # always tables have atleast 5 row
|
||||
table_fix_str = table[0]
|
||||
table_fix_str += '<tr></tr>' * diff if tr_number < PIO_TABLE_MIN_HEIGHT
|
||||
tr_strings = table_fix_str.scan(tr_regex)
|
||||
contents = {}
|
||||
contents['data'] = []
|
||||
tr_strings.each_with_index do |tr, tr_counter|
|
||||
td_strings = tr[0].scan(td_regex)
|
||||
contents['data'][tr_counter] = []
|
||||
td_counter = td_strings.count
|
||||
diff = PIO_TABLE_MIN_WIDTH - td_counter
|
||||
td_strings.each do |td|
|
||||
td_stripped = ActionController::Base.helpers.strip_tags(td[0])
|
||||
contents['data'][tr_counter].push(td_stripped)
|
||||
end
|
||||
next if td_counter >= PIO_TABLE_MIN_WIDTH
|
||||
diff.times { contents['data'][tr_counter].push(' ') }
|
||||
end
|
||||
tables[table_counter.to_s]['contents'] = Base64.encode64(
|
||||
contents.to_s.sub('=>', ':')
|
||||
|
|
Loading…
Add table
Reference in a new issue