Skip to content

Commit 226bee0

Browse files
added small tweaks to frames and woql
1 parent b103bb3 commit 226bee0

File tree

5 files changed

+101
-40
lines changed

5 files changed

+101
-40
lines changed

dist/terminus-client.min.js

Lines changed: 4 additions & 4 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/framePattern.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -306,36 +306,43 @@ function FrameRule(){
306306
return this;
307307
}
308308

309+
310+
FrameRule.prototype.unpack = function(arr, nonstring){
311+
if(nonstring) var str = arr.join(",");
312+
var str = "'" + arr.join("','") + "'";
313+
return str;
314+
}
315+
309316
FrameRule.prototype.prettyPrint = function(type){
310317
//starts with obj. ...
311318
if(this.scope() == "*"){
312-
var str = ".all()";
319+
var str = "all()";
313320
}
314321
else {
315-
var str = "." + this.scope() + "()";
322+
var str = this.scope() + "()";
316323
}
317324
if(typeof this.frameType() != "undefined"){
318-
str += ".frame_type(" + JSON.stringify(this.frameType()) + ")";
325+
str += ".frame_type(" + this.unpack(this.frameType()) + ")";
319326
}
320327
if(typeof this.label() != "undefined"){
321-
str += ".label(" + JSON.stringify(this.label()) + ")";
328+
str += ".label(" + this.unpack(this.label()) + ")";
322329
}
323330
if(typeof this.subject() != "undefined"){
324-
str += ".subject(" + JSON.stringify(this.subject()) + ")";
331+
str += ".subject(" + this.unpack(this.subject()) + ")";
325332
}
326333
if(typeof this.subjectClass() != "undefined"){
327-
str += ".subjectClass(" + JSON.stringify(this.subjectClass()) + ")";
334+
str += ".subjectClass(" + this.unpack(this.subjectClass()) + ")";
328335
}
329336
if(typeof this.property() != "undefined"){
330-
str += ".property(" + JSON.stringify(this.property()) + ")";
337+
str += ".property(" + this.unpack(this.property()) + ")";
331338
}
332339
if(typeof this.range() != "undefined"){
333-
str += ".range(" + JSON.stringify(this.range()) + ")";
340+
str += ".range(" + this.unpack(this.range()) + ")";
334341
}
335342
if(typeof this.value() != "undefined"){
336-
str += ".value(" + JSON.stringify(this.range()) + ")";
343+
str += ".value(" + this.unpack(this.value()) + ")";
337344
}
338-
if(typeof this.children() != "undefined"){
345+
if(typeof this.children() != "undefined" && this.children.length > 0){
339346
str += ".children(\n";
340347
var kids = this.children();
341348
for(var i = 0; i< kids.length; i++){
@@ -350,13 +357,10 @@ FrameRule.prototype.prettyPrint = function(type){
350357
str += ".depth('" + this.depth() + "')";
351358
}
352359
if(typeof this.index() != "undefined"){
353-
str += ".index(" + JSON.stringify(this.index()) + ")";
360+
str += ".index(" + this.unpack(this.index(), true) + ")";
354361
}
355362
if(typeof this.status() != "undefined"){
356-
str += ".status(" + JSON.stringify(this.status()) + ")";
357-
}
358-
if(typeof this.args() != "undefined"){
359-
str += ".args(" + JSON.stringify(this.status()) + ")";
363+
str += ".status(" + this.unpack(this.status()) + ")";
360364
}
361365
if(typeof this.renderer() != "undefined"){
362366
str += ".renderer('" + this.renderer() + "')";
@@ -386,10 +390,10 @@ FrameRule.prototype.prettyPrint = function(type){
386390
str += ".header(" + this.header() + ")";
387391
}
388392
if(typeof this.features() != "undefined"){
389-
str += ".features(" + JSON.stringify(this.features()) + ")";
393+
str += ".features(" + this.unpack(this.features()) + ")";
390394
}
391395
if(typeof this.headerFeatures() != "undefined"){
392-
str += ".headerFeatures(" + JSON.stringify(this.headerFeatures()) + ")";
396+
str += ".headerFeatures(" + this.unpack(this.headerFeatures()) + ")";
393397
}
394398
if(typeof this.showEmpty() != "undefined"){
395399
str += ".showEmpty(" + this.show_empty() + ")";
@@ -411,7 +415,6 @@ FrameRule.prototype.prettyPrint = function(type){
411415
return str;
412416
}
413417

414-
415418
FrameRule.prototype.scope = function(scope){
416419
if(typeof scope == "undefined") return this.rule.pattern.scope;
417420
this.rule.pattern.scope = scope;

lib/objectFrame.js

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ ObjectFrame.prototype.loadClassFrames = function (classframes) {
4747

4848
const cf = new ClassFrame(classframes[j]);
4949
if (cf.isValid()) {
50-
if (typeof this.classframes[classframes[j].property] === 'undefined') {
50+
if(!this.classframes) this.classframes = {};
51+
if(typeof this.classframes[classframes[j].property] === 'undefined') {
5152
this.classframes[classframes[j].property] = [];
5253
}
5354
this.classframes[classframes[j].property] = cf;
@@ -108,7 +109,7 @@ ObjectFrame.prototype.getAsFrame = function (prop, parent) {
108109
ff.domainValue = parent.subjid;
109110
ff.frame = [];
110111
for (const prop of Object.keys(this.properties)) {
111-
ff.frame = ff.frame.concat(ff.frame, this.properties[prop].getAsFrames())
112+
ff.frame = ff.frame.concat(ff.frame, this.properties[prop].getAsFrames());
112113
}
113114
return ff;
114115
};
@@ -164,11 +165,11 @@ ObjectFrame.prototype.clear = function () {
164165
ObjectFrame.prototype.filter = function (rules, onmatch, options) {
165166
const cascading = (options && options.ignore_failure ? true : false);
166167
var hits = FramePattern.FramePatternMatcher.testRules(rules, this, onmatch);
167-
if(hits.length || cascading){
168+
//if(hits.length || cascading){
168169
for (const prop of Object.keys(this.properties)) {
169170
this.properties[prop].filter(rules, onmatch, options);
170171
}
171-
}
172+
//}
172173
return this;
173174
};
174175

@@ -496,9 +497,9 @@ PropertyFrame.prototype.addFrame = function (frame) {
496497

497498
PropertyFrame.prototype.fillFromSchema = function(newid){
498499
if (this.isData() || (this.isObject() && !this.isClassChoice())) {
499-
if (this.hasRestriction() && this.restriction.min) {
500+
if (this.cframe.hasRestriction() && this.cframe.restriction.min) {
500501
values = [];
501-
for (let i = 0; i < this.restriction.min; i += 1) {
502+
for (let i = 0; i < this.cframe.restriction.min; i += 1) {
502503
values.push(this.createEmpty(newid));
503504
}
504505
}
@@ -579,35 +580,73 @@ PropertyFrame.prototype.deletePropertyValue = function(value, index){
579580
PropertyFrame.prototype.get = function(){
580581
var gets = [];
581582
for(var i = 0; i<this.values.length; i++){
582-
gets.push(this.values[i].get());
583+
if(this.values[i]) {
584+
var x = this.values[i].get();
585+
if(x) gets.push(x);
586+
}
583587
}
584-
return get;
588+
return gets;
585589
}
586590

587591

588592
PropertyFrame.prototype.clear = function(){
589-
alert("need clear");
593+
for(var i = 0 ; i<this.values.length; i++){
594+
this.values[i].clear();
595+
}
590596
}
591597
PropertyFrame.prototype.clone = function(){
592-
alert("need clone");
598+
const cvalues = [];
599+
const cloned = new PropertyFrame(this.predicate, this.cframe, this.parent);
600+
for(var i = 0 ; i<this.values.length; i++){
601+
cvalues.push(this.values[i].clone());
602+
}
603+
cloned.values = cvalues;
604+
return cloned;
605+
//
593606
}
594607

595608
PropertyFrame.prototype.getAsFrames = function(){
596-
alert("need gaf");
609+
var fs = [];
610+
for(var i = 0; i<this.values.length; i++){
611+
if(this.values[i]){
612+
if(this.isData()){
613+
fs.push(this.values[i].getAsFrame());
614+
}
615+
else {
616+
fs = fs.concat(this.values[i].getAsFrames());
617+
}
618+
}
619+
}
620+
return fs;
597621
}
598622

599623
PropertyFrame.prototype.createEmpty = function(){
600-
alert("creatempty");
624+
if (this.cframe.isData()) {
625+
const df = this.cframe.copy();
626+
df.set('');
627+
return df;
628+
}
629+
else if (this.cframe.isObject()) {
630+
if (!this.cframe.isClassChoice()) {
631+
const df = this.cframe.createEmpty(FrameHelper.genBNID());
632+
return df;
633+
}
634+
const clss = this.cframe.getClassChoices();
635+
if (clss && clss.length) {
636+
const df = this.cframe.createEmptyChoice(clss[0], FrameHelper.genBNID());
637+
return df;
638+
}
639+
}
601640
}
602641

603642
PropertyFrame.prototype.filter = function (rules, onmatch, options) {
604643
const cascading = (options && options.ignore_failure ? true : false);
605644
var hits = FramePattern.FramePatternMatcher.testRules(rules, this, onmatch);
606-
if(hits.length || cascading){
645+
//if(hits.length || cascading){
607646
for (var i = 0; i<this.values.length; i++){
608647
this.values[i].filter(rules, onmatch, options);
609648
}
610-
}
649+
//}
611650
return this;
612651
}
613652

@@ -625,7 +664,7 @@ PropertyFrame.prototype.renderValues = function(){
625664
var sortedVals = this.sortValues();
626665
var vals = [];
627666
for(var i = 0; i<sortedVals.length; i++){
628-
if(sortedVals[i].render){
667+
if(sortedVals[i] && sortedVals[i].render){
629668
var rend = sortedVals[i].render(sortedVals[i]);
630669
if(rend) vals.push(rend);
631670
}

lib/woql.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,14 @@ WOQLQuery.prototype.documentMetadata = function(){
585585
);
586586
}
587587

588-
589-
588+
WOQLQuery.prototype.concreteDocumentClasses = function(){
589+
return this.and(
590+
WOQL.sub("v:Class", "tcs:Document"),
591+
WOQL.not().abstract("v:Class"),
592+
WOQL.opt().quad("v:Class", "rdfs:label", "v:Label", "db:schema"),
593+
WOQL.opt().quad("v:Class", "rdfs:comment", "v:Comment", "db:schema")
594+
);
595+
}
590596

591597
WOQLQuery.prototype.propertyMetadata = function(){
592598
return this.and(
@@ -644,6 +650,19 @@ WOQLQuery.prototype.documentProperties = function(id){
644650
);
645651
}
646652

653+
WOQLQuery.prototype.getDocumentConnections = function(id){
654+
return this.and(
655+
this.or(
656+
WOQL.triple(id, "v:Outgoing", "v:Entid"),
657+
WOQL.triple("v:Entid", "v:Incoming", id)
658+
),
659+
WOQL.isa("v:Entid", "v:Enttype"),
660+
WOQL.sub("v:Enttype", "tcs:Document"),
661+
WOQL.opt().triple("v:Entid", "rdfs:label", "v:Label"),
662+
WOQL.opt().quad("v:Enttype", "rdfs:label", "v:Class_Label", "db:schema")
663+
);
664+
}
665+
647666
WOQLQuery.prototype.getInstanceMeta = function(url){
648667
return this.and(
649668
WOQL.triple(url, "rdf:type", "v:InstanceType"),

0 commit comments

Comments
 (0)