Skip to content

Commit

Permalink
Fix: adding new submission action and add a system for it (#403)
Browse files Browse the repository at this point in the history
* add sort by notes and projects to browse page

* fix chips button component to be clickable again

* make the visibility property in the ontology form required

* extract and reuse group chip component from browse page to ontology form

* add the add new submission to an ontology flow test

* prevent the add new submission form to copy all the old submission vals
  • Loading branch information
syphax-bouazzouni authored Dec 7, 2023
1 parent 61927a4 commit 8b196b5
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests-real-data-stageportal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: "Run remote API (stageportal) tests CI"

on:
push:
pull_request_target:
pull_request:
types: [ opened, reopened ]
env:
API_URL: https://data.stageportal.lirmm.fr/ # or ${{ secrets.API_URL }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-real-data-testportal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: "Run remote API (testportal) tests CI"

on:
push:
pull_request_target:
pull_request:
types: [ opened, reopened ]
env:
API_URL: https://data.testportal.lirmm.fr/ # or ${{ secrets.API_URL }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: "Run system tests CI"

on:
push:
pull_request_target:
pull_request:
types: [ opened, reopened ]
env:
API_URL: http://localhost:9393
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: "Run local API tests CI"

on:
push:
pull_request_target:
pull_request:
types: [ opened, reopened ]
env:
API_URL: http://localhost:9393
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
- if @type == "static"
%span.chip_button_container{@html_options}
= @text || content
- elsif !content
%a.chip_button_container_clickable{@html_options}
= @text
- else
%span.chip_button_container_clickable{@html_options}
= @text || content
= content
37 changes: 26 additions & 11 deletions app/controllers/concerns/ontology_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ def update_existent_ontology(acronym)
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(acronym).first
return nil if @ontology.nil?

[@ontology, @ontology.update(values: ontology_params)]
new_values = ontology_params
new_values.each do |key, values|
@ontology.send("#{key}=", values)
rescue StandardError
next
end
[@ontology, @ontology.update(values: new_values)]
end

def ontology_from_params
Expand Down Expand Up @@ -55,20 +61,19 @@ def errors_attributes
@errors.keys.map(&:to_s) if @errors.is_a?(Hash)
end

def new_submission_hash(ontology)
@submission = ontology.explore.latest_submission({ display: 'all' })

submission_params = submission_params(params[:submission])
def new_submission_hash(ontology, submission = nil)
@submission = submission
new_submission_params = submission_params(params[:submission])

if @submission
submission_params = submission_params(ActionController::Parameters.new(@submission.to_hash.delete_if do |k, v|
v.nil? || v.respond_to?(:empty?) && v.empty?
end.merge(submission_params)))
old_submission_values = @submission.to_hash.delete_if { |k, v| !copyable_submission_params?(k, v)}
new_submission_params = ActionController::Parameters.new(old_submission_values.merge(new_submission_params))
new_submission_params = submission_params(new_submission_params)
end

submission_params.delete 'submissionId'
submission_params[:ontology] = @ontology.acronym
ActionController::Parameters.new(submission_params)
new_submission_params.delete 'submissionId'
new_submission_params[:ontology] = ontology.acronym
ActionController::Parameters.new(new_submission_params)
end

def update_submission_hash(acronym)
Expand All @@ -88,4 +93,14 @@ def reset_agent_attributes
@submission[attr] = new_values
end
end

def copyable_submission_params?(key, value)
return false if value.nil? || (value.respond_to?(:empty?) && value.empty?)

attr_to_not_copy = [:versionIRI, :version, :deprecated, :valid, :curatedOn,
:pullLocation, :metadataVoc, :hasPriorVersion,
:submissionStatus]

!attr_to_not_copy.include?(key.to_sym)
end
end
6 changes: 6 additions & 0 deletions app/controllers/concerns/submission_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def submissions_paginate_filter(params)
submissions = submissions.sort_by { |x| -x[:popularity] }
elsif @selected_sort_by.eql?('fair')
submissions = submissions.sort_by { |x| -x[:fairScore] }
elsif @selected_sort_by.eql?('notes')
submissions = submissions.sort_by { |x| -x[:note_count] }
elsif @selected_sort_by.eql?('projects')
submissions = submissions.sort_by { |x| -x[:project_count] }
end
submissions
end
Expand Down Expand Up @@ -194,6 +198,8 @@ def ontology_filters_init(categories, groups)
['Sort by release date', 'released'],
['Sort by FAIR score', 'fair'],
['Sort by popularity', 'visits'],
['Sort by notes', 'notes'],
['Sort by projects', 'projects'],
]

init_filters(params)
Expand Down
9 changes: 2 additions & 7 deletions app/controllers/concerns/submission_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,9 @@ def submission_params(params)
]

submission_metadata.each do |m|

m_attr = m["attribute"].to_sym

attributes << if m["enforce"].include?("list")
[{ m_attr => {} }, { m_attr => []}]
else
m_attr
end
m_attr = Array(m["enforce"]).include?("list") ? [{ m_attr => {} }, { m_attr => []}] : m_attr
attributes << m_attr
end
p = params.permit(attributes.uniq)
p['pullLocation'] = '' if p['isRemote']&.eql?('3')
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def create
return
end
end
@submission = save_submission(new_submission_hash(@ontology))
@submission = @ontology.explore.latest_submission({ display: 'all' })
@submission = save_submission(new_submission_hash(@ontology, @submission))

if response_error?(@submission)
show_new_errors(@submission)
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,21 @@ def truncate_with_more(text, options = {})
output = "<span class='more_less_container'><span class='truncated_more'>#{truncate(text, :length => length, :omission => trailing_text)}" + more + "</span>"
end

def chips_component(id: , name: , label: , value: , checked: false , tooltip: nil, &block)
content_tag(:div, data: { controller: 'tooltip' }, title: tooltip) do
check_input(id: id, name: name, value: value, label: label, checked: checked, &block)
end
end

def group_chip_component(id: nil, name: , object: , checked: , value: nil, title: nil, &block)
title ||= object["name"]
value ||= (object["value"] || object["acronym"] || object["id"])

chips_component(id: id || value, name: name, label: object["acronym"],
checked: checked,
value: value, tooltip: title, &block)
end
alias :category_chip_component :group_chip_component

def add_comment_button(parent_id, parent_type)
if session[:user].nil?
Expand Down
8 changes: 6 additions & 2 deletions app/helpers/inputs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def select_input(name:, values:, id: nil, label: nil, selected: nil, multiple: f
data: data)
end

def check_input(id:, name:, value:, label: '', checked: false)
render ChipsComponent.new(name: name, id: id, label: label, value: value, checked: checked)
def check_input(id:, name:, value:, label: '', checked: false, &block)
render ChipsComponent.new(name: name, id: id, label: label, value: value, checked: checked) do |c|
if block_given?
capture(c, &block)
end
end
end

def switch_input(id:, name:, label:, checked: false, value: '', boolean_switch: false, style: nil)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def metadata_formats_buttons
['JsonLd', 'MOD/json-ld'],
['XML', 'MOD/rdf-xml']
]) do |format, label|
render ChipButtonComponent.new(type: 'clickable', 'data-action': "metadata-downloader#download#{format}") do
render ChipButtonComponent.new(type: 'clickable', 'data-action': "click->metadata-downloader#download#{format}") do
concat content_tag(:span, label)
concat content_tag(:span, inline_svg("summary/download.svg", width: '15px', height: '15px'))
end
Expand Down Expand Up @@ -607,7 +607,7 @@ def projects_field(projects, ontology_acronym = @ontology.acronym)
empty_state_message("No projects using #{ontology_acronym}")
else
horizontal_list_container(projects) do |project|
render ChipButtonComponent.new(url: project_path(project.acronym), text: project.name, type: "clickable")
render ChipButtonComponent.new(url: project_path(project.acronym), text: project.name, type: "clickable")
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions app/helpers/submission_inputs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def ontology_categories_input(ontology = @ontology, categories = @categories)
content_tag(:div, class: 'upload-ontology-chips-container') do
hidden_field_tag('ontology[hasDomain][]') +
categories.map do |category|
check_input(name: "ontology[hasDomain][]", id: category[:acronym], label: category[:acronym], value: category[:id], checked: ontology.hasDomain&.any? { |x| x.eql?(category[:id]) })
category_chip_component(id: category[:acronym], name: "ontology[hasDomain][]",
object: category, value: category[:id],
checked: ontology.hasDomain&.any? { |x| x.eql?(category[:id]) })
end.join.html_safe
end
end
Expand All @@ -159,7 +161,9 @@ def ontology_groups_input(ontology = @ontology, groups = @groups)
content_tag(:div, class: 'upload-ontology-chips-container') do
hidden_field_tag('ontology[group][]') +
groups.map do |group|
check_input(name: "ontology[group][]", id: group[:acronym], label: group[:acronym], value: group[:id], checked: ontology.group&.any? { |x| x.eql?(group[:id]) })
group_chip_component(name: "ontology[group][]", id: group[:acronym],
object: group, value: group[:id],
checked: ontology.group&.any? { |x| x.eql?(group[:id]) })
end.join.html_safe
end
end
Expand All @@ -173,7 +177,9 @@ def ontology_visibility_input(ontology = @ontology)

render(Layout::RevealComponent.new(init_show: ontology.viewingRestriction&.eql?('private'), show_condition: 'private')) do |c|
c.button do
select_input(label: "Visibility", name: "ontology[viewingRestriction]", values: %w[public private], selected: ontology.viewingRestriction)
select_input(label: "Visibility", name: "ontology[viewingRestriction]", required: true,
values: %w[public private],
selected: ontology.viewingRestriction)
end
content_tag(:div, class: 'upload-ontology-input-field-container') do
select_input(label: "Add or remove accounts that are allowed to see this ontology in #{portal_name}.", name: "ontology[acl]", values: @user_select_list, selected: ontology.acl, multiple: true)
Expand Down
18 changes: 7 additions & 11 deletions app/views/ontologies/browser/browse.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,13 @@
.collapse{id: "browse-#{key}-filter", class: "#{values[2].positive? ? 'show': ''}"}
.browse-filter-checks-container
- values.first.each do |object|
- title = (key.eql?(:categories) || key.eql?(:groups) ? object["name"] : '')
- value = (object["value"] || object["acronym"] || object["id"])
%div{data: {controller: 'tooltip'}, title: title}
= render ChipsComponent.new(id: value, name: key, value: value,
label: object["acronym"].humanize,
checked: values[1]&.include?(object["id"])) do |c|
- c.count do
%span.badge.badge-light.ml-1
= turbo_frame_tag "count_#{key}_#{object["id"]}", busy: true
%span.show-if-loading
= render LoaderComponent.new(small:true)
- title = (key.eql?(:categories) || key.eql?(:groups)) ? nil : ''
= group_chip_component(name: key, object: object, checked: values[1]&.include?(object["id"]), title: title) do |c|
- c.count do
%span.badge.badge-light.ml-1
= turbo_frame_tag "count_#{key}_#{object["id"]}", busy: true
%span.show-if-loading
= render LoaderComponent.new(small:true)

.browse-second-row
.browse-search-bar
Expand Down
5 changes: 3 additions & 2 deletions app/views/ontologies/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
.upload-ontology-input-field-container
= attribute_input('description', long_text: true)
- if @is_update_ontology
.upload-ontology-input-field-container
.upload-ontology-input-field-container{id: "submissionnotes_from_group_input"}
= attribute_input("notes", label: 'Change notes')
.upload-ontology-field-container
= render Layout::RevealComponent.new(init_show: @submission.hasOntologyLanguage&.eql?('SKOS'), show_condition: 'SKOS') do |c|
Expand All @@ -44,6 +44,7 @@
- c.button do
= attribute_input("status")
.upload-ontology-field-container
- @submission.valid = nil unless @submission.status&.eql?('retired')
= attribute_input("valid")
.upload-ontology-field-container
= render partial: 'ontologies/submission_location_form'
Expand All @@ -54,5 +55,5 @@
= attribute_input('modificationDate', label: 'Modification date', max_date: Date.today)
- else
= attribute_input('released', label: 'Date of original creation', max_date: Date.today)
.upload-ontology-contact
.upload-ontology-contact{id: "submissioncontact_from_group_input"}
= contact_input(show_help: false)
Loading

0 comments on commit 8b196b5

Please sign in to comment.