From 9be27524dfbb3e5a178c7a4ca052d469618547d6 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Fri, 22 Mar 2024 10:05:15 +0100 Subject: [PATCH] Feature: update metadata curator design and fix show all submissions (#551) * Feature: Update ontologies selector component (#508) * init ontologies selector design * ontologies selector options * display ontologies in ontologies selector * finalize ontologies selector design * put ontologies selector in the modal component * fix ontologies result display in ontologies selector * Make ontologies selector search bar work * show ontologies results count in ontologies selector * make groups filter work in ontologies selector * make filter by categories work in ontologies selector * add ontologies selector loading animation * make submission related filters work for ontologies selector * make select all work in ontologies selector * make retired ontologies and views filters work in ontologies selector * fix ontologies style in ontologies selector * add unselect all in ontologies selector * show tab selected checks count in ontologies selector * Clean ontologies selector js controller code * Add loading animation to ontologies selector * make ontology selection work in ontologies selector * add clear selection to ontologies selector * make ontologies selector component * remove duplicated cross icon in ontologies selector * clean ontologies controller code * use rails cache in ontologies selector * replace use cases of the old ontologies selector * delete old ontologies selector code * convert ontologies selector ui component into a helper * replace the usages of the ontologies selector ui component by the ontologies selector helper * replace 'selector' by 'ontologies_selector' in ontologies controller * add internationalisation to ontologies selector * remove the usage of static cache in ontologies selector * extract save and cancel buttons to a reusable helper in ontologies selector * undo extract save and cancel buttons to a reusable helper * add another type to the loader component that uses the style of the three dots * don't use display all in submissions fetching to make it faster in ontologies controller * remove ontology_picker_single code and replace its usages * give type argument in loader component a more significant value * replace ontologies selector text input by text input helper * replace ontologies selector chips components by chips components helpers * extract save and cancel buttons to helpers in the ontologies selector * fix ontologies selector name fild in search annotator and recommender page * fix text input helper label --------- Co-authored-by: Syphax bouazzouni * fix metadata curator show all submissions options that was not working * disable metadata curator bulk edit button see if re-enable in futur * use table and button components in the curator page --------- Co-authored-by: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> --- .../ontologies_metadata_curator_controller.rb | 48 +++++++++++++------ app/helpers/application_helper.rb | 4 +- .../_metadata_tab.html.haml | 10 ++-- .../_metadata_table.html.haml | 21 ++++---- 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/app/controllers/ontologies_metadata_curator_controller.rb b/app/controllers/ontologies_metadata_curator_controller.rb index 5e0e3564b..b66c5df32 100644 --- a/app/controllers/ontologies_metadata_curator_controller.rb +++ b/app/controllers/ontologies_metadata_curator_controller.rb @@ -9,24 +9,42 @@ def result @metadata_sel = params[:search] ? params[:search][:metadata] : [] @show_submissions = !params[:show_submissions].nil? @submissions = [] - + @ontologies = [] display_attribute = equivalent_properties(@metadata_sel) + %w[submissionId] - @submissions = LinkedData::Client::Models::OntologySubmission.all(acronym: @ontologies_ids.join('|'), display_links: false, display_context: false, include: display_attribute.join(','), include_status: 'RDF') - @submissions.reject!{|x| !@ontologies_ids.include?(x.id.split('/')[-3])} unless @ontologies_ids.empty? - @submissions.sort_by!{|x| x.id} + if @show_submissions + if @ontologies_ids.nil? || @ontologies_ids.empty? + @ontologies = LinkedData::Client::Models::Ontology.all + else + @ontologies_ids.each do |data| + @ontologies << LinkedData::Client::Models::Ontology.find_by_acronym(data).first + end + end + @ontologies.each do |ont| + submissions = ont.explore.submissions({ include: display_attribute.join(',') }) + submissions.each { |sub| append_submission(ont, sub) } + end + else + @submissions = LinkedData::Client::Models::OntologySubmission.all(acronym: @ontologies_ids.join('|'), display_links: false, display_context: false, include: display_attribute.join(',')) + @submissions.reject! { |x| !@ontologies_ids.include?(x.id.split('/')[-3]) } unless @ontologies_ids.empty? + @submissions.sort_by! { |x| x.id } + end + + + respond_to do |format| format.html { redirect_to admin_index_path } format.turbo_stream { render turbo_stream: [ - replace("selection_metadata_form", partial: "ontologies_metadata_curator/metadata_table"), - replace('edit_metadata_btn') do - " - #{helpers.button_tag(t('ontologies_metadata_curator.bulk_edit'), onclick: 'showEditForm(event)', class: "btn btn-outline-primary mx-1 w-100")} - #{raw helpers.help_tooltip(t('ontologies_metadata_curator.use_the_bulk_edit'))} - ".html_safe - end - ]} + replace("selection_metadata_form", partial: "ontologies_metadata_curator/metadata_table") + # TODO put again when bulk edit fixed + # replace('edit_metadata_btn') do + # " + # #{helpers.button_tag(t('ontologies_metadata_curator.bulk_edit'), onclick: 'showEditForm(event)', class: "btn btn-outline-primary mx-1 w-100")} + # #{raw helpers.help_tooltip(t('ontologies_metadata_curator.use_the_bulk_edit'))} + # ".html_safe + # end + ] } end end @@ -52,7 +70,7 @@ def show_metadata_value def edit if params[:selected_acronyms].nil? || params[:selected_metadata].nil? - render_turbo_stream alert_error(id: 'application_modal_content') {t('ontologies_metadata_curator.start_the_bulk_edit')} + render_turbo_stream alert_error(id: 'application_modal_content') { t('ontologies_metadata_curator.start_the_bulk_edit') } return end @@ -67,7 +85,7 @@ def update @active_ontology = ontology_and_submission_id(params[:active_ontology]) @all_metadata = params[:all_metadata]&.split error_responses = [] - @submissions = [] + @submissions = [] active_submission_data = params['submission']["#{@active_ontology[0]}_#{@active_ontology[1]}"] @selected_ontologies.each do |onto, sub_i| @@ -89,7 +107,7 @@ def update else streams = [alert_success { t('ontologies_metadata_curator.alert_success_submissions') }] @submissions.each do |submission| - submission.ontology = OpenStruct.new({acronym: submission.ontology}) + submission.ontology = OpenStruct.new({ acronym: submission.ontology }) streams << replace("#{ontology_submission_id_label(submission.ontology.acronym, submission.submissionId)}_row", partial: 'ontologies_metadata_curator/submission', locals: { submission: submission, attributes: @all_metadata }) end render_turbo_stream(*streams) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ba8629461..781a95cf8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -610,9 +610,9 @@ def ontologies_selector(id:, label: nil, name: nil, selected: nil) end end - def save_button_component(class_name: nil, id: , value:, data: nil) + def save_button_component(class_name: nil, id: , value:, data: nil, size: nil, type: nil) content_tag(:div, data: data, class: class_name) do - render Buttons::RegularButtonComponent.new(id:id, value: value, variant: "primary", state: 'regular') do |btn| + render Buttons::RegularButtonComponent.new(id:id, value: value, variant: "primary", state: 'regular', size: size, type: type) do |btn| btn.icon_right do inline_svg_tag "check.svg" end diff --git a/app/views/ontologies_metadata_curator/_metadata_tab.html.haml b/app/views/ontologies_metadata_curator/_metadata_tab.html.haml index 9e43f06ce..9aa15ac3d 100644 --- a/app/views/ontologies_metadata_curator/_metadata_tab.html.haml +++ b/app/views/ontologies_metadata_curator/_metadata_tab.html.haml @@ -1,20 +1,20 @@ %div.mt-5 - .rounded-json-button - = rounded_button_component("#{$REST_URL}/submissions?display=all&apikey=#{get_apikey}") + %div.mx-auto.w-75 = form_tag("/ontologies_metadata_curator/result", method: "post", data: { turbo: true, turbo_frame: 'selection_metadata_form'}) do %div %div.mx-1.pt-3 - = ontologies_selector(id:'metadata_curator_ontologies_selector', label: t("ontologies_metadata_curator.ontologies") ,name: 'ontology[ontologyId]', selected: @ontologies_ids) + = ontologies_selector(id:'metadata_curator_ontologies_selector', label: t("ontologies_metadata_curator.ontologies") ,name: 'ontology[ontologyId][]', selected: @ontologies_ids) %div.d-flex.align-items-center.mb-5 %div.mx-1{style: 'width: 65%'} = submission_metadata_selector %div.mx-1.mt-3{style: 'width: 15%'} = render SwitchInputComponent.new(id:"show_submissions", name: "show_submissions", label: t("ontologies_metadata_curator.include_all_submissions")) %div.mt-3.flex-shrink-0 - %button{type: "submit", class: "btn btn-success"} - = t("ontologies_metadata_curator.get_values") + = save_button_component(type: 'submit', id: 'curator-save-btn', value: t("ontologies_metadata_curator.get_values"), size: 'slim') %div.mt-3.flex-shrink-0.flex-fill.d-flex.align-items-center + .mx-2 + = rounded_button_component("#{$REST_URL}/submissions?display=all&apikey=#{get_apikey}") = turbo_frame_tag "edit_metadata_btn" = render TurboFrameComponent.new(id: 'selection_metadata_form') do diff --git a/app/views/ontologies_metadata_curator/_metadata_table.html.haml b/app/views/ontologies_metadata_curator/_metadata_table.html.haml index bcdedb855..665f98e46 100644 --- a/app/views/ontologies_metadata_curator/_metadata_table.html.haml +++ b/app/views/ontologies_metadata_curator/_metadata_table.html.haml @@ -9,16 +9,13 @@ = hidden_field_tag :all_metadata, @metadata_sel = submit_to_modal("Edit metadata values" , id:"show_bulk_edit_from_btn", class: "d-none", data: { show_modal_title_value: "Metadata curator editor", show_modal_size_value: 'modal-xl' }) - %div.table-container.mx-3 - %table.zebra - %thead - %tr - %th Ontologies - - @metadata_sel.each do |meta| - %th - %div - = render SwitchInputComponent.new(id: meta, name: 'selected_metadata[]', value: meta) do - %h6{style:'margin-top: 0.2rem'}=attr_label(meta, attr_metadata: attr_metadata(meta)) + = render TableComponent.new(id: 'metadata-curator-table', custom_class: 'border rounded p-1') do |t| + - t.header do |h| + - h.th {'Ontologies'} + - @metadata_sel.each do |meta| + - h.th do + %div + = render SwitchInputComponent.new(id: meta, name: 'selected_metadata[]', value: meta) do + %h6{style:'margin-top: 0.2rem'}=attr_label(meta, attr_metadata: attr_metadata(meta)) - %tbody - = render partial: 'submission', collection: @submissions, locals: {attributes: @metadata_sel} + = render partial: 'submission', collection: @submissions, locals: {attributes: @metadata_sel}