Skip to content

Commit

Permalink
Feature: Dynamic routes for ontologies content dereferencement (#568)
Browse files Browse the repository at this point in the history
* Add uri redirection for /ontologies/:acronym/:id to the appropriate page

* small fixes: remove binding.pry and return resource_id in find_type_by_search

* Add copy agroportal link functionality

- this functionality is using the ClipboardComponent because it works the same but differ only in the content and icon
- the clipboard component has been changed to accept title and icon

* redirect to content finder page when no type is valid

* Updated route to use redirect action instead of show_redirection

* Use default icon and title arguments in the Clipboard Component

* rename and internationalize clipboard component titles

* small fix: remove % from svg icon

* Add the copy title to the components section in en.yml and fr.yml

* Show the generated uri when user hover over the copy link icon

* Make the dynamic route content negotiable

- based on the accept header we will
  - if "text/html" we will redirect to the agroportal page
  - else we will call the api and get the content serialized in the format specified and return it

* update serialize content to return accept_header

* translate copy_original_uri and copy_portal_uri to french

* reuse search content concern in uri redirection concern

* remove duplicate link_last_part method

* update the ontology redirection action to use ontology URI if resource_id nil

* update the content serializer to translate ntriples to an html table if asked for html format

* in the ontology redirection by default redirect to content finder with in html format

* remove the ":" from the copy the portal URI tooltip text

* change the order of the icons in the link_with_action  component

---------

Co-authored-by: Syphax bouazzouni <gs_bouazzouni@esi.dz>
  • Loading branch information
2 people authored and Bilelkihal committed Jun 12, 2024
1 parent 2a35302 commit 2c3d7ad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%div.clipboard.d-flex.align-items-center{data:{controller: 'clipboard'}, style: 'cursor:pointer;'}
%div{data: {'clipboard-target': 'content'}, class: @show_content ? '' : 'd-none'}
= @message || content
%div
%div.ml-2
%div.copy{data: {controller:'tooltip', action: 'click->clipboard#copy', 'clipboard-target': 'copy'}, title: @title}
= inline_svg_tag(@icon, width: '20', height: '21px', fill: 'none')
%div.d-none.check{data: {controller:'tooltip', 'clipboard-target': 'check'}, title: 'Copied!'}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/content_finder_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ContentFinderController < ApplicationController
include OntologyContentSerializer

def index
@result = serialize_content(ontology_acronym: params[:acronym],
@result, _ = serialize_content(ontology_acronym: params[:acronym],
concept_id: params[:uri],
format: params[:output_format])
render 'content_finder/index', layout: 'tool'
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,30 @@ def submit_success
render 'submit_success'
end

# GET /ontologies/:acronym/:id
def redirect
return not_found unless params[:acronym] && params[:id]

request_accept_header = request.env["HTTP_ACCEPT"].split(",")[0]
type, resource_id = find_type_by_id(params[:id], params[:acronym])

if resource_id.nil?
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:acronym]).first
@submission_latest = @ontology.explore.latest_submission(include: "URI")
resource_id = @submission_latest.URI
end

if request_accept_header == "text/html"
if type.nil? || resource_id.blank?
redirect_to ontology_path(id: params[:acronym], p: 'summary')
else
redirect_to link_by_type(resource_id, params[:acronym], type)
end
else
content, serializer_content_type = serialize_content(ontology_acronym: params[:acronym], concept_id: resource_id, format: request_accept_header)
render plain: content, content_type: serializer_content_type
end
end

# Main ontology description page (with metadata): /ontologies/ACRONYM
def summary
Expand Down
16 changes: 9 additions & 7 deletions app/views/content_finder/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#submit_button
= render Buttons::RegularButtonComponent.new(id:'regular-button', value: "Fetch", variant: "primary", size: "slim", type:"submit")

- if @result && !@result.empty?
%div.p-2.card.content-finder-result
= rdf_highlighter_container(@format, @result)
- if !@result&.empty?
%div.p-2.card.content-finder-result.mb-3
- if params[:output_format] != "html"
= rdf_highlighter_container(@format, @result)
- else
= n_triples_to_table(@result)

- else
= empty_state("Content not found")

- if params[:output_format] == "html"
.content-finder-html-result.bg-white.p-2.card
= render TurboFrameComponent.new(id: "concept_details" , src: "/ajax/class_details?&ontology=#{@acronym}&conceptid=#{CGI.escape(params[:uri])}&styled=false")


0 comments on commit 2c3d7ad

Please sign in to comment.