Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions app/dictionaries/keywords_dictionary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dictionary of Keywords
class KeywordsDictionary < Dictionary

DEFAULT_FILE = 'keywords.yml'

private

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
15 changes: 8 additions & 7 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,6 +36,14 @@ 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 %>">
Expand Down
12 changes: 10 additions & 2 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' %>
<%= f.dropdown :keywords,
options: KeywordsDictionary.instance.options_for_select,
Comment thread
mikesndrs marked this conversation as resolved.
label: t('activerecord.attributes.event.keywords'),
Comment thread
mikesndrs marked this conversation as resolved.
Outdated
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 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'),
Comment thread
mikesndrs marked this conversation as resolved.
Outdated
errors: @material.errors[:keywords],
title: t('events.hints.keywords'),
Comment thread
mikesndrs marked this conversation as resolved.
Outdated
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
3 changes: 3 additions & 0 deletions config/dictionaries/keywords.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
placeholder:
title: placeholder
description: 'Placeholder'
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