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

Add a natural language selector to the ontology submission form #314

Merged
merged 6 commits into from
Apr 24, 2024
Merged
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ gem 'graphql-client'
gem 'haml', '~> 5.1'
gem 'i18n'
gem 'iconv'
gem 'iso-639', '~> 0.3.6'
gem 'multi_json'
gem 'mysql2', '0.5.5'
gem 'oj'
Expand Down
20 changes: 11 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ GEM
concurrent-ruby (~> 1.0)
iconv (1.0.8)
io-console (0.7.2)
irb (1.11.1)
irb (1.12.0)
rdoc
reline (>= 0.4.2)
iso-639 (0.3.6)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand All @@ -192,7 +193,7 @@ GEM
railties (>= 3.2.16)
jsbundling-rails (1.3.0)
railties (>= 6.0.0)
json (2.7.1)
json (2.7.2)
language_server-protocol (3.17.0.3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
Expand Down Expand Up @@ -291,16 +292,16 @@ GEM
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.1.0)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rdoc (6.3.3)
rdoc (6.3.4.1)
recaptcha (5.9.0)
json
redis (4.8.1)
regexp_parser (2.9.0)
reline (0.4.2)
reline (0.5.0)
io-console (~> 0.5)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
Expand All @@ -325,19 +326,19 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.60.2)
rubocop (1.63.3)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
ruby_parser (3.20.3)
Expand Down Expand Up @@ -422,6 +423,7 @@ DEPENDENCIES
html2haml
i18n
iconv
iso-639 (~> 0.3.6)
jquery-rails
jquery-ui-rails
jsbundling-rails (~> 1.3)
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/submissions.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jQuery(document).ready(function(){
jQuery("#contacts").on("click", ".add-contact", addContact);
jQuery("#contacts").on("click", ".remove-contact", removeContact);

jQuery("#submission_naturalLanguage").select2({
dropdownParent: jQuery(".submissions form"),
include_hidden: false,
});

jQuery("#ontology_submission_form").validate({
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def new
def create
# Make the contacts an array
params[:submission][:contact] = params[:submission][:contact].values
params[:submission][:naturalLanguage].compact_blank!

@submission = LinkedData::Client::Models::OntologySubmission.new(values: submission_params)
@ontology = LinkedData::Client::Models::Ontology.get(params[:submission][:ontology])
Expand Down Expand Up @@ -53,8 +54,8 @@ def edit
def update
# Make the contacts an array
params[:submission][:contact] = params[:submission][:contact].values

params[:submission][:contact].delete_if { |c| c[:name].empty? || c[:email].empty? }
params[:submission][:naturalLanguage].compact_blank!

@ontology = LinkedData::Client::Models::Ontology.get(params[:submission][:ontology])
submissions = @ontology.explore.submissions
Expand All @@ -80,7 +81,7 @@ def submission_params
:synonymProperty, :definitionProperty, :authorProperty, :obsoleteProperty,
:obsoleteParent, :version, :status, :released, :isRemote, :pullLocation,
:filePath, { contact: [:name, :email] }, :homepage, :documentation,
:publication)
:publication, naturalLanguage: [])
p.to_h
end
end
13 changes: 13 additions & 0 deletions app/helpers/submissions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ def acronym_from_submission_muted(submission)
def acronym_from_params_muted
tag.small "for #{params[:ontology_id]}", class: 'text-muted'
end

def natural_language_selector(submission)
language_codes = ISO_639::ISO_639_1.map do |code|
# Get the alpha-2 code and English name
code.slice(2, 2).reverse
end
language_codes.sort! { |a, b| a.first.downcase <=> b.first.downcase }

selected = submission.naturalLanguage
select(:submission, :naturalLanguage, options_for_select(language_codes, selected),
{ include_blank: true },
{ multiple: true, class: 'form-select', 'aria-describedby': 'languageHelpBlock' })
end
end
8 changes: 8 additions & 0 deletions app/views/submissions/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
%div.col-sm-10
= text_field(:submission, :version, value: @submission.version, class: 'form-control')

-# Natural language
%div.row.mb-3
%label{class: 'col-sm-2 col-form-label'} Language
%div.col-sm-10
= natural_language_selector(@submission)
%div{id: 'languageHelpBlock', class: 'form-text'}
Enter the language of the content of the ontology, i.e., English, French, etc.

-# Status
%div.row.mb-3
%label{class: 'col-sm-2 col-form-label', for: "submission_status"}
Expand Down
Loading