From 2eeedafbe5b18e77902ba5f9bf0a876afba77d76 Mon Sep 17 00:00:00 2001 From: Mike Sanders Date: Wed, 20 Nov 2024 11:19:50 +0100 Subject: [PATCH] hide disabled fields in show page --- app/helpers/materials_helper.rb | 37 ++++++++++++++++++++------------- app/models/event.rb | 2 ++ app/views/events/_form.html.erb | 8 +++++-- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/app/helpers/materials_helper.rb b/app/helpers/materials_helper.rb index 82136fd85..637979968 100644 --- a/app/helpers/materials_helper.rb +++ b/app/helpers/materials_helper.rb @@ -5,11 +5,11 @@ module MaterialsHelper with description and other meta information (e.g. ontological categorization, keywords, etc.).\n\n Materials can be added manually or automatically harvested from a provider's website.\n\n\ If your website contains training materials that you wish to include in #{TeSS::Config.site['title_short']},\ - %{link}.".freeze + %s.".freeze ELEARNING_MATERIALS_INFO = "e-Learning materials are curated materials focused on e-Learning.\n\n"\ "If your website contains e-Learning materials that you wish to include in #{TeSS::Config.site['title_short']},\ - %{link}.".freeze + %s.".freeze TOPICS_INFO = "#{TeSS::Config.site['title_short']} generates a scientific topic suggestion for each resource registered. It does this by passing the description and title of the resource to the Bioportal Annotator Web service. @@ -35,13 +35,13 @@ module MaterialsHelper ".freeze def materials_info - MATERIALS_INFO % { link: link_to('see here for details on automatic registration', - registering_resources_path(anchor: 'automatic')) } + format(MATERIALS_INFO, link: link_to('see here for details on automatic registration', + registering_resources_path(anchor: 'automatic'))) end def elearning_materials_info - ELEARNING_MATERIALS_INFO % { link: link_to('see here for details on automatic registration', - registering_resources_path(anchor: 'automatic')) } + format(ELEARNING_MATERIALS_INFO, link: link_to('see here for details on automatic registration', + registering_resources_path(anchor: 'automatic'))) end def learning_paths_info @@ -87,19 +87,25 @@ def target_audience_title_for_label(label) end def display_difficulty_level(resource) - value = resource.send("difficulty_level") + value = resource.send('difficulty_level') if value == 'beginner' - "• " + value + '• ' + value elsif value == 'intermediate' - "•• " + value + '•• ' + value elsif value == 'advanced' - "••• " + value + '••• ' + value else - "" + '' end end def display_attribute(resource, attribute, show_label: true, title: nil, markdown: false, list: false) + return if [ + TeSS::Config.feature['disabled'].include?(attribute.to_s), + (TeSS::Config.feature['materials_disabled'].include?(attribute.to_s) && resource.is_a?(Material)), + (TeSS::Config.feature['content_providers_disabled'].include?(attribute.to_s) && resource.is_a?(ContentProvider)) + ].any? + value = resource.send(attribute) value = render_markdown(value) if markdown value = yield(value) if block_given? && value.present? && !list @@ -107,11 +113,11 @@ def display_attribute(resource, attribute, show_label: true, title: nil, markdow unless value.blank? || value.try(:strip) == 'License Not Specified' string << " #{title || resource.class.human_attribute_name(attribute)}: " if show_label if list - string << "' else string << value.to_s end @@ -121,12 +127,13 @@ def display_attribute(resource, attribute, show_label: true, title: nil, markdow end def display_attribute_no_label(resource, attribute, markdown: false, &block) # resource e.g. <#Material> & symbol e.g. :target_audience - display_attribute(resource, attribute, markdown: markdown, show_label: false, &block) + display_attribute(resource, attribute, markdown:, show_label: false, &block) end def embed_youtube(material) renderer = Renderers::Youtube.new(material) return unless renderer.can_render? + content_tag(:div, class: 'embedded-content') do renderer.render_content.html_safe end @@ -135,7 +142,7 @@ def embed_youtube(material) def keywords_and_topics(resource, limit: nil) tags = [] - [:scientific_topic_names, :operation_names, :keywords].each do |field| + %i[scientific_topic_names operation_names keywords].each do |field| tags |= resource.send(field) if resource.respond_to?(field) end diff --git a/app/models/event.rb b/app/models/event.rb index fe2a879a5..bf5ec0d4c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -203,6 +203,8 @@ def self.facet_fields field_list.delete('fields') if TeSS::Config.feature['disabled'].include? 'ardc_fields_of_research' field_list.delete('node') unless TeSS::Config.feature['nodes'] field_list.delete('collections') unless TeSS::Config.feature['collections'] + field_list.delete('organizer') unless TeSS::Config.feature['organizer'] + field_list.delete('contact') unless TeSS::Config.feature['contact'] field_list end diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index 726cf424f..6b061875c 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -74,10 +74,14 @@ title: t('events.hints.eligibility') %> - <%= f.input :organizer, field_lock: true, label: 'Organiser', input_html: { title: t('events.hints.organizer') } %> + <% if !TeSS::Config.feature['disabled'].include? 'organizer' %> + <%= f.input :organizer, field_lock: true, label: 'Organiser', input_html: { title: t('events.hints.organizer') } %> + <% end %> - <%= f.input :contact, input_html: { rows: '5', title: t('events.hints.contact') }, field_lock: true %> + <% if !TeSS::Config.feature['disabled'].include? 'organizer' %> + <%= f.input :contact, input_html: { rows: '5', title: t('events.hints.contact') }, field_lock: true %> + <% end %> <%= f.multi_input :host_institutions, errors: @event.errors[:host_institutions],