Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Migrate Label Ajax stimulus and Jquery code to Turbo #821

Merged
merged 16 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
9c4bb90
update select_language_label helper to select f no english found any…
syphax-bouazzouni Oct 30, 2024
1a3c772
Merge branch 'fix/all-languages-selection' into development
syphax-bouazzouni Oct 30, 2024
375f116
Merge remote-tracking branch 'origin/development' into development
syphax-bouazzouni Oct 30, 2024
062fb4f
Merge remote-tracking branch 'origin/development' into development
syphax-bouazzouni Oct 31, 2024
8030df0
disable label ajax container
syphax-bouazzouni Oct 31, 2024
bcf103c
create label fetch component that for a id/uri fetch its label if found
syphax-bouazzouni Nov 1, 2024
ac53e73
add the possibility for the turbo frame to have custom error messages
syphax-bouazzouni Nov 1, 2024
6879a40
remove and replace ontology entities link helpers
syphax-bouazzouni Nov 1, 2024
0b8fa1a
replace the label-ajax stimulus with turbo frame using ajax_link_chip
syphax-bouazzouni Nov 1, 2024
8d5f1b5
fix an uncatched error in concept label helper
syphax-bouazzouni Nov 1, 2024
100170f
remove label-ajax stimulus code
syphax-bouazzouni Nov 1, 2024
29930bc
remove bp_ajax_controller old js code and update mappings to use the …
syphax-bouazzouni Nov 1, 2024
c2fda98
fix bug of not opening eternal mapping details popup
syphax-bouazzouni Nov 1, 2024
9a58568
remove label_link component
syphax-bouazzouni Nov 1, 2024
4f538a9
add a helper for the label fetcher component for clarity
syphax-bouazzouni Nov 1, 2024
2afeb07
add extern_link argument to ajax_link_chip to enforce external or not
syphax-bouazzouni Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
//
//= require bioportal
//= require admin/licenses
//= require bp_ajax_controller
//= require bp_notes
//= require bp_form_complete
//= require bp_admin
//= require concepts
//= require projects
//= require Chart.min
//= require application_esbuild


187 changes: 0 additions & 187 deletions app/assets/javascripts/bp_ajax_controller.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
56 changes: 56 additions & 0 deletions app/components/label_fetcher_component.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 0 additions & 22 deletions app/components/label_link_component.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/components/turbo_frame_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
%span{'data-turbo-frame-error-target': 'errorMessage', style:'display: none; width: 100%'}
- if error?
= error
- else
%div
= render Display::AlertComponent.new(type:'danger')
11 changes: 6 additions & 5 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions app/controllers/label_xl_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class LabelXlController < ApplicationController
include LabelXlHelper
include LabelXlHelper, UrlsHelper

def show
@label_xl = get_request_label_xl
Expand All @@ -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
Expand Down
Loading
Loading