mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 05:34:55 +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
|
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 + 2 above (in title) is there because if the length was at the limit,
|
||||||
# the cutter method had issues, this gives it some space
|
# 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)
|
def protocolsio_string_to_table_element(description_string)
|
||||||
string_without_tables = string_html_table_remove(description_string)
|
string_without_tables = string_html_table_remove(description_string)
|
||||||
table_regex = %r{<table\b[^>]*>(.*?)<\/table>}m
|
table_regex = %r{<table\b[^>]*>(.*?)<\/table>}m
|
||||||
tr_regex = %r{<tr\b[^>]*>(.*?)<\/tr>}m
|
tr_regex = %r{<tr\b[^>]*>(.*?)<\/tr>}m
|
||||||
td_regex = %r{<td\b[^>]*>(.*?)<\/td>}m
|
td_regex = %r{<td\b[^>]*>(.*?)<\/td>}m
|
||||||
tables = {}
|
tables = {}
|
||||||
|
description_string.gsub! '<th>', '<td>'
|
||||||
|
description_string.gsub! '</th>', '</td>'
|
||||||
table_strings = description_string.scan(table_regex)
|
table_strings = description_string.scan(table_regex)
|
||||||
table_strings.each_with_index do |table, table_counter|
|
table_strings.each_with_index do |table, table_counter|
|
||||||
tables[table_counter.to_s] = {}
|
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 = {}
|
||||||
contents['data'] = []
|
contents['data'] = []
|
||||||
tr_strings.each_with_index do |tr, tr_counter|
|
tr_strings.each_with_index do |tr, tr_counter|
|
||||||
td_strings = tr[0].scan(td_regex)
|
td_strings = tr[0].scan(td_regex)
|
||||||
contents['data'][tr_counter] = []
|
contents['data'][tr_counter] = []
|
||||||
|
td_counter = td_strings.count
|
||||||
|
diff = PIO_TABLE_MIN_WIDTH - td_counter
|
||||||
td_strings.each do |td|
|
td_strings.each do |td|
|
||||||
td_stripped = ActionController::Base.helpers.strip_tags(td[0])
|
td_stripped = ActionController::Base.helpers.strip_tags(td[0])
|
||||||
contents['data'][tr_counter].push(td_stripped)
|
contents['data'][tr_counter].push(td_stripped)
|
||||||
end
|
end
|
||||||
|
next if td_counter >= PIO_TABLE_MIN_WIDTH
|
||||||
|
diff.times { contents['data'][tr_counter].push(' ') }
|
||||||
end
|
end
|
||||||
tables[table_counter.to_s]['contents'] = Base64.encode64(
|
tables[table_counter.to_s]['contents'] = Base64.encode64(
|
||||||
contents.to_s.sub('=>', ':')
|
contents.to_s.sub('=>', ':')
|
||||||
|
|
Loading…
Add table
Reference in a new issue