Skip to content

Commit adf622f

Browse files
committed
2 parents d1f881e + f552b7b commit adf622f

File tree

9 files changed

+311
-142
lines changed

9 files changed

+311
-142
lines changed

lib/dispatchRequest.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
8585
case CONST.READ_DATABASE:
8686
case CONST.READ_ORGANIZATION:
8787
case CONST.CONNECT:
88-
case CONST.CLASS_FRAME:
8988
case CONST.GET_CSV:
9089
if (payload) {
9190
const ext = UTILS.URIEncodePayload(payload)

lib/query/woqlCore.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,26 @@ WOQLQuery.prototype.cleanPredicate = function(p) {
257257
return '' + p
258258
}
259259
if (p.indexOf(':') != -1) pred = p
260-
else if (this.vocab && this.vocab[p]) pred = this.vocab[p]
260+
else if (this.wellKnownPredicate(p) ) pred = this.vocab[p]
261261
else pred = 'scm:' + p
262262
return this.expandVariable(pred)
263263
}
264264

265+
WOQLQuery.prototype.wellKnownPredicate = function(p) {
266+
if (this.vocab && this.vocab[p]){
267+
let full = this.vocab[p]
268+
let start = full.substring(0, 3)
269+
if(full == "system:abstract" || start == "xdd" || start == "xsd") return false
270+
return true
271+
}
272+
return false
273+
}
274+
275+
265276
WOQLQuery.prototype.cleanPathPredicate = function(p) {
266277
let pred = false
267278
if (p.indexOf(':') != -1) pred = p
268-
else if (this.vocab && this.vocab[p]) pred = this.vocab[p]
279+
else if (this.wellKnownPredicate(p) ) pred = this.vocab[p]
269280
else pred = 'scm:' + p
270281
return pred
271282
}

lib/utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ Utils.empty = function(obj) {
7575
}
7676

7777
/**
78-
* Generates a unique blank node id
78+
* Generates a unique node id
7979
*/
80-
Utils.genBNID = function() {
80+
Utils.genBNID = function(base) {
81+
base = base || ""
8182
const r = Math.random()
8283
.toString(36)
8384
.substring(7)
8485
const d = new Date()
85-
const bnid = `_:${r}${d.getTime()}`
86+
const bnid = `doc:${base}${r}${d.getTime()}`
8687
return bnid
8788
}
8889

@@ -109,18 +110,16 @@ Utils.getShorthand = function(link) {
109110
Utils.compareIDs = function(ida, idb) {
110111
if (ida === idb) return true
111112
if (this.unshorten(ida) === idb) return true
113+
if (this.shorten(ida) === idb) return true
112114
if (this.unshorten(ida) === this.unshorten(idb)) return true
113-
const sha = this.getShorthand(ida)
114-
const shb = this.getShorthand(idb)
115-
if (sha && (sha === idb || sha === shb)) return true
116-
if (shb && shb === ida) return true
117115
return false
118116
}
119117

120118
/**
121119
* Shortens a URL to its compressed format - returns the full URL if not possible
122120
*/
123121
Utils.shorten = function(url, prefixes) {
122+
if(!url) return url
124123
prefixes = prefixes || Utils.standard_urls
125124
for (const pref in prefixes) {
126125
if (prefixes[pref] == url.substring(0, prefixes[pref].length)) {
@@ -134,6 +133,7 @@ Utils.shorten = function(url, prefixes) {
134133
* Expands a URL to its full URL format - returns the passed string if not possible to expand
135134
*/
136135
Utils.unshorten = function(url) {
136+
if(!url) return url
137137
if (this.validURL(url)) return url
138138
if (!url) return url
139139
const bits = url.split(':')
@@ -150,6 +150,7 @@ Utils.unshorten = function(url) {
150150
* Valid URLs are those that start with http:// or https://
151151
*/
152152
Utils.validURL = function(str) {
153+
if(str && typeof str != "string") str = "" + str
153154
if (str && (str.substring(0, 7) === 'http://' || str.substring(0, 8) === 'https://'))
154155
return true
155156
return false

lib/viewer/documentFrame.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@ DocumentFrame.prototype.db = function(dburl){
2424
return this;
2525
}
2626

27-
DocumentFrame.prototype.load = function(url, cls){
28-
if(url) {
29-
if(url.substring(0,4) == "doc:"){
30-
url = url.substring(4);
31-
}
32-
if(this.config.load_schema()){
33-
return this.loadComplete(url, cls)
34-
}
35-
else {
36-
return this.loadDocument(url);
37-
}
38-
}
39-
if(cls){
40-
return this.loadSchema(cls);
41-
}
42-
//return Promise.reject
43-
}
44-
4527
/**
4628
* @param {String} url - loads the document frame from the document API in frame form
4729
* - loads the frame encapsulates more meta-data in the json and reduces the number of api calls we need to make
@@ -90,28 +72,36 @@ DocumentFrame.prototype.loadJSON = function(json, type){
9072
console.error("Either docid or clid must be set before load is called")
9173
}
9274

93-
DocumentFrame.prototype.loadDataFrames = function(dataframes, cls, classframes){
75+
DocumentFrame.prototype.loadData = function(jsonld, cls, classframes){
9476
if(!cls){
9577
if(this.document) cls = this.document.cls;
9678
else {
97-
if(dataframes && dataframes.length && dataframes[0] && dataframes[0].domain){
98-
cls = dataframes[0].domain;
79+
if(jsonld && jsonld["@type"]){
80+
cls = jsonld["@type"];
9981
}
10082
}
10183
}
10284
if(cls){
10385
if(!this.document){
104-
this.document = new ObjectFrame(cls, dataframes, classframes);
86+
alert("Yo")
87+
this.document = new ObjectFrame(cls, jsonld, classframes);
10588
}
10689
else {
107-
this.document.loadDataFrames(dataframes);
108-
}
90+
alert("Yo2")
91+
this.document.loadJSONLDDocument(jsonld);
92+
}
93+
alert(this.document.subjid)
10994
}
11095
else {
11196
console.log("Missing Class" + " " + "Failed to add dataframes due to missing class");
11297
}
11398
}
11499

100+
DocumentFrame.prototype.load = function(classframes, doc){
101+
this.document = new ObjectFrame(doc["@type"], doc, classframes)
102+
}
103+
104+
115105
DocumentFrame.prototype.loadSchemaFrames = function(classframes, cls){
116106
if(!cls){
117107
if(classframes && classframes.length && classframes[0] && classframes[0].domain){
@@ -126,7 +116,7 @@ DocumentFrame.prototype.loadSchemaFrames = function(classframes, cls){
126116
this.document.loadClassFrames(classframes);
127117
if(!this.document.subjid){
128118
this.document.newDoc = true;
129-
this.document.fillFromSchema("_:");
119+
this.document.fillFromSchema(FrameHelper.genBNID(FrameHelper.urlFragment(cls)+"_"));
130120
}
131121
}
132122
}
@@ -135,13 +125,36 @@ DocumentFrame.prototype.loadSchemaFrames = function(classframes, cls){
135125
}
136126
}
137127

128+
DocumentFrame.prototype.filterFrame = function(loadRenderer){
129+
var myfilt = function(frame, rule){
130+
if(typeof rule.render() != "undefined"){
131+
frame.render = rule.render();
132+
}
133+
else {
134+
if(rule.renderer()){
135+
var renderer = loadRenderer(rule.renderer(), frame, rule.args);
136+
}
137+
if(renderer){
138+
frame.render = function(fframe){
139+
return renderer(fframe);
140+
}
141+
}
142+
}
143+
if(rule.compare()){
144+
frame.compare = rule.compare();
145+
}
146+
}
147+
this.applyRules(false, false, myfilt);
148+
}
149+
150+
138151
/*
139152
* adds render and compare functions to object frames
140153
*/
141154
DocumentFrame.prototype.applyRules = function(doc, config, mymatch){
142-
doc = (doc ? doc : this.document);
155+
doc = doc || this.document;
156+
if(!doc) return
143157
config = (config ? config : this.config);
144-
var self = this;
145158
var onmatch = function(frame, rule){
146159
config.setFrameDisplayOptions(frame, rule);
147160
if(mymatch) mymatch(frame, rule);

lib/viewer/frameConfig.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const Config = require('./viewConfig.js');
32
const FrameRule = require('./frameRule.js');
43
const DocumentFrame = require('./documentFrame.js');

0 commit comments

Comments
 (0)