diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 531b4fd6ff..cc65fc2408 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index f4ea240873..28f42ff7c6 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -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