Skip to content

Commit

Permalink
Fix: project page ontologies not selected (#790)
Browse files Browse the repository at this point in the history
* fix the issue in the projects page when the ontologies are private

* fix ontologies selector name in projects from

* pass the correct project ontologies value in project ontologies selector

* pass an empty array if used ontologies of a group is nil
  • Loading branch information
Bilelkihal authored Oct 30, 2024
1 parent 8bf8a9d commit e5387e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def show
redirect_to projects_path
return
end

@project = projects.first
@ontologies_used = []
onts_used = @project.ontologyUsed
onts_used.each do |ont_used|
ont = LinkedData::Client::Models::Ontology.find(ont_used)
unless ont.nil?
unless ont.nil? || ont.errors
@ontologies_used << Hash["name", ont.name, "acronym", ont.acronym]
end
end
Expand Down Expand Up @@ -62,7 +62,7 @@ def edit
@project = projects.first
@user_select_list = LinkedData::Client::Models::User.all.map {|u| [u.username, u.id]}
@user_select_list.sort! {|a,b| a[1].downcase <=> b[1].downcase}
@usedOntologies = @project.ontologyUsed || []
@usedOntologies = @project.ontologyUsed&.map{|o| o.split('/').last}
@ontologies = LinkedData::Client::Models::Ontology.all
end

Expand All @@ -76,7 +76,7 @@ def create

@project = LinkedData::Client::Models::Project.new(values: project_params)
@project_saved = @project.save

# Project successfully created.
if response_success?(@project_saved)
flash[:notice] = t('projects.project_successfully_created')
Expand Down Expand Up @@ -160,10 +160,10 @@ def destroy
def project_params
p = params.require(:project).permit(:name, :acronym, :institution, :contacts, { creator:[] }, :homePage,
:description, { ontologyUsed:[] })

p[:creator]&.reject!(&:blank?)
p[:ontologyUsed]&.reject!(&:blank?)
p.to_h
p[:ontologyUsed] ||= []
p = p.to_h
end

def flash_error(msg)
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
%div#ontology_picker_project{style: "padding-top: 2em;"}
- selected_ontologies = @project.ontologyUsed && @project.ontologyUsed.map {|id| id.split('/').last } || []
- locals = { sel_text: t('projects.form.select_ontologies'), selected_ontologies: selected_ontologies, form_object: :project, form_attribute: "ontologyUsed" }
= ontologies_selector(id:'projects_page_ontologies_selector' ,name: 'ontologies')
= ontologies_selector(id:'projects_page_ontologies_selector' ,name: 'project[ontologyUsed][]', selected: @usedOntologies)

0 comments on commit e5387e5

Please sign in to comment.