Skip to content

Commit 507e80e

Browse files
added all the new WOQL API stuff
1 parent 3714c6c commit 507e80e

File tree

6 files changed

+107
-16
lines changed

6 files changed

+107
-16
lines changed

dist/terminus-client.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/terminus-client.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/frameHelper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const FrameHelper = {
1010
tcs: 'http://terminusdb.com/schema/tcs#',
1111
tbs: 'http://terminusdb.com/schema/tbs#',
1212
xdd: 'http://terminusdb.com/schema/xdd#',
13+
v: 'http://terminusdb.com/woql/variable/',
1314
terminus: 'http://terminusdb.com/schema/terminus#',
1415
vio: 'http://terminusdb.com/schema/vio#',
1516
docs: 'http://terminusdb.com/schema/documentation#'

lib/objectFrame.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ ObjectFrame.prototype.renderProperties = function(){
400400
return props;
401401
}
402402

403-
404403
function PropertyFrame(property, cframe, parent){
405404
this.predicate = property;
406405
this.cframe = cframe;

lib/woql.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ WOQLQuery.prototype.addStart = function(val, q){
113113
return this;
114114
}
115115

116+
WOQLQuery.prototype.getContext = function(q){
117+
q = (q ? q : this.query);
118+
for (const prop of Object.keys(q)) {
119+
if(prop == "@context") return q[prop];
120+
alert("not " + prop);
121+
if(this.paging_transitive_properties.indexOf(prop) !== -1){
122+
var nq = q[prop][1];
123+
var nc = this.getContext(nq);
124+
if(nc) return nc;
125+
}
126+
}
127+
}
116128

117129

118130
WOQLQuery.prototype.getLimit = function(){
@@ -214,17 +226,12 @@ WOQLQuery.prototype.defaultContext = function(DB_IRI){
214226
*/
215227
WOQLQuery.prototype.execute = function(client){
216228
if(!this.query["@context"]){
217-
var json = {};
218-
json["@context"] = this.defaultContext(client.connectionConfig.dbURL());
219-
var njson = this.json();
220-
for(var key in njson){
221-
json[key] = njson[key];
222-
}
229+
this.query["@context"] = this.defaultContext(client.connectionConfig.dbURL());
230+
var json = this.json();
223231
}
224232
else {
225233
var json = this.json();
226234
}
227-
228235
if(this.contains_update){
229236
return client.update(false, json);
230237
}
@@ -527,12 +534,17 @@ function WOQLResult(results, query){
527534
}
528535

529536
WOQLResult.prototype.compress = function(context){
530-
context = (context ? context : this.query["@context"]);
537+
context = (context ? context : this.query.getContext());
531538
for(var i = 0; i<this.bindings.length; i++){
532539
for (const prop of Object.keys(this.bindings[i])) {
533-
if(typeof this.bindings[i][prop] == "string"){
534-
this.bindings[i][prop] = TerminusClient.FrameHelper.shorten(this.bindings[i][prop]);
535-
}
540+
const nprop = TerminusClient.FrameHelper.shorten(prop, context);
541+
const nval = ((typeof this.bindings[i][prop] == "string")
542+
? TerminusClient.FrameHelper.shorten(this.bindings[i][prop], context)
543+
: this.bindings[i][prop]
544+
);
545+
alert(JSON.stringify(nval));
546+
delete(this.bindings[i][prop]);
547+
this.bindings[i][nprop] = nval;
536548
}
537549
}
538550
}

test.html

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Woql Client</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="lib/woql.js"></script>
9+
<script type="text/javascript" src="lib/viewers.js"></script>
10+
<script src="http://localhost/terminus-client/dist/terminus-client.min.js"></script>
11+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
12+
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
13+
crossorigin="anonymous"></script>
14+
15+
<script type="text/javascript">
16+
17+
function showTerminus(doc){
18+
document.getElementById('dvterm').appendChild(document.createTextNode(doc.subjid));
19+
const lab = doc.getProperty("rdfs:label").first() || doc.subjid;
20+
document.getElementById('dvlab').appendChild(document.createTextNode(lab))
21+
}
22+
23+
var adminrules = [
24+
{
25+
pattern: { renderer: "object"},
26+
render: function(frame){
27+
//alert(' objrend ' + frame.subject());
28+
subs = frame.renderProperties();
29+
}
30+
},
31+
{
32+
pattern: { renderer: "property"},
33+
render: function(frame){
34+
//alert('prop rend ' + frame.property());
35+
vals = frame.renderValues();
36+
}
37+
},
38+
{
39+
pattern: { renderer: "data"},
40+
render: function(frame){
41+
//alert('data rend ' + frame.get());
42+
}
43+
}
44+
]
45+
46+
47+
var tdb = "http://localhost:6363/terminus";
48+
49+
var dbClient= new TerminusClient.WOQLClient();
50+
var connection=dbClient.connect("http://localhost:6363/", "root");
51+
connection.then((response)=>{
52+
dbClient.connectionConfig.setDB("terminus");
53+
var whtml = new TerminusHTMLViewer(dbClient);
54+
var tab = whtml.table(WOQL.from(tdb).getEverything());
55+
var chooser = whtml.chooser(WOQL.from(tdb).classMetadata(), { element_value: "v:Element", element_label: "v:Label"});
56+
var d2 = whtml.document("admin", { rules: adminrules});
57+
whtml.document("terminus", { render: showTerminus });
58+
document.getElementById('dv2target').appendChild(d2);
59+
document.getElementById('table-target').appendChild(tab);
60+
document.getElementById('chooser-target').appendChild(chooser);
61+
});
62+
63+
64+
</script>
65+
<div id="dvtarget"><div id='dvterm'></div> <div id='dvlab'></div></div>
66+
<div id="dv2target">
67+
68+
</div>
69+
<div id="chooser-target"></div>
70+
<div id="table-target"></div>
71+
<div id="property-template" style="display:none">
72+
<div class='property-view'>
73+
<P>Property Label: <span class='property-label'></span></P>
74+
<P>Property Comment: <span class='property-comment'></span></P>
75+
<P>Property Values: <span class='property-values'></span></P>
76+
</div>
77+
</div>
78+
</body>
79+
</html>

0 commit comments

Comments
 (0)