From b7318e03ccce5777ed05695e90852970ceaf4c43 Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:41:33 +0100 Subject: [PATCH 01/26] Fix: Browse page switch style, and don't display current portal name button in browse results (#828) * fix broken switch style when using a long text with it * don't show current portal name button in browse page results * adjest switch text max-width only for browse filter * don't show portal name only if it's unique in browse page federated results --- app/assets/stylesheets/browse.scss | 3 +++ app/controllers/concerns/submission_filter.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/app/assets/stylesheets/browse.scss b/app/assets/stylesheets/browse.scss index a55292bde..57e857442 100644 --- a/app/assets/stylesheets/browse.scss +++ b/app/assets/stylesheets/browse.scss @@ -266,6 +266,9 @@ z-index: 1; } +.browse-filter .switch-filter > p, .switch-filter > div{ + max-width: 207px; +} .browse-search-bar input:focus { box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px; diff --git a/app/controllers/concerns/submission_filter.rb b/app/controllers/concerns/submission_filter.rb index c03914728..5bb9937e1 100644 --- a/app/controllers/concerns/submission_filter.rb +++ b/app/controllers/concerns/submission_filter.rb @@ -72,6 +72,7 @@ def merge_by_acronym(submissions) submissions.group_by { |x| x[:ontology]&.acronym }.each do |acronym, ontologies| ontology = canonical_ontology(ontologies) ontology[:sources] = ontologies.map { |x| x[:id] } + ontology[:sources].reject! { |id| id.include?(portal_name.downcase) } if ontology[:sources].size.eql?(1) merged_submissions << ontology end merged_submissions From a9dd3b7148f426434cdce965a118f5d271a9434e Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Thu, 7 Nov 2024 05:32:42 +0100 Subject: [PATCH 02/26] Fix: Search federation duplicated results merging issue (#830) * replace unexisting key :ontology_acronym and get the ontology acronym from the ontology_id when checking ontology duplication in federation * clean code of merge federated results method --- app/controllers/concerns/search_aggregator.rb | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/controllers/concerns/search_aggregator.rb b/app/controllers/concerns/search_aggregator.rb index 078c89c5c..f1f074272 100644 --- a/app/controllers/concerns/search_aggregator.rb +++ b/app/controllers/concerns/search_aggregator.rb @@ -251,17 +251,15 @@ def blacklist_cls_id_components(cls_id, blacklist_words) def merge_federated_results(search_results) search_results.each do |element| element[:root][:other_portals] = [] + element[:reuses].reject! do |reuse| - if (element[:root][:ontology_acronym] == reuse[:root][:ontology_acronym]) && (element[:root][:uri] == reuse[:root][:uri]) - portal_name = reuse[:root][:portal_name] - link = reuse[:root][:link] - element[:root][:other_portals] << { - name: portal_name, - color: federated_portal_color(portal_name), - light_color: federated_portal_light_color(portal_name), - link: link, - ontology_id: reuse[:root][:ontology_id] - } + element_ontology_id = element[:root][:ontology_id].split('/').last + element_uri = element[:root][:uri] + reuse_ontology_id = reuse[:root][:ontology_id].split('/').last + reuse_uri = reuse[:root][:uri] + + if element_ontology_id == reuse_ontology_id && element_uri == reuse_uri + element[:root][:other_portals] << build_other_portal_entry(reuse) true else false @@ -270,6 +268,16 @@ def merge_federated_results(search_results) end end + def build_other_portal_entry(reuse) + { + name: reuse[:root][:portal_name], + color: federated_portal_color(reuse[:root][:portal_name]), + light_color: federated_portal_light_color(reuse[:root][:portal_name]), + link: reuse[:root][:link], + ontology_id: reuse[:root][:ontology_id] + } + end + def swap_canonical_portal_results_first(search_results) all_submissions = LinkedData::Client::Models::OntologySubmission.all(include: 'pullLocation', include_views: true, display_links: false, display_context: false) From a3b1d97e034a6500d703d1c94487e8ef5057b0f3 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Thu, 7 Nov 2024 10:15:19 +0100 Subject: [PATCH 03/26] Feature: Migrate Label Ajax stimulus and Jquery code to Turbo (#821) * update select_language_label helper to select f no english found any language remaining over the not tagged * disable label ajax container * create label fetch component that for a id/uri fetch its label if found * add the possibility for the turbo frame to have custom error messages * remove and replace ontology entities link helpers * replace the label-ajax stimulus with turbo frame using ajax_link_chip * fix an uncatched error in concept label helper * remove label-ajax stimulus code * remove bp_ajax_controller old js code and update mappings to use the label fetcher component * fix bug of not opening eternal mapping details popup * remove label_link component * add a helper for the label fetcher component for clarity * add extern_link argument to ajax_link_chip to enforce external or not --- app/assets/javascripts/application.js | 3 - app/assets/javascripts/bp_ajax_controller.js | 187 ------------------ .../chip_button_component.html.haml | 2 +- app/components/label_fetcher_component.rb | 56 ++++++ .../label_fetcher_component.html.haml | 10 + app/components/label_link_component.rb | 22 --- app/components/turbo_frame_component.rb | 1 + .../turbo_frame_component.html.haml | 8 +- app/controllers/collections_controller.rb | 11 +- app/controllers/concepts_controller.rb | 16 +- app/controllers/label_xl_controller.rb | 7 +- app/controllers/mappings_controller.rb | 3 +- app/controllers/schemes_controller.rb | 13 +- app/helpers/application_helper.rb | 96 ++------- app/helpers/collections_helper.rb | 10 +- app/helpers/components_helper.rb | 4 + app/helpers/concepts_helper.rb | 16 +- app/helpers/mappings_helper.rb | 39 ++-- app/helpers/schemes_helper.rb | 11 +- app/javascript/controllers/index.js | 6 - .../controllers/label_ajax_controller.js | 83 -------- .../labels_ajax_container_controller.js | 10 - .../turbo_frame_error_controller.js | 5 +- app/views/collections/_list_view.html.haml | 2 +- app/views/concepts/_show.html.haml | 2 +- app/views/mappings/_mapping_table.html.haml | 4 - app/views/mappings/_show.html.haml | 9 +- 27 files changed, 162 insertions(+), 474 deletions(-) delete mode 100644 app/assets/javascripts/bp_ajax_controller.js create mode 100644 app/components/label_fetcher_component.rb create mode 100644 app/components/label_fetcher_component/label_fetcher_component.html.haml delete mode 100644 app/components/label_link_component.rb delete mode 100644 app/javascript/controllers/label_ajax_controller.js delete mode 100644 app/javascript/controllers/labels_ajax_container_controller.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1a42c6580..617e38d37 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,7 +12,6 @@ // //= require bioportal //= require admin/licenses -//= require bp_ajax_controller //= require bp_notes //= require bp_form_complete //= require bp_admin @@ -20,5 +19,3 @@ //= require projects //= require Chart.min //= require application_esbuild - - diff --git a/app/assets/javascripts/bp_ajax_controller.js b/app/assets/javascripts/bp_ajax_controller.js deleted file mode 100644 index a67e66550..000000000 --- a/app/assets/javascripts/bp_ajax_controller.js +++ /dev/null @@ -1,187 +0,0 @@ - -"use strict"; - -// Note similar code in concepts_helper.rb mirrors the following code: -function bp_ont_link(ont_acronym){ - return "/ontologies/" + ont_acronym; -} -function bp_cls_link(cls_id, ont_acronym){ - return bp_ont_link(ont_acronym) + "?p=classes&conceptid=" + encodeURIComponent(cls_id); -} -function get_link_for_cls_ajax(cls_id, ont_acronym) { - // ajax call will replace the class label using data attributes (triggered by class='cls4ajax') - let ajax_uri = '/ajax/classes/label' - let data_cls = `data-label-ajax-cls-id-value='${cls_id}' ` - let data_ont = `data-label-ajax-ontology-acronym-value='${ont_acronym}'` - let data_ajax_uri = `data-label-ajax-ajax-uri-value='${ajax_uri}' ` - - let data = `data-controller='label-ajax' ${data_ont} ${data_cls} ${data_ajax_uri}` - - return `${cls_id}` -} - -function get_link_for_ont_ajax(ont_acronym) { - var data_ont = " data-ont='" + ont_acronym + "' "; - return "" + ont_acronym + ""; -} - -var - ajax_process_interportal_cls_interval = null, - ajax_process_ont_interval = null, - ajax_process_timeout = 20, // Timeout after 20 sec. - ajax_process_timing = 250; // It takes about 250 msec to resolve a class ID to a prefLabel - -var ajax_process_init = function () { - ajax_process_ont_init(); - ajax_process_interportal_cls_init(); -}; - -var ajax_process_halt = function () { - ajax_process_ont_halt(); - ajax_process_interportal_cls_halt(); -}; - - -// ************************************************************************************** -// ONTOLOGY NAMES - -// Note: If we don't query every time, using the array should be faster; it -// means the ajax_ont_init must be called after all the elements -// are created because they will not be detected in a dynamic iteration. -var ajax_ont_array = []; -var ajax_process_ont_init = function() { - ajax_ont_array = jQuery("a.ont4ajax").toArray(); - ajax_process_ont_interval = window.setInterval(ajax_process_ont, ajax_process_timing); -}; -var ajax_process_ont_halt = function () { - ajax_ont_array = []; - window.clearInterval(ajax_process_ont_interval); // stop the ajax process - // Note: might leave faulty href links, but it usually means moving on to entirely different content - // so it's not likely those links will be available for interaction. - // clear all the classes and ontologies to be resolved by ajax - //jQuery("a.ont4ajax").removeClass('ont4ajax'); - //jQuery("a.ajax-modified-ont").removeClass('ajax-modified-ont'); -}; -var ajax_process_ont = function() { - if( ajax_ont_array.length === 0 ){ - ajax_process_ont_halt(); - return true; - } - // Note: If we don't query every time, using the array should be faster; it - // means the ajax_ont_init must be called after all the elements - // are created because they will not be detected in a dynamic iteration. - //var linkA = jQuery("a.ont4ajax").first(); - var linkA = ajax_ont_array.shift(); - if(linkA === undefined){ - return true; - } - linkA = jQuery(linkA); - if(linkA.hasClass('ajax-modified-ont') ){ - // How did we get here? It should not have the ont4ajax class! - linkA.removeClass('ont4ajax'); - return true; // processed this one already. - } - linkA.removeClass('ont4ajax'); // processing this one. - var ont_acronym = linkA.attr('data-ont'); - var ajax_uri = "/ajax/json_ontology/?ontology=" + encodeURIComponent(ont_acronym); - jQuery.ajax({ - url: ajax_uri, - timeout: ajax_process_timeout * 1000, - success: function(data){ - if(typeof data !== "undefined" && data.hasOwnProperty('name')){ - var ont_name = data.name; - linkA.text(ont_name); - linkA.addClass('ajax-modified-ont'); // processed this one. - // find and process any identical ontologies - jQuery('a[href="/ontologies/' + data.acronym + '"]').each(function(i,e){ - var link = jQuery(this); - if(! link.hasClass('ajax-modified-ont') ){ - link.removeClass('ont4ajax'); // processing this one. - link.text(ont_name); - link.addClass('ajax-modified-ont'); // processed this one. - } - }); - } - }, - error: function(data){ - linkA.addClass('ajax-error'); // processed this one. - } - }); -}; - - -// ************************************************************************************** -// INTERPORTAL CLASS LABELS - -// Note: If we don't query every time, using the array should be faster; it -// means the ajax_process_init must be called after all the elements -// are created because they will not be detected in a dynamic iteration. -var ajax_interportal_cls_array = []; - -var ajax_process_interportal_cls_init = function() { - ajax_interportal_cls_array = jQuery("a.interportalcls4ajax").toArray(); - ajax_process_interportal_cls_interval = window.setInterval(ajax_process_interportal_cls, ajax_process_timing); -}; - -var ajax_process_interportal_cls_halt = function () { - ajax_interportal_cls_array = []; - window.clearInterval(ajax_process_interportal_cls_interval); // stop the ajax process - // Note: might leave faulty href links, but it usually means moving on to entirely different content - // so it's not likely those links will be available for interaction. - // clear all the classes and ontologies to be resolved by ajax - //jQuery("a.cls4ajax").removeClass('cls4ajax'); - //jQuery("a.ajax-modified-cls").removeClass('ajax-modified-cls'); -}; - -var ajax_process_interportal_cls = function() { - // Check on whether to stop the ajax process - if( ajax_interportal_cls_array.length === 0 ){ - ajax_process_interportal_cls_halt(); - return true; - } - // Note: If we don't query every time, using the array should be faster; it - // means the ajax_process_init must be called after all the elements - // are created because they will not be detected in a dynamic iteration. - //var linkA = jQuery("a.cls4ajax").first(); - var linkA = ajax_interportal_cls_array.shift(); // put first item in linkA and delete it from array - if(linkA === undefined){ - return true; - } - linkA = jQuery(linkA); - if(linkA.hasClass('ajax-modified-cls') ){ - // How did we get here? It should not have the interportalcls4ajax class! - linkA.removeClass('interportalcls4ajax'); - return true; // processing or processed this one already. - } - linkA.removeClass('interportalcls4ajax'); // processing this one. - var unique_id = linkA.attr('href'); - - var portal_acronym = linkA.attr('portal-cls'); - var ajax_uri = linkA.attr('data-cls') + jQuery(document).data().bp.config.interportal_hash[portal_acronym].apikey; - jQuery.ajax({ - url: ajax_uri, - timeout: ajax_process_timeout * 1000, - success: function(data){ - var label = data.prefLabel - if (typeof label !== "undefined" && label.length > 0) { - linkA.html(label); - linkA.addClass('ajax-modified-cls'); - // find and process any identical classes (low probability) - jQuery( 'a[href="' + unique_id + '"]').each(function(i,e){ - var link = jQuery(this); - if(! link.hasClass('ajax-modified-cls') ){ - link.removeClass('interportalcls4ajax'); // processing this one. - link.html(label); - link.addClass('ajax-modified-cls'); // processed this one. - } - }); - } else { - // remove the unique_id separator and the ontology acronym from the href - linkA.addClass('ajax-modified-cls'); - } - }, - error: function(data){ - linkA.addClass('ajax-error'); // processed this one. - } - }); -}; diff --git a/app/components/chip_button_component/chip_button_component.html.haml b/app/components/chip_button_component/chip_button_component.html.haml index 26172a548..f2dd0d3dd 100644 --- a/app/components/chip_button_component/chip_button_component.html.haml +++ b/app/components/chip_button_component/chip_button_component.html.haml @@ -4,7 +4,7 @@ = @text || content - elsif !content %a.chip_button_container_clickable{@html_options} - = @text + = @text.html_safe - else %span.chip_button_container_clickable{@html_options} = content diff --git a/app/components/label_fetcher_component.rb b/app/components/label_fetcher_component.rb new file mode 100644 index 000000000..f89f39d16 --- /dev/null +++ b/app/components/label_fetcher_component.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +class LabelFetcherComponent < ViewComponent::Base + include UrlsHelper, Turbo::FramesHelper, ModalHelper + + def initialize(id:, label: nil, link: nil, ajax_src: nil, open_in_modal: false, target: nil, external: false) + super + @id = id + @link = link + @ajax_src = ajax_src + @open_in_modal = open_in_modal + @target = target + @external = external + @label = label + + if external_link? + @link = id + @target ||= '_blank' + else + @target ||= '_top' + end + + end + + def external_link? + (@label.nil? || @label.eql?(@id)) && @external + end + + def label_fetcher_container(&block) + id = "#{escape(@id)}_label" + if @ajax_src + render(TurboFrameComponent.new(id: id, src: "#{@ajax_src}&target=#{@target}", loading: 'lazy')) do |t| + t.loader do + render ChipButtonComponent.new(url: @id, text: "#{@id} #{render(LoaderComponent.new(small: true))}", type: 'clickable', target: '_blank') + end + + t.error do + capture(&block) + end + end + else + turbo_frame_tag(id) do + capture(&block) + end + end + + end + + def link_with_icon + if external_link? + ExternalLinkTextComponent.new(text: @label).call + else + InternalLinkTextComponent.new(text: @label).call + end + end +end diff --git a/app/components/label_fetcher_component/label_fetcher_component.html.haml b/app/components/label_fetcher_component/label_fetcher_component.html.haml new file mode 100644 index 000000000..80587133d --- /dev/null +++ b/app/components/label_fetcher_component/label_fetcher_component.html.haml @@ -0,0 +1,10 @@ += label_fetcher_container do + - if @open_in_modal + = render ChipButtonComponent.new(type: 'clickable') do + = link_to_modal(@label, @link) + - else + %span + = render ChipButtonComponent.new(url: @link, + type: 'clickable', + text: link_with_icon, + target: @target) diff --git a/app/components/label_link_component.rb b/app/components/label_link_component.rb deleted file mode 100644 index 3d8ecee98..000000000 --- a/app/components/label_link_component.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class LabelLinkComponent < ViewComponent::Base - - def initialize(id:, text:, icon: 'popup-link') - @id = id - @text = text - @icon = icon - end - - def call - if @id.eql?(@text) - ExternalLinkTextComponent.new(text: @text).call - else - InternalLinkTextComponent.new(text: @text).call - end - end - - def self.inline(id, text) - { plain: LabelLinkComponent.new(id: id, text: text).call } - end -end diff --git a/app/components/turbo_frame_component.rb b/app/components/turbo_frame_component.rb index d25322e15..1e54e24ce 100644 --- a/app/components/turbo_frame_component.rb +++ b/app/components/turbo_frame_component.rb @@ -4,6 +4,7 @@ class TurboFrameComponent < ViewComponent::Base include Turbo::FramesHelper renders_one :loader + renders_one :error def initialize(id:, src: '', **html_options) @id = id diff --git a/app/components/turbo_frame_component/turbo_frame_component.html.haml b/app/components/turbo_frame_component/turbo_frame_component.html.haml index 1c5d0d9f5..a288d8eac 100644 --- a/app/components/turbo_frame_component/turbo_frame_component.html.haml +++ b/app/components/turbo_frame_component/turbo_frame_component.html.haml @@ -8,5 +8,9 @@ - else %div.p-3 = render LoaderComponent.new(type: 'pulsing') - %div{'data-turbo-frame-error-target': 'errorMessage', style:'display: none; width: 100%'} - = render Display::AlertComponent.new(type:'danger') \ No newline at end of file + %span{'data-turbo-frame-error-target': 'errorMessage', style:'display: none; width: 100%'} + - if error? + = error + - else + %div + = render Display::AlertComponent.new(type:'danger') diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index c01c0cf87..fcfda0256 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -1,7 +1,6 @@ class CollectionsController < ApplicationController include CollectionsHelper,SearchContent - def index acronym = params[:ontology] @ontology = LinkedData::Client::Models::Ontology.find_by_acronym(acronym).first @@ -47,11 +46,13 @@ def show def show_label collection_label = '' - collection = get_request_collection - collection_label = collection['prefLabel'] if collection - collection_label = params[:id] if collection_label.nil? || collection_label.empty? + collection = get_request_collection + collection_label = collection['prefLabel'] if collection + collection_label = params[:id] if collection_label.nil? || collection_label.empty? - render LabelLinkComponent.inline(params[:id], helpers.main_language_label(collection_label)) + label = helpers.main_language_label(collection_label) + link = collection_path(collection_id: params[:id], ontology_id: params[:ontology_id], language: request_lang) + render(inline: helpers.ajax_link_chip(params[:id], label, link, external: collection.blank?), layout: false) end def show_members diff --git a/app/controllers/concepts_controller.rb b/app/controllers/concepts_controller.rb index 1063c953b..97e316c6a 100644 --- a/app/controllers/concepts_controller.rb +++ b/app/controllers/concepts_controller.rb @@ -63,10 +63,14 @@ def index end def show_label - cls_id = params[:concept] || params[:id] # cls_id should be a full URI - ont_id = params[:ontology] # ont_id could be a full URI or an acronym - - render LabelLinkComponent.inline(cls_id, helpers.main_language_label(concept_label(ont_id, cls_id))) + cls_id = params[:concept] || params[:id] + ont_id = params[:ontology] + pref_label = concept_label(ont_id, cls_id) + cls = @ontology.explore.single_class({ language: request_lang, include: 'prefLabel' }, cls_id) + label = helpers.main_language_label(pref_label) + link = concept_path(cls_id, ont_id, request_lang) + + render(inline: helpers.ajax_link_chip(cls_id, label, link, external: cls.nil? || cls.errors), layout: nil) end def show_definition @@ -87,8 +91,8 @@ def show_tree not_found(t('concepts.missing_roots')) if @root.nil? render inline: helpers.concepts_tree_component(@root, @concept, - @ontology.acronym, Array(params[:concept_schemes]&.split(',')), request_lang, - id: 'concepts_tree_view', auto_click: params[:auto_click] || true) + @ontology.acronym, Array(params[:concept_schemes]&.split(',')), request_lang, + id: 'concepts_tree_view', auto_click: params[:auto_click] || true) end end diff --git a/app/controllers/label_xl_controller.rb b/app/controllers/label_xl_controller.rb index 521d35fb7..e62a74908 100644 --- a/app/controllers/label_xl_controller.rb +++ b/app/controllers/label_xl_controller.rb @@ -1,5 +1,5 @@ class LabelXlController < ApplicationController - include LabelXlHelper + include LabelXlHelper, UrlsHelper def show @label_xl = get_request_label_xl @@ -9,8 +9,9 @@ def show_label label_xl = get_request_label_xl label_xl_label = label_xl ? label_xl['literalForm'] : nil label_xl_label = params[:id] if label_xl_label.nil? || label_xl_label.empty? - - render LabelLinkComponent.inline(params[:id], helpers.main_language_label(label_xl_label)) + label = helpers.main_language_label(label_xl_label) + link = "/ajax/label_xl/?id=#{escape(params[:id])}&ontology=#{params[:ontology_id]}&cls_id=#{escape(params[:cls_id])}" + render(inline: helpers.ajax_link_chip(params[:id], label, link, open_in_modal: true, external: label_xl.blank?), layout: false) end private diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index df582acb4..0ca5fd8b7 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -118,7 +118,7 @@ def show_mappings ontology_acronym = @ontology.acronym @ontology_name = ontology_acronym end - if @target_ontology.nil? + if @target_ontology.nil? || @target_ontology.errors if params[:target] == EXTERNAL_MAPPINGS_GRAPH target_acronym = EXTERNAL_URL_PARAM_STR @target_ontology_name = t('mappings.external_mappings') @@ -132,7 +132,6 @@ def show_mappings end ontologies = [ontology_acronym, target_acronym] - @mapping_pages = LinkedData::Client::HTTP.get("#{MAPPINGS_URL}", { page: page, ontologies: ontologies.join(',') }) not_found(@mapping_pages.errors) if @mapping_pages.respond_to?(:errors) @mappings = @mapping_pages.collection diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 8c5c97f1f..1116e6a74 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -23,9 +23,9 @@ def index render inline: helpers.render_search_paginated_list(container_id: 'schemes_sorted_list', - next_page_url: "/ontologies/#{@ontology.acronym}/schemes", - child_url: "/ontologies/#{@ontology.acronym}/schemes/show", child_turbo_frame: 'scheme', - child_param: :schemeid, + next_page_url: "/ontologies/#{@ontology.acronym}/schemes", + child_url: "/ontologies/#{@ontology.acronym}/schemes/show", child_turbo_frame: 'scheme', + child_param: :schemeid, results: results, next_page: next_page, total_count: total_count) end @@ -35,7 +35,7 @@ def show redirect_to(ontology_path(id: params[:ontology], p: 'schemes', schemeid: params[:id],lang: request_lang)) and return unless turbo_frame_request? @scheme = get_request_scheme - + render partial: "schemes/show" end @@ -43,8 +43,9 @@ def show_label scheme = get_request_scheme scheme_label = scheme ? scheme['prefLabel'] : params[:id] scheme_label = scheme_label.nil? || scheme_label.empty? ? params[:id] : scheme_label - - render LabelLinkComponent.inline(params[:id], helpers.main_language_label(scheme_label)) + label = helpers.main_language_label(scheme_label) + link = scheme_path(scheme_id: params[:id], ontology_id: params[:ontology_id]) + render(inline: helpers.ajax_link_chip(params[:id], label, link, external: scheme.blank?), layout: false) end private diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6d565bdb2..2a319d687 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,7 +9,7 @@ module ApplicationHelper REST_URI = $REST_URL API_KEY = $API_KEY - include ModalHelper, MultiLanguagesHelper, UrlsHelper + include ModalHelper, MultiLanguagesHelper, UrlsHelper, ComponentsHelper RESOLVE_NAMESPACE = {:omv => "http://omv.ontoware.org/2005/05/ontology#", :skos => "http://www.w3.org/2004/02/skos/core#", :owl => "http://www.w3.org/2002/07/owl#", @@ -19,7 +19,7 @@ module ApplicationHelper :umls => "http://bioportal.bioontology.org/ontologies/umls/", :door => "http://kannel.open.ac.uk/ontology#", :dct => "http://purl.org/dc/terms/", :void => "http://rdfs.org/ns/void#", :foaf => "http://xmlns.com/foaf/0.1/", :vann => "http://purl.org/vocab/vann/", :adms => "http://www.w3.org/ns/adms#", :voaf => "http://purl.org/vocommons/voaf#", :dcat => "http://www.w3.org/ns/dcat#", :mod => "http://www.isibang.ac.in/ns/mod#", :prov => "http://www.w3.org/ns/prov#", - :cc => "http://creativecommons.org/ns#", :schema => "http://schema.org/", :doap => "http://usefulinc.com/ns/doap#", :bibo => "http://purl.org/ontology/bibo/", + :cc => "http://creativecommons.org/ns#", :schema => "http://schema.org/", :doap => "http://usefulinc.com/ns/doap#", :bibo => "http://purl.org/ontology/bibo/", :wdrs => "http://www.w3.org/2007/05/powder-s#", :cito => "http://purl.org/spar/cito/", :pav => "http://purl.org/pav/", :nkos => "http://w3id.org/nkos/nkostype#", :oboInOwl => "http://www.geneontology.org/formats/oboInOwl#", :idot => "http://identifiers.org/idot/", :sd => "http://www.w3.org/ns/sparql-service-description#", :cclicense => "http://creativecommons.org/licenses/", @@ -55,7 +55,6 @@ def get_apikey end end - def omniauth_providers_info $OMNIAUTH_PROVIDERS end @@ -76,7 +75,6 @@ def current_user_admin? session[:user] && session[:user].admin? end - def child_id(child) child.id.to_s.split('/').last end @@ -155,7 +153,6 @@ def add_proposal_button(parent_id, parent_type) end end - def subscribe_button(ontology_id) return if ontology_id.nil? render TurboFrameComponent.new(id: 'subscribe_button', src: ontology_subscriptions_path(ontology_id: ontology_id.split('/').last), class: 'ml-1') do |t| @@ -226,95 +223,40 @@ def notification_type(flash_key) bootstrap_alert_class[flash_key] end - def bp_ont_link(ont_acronym) - return "/ontologies/#{ont_acronym}" - end - - def bp_class_link(cls_id, ont_acronym) - return "#{bp_ont_link(ont_acronym)}?p=classes&conceptid=#{escape(cls_id)}&language=#{request_lang}" - end - - def bp_scheme_link(scheme_id, ont_acronym) - return "#{bp_ont_link(ont_acronym)}?p=schemes&schemeid=#{escape(scheme_id)}" - end - - def bp_label_xl_link(label_xl_id, ont_acronym) - return "#{bp_ont_link(ont_acronym)}/?label_xl_id=#{escape(label_xl_id)}" - end - - def bp_collection_link(collection_id, ont_acronym) - "#{bp_ont_link(ont_acronym)}?p=collection&collectionid=#{escape(collection_id)}" - end + def label_ajax_link(id, ont_acronym, ajax_uri, target) + ajax_uri = if ajax_uri.include?('?') + "#{ajax_uri}&ontology=#{ont_acronym}&id=#{escape(id)}" + else + "#{ajax_uri}?ontology=#{ont_acronym}&id=#{escape(id)}" + end - def label_ajax_data_h(cls_id, ont_acronym, ajax_uri, cls_url) - { data: - { - 'label-ajax-cls-id-value': cls_id, - 'label-ajax-ontology-acronym-value': ont_acronym, - 'label-ajax-ajax-url-value': ajax_uri, - 'label-ajax-cls-id-url-value': cls_url - } - } - end - - def label_ajax_data(cls_id, ont_acronym, ajax_uri, cls_url) - label_ajax_data_h(cls_id, ont_acronym, ajax_uri, cls_url) - end - - def label_ajax_link(link, cls_id, ont_acronym, ajax_uri, cls_url, target = nil) - data = label_ajax_data(cls_id, ont_acronym, ajax_uri, cls_url) - options = { 'data-controller': 'label-ajax' }.merge(data) - options = options.merge({ target: target }) if target - content_tag(:span, class: 'mx-1') do - render ChipButtonComponent.new(url: link, text: cls_id, type: 'clickable', **options) + content_tag(:span, class: 'concepts-mapping-count') do + ajax_link_chip(id, ajax_src: ajax_uri, target: target) end end def get_link_for_cls_ajax(cls_id, ont_acronym, target = nil) if cls_id.start_with?('http://') || cls_id.start_with?('https://') - link = bp_class_link(cls_id, ont_acronym) ajax_url = '/ajax/classes/label' - cls_url = "/ontologies/#{ont_acronym}?p=classes&conceptid=#{CGI.escape(cls_id)}" - label_ajax_link(link, cls_id, ont_acronym, ajax_url , cls_url ,target) + label_ajax_link(cls_id, ont_acronym, ajax_url, target) else content_tag(:div, cls_id) end end - def get_link_for_ont_ajax(ont_acronym) - # ajax call will replace the acronym with an ontology name (triggered by class='ont4ajax') - href_ont = " href='#{bp_ont_link(ont_acronym)}' " - data_ont = " data-ont='#{ont_acronym}' " - return "#{ont_acronym}" - end - def get_link_for_scheme_ajax(scheme, ont_acronym, target = '_blank') - link = bp_scheme_link(scheme, ont_acronym) ajax_url = "/ajax/schemes/label?language=#{request_lang}" - scheme_url = "?p=schemes&schemeid=#{CGI.escape(scheme)}" - label_ajax_link(link, scheme, ont_acronym, ajax_url, scheme_url, target) + label_ajax_link(scheme, ont_acronym, ajax_url, target) end def get_link_for_collection_ajax(collection, ont_acronym, target = '_blank') - link = bp_collection_link(collection, ont_acronym) ajax_url = "/ajax/collections/label?language=#{request_lang}" - collection_url = "?p=collections&collectionid=#{CGI.escape(collection)}" - label_ajax_link(link, collection, ont_acronym, ajax_url, collection_url, target) - end - - def get_link_for_label_xl_ajax(label_xl, ont_acronym, cls_id, modal: true) - link = label_xl - ajax_uri = "/ajax/label_xl/label?cls_id=#{CGI.escape(cls_id)}" - label_xl_url = "/ajax/label_xl/?id=#{CGI.escape(label_xl)}&ontology=#{ont_acronym}&cls_id=#{CGI.escape(cls_id)}" - data = label_ajax_data_h(label_xl, ont_acronym, ajax_uri, label_xl_url) - data[:data][:controller] = 'label-ajax' - if modal - link_to_modal(cls_id, link, {data: data[:data] , class: 'btn btn-sm btn-light m-1'}) - else - link_to(link,'', {data: data[:data], class: 'btn btn-sm btn-light m-1', target: '_blank'}) - end - + label_ajax_link(collection, ont_acronym, ajax_url, target) + end + def get_link_for_label_xl_ajax(label_xl, ont_acronym, cls_id, target = nil) + ajax_url = "/ajax/label_xl/label?cls_id=#{CGI.escape(cls_id)}" + label_ajax_link(label_xl, ont_acronym, ajax_url, target) end def ontology_viewer_page_name(ontology_name, concept_label, page) @@ -449,14 +391,14 @@ def prefixed_url(url) def show_advanced_options_button(text: nil, init: nil) content_tag(:div, class: "#{init ? 'd-none' : ''} advanced-options-button", 'data-action': 'click->reveal-component#show', 'data-reveal-component-target': 'showButton') do inline_svg_tag('icons/settings.svg') + - content_tag(:div, text, class: 'text') + content_tag(:div, text, class: 'text') end end def hide_advanced_options_button(text: nil, init: nil) content_tag(:div, class: "#{init ? '' : 'd-none'} advanced-options-button", 'data-action': 'click->reveal-component#hide', 'data-reveal-component-target': 'hideButton') do inline_svg_tag('icons/hide.svg') + - content_tag(:div, text, class: 'text') + content_tag(:div, text, class: 'text') end end diff --git a/app/helpers/collections_helper.rb b/app/helpers/collections_helper.rb index 9a80d2411..f8593cba2 100644 --- a/app/helpers/collections_helper.rb +++ b/app/helpers/collections_helper.rb @@ -1,5 +1,5 @@ module CollectionsHelper - include MultiLanguagesHelper + include MultiLanguagesHelper, UrlsHelper def get_collections(ontology, add_colors: false) @@ -49,8 +49,8 @@ def no_collections_alert end end - def collection_path(collection_id = '', language = '') - "/ontologies/#{@ontology.acronym}/collections/show?id=#{escape(collection_id)}&language=#{language}" + def collection_path(collection_id: '', ontology_id: @ontology.acronym, language: request_lang) + "/ontologies/#{ontology_id}/collections/show?id=#{escape(collection_id)}&language=#{language}" end def request_collection_id @@ -65,8 +65,8 @@ def link_to_collection(collection, selected_collection_id) pref_label_lang, pref_label_html = get_collection_label(collection) tooltip = pref_label_lang.to_s.eql?('@none') ? '' : "data-controller='tooltip' data-tooltip-position-value='right' title='#{pref_label_lang.upcase}'" <<-EOS - #{pref_label_html} diff --git a/app/helpers/components_helper.rb b/app/helpers/components_helper.rb index a63ba8edb..180ea336e 100644 --- a/app/helpers/components_helper.rb +++ b/app/helpers/components_helper.rb @@ -172,6 +172,10 @@ def tree_component(root, selected, target_frame:, sub_tree: false, id: nil, auto end end + def ajax_link_chip(id, label = nil, link = nil, external: false, open_in_modal: false, ajax_src: nil, target: '_blank') + render LabelFetcherComponent.new(id: id, label: label, link: link, open_in_modal: open_in_modal, ajax_src: ajax_src, target: target, external: external) + end + def chart_component(title: '', type:, labels:, datasets:, index_axis: 'x', show_legend: false) data = { controller: 'load-chart', diff --git a/app/helpers/concepts_helper.rb b/app/helpers/concepts_helper.rb index 3cec8ade6..1b62c06d7 100644 --- a/app/helpers/concepts_helper.rb +++ b/app/helpers/concepts_helper.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true module ConceptsHelper - include TermsReuses + include TermsReuses, UrlsHelper + + def concept_path(id, ontology_id, language) + "/ontologies/#{ontology_id}?p=classes&conceptid=#{escape(id)}&language=#{language}" + end + def concept_link(acronym, child, language) child.id.eql?('bp_fake_root') ? '#' : "/ontologies/#{acronym}/concepts/show?id=#{CGI.escape(child.id)}&language=#{language}" end @@ -76,14 +81,9 @@ def default_sub_menu_class def concept_label(ont_id, cls_id) @ontology = LinkedData::Client::Models::Ontology.find(ont_id) @ontology ||= LinkedData::Client::Models::Ontology.find_by_acronym(ont_id).first - ontology_not_found(ont_id) unless @ontology - # Retrieve a class prefLabel or return the class ID (URI) - # - mappings may contain class URIs that are not in bioportal (e.g. obo-xrefs) + ontology_not_found(ont_id) if @ontology.nil? || @ontology.errors cls = @ontology.explore.single_class({language: request_lang, include: 'prefLabel'}, cls_id) - # TODO: log any cls.errors - # TODO: NCBO-402 might be implemented here, but it throws off a lot of ajax result rendering. - #cls_label = cls.prefLabel({:use_html => true}) || cls_id - cls.prefLabel || cls_id + cls&.prefLabel || cls_id end def concept_id_param_exist?(params) diff --git a/app/helpers/mappings_helper.rb b/app/helpers/mappings_helper.rb index c1e503b54..09b2c4d67 100644 --- a/app/helpers/mappings_helper.rb +++ b/app/helpers/mappings_helper.rb @@ -77,24 +77,10 @@ def get_prefixed_uri(uri) uri end - # method to get (using http) prefLabel for interportal classes - # Using bp_ajax_controller.ajax_process_interportal_cls will try to resolve class labels. - def ajax_to_inter_portal_cls(cls) - inter_portal_acronym = get_inter_portal_acronym(cls.links['ui']) - href_cls = " href='#{cls.links["ui"]}' " - if inter_portal_acronym - data_cls = " data-cls='#{cls.links["self"]}?apikey=' " - portal_cls = " portal-cls='#{inter_portal_acronym}' " - raw("#{cls.id}") - else - raw("#{cls.id}") - end - - end - def ajax_to_internal_cls(cls) - link_to("#{cls.id}".html_safe, - ontology_path(cls.explore.ontology.acronym, p: 'classes', conceptid: cls.id), target: '_blank') + cls_id = cls.id + ont_acronym = cls.links['ontology'].split('/').last + get_link_for_cls_ajax(cls_id, ont_acronym, '_blank') end # to get the apikey from the interportal instance of the interportal class. @@ -111,18 +97,15 @@ def get_inter_portal_acronym(class_ui_url) end end - # method to extract the prefLabel from the external class URI - def get_label_for_external_cls(class_uri) - prefLabel = if class_uri.include? '#' - class_uri.split('#')[-1] - else - class_uri.split('/')[-1] - end - return prefLabel - end - def ajax_to_external_cls(cls) - raw("#{get_label_for_external_cls(cls.id)}") + class_uri = cls.id + text = if class_uri.include? '#' + class_uri.split('#')[-1] + else + class_uri.split('/')[-1] + end + text = render(ExternalLinkTextComponent.new(text: text)) + link_to text, cls.links['self'], target: '_blank' end # Replace the inter_portal mapping ontology URI (that link to the API) by the link to the ontology in the UI diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index 9d3019cd3..7eec737c7 100644 --- a/app/helpers/schemes_helper.rb +++ b/app/helpers/schemes_helper.rb @@ -1,4 +1,5 @@ module SchemesHelper + include UrlsHelper def get_schemes(ontology) ontology.explore.schemes(language: request_lang) @@ -47,8 +48,8 @@ def section_name(section) t("ontology_details.sections.#{section}") end - def scheme_path(scheme_id = '', language = '') - "/ontologies/#{@ontology.acronym}/schemes/show?id=#{escape(scheme_id)}&lang=#{language}" + def scheme_path(ontology_id: @ontology.acronym, scheme_id: '', language: request_lang) + "/ontologies/#{ontology_id}/schemes/show?id=#{escape(scheme_id)}&lang=#{language}" end def no_main_scheme? @@ -64,6 +65,7 @@ def no_main_scheme_alert t('schemes.no_main_scheme_alert') end end + def no_schemes_alert render Display::AlertComponent.new do t('schemes.no_schemes_alert', acronym: @ontology.acronym) @@ -88,7 +90,6 @@ def schemes_tree(schemes_labels, main_scheme_label, selected_scheme_id, submissi scheme end.compact - main_scheme = nil if main_scheme_label.nil? children = schemes @@ -105,8 +106,8 @@ def schemes_tree(schemes_labels, main_scheme_label, selected_scheme_id, submissi root.children = children selected_scheme = selected_scheme || main_scheme || root.children.first tree_component(root, selected_scheme, target_frame: 'scheme', auto_click: false, submission: submission) do |child| - href = scheme_path(child['@id'], request_lang) rescue '' - data = { schemeid: (child['@id'] rescue '')} + href = scheme_path(scheme_id: child['@id'], ontology_id: @ontology.acronym, language: request_lang) + data = { schemeid: child['@id']} ["#", data, href] end end diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index fa09b8541..7b99fc21d 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -34,12 +34,6 @@ application.register("form-options-display", FormDisplayController) import HistoryController from "./history_controller" application.register("history", HistoryController) -import LabelAjaxController from "./label_ajax_controller" -application.register("label-ajax", LabelAjaxController) - -import LabelsAjaxContainerController from "./labels_ajax_container_controller" -application.register("labels-ajax-container", LabelsAjaxContainerController) - import LanguageChangeController from "./language_change_controller" application.register("language-change", LanguageChangeController) diff --git a/app/javascript/controllers/label_ajax_controller.js b/app/javascript/controllers/label_ajax_controller.js deleted file mode 100644 index d3cbcfff4..000000000 --- a/app/javascript/controllers/label_ajax_controller.js +++ /dev/null @@ -1,83 +0,0 @@ -import {Controller} from "@hotwired/stimulus" -import useAjax from "../mixins/useAjax"; - -// Connects to data-controller="label-ajax" -export default class extends Controller { - static values = { - clsId: String, - ontologyAcronym: String, - ajaxUrl: String, - clsIdUrl: String, - } - - connect() { - setTimeout(() => { - this.linkA = jQuery(this.element); - - if (this.linkA.hasClass('ajax-modified-cls')) { - return true - } - - this.cls_id = this.clsIdValue; - this.ont_acronym = this.ontologyAcronymValue; - - let ajax_uri = new URL(this.ajaxUrlValue, document.location.origin) - - ajax_uri.searchParams.set('ontology', this.ont_acronym) - ajax_uri.searchParams.set('id', this.cls_id) - - - this.request = useAjax({ - url: ajax_uri.pathname + ajax_uri.search, - timeout: ajax_process_timeout * 1000, - success: this.#ajaxSuccess.bind(this), - error: this.#ajaxError.bind(this) - }); - },1) - } - - abort() { - if (this.request) { - this.request.abort() - this.request = null - } - } - - disconnect() { - this.abort() - } - - #ajaxSuccess(data) { - data = data.trim(); - if (typeof data !== "undefined" && data.length > 0 && data.indexOf("http") !== 0) { - let cls_name = data - let cls_uri = this.clsIdUrlValue - this.linkA.html(cls_name); - this.linkA.attr('href', cls_uri); - this.linkA.addClass('ajax-modified-cls'); - //find and process any identical classes (low probability) - this.#fillIdenticalIds(cls_name, cls_uri) - } else { - // remove the unique_id separator and the ontology acronym from the href - this.linkA.attr('href', this.cls_id); // it may not be an ontology class, don't use the cls_uri - this.linkA.addClass('ajax-modified-cls'); - } - } - - #ajaxError() { - this.linkA.addClass('ajax-error') - } - - #fillIdenticalIds(cls_name, cls_uri) { - - let unique_id = this.linkA.attr('href'); - jQuery('a[href="' + unique_id + '"]').each(function () { - let link = jQuery(this); - if (!link.hasClass('ajax-modified-cls')) { - link.html(cls_name); - link.attr('href', cls_uri); - link.addClass('ajax-modified-cls') - } - }); - } -} diff --git a/app/javascript/controllers/labels_ajax_container_controller.js b/app/javascript/controllers/labels_ajax_container_controller.js deleted file mode 100644 index a8f606114..000000000 --- a/app/javascript/controllers/labels_ajax_container_controller.js +++ /dev/null @@ -1,10 +0,0 @@ -import {Controller} from "@hotwired/stimulus" - -// Connects to data-controller="labels-ajax-container" -export default class extends Controller { - static outlets = ['label-ajax'] - - abortAll() { - this.labelAjaxOutlets.forEach((link) => {link.abort()}) - } -} diff --git a/app/javascript/controllers/turbo_frame_error_controller.js b/app/javascript/controllers/turbo_frame_error_controller.js index 782166bc5..16d2cbbd2 100644 --- a/app/javascript/controllers/turbo_frame_error_controller.js +++ b/app/javascript/controllers/turbo_frame_error_controller.js @@ -34,7 +34,10 @@ export default class extends Turbo_frame_controller { Array.from(styles).forEach(e => el.removeChild(e)) let body = el.querySelector('h1') - this.errorMessageTarget.firstElementChild.querySelector('.alert-message').innerHTML = (body ? body.innerText : el.innerHTML) + let alertContainer = this.errorMessageTarget.firstElementChild?.querySelector('.alert-message') + if(alertContainer){ + alertContainer.innerHTML = (body ? body.innerText : el.innerHTML) + } $(this.errorMessageTarget).show() } diff --git a/app/views/collections/_list_view.html.haml b/app/views/collections/_list_view.html.haml index a50abe0ce..d0594f157 100644 --- a/app/views/collections/_list_view.html.haml +++ b/app/views/collections/_list_view.html.haml @@ -11,6 +11,6 @@ - scheme = OpenStruct.new(collection) - scheme.prefLabel = Array(get_collection_label(collection)).last - scheme.id = scheme['@id'] - - tree_child.child(child: scheme, href: collection_path(collection['@id'], request_lang), + - tree_child.child(child: scheme, href: collection_path(collection_id: collection['@id'], ontology_id: @ontology.acronym, language: request_lang), children_href: '#', selected: scheme.id.eql?(selected_collection_id), target_frame: 'collection', data: {collectionid: collection['@id']}, is_reused: concept_reused?(submission: @submission, concept_id: scheme.id)) diff --git a/app/views/concepts/_show.html.haml b/app/views/concepts/_show.html.haml index 8d690b65f..bbbb95614 100644 --- a/app/views/concepts/_show.html.haml +++ b/app/views/concepts/_show.html.haml @@ -1,4 +1,4 @@ -= render TurboFrameComponent.new(id: 'concept_show', data: {controller:'labels-ajax-container', 'action': 'turbo:before-fetch-request->labels-ajax-container#abortAll', 'labels-ajax-container-label-ajax-outlet': '#concept_show a[data-controller="label-ajax"]'}) do += render TurboFrameComponent.new(id: 'concept_show') do - if @concept.id.eql?("bp_fake_root") = render Display::AlertComponent.new do = t('concepts.use_jump_to') diff --git a/app/views/mappings/_mapping_table.html.haml b/app/views/mappings/_mapping_table.html.haml index 20efcd92d..1492ce2ec 100644 --- a/app/views/mappings/_mapping_table.html.haml +++ b/app/views/mappings/_mapping_table.html.haml @@ -14,7 +14,3 @@ = render partial: 'mappings/show_line' , locals: {map: map, concept: @concept} %tr.empty-state %td.text-center{:colspan => "6"}= t("mappings.mapping_table.no_mappings") -:javascript - jQuery(document).ready(function(){ - ajax_process_init(); - }) diff --git a/app/views/mappings/_show.html.haml b/app/views/mappings/_show.html.haml index 6ca1cffe1..60bebf6d9 100644 --- a/app/views/mappings/_show.html.haml +++ b/app/views/mappings/_show.html.haml @@ -15,9 +15,7 @@ %tr - map.classes.each do |cls| %td - - if inter_portal_mapping?(cls) - = ajax_to_inter_portal_cls(cls) - - elsif internal_mapping?(cls) + - if internal_mapping?(cls) = ajax_to_internal_cls(cls) - else = ajax_to_external_cls(cls) @@ -25,8 +23,3 @@ #{map.source} #{(map.process || {})[:source_name]} .mappings-table-pagination = will_paginate @page_results, :update => 'mappings', :params => { :target => params[:target] } - - :javascript - jQuery(document).ready(function(){ - ajax_process_init(); // see bp_ajax_controller.js - }) \ No newline at end of file From aa7e2475d5f2de6bcc2a8725ad28db8cbd392346 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Thu, 7 Nov 2024 10:16:37 +0100 Subject: [PATCH 04/26] Fix: Remove ontolobrigde code and some Jquery code (#822) * update select_language_label helper to select f no english found any language remaining over the not tagged * remove ontology bridge code * remove ont_viewer data jquery code * remove no existent fetch_results action code --- .env.sample | 2 - app/assets/javascripts/bp_ontolobridge.js | 359 ------------------ .../stylesheets/application.css.scss.erb | 1 - app/assets/stylesheets/ontolobridge.scss | 35 -- app/controllers/concepts_controller.rb | 2 - app/controllers/ontolobridge_controller.rb | 64 ---- app/controllers/ontologies_controller.rb | 1 - app/helpers/application_helper.rb | 5 - .../class_search_auto_complete_controller.js | 11 +- app/views/concepts/_request_term.html.haml | 47 --- app/views/layouts/_header.html.erb | 6 +- app/views/layouts/_ontology_viewer.html.haml | 20 - app/views/layouts/appliance.html.haml | 2 - app/views/layouts/component_preview.html.erb | 6 +- .../component_preview_not_centred.html.erb | 6 +- app/views/layouts/popup.html.erb | 2 - app/views/layouts/tool.html.haml | 3 +- .../ontologies/sections/visualize.html.haml | 8 - config/application.rb | 1 - config/bioportal_config_env.rb.sample | 9 - config/locales/en.yml | 31 +- config/locales/fr.yml | 32 -- config/routes.rb | 25 +- db/schema.rb | 2 +- 24 files changed, 21 insertions(+), 659 deletions(-) delete mode 100644 app/assets/javascripts/bp_ontolobridge.js delete mode 100644 app/assets/stylesheets/ontolobridge.scss delete mode 100644 app/controllers/ontolobridge_controller.rb delete mode 100644 app/views/concepts/_request_term.html.haml diff --git a/.env.sample b/.env.sample index 94f4a336b..6a8e41d24 100644 --- a/.env.sample +++ b/.env.sample @@ -39,5 +39,3 @@ OP_API_URL="https://data.bioontology.org" API_IMAGE_REPOSITORY=agroportal ## Image tag/version from which the ontoportal api will be built API_IMAGE_TAG=master - - diff --git a/app/assets/javascripts/bp_ontolobridge.js b/app/assets/javascripts/bp_ontolobridge.js deleted file mode 100644 index d4acc3e97..000000000 --- a/app/assets/javascripts/bp_ontolobridge.js +++ /dev/null @@ -1,359 +0,0 @@ -function bindAddRequestTermClick() { - jQuery("a.add_request_term").live('click', function(){ - var id = jQuery(this).attr("data-parent-id"); - addRequestTermBox(id); - }); -} - -function bindCancelRequestTermClick() { - jQuery(".request_term_form_div .cancel").live('click', function() { - removeRequestTermBox(); - }); -} - -function bindNewTermInstructionsClick() { - jQuery("#new_term_instructions").live("click", function() { - jQuery(this).trumbowyg({ - btns: [ - ['viewHTML'], - ['undo', 'redo'], // Only supported in Blink browsers - ['formatting'], - ['strong', 'em', 'del'], - ['superscript', 'subscript'], - ['link'], - ['insertImage'], - ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'], - ['unorderedList', 'orderedList'], - ['horizontalRule'], - ['removeformat'], - ['fullscreen'] - ] - }); - jQuery("#new_term_instructions_submit").show(); - jQuery("#new_term_instructions_cancel").show(); - }); -} - -function bindNewTermInstructionsSubmit() { - jQuery("#new_term_instructions_submit").live("click", function() { - saveNewTermInstructions(); - }); -} - -function bindNewTermInstructionsCancel() { - jQuery("#new_term_instructions_cancel").live("click", function() { - var oldVal = jQuery("#new_term_instructions_old").val().trim(); - var curVal = jQuery('#new_term_instructions').html().trim(); - - if (oldVal != curVal) { - if (confirm('Are you sure you want to discard your changes?')) { - jQuery('#new_term_instructions').trumbowyg('destroy'); - jQuery('#new_term_instructions').html(oldVal); - hideButtons(); - } - } else { - jQuery('#new_term_instructions').trumbowyg('destroy'); - hideButtons(); - } - }); -} - -function preventNewTermInstructionsFormSubmit() { - jQuery("#new_term_instructions_form").submit(function(e) { - e.preventDefault(e); - }); -} - -function clearProgressMessage(parentContainerID) { - var progMsgElem = jQuery("#" + parentContainerID + " #progress_message"); - progMsgElem.hide(); - progMsgElem.html(""); -} - -function showProgressMessage(parentContainerID) { - clearProgressMessage(parentContainerID); - var msg = "Saving..."; - var progMsgElem = jQuery("#" + parentContainerID + " #progress_message"); - progMsgElem.text(msg).html(); - progMsgElem.show(); -} - -function saveNewTermInstructions() { - var params = jQuery('#new_term_instructions_form').serialize(); - var newInstructions = jQuery('#new_term_instructions').html().trim(); - params += '&new_term_instructions=' + newInstructions; - var parentContainerID = 'new_term_instructions_container'; - showProgressMessage(parentContainerID); - - jQuery.ajax({ - type: "POST", - url: "/ontolobridge/save_new_term_instructions", - dataType: "json", - data: params, - success: function(data) { - var status = data[1]; - - if (status && status >= 400 || data[0]['error'].length) { - showStatusMessages('', data[0]['error']); - } else { - jQuery('#new_term_instructions').trumbowyg('destroy'); - jQuery("#new_term_instructions_old").val(newInstructions); - showStatusMessages(data[0]["success"], ''); - setTimeout(function() { clearStatusMessages(); }, 5000); - } - }, - error: function(request, textStatus, errorThrown) { - showStatusMessages('', errorThrown); - }, - complete: function(request, textStatus) { - clearProgressMessage(parentContainerID); - hideButtons(); - } - }); -} - -function hideButtons() { - jQuery("#new_term_instructions_submit").hide(); - jQuery("#new_term_instructions_cancel").hide(); -} - -function bindRequestTermSaveClick() { - var success = ""; - var error = ""; - var user = jQuery(document).data().bp.user; - var ontology_id = jQuery(document).data().bp.ont_viewer.ontology_id; - var params = jQuery("#request_term_form").serialize(); - params += "&ontology=" + ontology_id + "&email=" + user["email"] - - if (user["firstName"] && user["lastName"]) { - params += "&submitter=" + user["firstName"] + " " + user["lastName"]; - } - - var parentContainerID = 'proposal_buttons'; - showProgressMessage(parentContainerID); - - jQuery.ajax({ - type: "POST", - url: "/ontolobridge", - data: params, - dataType: "json", - success: function(data) { - var status = data[1]; - - if (status && status >= 400) { - showStatusMessages('', data[0]["error"]); - } else { - var msg = "A new term request has been submitted successfully:

"; - removeRequestTermBox(); - - for (var i in data[0]) { - msg += i + ": " + data[0][i] + "
"; - } - showStatusMessages(msg, error); - } - }, - error: function(request, textStatus, errorThrown) { - error = "The following error has occurred: " + errorThrown + ". Please try again."; - showStatusMessages(success, error); - }, - complete: function(request, textStatus) { - clearProgressMessage(parentContainerID); - } - }); -} - -function removeRequestTermBox() { - jQuery(".request_term_form_div").html(""); -} - -function addRequestTermBox(id) { - clearStatusMessages(); - var formContainer = jQuery(".request_term_form_div"); - var requestTermForm = requestTermFields(id, formContainer); - var formID = requestTermForm.attr('id'); - var isPopulated = window.localStorage.getItem(formID + '_populated'); - - if (isPopulated) { - for (var key in window.localStorage) { - if (key.startsWith(formID)) { - var elemID = key.replace(formID + '_', ''); - var elem = jQuery('#' + formID + ' #' + elemID); - - if (elem.attr('type') === "checkbox") { - elem.prop("checked", true); - } else if (elem.length > 0) { - var val = window.localStorage.getItem(key); - elem.val(val); - } - window.localStorage.removeItem(key); - } - } - } - formContainer.show(); - jQuery("#label").focus(); -} - -function clearStatusMessages() { - jQuery("#ob_success_message").hide(); - jQuery("#ob_error_message").hide(); - jQuery("#ob_success_message").html(""); - jQuery("#ob_error_message").html(""); -} - -function showStatusMessages(success, error) { - if (success.length > 0) { - let ob = jQuery("#ob_success_message") - console.log('show ob message') - console.log(ob) - ob.html(success); - ob.show(); - } - - if (error.length > 0) { - jQuery("#ob_error_message").text(error).html(); - jQuery("#ob_error_message").show(); - } -} - -function requestTermButtons() { - var buttonSubmit = jQuery("