Skip to content

Commit

Permalink
update the ontology viewer to lazy the section that are not data
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 31, 2025
1 parent 12a62e8 commit de18fbd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@
@import "bootstrap_overrides";


<% if (ui_theme = $UI_THEME.to_s.parameterize).present? && File.exists?(Rails.root.join('app', 'assets', 'stylesheets', 'themes', ui_theme)) %>
<% if (ui_theme = $UI_THEME.to_s.parameterize).present? && File.exist?(Rails.root.join('app', 'assets', 'stylesheets', 'themes', ui_theme)) %>
@import "themes/<%= ui_theme %>/main";
<% end %>
9 changes: 7 additions & 2 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ def ontology_data_section?(section_title = current_section)
ontology_data_sections.include?(section_title)
end

def lazy_load_section?(section_title)
!(ontology_data_section?(section_title) || section_title.eql?('summary'))
end

def section_data(section_title)
if ontology_data_section?(section_title)
url_value = selected_section?(section_title) ? request.fullpath : "/ontologies/#{@ontology.acronym}?p=#{section_title}"
Expand All @@ -404,12 +408,13 @@ def section_data(section_title)
end
end

def lazy_load_section(section_title, &block)
def lazy_load_section(section_title, lazy_load: true, &block)
if current_section.eql?(section_title)
block.call
else
render TurboFrameComponent.new(id: section_title, src: "/ontologies/#{@ontology.acronym}?p=#{section_title}",
loading: "lazy",

loading: Rails.env.development? || lazy_load ? "lazy" : "eager",
target: '_top', data: { "turbo-frame-target": "frame" })
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_ontology_viewer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
- t.item_content do
%div.p-1{data: section_data(section_title)}
= language_selector_hidden_tag(section_title) if ontology_data_section?(section_title)
= lazy_load_section(section_title) { yield }
= lazy_load_section(section_title, lazy_load: lazy_load_section?(section_title)) { yield }


= render partial: "layouts/footer"
Expand Down

0 comments on commit de18fbd

Please sign in to comment.