Skip to content

Commit 4b2b97b

Browse files
committed
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents 5ec95b7 + 5f35607 commit 4b2b97b

File tree

7 files changed

+773
-180
lines changed

7 files changed

+773
-180
lines changed

.eslintrc

Lines changed: 0 additions & 26 deletions
This file was deleted.

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: 224 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const FramePatternMatcher = {}
1212
*/
1313
FramePatternMatcher.testRules = function(rules, frame, onmatch){
1414
var matched_rules = [];
15-
for(var i = 0; i<rules.length; i++){
16-
var match = (!rules[i].pattern || this.patternMatchesFrame(rules[i].pattern, frame));
17-
if(match){
18-
matched_rules.push(rules[i]);
19-
if(onmatch && typeof onmatch == "function"){
20-
onmatch(frame, rules[i]);
15+
if(rules && rules.length){
16+
for(var i = 0; i<rules.length; i++){
17+
var match = (!rules[i].rule.pattern || FramePatternMatcher.patternMatchesFrame(rules[i].rule.pattern, frame));
18+
if(match){
19+
matched_rules.push(rules[i]);
20+
if(onmatch && typeof onmatch == "function"){
21+
onmatch(frame, rules[i]);
22+
}
2123
}
2224
}
2325
}
@@ -66,7 +68,7 @@ FramePattern = function(pattern){
6668
}
6769

6870
FramePattern.prototype.setPattern = function(pattern){
69-
this.renderer = (pattern.renderer ? pattern.renderer : false);
71+
this.scope = (pattern.scope ? pattern.scope: false);
7072
this.label = (pattern.label ? pattern.label : false);
7173
this.frame_type = (pattern.frame_type ? pattern.frame_type : false);
7274
this.subject = (pattern.subject ? pattern.subject : false);
@@ -89,7 +91,7 @@ FramePattern.prototype.setPattern = function(pattern){
8991
FramePattern.prototype.checkFrame = function(frame){
9092
var rtype = this.getRendererType(frame);
9193
if(!rtype) return false;
92-
if(this.renderer && (this.renderer != rtype) && (this.renderer != "*" )) return false;
94+
if(this.scope && (this.scope != rtype) && (this.scope != "*" )) return false;
9395
if(this.illegalRuleType(rtype)) return false;
9496
if(this.frame_type && !this.checkFrameType(rtype, frame)) return false;
9597
if(this.label && !this.checkLabel(rtype, frame)) return false;
@@ -300,71 +302,169 @@ FramePattern.prototype.getRendererType = function(frame){
300302
}
301303

302304
function FrameRule(){
303-
this.rule = { pattern: {}};
305+
this.rule = { pattern: {} };
304306
return this;
305307
}
306308

307-
FrameRule.prototype.renderer = function(...rend){
308-
this.rule.pattern.renderer = rend;
309-
return this;
310-
}
311309

312-
FrameRule.prototype.setRenderer = function(rend){
313-
this.rule.renderer = rend;
314-
return this;
310+
FrameRule.prototype.unpack = function(arr, nonstring){
311+
if(nonstring) var str = arr.join(",");
312+
var str = "'" + arr.join("','") + "'";
313+
return str;
315314
}
316315

317-
FrameRule.prototype.render = function(func){
318-
this.rule.render = func;
319-
return this;
320-
}
321-
322-
FrameRule.prototype.args = function(json){
323-
this.rule.args = json;
324-
return this;
316+
FrameRule.prototype.prettyPrint = function(type){
317+
//starts with obj. ...
318+
if(this.scope() == "*"){
319+
var str = "all()";
320+
}
321+
else {
322+
var str = this.scope() + "()";
323+
}
324+
if(typeof this.frameType() != "undefined"){
325+
str += ".frame_type(" + this.unpack(this.frameType()) + ")";
326+
}
327+
if(typeof this.label() != "undefined"){
328+
str += ".label(" + this.unpack(this.label()) + ")";
329+
}
330+
if(typeof this.subject() != "undefined"){
331+
str += ".subject(" + this.unpack(this.subject()) + ")";
332+
}
333+
if(typeof this.subjectClass() != "undefined"){
334+
str += ".subjectClass(" + this.unpack(this.subjectClass()) + ")";
335+
}
336+
if(typeof this.property() != "undefined"){
337+
str += ".property(" + this.unpack(this.property()) + ")";
338+
}
339+
if(typeof this.range() != "undefined"){
340+
str += ".range(" + this.unpack(this.range()) + ")";
341+
}
342+
if(typeof this.value() != "undefined"){
343+
str += ".value(" + this.unpack(this.value()) + ")";
344+
}
345+
if(typeof this.children() != "undefined" && this.children.length > 0){
346+
str += ".children(\n";
347+
var kids = this.children();
348+
for(var i = 0; i< kids.length; i++){
349+
str += kids.prettyPrint() + "\n";
350+
}
351+
str += ")";
352+
}
353+
if(typeof this.parent() != "undefined"){
354+
str += ".parent(" + this.parent.prettyPrint() + ")";
355+
}
356+
if(typeof this.depth() != "undefined"){
357+
str += ".depth('" + this.depth() + "')";
358+
}
359+
if(typeof this.index() != "undefined"){
360+
str += ".index(" + this.unpack(this.index(), true) + ")";
361+
}
362+
if(typeof this.status() != "undefined"){
363+
str += ".status(" + this.unpack(this.status()) + ")";
364+
}
365+
if(typeof this.renderer() != "undefined"){
366+
str += ".renderer('" + this.renderer() + "')";
367+
}
368+
if(typeof this.render() != "undefined"){
369+
str += ".render(" + this.render() + ")";
370+
}
371+
if(typeof this.compare() != "undefined"){
372+
str += ".compare(" + this.compare() + ")";
373+
}
374+
if(typeof this.mode() != "undefined"){
375+
str += ".mode('" + this.mode() + "')";
376+
}
377+
if(typeof this.collapse() != "undefined"){
378+
str += ".collapse(" + this.collapse() + ")";
379+
}
380+
if(typeof this.hidden() != "undefined"){
381+
str += ".hidden(" + this.hidden() + ")";
382+
}
383+
if(typeof this.view() != "undefined"){
384+
str += ".view('" + this.view() + "')";
385+
}
386+
if(typeof this.showDisabledButtons() != "undefined"){
387+
str += ".showDisabledButtons(" + this.showDisabledButtons() + ")";
388+
}
389+
if(typeof this.header() != "undefined"){
390+
str += ".header(" + this.header() + ")";
391+
}
392+
if(typeof this.features() != "undefined"){
393+
str += ".features(" + this.unpack(this.features()) + ")";
394+
}
395+
if(typeof this.headerFeatures() != "undefined"){
396+
str += ".headerFeatures(" + this.unpack(this.headerFeatures()) + ")";
397+
}
398+
if(typeof this.showEmpty() != "undefined"){
399+
str += ".showEmpty(" + this.show_empty() + ")";
400+
}
401+
if(typeof this.dataviewer() != "undefined"){
402+
str += ".dataviewer('" + this.dataviewer() + "')";
403+
}
404+
if(typeof this.args() != "undefined"){
405+
str += ".args(" + JSON.stringify(this.args()) + ")";
406+
}
407+
if(typeof this.featureRenderers() != "undefined"){
408+
str += ".featureRenderers({";
409+
for(var f in this.featureRenderers()){
410+
str += JSON.stringify(f) + ":" + this.rule.feature_renderers[f] + ",";
411+
}
412+
str = str.substring(0, str.length-1);
413+
str += "})";
414+
}
415+
return str;
325416
}
326417

327-
FrameRule.prototype.compare = function(func){
328-
this.rule.compare = func;
418+
FrameRule.prototype.scope = function(scope){
419+
if(typeof scope == "undefined") return this.rule.pattern.scope;
420+
this.rule.pattern.scope = scope;
329421
return this;
330422
}
331423

332-
FrameRule.prototype.frame_type = function(...frametype){
424+
FrameRule.prototype.frameType = function(...frametype){
425+
if(typeof frametype == "undefined" || frametype.length == 0) return this.rule.pattern.frametype;
333426
this.rule.pattern.frametype = frame_type;
334427
return this;
335428
}
336429

337430
FrameRule.prototype.label = function(...label){
431+
if(typeof label == "undefined" || label.length == 0) return this.rule.pattern.label;
338432
this.rule.pattern.label = label;
339433
return this;
340434
}
341435

342436
FrameRule.prototype.subject = function(...subject){
437+
if(typeof subject == "undefined" || subject.length == 0) return this.rule.pattern.subject;
343438
this.rule.pattern.subject = subject;
344439
return this;
345440
}
346441

347442
FrameRule.prototype.subjectClass = function(...subjectClass){
443+
if(typeof subjectClass == "undefined" || subjectClass.length == 0) return this.rule.pattern.subjectClass;
348444
this.rule.pattern.subjectClass = subjectClass;
349445
return this;
350446
}
351447

352448
FrameRule.prototype.property = function(...property){
449+
if(typeof property == "undefined" || property.length == 0) return this.rule.pattern.property;
353450
this.rule.pattern.property = property;
354451
return this;
355452
}
356453

357454
FrameRule.prototype.depth = function(depth){
455+
if(typeof depth == "undefined") return this.rule.pattern.depth;
358456
this.rule.pattern.depth = depth;
359457
return this;
360458
}
361459

362460
FrameRule.prototype.range = function(...range){
461+
if(typeof range == "undefined" || range.length == 0) return this.rule.pattern.range;
363462
this.rule.pattern.range = range;
364463
return this;
365464
}
366465

367466
FrameRule.prototype.value = function(...value){
467+
if(typeof value == "undefined" || value.length == 0) return this.rule.pattern.value;
368468
this.rule.pattern.value = value;
369469
return this;
370470
}
@@ -378,11 +478,13 @@ FrameRule.prototype.json = function(){
378478
}
379479

380480
FrameRule.prototype.parent = function(parent){
481+
if(typeof parent == "undefined") return this.rule.pattern.parent;
381482
this.rule.pattern.parent = parent.pattern();
382483
return this;
383484
}
384485

385486
FrameRule.prototype.children = function(...children){
487+
if(typeof children == "undefined") return this.rule.pattern.children;
386488
if(typeof this.rule.pattern.children == "undefined"){
387489
this.rule.pattern.children = [];
388490
}
@@ -393,14 +495,108 @@ FrameRule.prototype.children = function(...children){
393495
}
394496

395497
FrameRule.prototype.index = function(...index){
498+
if(typeof index == "undefined" || index.length == 0) return this.rule.pattern.index;
396499
this.rule.pattern.index = index;
397500
return this;
398501
}
399502

400503
FrameRule.prototype.status = function(...status){
504+
if(typeof status == "undefined" || status.length == 0) return this.rule.pattern.status;
401505
this.rule.pattern.status = status;
402506
return this;
403507
}
404508

509+
FrameRule.prototype.renderer = function(rend){
510+
if(!rend) return this.rule.renderer;
511+
this.rule.renderer = rend;
512+
return this;
513+
}
514+
515+
FrameRule.prototype.render = function(func){
516+
if(func){
517+
this.rule.render = func;
518+
return this;
519+
}
520+
return func;
521+
}
522+
523+
FrameRule.prototype.args = function(json){
524+
if(!json) return this.rule.args;
525+
this.rule.args = json;
526+
return this;
527+
}
528+
529+
FrameRule.prototype.compare = function(func){
530+
if(!func) return this.rule.compare;
531+
this.rule.compare = func;
532+
return this;
533+
}
534+
535+
FrameRule.prototype.mode = function(m){
536+
if(!m) return this.rule.mode;
537+
this.rule.mode = m;
538+
return this;
539+
}
540+
541+
FrameRule.prototype.collapse = function(m){
542+
if(!m) return this.rule.collapse;
543+
this.rule.collapse = m;
544+
return this;
545+
}
546+
547+
548+
FrameRule.prototype.hidden = function(m){
549+
if(!m) return this.rule.hidden;
550+
this.rule.hidden = m;
551+
return this;
552+
}
553+
554+
FrameRule.prototype.view = function(m){
555+
if(!m) return this.rule.view;
556+
this.rule.view = m;
557+
return this;
558+
}
559+
560+
FrameRule.prototype.showDisabledButtons = function(m){
561+
if(!m) return this.rule.show_disabled_buttons;
562+
this.rule.show_disabled_buttons = m;
563+
return this;
564+
}
565+
566+
FrameRule.prototype.features = function(...m){
567+
if(typeof m == "undefined" || m.length == 0) return this.rule.features;
568+
this.rule.features = m;
569+
return this;
570+
}
571+
572+
FrameRule.prototype.headerFeatures = function(...m){
573+
if(typeof m == "undefined" || m.length == 0) return this.rule.header_features;
574+
this.rule.header_features = m;
575+
return this;
576+
}
577+
578+
FrameRule.prototype.header = function(m){
579+
if(!m) return this.rule.header;
580+
this.rule.header = m;
581+
return this;
582+
}
583+
584+
FrameRule.prototype.featureRenderers = function(m){
585+
if(!m) return this.rule.feature_renderers;
586+
this.rule.feature_renderers = m;
587+
return this;
588+
}
589+
590+
FrameRule.prototype.showEmpty = function(m){
591+
if(!m) return this.rule.show_empty;
592+
this.rule.show_empty = m;
593+
return this;
594+
}
595+
596+
FrameRule.prototype.dataviewer = function(m){
597+
if(!m) return this.rule.dataviewer;
598+
this.rule.dataviewer = m;
599+
return this;
600+
}
405601

406-
module.exports = {FramePatternMatcher, FrameRule} ;
602+
module.exports = {FramePatternMatcher, FramePattern, FrameRule } ;

0 commit comments

Comments
 (0)