sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
1 lines • 3.39 kB
JavaScript
const sparnatural=document.querySelector("spar-natural"),queryString=window.location.search,urlParams=new URLSearchParams(queryString);console.log("urlParams",urlParams);const lang=urlParams.get("lang");console.log("Configuration ",sparnatural.configuration),sparnatural.addEventListener("init",(e=>{console.log("init sparnatural..."),sparnatural.configuration={headers:{"User-Agent":"This is Sparnatural calling"},autocomplete:{maxItems:40}},console.log("Configuration ",sparnatural.configuration);for(const e in yasr.plugins)yasr.plugins[e].notifyConfiguration&&(console.log("notifying configuration for plugin "+e),yasr.plugins[e].notifyConfiguration(sparnatural.sparnatural.specProvider),console.log("sparnatural",sparnatural.sparnatural.specProvider))})),sparnatural.addEventListener("queryUpdated",(e=>{var n=sparnatural.expandSparql(e.detail.queryString);yasqe.setValue(n),document.getElementById("query-json").value=JSON.stringify(e.detail.queryStringFromJson);for(const n in yasr.plugins)yasr.plugins[n].notifyQuery&&yasr.plugins[n].notifyQuery(e.detail.queryStringFromJson)})),sparnatural.addEventListener("queryUpdated",(e=>{var n=sparnatural.expandSparql(e.detail.queryString),a=sparnatural.expandSparql(e.detail.queryStringFromJson);const t=document.getElementById("sparql-comparison-table"),r=document.createElement("tr"),l=document.createElement("td");l.textContent=n,r.appendChild(l);const s=document.createElement("td");s.textContent=a,r.appendChild(s);const o=document.createElement("td");o.textContent=n===a?"OK":"Pas OK",o.classList.add(n===a?"table-success":"table-danger"),r.appendChild(o),t.appendChild(r),document.getElementById("query-json").value=JSON.stringify(e.detail.queryJson);for(const n in yasr.plugins)yasr.plugins[n].notifyQuery&&yasr.plugins[n].notifyQuery(e.detail.queryJson)})),sparnatural.addEventListener("submit",(e=>{console.log(e),sparnatural.disablePlayBtn(),yasqe.query()})),console.log("init yasr & yasqe...");const yasqe=new Yasqe(document.getElementById("yasqe"),{requestConfig:{endpoint:$("#endpoint").text()},copyEndpointOnNewTab:!1});Yasr.registerPlugin("TableX",SparnaturalYasguiPlugins.TableX),Yasr.registerPlugin("Map",SparnaturalYasguiPlugins.MapPlugin),Yasr.registerPlugin("GridPlugin",SparnaturalYasguiPlugins.GridPlugin),Yasr.plugins.TableX.defaults.openIriInNewWindow=!0,delete Yasr.plugins.table;const yasr=new Yasr(document.getElementById("yasr"),{pluginOrder:["TableX","Response","Map","GridPlugin","StatsPlugin"],defaultPlugin:"TableX",getUsedPrefixes:yasqe.getPrefixesFromQuery,drawOutputSelector:!1,drawDownloadIcon:!1,persistency:{prefix:!1,results:{key:!1}}});yasqe.on("queryResponse",(function(e,n,a){yasr.setResponse(n,a),sparnatural.enablePlayBtn()})),document.getElementById("switch-language").onclick=function(){document.querySelector("spar-natural").setAttribute("lang","en"),sparnatural.display()},document.getElementById("export").onclick=function(){var e=JSON.stringify(JSON.parse(document.getElementById("query-json").value),null,2);$("#export-json").val(e),$("#exportModal").modal("show")},document.getElementById("load").onclick=function(){$("#loadModal").modal("show")},document.getElementById("loadJson").onclick=function(){sparnatural.loadQuery(JSON.parse(document.getElementById("load-json").value)),$("#loadModal").modal("hide")},document.getElementById("clear").onclick=function(){sparnatural.clear()};