Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide disabled fields in show page #1051

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions app/helpers/materials_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
%<link>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
%<link>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.
Expand All @@ -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
Expand Down Expand Up @@ -87,31 +87,37 @@ 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
string = "<p class=\"#{attribute}#{show_label ? ' no-spacing' : ''}\">"
unless value.blank? || value.try(:strip) == 'License Not Specified'
string << "<strong class='text-primary'> #{title || resource.class.human_attribute_name(attribute)}: </strong>" if show_label
if list
string << "<ul>"
string << '<ul>'
value.each do |v|
string << "<li>#{block_given? ? yield(v) : v}</li>"
end
string << "</ul>"
string << '</ul>'
else
string << value.to_s
end
Expand All @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@
title: t('events.hints.eligibility') %>

<!-- Field: Organiser -->
<%= 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 %>

<!-- Field: Contact -->
<%= 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 %>

<!-- Field: Host Institutions -->
<%= f.multi_input :host_institutions, errors: @event.errors[:host_institutions],
Expand Down
Loading