Skip to content

Commit

Permalink
add SPARQL section to the ontology viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Dec 30, 2023
1 parent 7fd5056 commit 93e3a73
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
15 changes: 13 additions & 2 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class OntologiesController < ApplicationController
include MappingStatistics
include OntologyUpdater
include TurboHelper
include SparqlHelper
include SubmissionFilter

require 'multi_json'
Expand All @@ -22,7 +23,7 @@ class OntologiesController < ApplicationController

before_action :authorize_and_redirect, :only => [:edit, :update, :create, :new]
before_action :submission_metadata, only: [:show]
KNOWN_PAGES = Set.new(["terms", "classes", "mappings", "notes", "widgets", "summary", "properties", "instances", "schemes", "collections"])
KNOWN_PAGES = Set.new(["terms", "classes", "mappings", "notes", "widgets", "summary", "properties", "instances", "schemes", "collections", "sparql"])
EXTERNAL_MAPPINGS_GRAPH = "http://data.bioontology.org/metadata/ExternalMappings"
INTERPORTAL_MAPPINGS_GRAPH = "http://data.bioontology.org/metadata/InterportalMappings"

Expand Down Expand Up @@ -208,6 +209,14 @@ def collections
end
end


def sparql
if request.xhr?
render partial: 'ontologies/sections/sparql', layout: false
else
render partial: 'ontologies/sections/sparql', layout: 'ontology_viewer'
end
end
# GET /ontologies/ACRONYM
# GET /ontologies/1.xml
def show
Expand Down Expand Up @@ -240,7 +249,7 @@ def show

# Note: find_by_acronym includes ontology views
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
ontology_not_found(params[:ontology]) if @ontology.nil?
ontology_not_found(params[:ontology]) if @ontology.nil? || @ontology.errors

# Handle the case where an ontology is converted to summary only.
# See: https://github.com/ncbo/bioportal_web_ui/issues/133.
Expand Down Expand Up @@ -288,6 +297,8 @@ def show
self.schemes
when 'collections'
self.collections
when 'sparql'
self.sparql
else
self.summary
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def sections_to_show
sections += %w[properties]
sections += %w[schemes collections] if skos?
sections += %w[instances] unless skos?
sections += %w[notes mappings widgets]
sections += %w[notes mappings widgets sparql]
end
sections
end
Expand Down
1 change: 1 addition & 0 deletions app/helpers/sparql_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def is_allowed_query?(sparql_query)
end

def sparql_query(query)
return 'No SPARQL endpoint configured' if $SPARQL_URL.blank?
return 'INSERT Queries not permitted' unless is_allowed_query?(query)
endpoint = $SPARQL_URL.gsub('test', 'sparql')
begin
Expand Down
2 changes: 2 additions & 0 deletions app/views/ontologies/sections/_sparql.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
= render TurboFrameComponent.new(id: "sparql", data: {"turbo-frame-target": "frame"} ) do
= sparql_query_container(graph: @submission_latest.id )
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

get '' => 'home#index'

post 'sparql_proxy', to: 'admin#sparql_endpoint'
match 'sparql_proxy', to: 'admin#sparql_endpoint', via: [:get, :post]

# Top-level pages
match '/feedback', to: 'home#feedback', via: [:get, :post]
Expand Down

0 comments on commit 93e3a73

Please sign in to comment.