Skip to content

Commit

Permalink
Merge pull request #331 from ncbo/bugfix/saving-custom-ontologies
Browse files Browse the repository at this point in the history
Fix misleading error message after custom ontology set save
  • Loading branch information
jvendetti authored Sep 19, 2024
2 parents 0b21134 + 8a8b346 commit a8753d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 8 additions & 9 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,23 @@ def destroy
end

def custom_ontologies
@user = LinkedData::Client::Models::User.find(params[:id])
@user = LinkedData::Client::Models::User.find_by_username(params[:id]).first if @user.nil?
@user = LinkedData::Client::Models::User.get(params[:id])

custom_ontologies = params[:ontology] ? params[:ontology][:ontologyId] : []
custom_ontologies.reject!(&:blank?)
@user.update_from_params(customOntology: custom_ontologies)
error_response = @user.update
response = @user.update

if error_response
flash[:notice] = 'Error saving Custom Ontologies, please try again'
else
updated_user = LinkedData::Client::Models::User.find(@user.id)
if response.success?
updated_user = LinkedData::Client::Models::User.get(@user.id, include: 'customOntology')
session[:user].update_from_params(customOntology: updated_user.customOntology)
flash[:notice] = if updated_user.customOntology.empty?
'Custom Ontologies were cleared'
'Custom ontology set successfully cleared'
else
'Custom Ontologies were saved'
'Custom ontology set successfully saved'
end
else
flash[:error] = 'Error saving custom ontology set. Please try again.'
end
redirect_to user_path(@user.username)
end
Expand Down
6 changes: 3 additions & 3 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@
}

%h4{class: 'pb-2 mt-5 mb-4 border-bottom'} Custom ontology set
#custom_ontologies.enable-lists
#custom_ontologies
- if at_slice?
= custom_ontology_set_slice_text
- else
= custom_ontology_set_intro_text
= button_tag('Select ontologies', type: 'button', id: 'edit_custom_ontologies', class: 'btn btn-primary')
- if @user_ontologies.present?
%ul
%ul{class: 'list-unstyled mt-3 mb-5'}
- @user_ontologies.each do |ont|
- ont = LinkedData::Client::Models::Ontology.get(ont)
- ont = LinkedData::Client::Models::Ontology.get(ont, include: 'name,acronym')
%li
#{ont.name} (#{ont.acronym})
- else
Expand Down

0 comments on commit a8753d9

Please sign in to comment.