Skip to content
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
6 changes: 5 additions & 1 deletion app/dictionaries/dictionary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def keys
private

def load_dictionary
YAML.safe_load(File.read(dictionary_filepath)).with_indifferent_access
if File.exist?(dictionary_filepath)
YAML.safe_load(File.read(dictionary_filepath)).with_indifferent_access
else
{}
end
Comment on lines +81 to +85
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would hide legit errors e.g. if you typo'd the dictionary name

end

def get_file_path(config_file, default_file)
Expand Down
10 changes: 10 additions & 0 deletions app/dictionaries/keywords_dictionary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Dictionary of Keywords
class KeywordsDictionary < Dictionary

DEFAULT_FILE = 'keywords.yml'

def dictionary_filepath
get_file_path 'keywords', DEFAULT_FILE
end
Comment on lines +1 to +8
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be a concern as deployments with controlled vocabulary should not have the other values anyway

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda agree with copilot. It is a bit weird to have this as a dictionary when really it just needs to be a list of values. If you wanted to have a controlled list of 50 keywords you would have to make up 50 random ids that are never actually used anywhere.

It could easily just be a txt file with each keyword separated by a linebreak, or a YAML file with just a list of strings. But maybe that would require too many changes?


end
2 changes: 0 additions & 2 deletions app/dictionaries/target_audience_dictionary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class TargetAudienceDictionary < Dictionary

DEFAULT_FILE = 'target_audience.yml'

private

Comment on lines -6 to -7
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this private

def dictionary_filepath
get_file_path 'target_audience', DEFAULT_FILE
end
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def field_lock(name, _options = {})
def dropdown(name, options = {})
existing_values = object.send(name.to_sym)
existing = options[:options].select { |_label, value| existing_values.include?(value) }
visibility_toggle = options[:visibility_toggle] || []
@template.render(partial: 'common/dropdown', locals: { field_name: name, f: self,
model_name: options[:model_name],
resource: object,
Expand All @@ -370,7 +371,8 @@ def dropdown(name, options = {})
field_label: options[:label],
required: options[:required],
errors: options[:errors],
title: options[:title] })
title: options[:title],
hidden: hidden?(name, visibility_toggle) })
end

def hidden?(name, visibility_toggle)
Expand Down
17 changes: 9 additions & 8 deletions app/views/common/_dropdown.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ render :partial => 'common/dropdown',
options ||= format_for_dropdown(field_name.capitalize.constantize.all)
existing ||= format_for_dropdown(resource.send(field_name.pluralize))

# Remove existing objects from the pool of options
options = options - existing
dropdown_toggle_button_name ||= ''
if dropdown_toggle_button_name.blank?
dropdown_toggle_button_name = "Add #{field_name.to_s.sub(/_ids?\z/, '').humanize}"
end

# show the required label?
required ||= false

Expand All @@ -43,9 +36,17 @@ render :partial => 'common/dropdown',

# check title
title ||= ''

# Remove existing objects from the pool of options
options = options - existing
dropdown_toggle_button_name ||= ''
if dropdown_toggle_button_name.blank?
dropdown_toggle_button_name = "Add #{field_label.to_s.sub(/_ids?\z/, '').humanize}"
end

%>

<div class="form-group<%= ' has-error' if errors.size > 0 %>">
<div class="form-group<%= ' has-error' if errors.size > 0 %><%= ' hidden' if hidden %>">

<% if required %><label class="control-label string required"><abbr title="required">*</abbr></label><% end %>
<%= f.label field_label, class: 'control-label' %>
Expand Down
14 changes: 11 additions & 3 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@
title: t('events.hints.hosts') %>

<!-- Field: Keywords -->
<%= f.multi_input :keywords, errors: @event.errors[:keywords],
title: t('events.hints.keywords') %>
<% if TeSS::Config.feature['controlled_vocabulary_vars'].include? 'keywords' && File.exist?(KeywordsDictionary.instance.dictionary_filepath) %>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this check here

<%= f.dropdown :keywords,
options: KeywordsDictionary.instance.options_for_select,
Comment thread
mikesndrs marked this conversation as resolved.
label: t('activerecord.attributes.event.keywords', default: 'Keywords'),
errors: @event.errors[:keywords],
title: t('events.hints.keywords') %>
<% else %>
<%= f.multi_input :keywords, errors: @event.errors[:keywords],
title: t('events.hints.keywords') %>
<% end %>

<!-- Field: Fields -->
<% if !TeSS::Config.feature['disabled'].include? 'ardc_fields_of_research' %>
Expand All @@ -105,7 +113,7 @@
<% end %>

<!-- Field: Target Audience -->
<% if TeSS::Config.feature['controlled_vocabulary_vars'].include? 'target_audience' %>
<% if TeSS::Config.feature['controlled_vocabulary_vars'].include? 'target_audience' && File.exist?(TargetAudienceDictionary.instance.dictionary_filepath) %>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this check here

<%= f.dropdown :target_audience,
options: TargetAudienceDictionary.instance.options_for_select,
label: 'Target audiences',
Expand Down
11 changes: 10 additions & 1 deletion app/views/materials/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@
<hr>

<!-- Field: Keywords -->
<%= f.multi_input :keywords, title: t('materials.hints.keywords'), visibility_toggle: TeSS::Config.feature['materials_disabled'] %>
<% if TeSS::Config.feature['controlled_vocabulary_vars'].include? 'keywords' %>
<%= f.dropdown :keywords,
options: KeywordsDictionary.instance.options_for_select,
label: t('activerecord.attributes.event.keywords', default: 'Keywords'),
errors: @material.errors[:keywords],
title: t('materials.hints.keywords'),
visibility_toggle: TeSS::Config.feature['materials_disabled'] %>
Comment thread
mikesndrs marked this conversation as resolved.
<% else %>
<%= f.multi_input :keywords, title: t('materials.hints.keywords'), visibility_toggle: TeSS::Config.feature['materials_disabled'] %>
Comment thread
mikesndrs marked this conversation as resolved.
<% end %>

<!-- Field: Licence -->
<%= f.input :licence, collection: licence_options_for_select, as: :grouped_select, group_method: :last, group_label_method: :first,
Expand Down
2 changes: 1 addition & 1 deletion config/tess.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ default: &default
bioschemas_testing: false
collection_curation: true
auto_parse_vars: [] # available features to auto parse from description: ['keywords', 'target_audience']
controlled_vocabulary_vars: [] # available features: ['target_audience']
controlled_vocabulary_vars: [] # available features: ['keywords', 'target_audience']

# User login
invitation: false
Expand Down
Loading