diff --git a/application.rb b/application.rb index 3a1113e..200a45b 100644 --- a/application.rb +++ b/application.rb @@ -70,11 +70,16 @@ end # sparql endpoint access -get '/sparql/:query?' do +#get '/sparql/:query?' do +get '/sparql/?' do + halt 400, "Missing query parameter.\n" unless params[:query] + halt 400, "Missing query parameter.\n" if params[:query].empty? sparqlstring = params[:query] halt 400, "Not allowed SPARQL keyword.\n" if !!(sparqlstring =~ /\b(delete|insert|load|clear)\b/i) type = request.env["HTTP_ACCEPT"] - if (sparqlstring =~ /^select/i ? @accepted_select.include?(type) : @accepted_construct.include?(type) ) + + #if (sparqlstring =~ /^select/i ? @accepted_select.include?(type) : @accepted_construct.include?(type) ) + if ( @accepted_select.include?(type) || @accepted_construct.include?(type) ) RestClient::Resource.new(URI.encode("#{$service_uri}/sparql/?query=#{sparqlstring}"), :verify_ssl => 0, :headers => {:accept => type } ).get do |response,request,result| if response.code == 400 halt response.code, "malformed query\n" @@ -91,12 +96,12 @@ # sparql result as file download in various formats get "/download" do - type = params[:query_type] - sparqlstring = params[:queryfield] + type = params[:queryType] + sparqlstring = params[:queryField] halt 400, "Not allowed SPARQL keyword.\n" if !!(sparqlstring =~ /\b(delete|insert|load|clear)\b/i) file = Tempfile.new("enm") - - if (sparqlstring =~ /\b(select)\b/i ? @accepted_select.include?(type) : @accepted_construct.include?(type) ) + #TODO check for SELECT keyword else return a message instead wrong type + if ( @accepted_select.include?(type) || @accepted_construct.include?(type) ) RestClient::Resource.new(URI.encode("#{$service_uri}/sparql/?query=#{sparqlstring}"), :verify_ssl => 0, :headers => {:accept => type}).get do |response, request, result| if response.code == 400 halt response.code, "malformed query\n" diff --git a/config.ru b/config.ru index 540865b..27cb8a4 100644 --- a/config.ru +++ b/config.ru @@ -4,6 +4,6 @@ require File.expand_path './application.rb' require "sinatra/reloader" if development? FileUtils.mkdir_p 'log' unless File.exists?('log') log = File.new("log/enm-ontoviewer.log", "a") -$stdout.reopen(log) +#$stdout.reopen(log) #$stderr.reopen(log) run Sinatra::Application diff --git a/help.md b/help.md index 4a8aca3..50485ca 100644 --- a/help.md +++ b/help.md @@ -8,4 +8,4 @@ Please also note the part `{,5}` which is a [property path](https://www.w3.org/T --- #### Sparql -This page allows you to write [SPARQL](https://www.w3.org/TR/rdf-sparql-query/) queries without any restrictions and with full [SPARQL](https://www.w3.org/TR/rdf-sparql-query/) syntax support including subqueries. The result can be downloaded to your computer. Please choose one of the output formats from the drop-down list. +This page allows you to write [SPARQL](https://www.w3.org/TR/rdf-sparql-query/) queries without any restrictions and with full [SPARQL](https://www.w3.org/TR/rdf-sparql-query/) syntax support including subqueries. The result can be downloaded to your computer. Please choose one of the output formats from the drop-down list. There is also an option to render results as HTML table to the page. diff --git a/public/examples/example1 b/public/examples/example1 index 301e5f0..9261465 100644 --- a/public/examples/example1 +++ b/public/examples/example1 @@ -12,8 +12,9 @@ SELECT DISTINCT ?resource ?epLabel ?value ?unit WHERE { obo:OBI_0000299 ?endpoint . ?endpoint sio:has-value ?value ; sio:has-unit ?unit ; - rdfs:label ?epLabel. + rdfs:label ?endpLabel. } BIND("PARTICLE SIZE" AS ?epLabel) FILTER(BOUND(?endpoint)) + FILTER(?unit ="nm") } diff --git a/public/examples/example3 b/public/examples/example3 index 6e6ee26..a6dc8a9 100644 --- a/public/examples/example3 +++ b/public/examples/example3 @@ -12,8 +12,9 @@ SELECT DISTINCT ?resource ?epLabel ?value ?unit WHERE { obo:OBI_0000299 ?endpoint . ?endpoint sio:has-value ?value ; sio:has-unit ?unit ; - rdfs:label ?epLabel. + rdfs:label ?endpLabel. } BIND("ZETA POTENTIAL" AS ?epLabel) - FILTER(!BOUND(?endpoint)) + FILTER(BOUND(?endpoint)) + FILTER(?unit ="mV") } diff --git a/views/query.haml b/views/query.haml index 7b2210f..3f6e1f9 100644 --- a/views/query.haml +++ b/views/query.haml @@ -1,4 +1,15 @@ :javascript + $(document).ready(function() { + $('#selType').on('change', function() { + var el = document.getElementById('selType'); + var button = document.getElementById('submitRender'); + if (el.value == "text/html"){ + button.style.display='inline'; + }else{ + button.style.display='none'; + } + }); + }); var HttpClient = function() { this.get = function(aUrl, aCallback) { var anHttpRequest = new XMLHttpRequest(); @@ -14,14 +25,23 @@ function renderResponse() { var type = "text/html"; var query = d3.select("#sparqlDownload").property("value"); - var uri = "#{to("/download?query_type=")}"+type+"&queryfield="+escape(query); + var uri = "#{to("/download?queryType=")}"+type+"&queryField="+escape(query); var div = document.getElementById("render"); div.innerHTML = ""; - aClient = new HttpClient(); - aClient.get(uri, function(response) { - var el = document.createElement("response"); - el.innerHTML = response; - document.getElementById("render").appendChild(el); + aClient = new HttpClient(); + aClient.get(uri, function(response) { + var el = document.createElement("response"); + el.innerHTML = response; + document.getElementById("render").appendChild(el); + $(".sparql a").click(function() { + var t = $(this).text(); + $(this).attr('alt', 'Link opens in new window.'); + $(this).attr('title', 'Link opens in new window.'); + $(this).attr('target', '_blank'); + if (t.includes("onto")){ + $(this).attr('href', 'http://bioportal.bioontology.org/ontologies/ENM/?p=classes&conceptid='+escape(t)); + }; + }); }); } @@ -89,11 +109,11 @@ #query{:style => "margin: 10px"} %ul.nav.nav-tabs %li.active - %a{:href=>"#viewer", :data=>{:toggle=>"tab"}, :onclick=>"clearView();"} Viewer + %a{:href=>"#viewer", :data=>{:toggle=>"tab"}, :onclick=>"clearView();"} VIEWER %li - %a{:href=>"#download", :data=>{:toggle=>"tab"}, :onclick=>"clearView();"} Sparql + %a{:href=>"#download", :data=>{:toggle=>"tab"}, :onclick=>"clearView();"} SPARQL %li - %a{:href=>"#help", :data=>{:toggle=>"tab"}, :onclick=>"clearView();"} Help + %a{:href=>"#help", :data=>{:toggle=>"tab"}, :onclick=>"clearView();"} HELP %div.tab-content{:style=>"padding-top:2em;"} %input#endpoint{:size=>"50",:type => "text", :value => to("/search/"), :disabled=>"disabled", :style=>"display:none;"} @@ -146,16 +166,17 @@ #{File.read(File.join("public/examples/"+example[0]))} %form.form-inline.col-md-12{:id=>"form2", :role=>"form", :action=> to("/download"), :method=>"get", :style=>"padding:0;"} %div.form-group - %select.form-control{:id=>"selType", :autocomplete=>"off", :name=>"query_type",:value=>""} + %select.form-control{:id=>"selType", :autocomplete=>"off", :name=>"queryType",:value=>""} %optgroup{:label=>"SELECT"} - @accepted_select.sort.each do |type| - %option{:value => type}= type + %option{:value => type, :style => ("color:green;" if type == "text/html")}= type %optgroup{:label=>"CONSTRUCT"} - @accepted_construct.sort.each do |type| %option{:value => type}= type - %input#inputquery{:type=>"hidden",:name=>"queryfield", :value=>""} + %input#inputquery{:type=>"hidden",:name=>"queryField", :value=>""} %input#renderType{:type=>"hidden",:name=>"renderType", :value=>""} - %button.btn.btn-default{:id=>"submitSubmit", :type=>"button", :title=>"render as HTML table", :onclick=>"renderResponse();"} render + %button.btn.btn-default{:id=>"submitRender", :type=>"button", :title=>"render as HTML table", :onclick=>"renderResponse();", :style=>"display:none;color:green;"} render + -#%button.btn.btn-default{:id=>"submitRender", :type=>"submit", :title=>"download as file", :onclick=>"sparqlValue('inline');"} render %button.btn.btn-default{:id=>"submitDownload", :type=>"submit", :title=>"download as file", :onclick=>"sparqlValue('attachment');"} download %div.col-md-6{:style=>"padding:0;"} @@ -164,10 +185,8 @@ %p Physico-Chemical Characteristics %fieldset - @examples.each_with_index do |example, idx| - %input{:id=> idx, :type=>"radio", :name=>"examples", :value=>"", :onclick=>"refresh_template(#{idx})"} - = example[0] - %br - %label{:for=>example[0]} + %input{:id=> idx, :type=>"radio", :name=>"examples", :value=>idx, :onclick=>"refresh_template(#{idx})"} + %label{:for=>idx} = example[1] %br #render.col-md-12{:style=>"padding:0;margin-top:50px;minwidth:100%;maxwidth:100%;"}