From 53c162ffd87a96cbe208f25d39fbc3b5952c78bd Mon Sep 17 00:00:00 2001 From: Mike Sanders Date: Fri, 24 Apr 2026 13:49:04 +0200 Subject: [PATCH 1/2] make keywords available for controlled vocabulary --- app/dictionaries/keywords_dictionary.rb | 12 ++++++++++++ app/views/common/_dropdown.html.erb | 15 ++++++++------- app/views/events/_form.html.erb | 12 ++++++++++-- app/views/materials/_form.html.erb | 11 ++++++++++- config/dictionaries/keywords.yml | 3 +++ config/tess.example.yml | 2 +- 6 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 app/dictionaries/keywords_dictionary.rb create mode 100644 config/dictionaries/keywords.yml diff --git a/app/dictionaries/keywords_dictionary.rb b/app/dictionaries/keywords_dictionary.rb new file mode 100644 index 000000000..0bb8e372a --- /dev/null +++ b/app/dictionaries/keywords_dictionary.rb @@ -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 + +end \ No newline at end of file diff --git a/app/views/common/_dropdown.html.erb b/app/views/common/_dropdown.html.erb index fb5401501..6c61cdfa2 100644 --- a/app/views/common/_dropdown.html.erb +++ b/app/views/common/_dropdown.html.erb @@ -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 @@ -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 + %>
diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index b74a07d25..b2f309379 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -90,8 +90,16 @@ title: t('events.hints.hosts') %> - <%= 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, + label: t('activerecord.attributes.event.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 %> <% if !TeSS::Config.feature['disabled'].include? 'ardc_fields_of_research' %> diff --git a/app/views/materials/_form.html.erb b/app/views/materials/_form.html.erb index 22eb23b4e..0c901d641 100644 --- a/app/views/materials/_form.html.erb +++ b/app/views/materials/_form.html.erb @@ -37,7 +37,16 @@
- <%= 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'), + errors: @material.errors[:keywords], + title: t('events.hints.keywords'), + visibility_toggle: TeSS::Config.feature['materials_disabled'] %> + <% else %> + <%= f.multi_input :keywords, title: t('materials.hints.keywords'), visibility_toggle: TeSS::Config.feature['materials_disabled'] %> + <% end %> <%= f.input :licence, collection: licence_options_for_select, as: :grouped_select, group_method: :last, group_label_method: :first, diff --git a/config/dictionaries/keywords.yml b/config/dictionaries/keywords.yml new file mode 100644 index 000000000..28bbf0586 --- /dev/null +++ b/config/dictionaries/keywords.yml @@ -0,0 +1,3 @@ +placeholder: + title: placeholder + description: 'Placeholder' diff --git a/config/tess.example.yml b/config/tess.example.yml index 70560649e..a3c642f48 100644 --- a/config/tess.example.yml +++ b/config/tess.example.yml @@ -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 From 70d6272bada7c363c81ffc67e141b221ba37b723 Mon Sep 17 00:00:00 2001 From: Mike Sanders Date: Tue, 19 May 2026 15:14:08 +0200 Subject: [PATCH 2/2] copilot comments --- app/dictionaries/dictionary.rb | 6 +++++- app/dictionaries/keywords_dictionary.rb | 2 -- app/dictionaries/target_audience_dictionary.rb | 2 -- app/helpers/application_helper.rb | 4 +++- app/views/common/_dropdown.html.erb | 2 +- app/views/events/_form.html.erb | 6 +++--- app/views/materials/_form.html.erb | 4 ++-- config/dictionaries/keywords.yml | 3 --- 8 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 config/dictionaries/keywords.yml diff --git a/app/dictionaries/dictionary.rb b/app/dictionaries/dictionary.rb index fa71f9253..70bb91051 100644 --- a/app/dictionaries/dictionary.rb +++ b/app/dictionaries/dictionary.rb @@ -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 end def get_file_path(config_file, default_file) diff --git a/app/dictionaries/keywords_dictionary.rb b/app/dictionaries/keywords_dictionary.rb index 0bb8e372a..17f9236f6 100644 --- a/app/dictionaries/keywords_dictionary.rb +++ b/app/dictionaries/keywords_dictionary.rb @@ -3,8 +3,6 @@ class KeywordsDictionary < Dictionary DEFAULT_FILE = 'keywords.yml' - private - def dictionary_filepath get_file_path 'keywords', DEFAULT_FILE end diff --git a/app/dictionaries/target_audience_dictionary.rb b/app/dictionaries/target_audience_dictionary.rb index daa1d21e2..aa37b6805 100644 --- a/app/dictionaries/target_audience_dictionary.rb +++ b/app/dictionaries/target_audience_dictionary.rb @@ -3,8 +3,6 @@ class TargetAudienceDictionary < Dictionary DEFAULT_FILE = 'target_audience.yml' - private - def dictionary_filepath get_file_path 'target_audience', DEFAULT_FILE end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8c1ef2d02..d7a2483bd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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, @@ -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) diff --git a/app/views/common/_dropdown.html.erb b/app/views/common/_dropdown.html.erb index 6c61cdfa2..2b96604cf 100644 --- a/app/views/common/_dropdown.html.erb +++ b/app/views/common/_dropdown.html.erb @@ -46,7 +46,7 @@ render :partial => 'common/dropdown', %> -
+