11import { config } from "../config/config" ;
2+ import { params } from "./params" ;
23import { loadGraphFromSparql } from "../loadGraphFromSparql" ;
34import { loadGraphFromJsonFile , loadLayoutFromJsonObject } from "./load" ;
45import { Search } from "./search" ;
@@ -13,64 +14,15 @@ import { Graph } from "./graph";
1314import type { LayoutJson } from "./save.ts" ;
1415import { View } from "./view" ;
1516
16- interface Params {
17- empty : boolean ;
18- benchmark : boolean ;
19- instances : boolean ;
20- virtual : boolean ;
21- class : string ;
22- json : string ;
23- sparql : string ;
24- graph : string ;
25- sub : string ;
26- }
27-
28- /** A flag is a GET parameter with a boolean value.
29- Allow setting a flag without a value, for example <https://www.snik.eu/graph?instances>.
30- In this case the empty string is returned, see <https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/get>.
31- The alternative is <https://www.snik.eu/graph?instances=true> but all other values are treated as false.
32- This is needed in case one wants to override a flag that is active by default through the configuration. */
33- function parseFlag ( f : string ) : boolean {
34- return f === "" || f === "true" ;
35- }
36-
37- /** Parse browser URL GET parameters. */
38- function parseParams ( ) : Params {
39- const url = new URL ( window . location . href ) ;
40- const defaults = {
41- sparql : config . ontology . sparql . endpoint ,
42- instances : config . ontology . sparql . instances ,
43- } ;
44- // TypeScript interfaces don't exist on runtime, keep in sync with Params interface.
45- const paramKeys = new Set ( [ "empty" , "benchmark" , "instances" , "virtual" , "class" , "json" , "sparql" , "graph" , "sub" ] ) ;
46- const unknown = new Set ( Array . from ( url . searchParams . keys ( ) ) ) . difference ( paramKeys ) ;
47- if ( unknown . size > 0 ) {
48- log . warn ( "Unknown GET parameters: " + Array . from ( unknown ) . join ( ", " ) ) ;
49- }
50- return Object . assign ( defaults , {
51- empty : parseFlag ( url . searchParams . get ( "empty" ) ) ,
52- benchmark : parseFlag ( url . searchParams . get ( "benchmark" ) ) ,
53- // load and show instances when loading from endpoint, not only classes
54- ...( url . searchParams . get ( "instances" ) && { instances : parseFlag ( url . searchParams . get ( "instances" ) ) } ) ,
55- virtual : parseFlag ( url . searchParams . get ( "virtual" ) ) , // create "virtual triples" to visualize connections like domain-range
56- class : url . searchParams . get ( "class" ) ,
57- json : url . searchParams . get ( "json" ) ,
58- ...( url . searchParams . get ( "sparql" ) && { sparql : url . searchParams . get ( "sparql" ) } ) , // don't overwrite default with null
59- graph : url . searchParams . get ( "graph" ) ,
60- sub : url . searchParams . get ( "sub" ) ,
61- } ) ;
62- }
63-
6417/**
6518 * Apply parameters and load graph.
6619@param graph - the graph to apply the params to
6720@param params - parameter object */
68- async function applyParams ( graph : Graph , params : Params ) : Promise < void > {
21+ async function applyParams ( graph : Graph ) : Promise < void > {
6922 try {
7023 if ( params . benchmark ) {
7124 addBenchmarkOverlay ( graph . cy ) ;
7225 }
73-
7426 if ( params . empty ) {
7527 log . info ( `Parameter "empty" detected. Skip loading and display file load prompt.` ) ;
7628 const loadArea = document . getElementById ( "loadarea" ) ;
@@ -172,8 +124,7 @@ export async function fillInitialGraph(graph: Graph): Promise<void> {
172124
173125 // GET parameters
174126 await progress ( async ( ) => {
175- const params = parseParams ( ) ;
176- await applyParams ( graph , params ) ;
127+ await applyParams ( graph ) ;
177128 new Search ( util . getElementById ( "search" ) as HTMLFormElement ) ;
178129 initHelp ( ) ;
179130 } ) ;
0 commit comments