diff src/layout/ViewConfig.ts @ 139:cf642d395be4

new simpler Patch class; fancier 'hide' view config support
author drewp@bigasterisk.com
date Mon, 08 May 2023 13:05:20 -0700
parents 5a1a79f54779
children
line wrap: on
line diff
--- a/src/layout/ViewConfig.ts	Sat May 06 15:35:11 2023 -0700
+++ b/src/layout/ViewConfig.ts	Mon May 08 13:05:20 2023 -0700
@@ -1,8 +1,9 @@
 import Immutable from "immutable"; // mostly using this for the builtin equals() testing, since NamedNode(x)!=NamedNode(x)
 import { DataFactory, NamedNode, Quad_Predicate, Term } from "n3";
 import { MultiStore } from "../MultiStore";
-import { EX } from "./namespaces";
+import { EX, RDF } from "./namespaces";
 import { uriValue } from "./rdf_value";
+import { Quad_Graph } from "rdf-js";
 const Uri = DataFactory.namedNode;
 
 function firstElem<E>(seq: Iterable<E>): E {
@@ -31,17 +32,17 @@
   viewRoot: NamedNode; // this structure...
   graph: MultiStore; // in this graph...
   tables: TableDesc[] = []; // populates all the rest of these fields for use by Layout
-  freeStatementsHidePred: Immutable.Set<Quad_Predicate> = Immutable.Set();
+  hidePredFrees: Immutable.Set<Quad_Predicate> = Immutable.Set();
+  hideGraphEverywhere: Immutable.Set<Quad_Graph> = Immutable.Set();
 
   constructor(graph: MultiStore, viewUri: NamedNode) {
     this.graph = graph;
     this.viewRoot = viewUri;
     // todo
-    const here = "https://bigasterisk.com/lanscape/";
-    if (this.viewRoot.value.startsWith(here)) {
-      this.viewRoot = new NamedNode(this.viewRoot.value.slice(here.length));
-    }
-    // todo: might need to reread if graph changes
+    // const here = "https://bigasterisk.com/lanscape/";
+    // if (this.viewRoot.value.startsWith(here)) {
+    //   this.viewRoot = new NamedNode(this.viewRoot.value.slice(here.length));
+    // }
     this.read();
   }
 
@@ -56,19 +57,20 @@
   }
 
   private readHides() {
-    for (let hideInstruction of this.graph.getObjects(
-      this.viewRoot,
-      EX("freeStatementsHide"),
-      null
-    )) {
-      for (let pred of this.graph.getObjects(
-        hideInstruction,
-        EX("predicate"),
-        null
-      )) {
-        this.freeStatementsHidePred = this.freeStatementsHidePred.add(
-          pred as Quad_Predicate
-        );
+    for (let instr of this.graph.getObjects(this.viewRoot, EX("hide"), null)) {
+      const types = this.graph.getObjects(instr, RDF("type"), null);
+      if (types.length == 1 && types[0].equals(EX("HideEverywhere"))) {
+        for (let g of this.graph.getObjects(instr, EX("graph"), null)) {
+          this.hideGraphEverywhere = this.hideGraphEverywhere.add(
+            g as Quad_Graph
+          );
+        }
+      } else if (types.length == 1 && types[0].equals(EX("HideFreeStatements"))) {
+        for (let pred of this.graph.getObjects(instr, EX("predicate"), null)) {
+          this.hidePredFrees = this.hidePredFrees.add(pred as Quad_Predicate);
+        }
+      } else {
+        throw new Error(":hide instruction must have 1 valid type");
       }
     }
   }