Skip to content

Commit b103bb3

Browse files
small tweaks to woql and patterns for latest update to client
1 parent 7820569 commit b103bb3

File tree

3 files changed

+238
-30
lines changed

3 files changed

+238
-30
lines changed

lib/framePattern.js

Lines changed: 129 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ FramePatternMatcher.testRules = function(rules, frame, onmatch){
1414
var matched_rules = [];
1515
if(rules && rules.length){
1616
for(var i = 0; i<rules.length; i++){
17-
var match = (!rules[i].pattern || FramePatternMatcher.patternMatchesFrame(rules[i].pattern, frame));
17+
var match = (!rules[i].rule.pattern || FramePatternMatcher.patternMatchesFrame(rules[i].rule.pattern, frame));
1818
if(match){
1919
matched_rules.push(rules[i]);
2020
if(onmatch && typeof onmatch == "function"){
@@ -306,47 +306,162 @@ function FrameRule(){
306306
return this;
307307
}
308308

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

314-
FrameRule.prototype.frame_type = function(...frametype){
421+
FrameRule.prototype.frameType = function(...frametype){
422+
if(typeof frametype == "undefined" || frametype.length == 0) return this.rule.pattern.frametype;
315423
this.rule.pattern.frametype = frame_type;
316424
return this;
317425
}
318426

319427
FrameRule.prototype.label = function(...label){
428+
if(typeof label == "undefined" || label.length == 0) return this.rule.pattern.label;
320429
this.rule.pattern.label = label;
321430
return this;
322431
}
323432

324433
FrameRule.prototype.subject = function(...subject){
434+
if(typeof subject == "undefined" || subject.length == 0) return this.rule.pattern.subject;
325435
this.rule.pattern.subject = subject;
326436
return this;
327437
}
328438

329439
FrameRule.prototype.subjectClass = function(...subjectClass){
440+
if(typeof subjectClass == "undefined" || subjectClass.length == 0) return this.rule.pattern.subjectClass;
330441
this.rule.pattern.subjectClass = subjectClass;
331442
return this;
332443
}
333444

334445
FrameRule.prototype.property = function(...property){
446+
if(typeof property == "undefined" || property.length == 0) return this.rule.pattern.property;
335447
this.rule.pattern.property = property;
336448
return this;
337449
}
338450

339451
FrameRule.prototype.depth = function(depth){
452+
if(typeof depth == "undefined") return this.rule.pattern.depth;
340453
this.rule.pattern.depth = depth;
341454
return this;
342455
}
343456

344457
FrameRule.prototype.range = function(...range){
458+
if(typeof range == "undefined" || range.length == 0) return this.rule.pattern.range;
345459
this.rule.pattern.range = range;
346460
return this;
347461
}
348462

349463
FrameRule.prototype.value = function(...value){
464+
if(typeof value == "undefined" || value.length == 0) return this.rule.pattern.value;
350465
this.rule.pattern.value = value;
351466
return this;
352467
}
@@ -360,11 +475,13 @@ FrameRule.prototype.json = function(){
360475
}
361476

362477
FrameRule.prototype.parent = function(parent){
478+
if(typeof parent == "undefined") return this.rule.pattern.parent;
363479
this.rule.pattern.parent = parent.pattern();
364480
return this;
365481
}
366482

367483
FrameRule.prototype.children = function(...children){
484+
if(typeof children == "undefined") return this.rule.pattern.children;
368485
if(typeof this.rule.pattern.children == "undefined"){
369486
this.rule.pattern.children = [];
370487
}
@@ -375,11 +492,13 @@ FrameRule.prototype.children = function(...children){
375492
}
376493

377494
FrameRule.prototype.index = function(...index){
495+
if(typeof index == "undefined" || index.length == 0) return this.rule.pattern.index;
378496
this.rule.pattern.index = index;
379497
return this;
380498
}
381499

382500
FrameRule.prototype.status = function(...status){
501+
if(typeof status == "undefined" || status.length == 0) return this.rule.pattern.status;
383502
this.rule.pattern.status = status;
384503
return this;
385504
}
@@ -435,20 +554,20 @@ FrameRule.prototype.view = function(m){
435554
return this;
436555
}
437556

438-
FrameRule.prototype.show_disabled_buttons = function(m){
557+
FrameRule.prototype.showDisabledButtons = function(m){
439558
if(!m) return this.rule.show_disabled_buttons;
440-
this.rule.hide_disabled_buttons = m;
559+
this.rule.show_disabled_buttons = m;
441560
return this;
442561
}
443562

444-
FrameRule.prototype.features = function(m){
445-
if(!m) return this.rule.features;
563+
FrameRule.prototype.features = function(...m){
564+
if(typeof m == "undefined" || m.length == 0) return this.rule.features;
446565
this.rule.features = m;
447566
return this;
448567
}
449568

450-
FrameRule.prototype.header_features = function(m){
451-
if(!m) return this.rule.header_features;
569+
FrameRule.prototype.headerFeatures = function(...m){
570+
if(typeof m == "undefined" || m.length == 0) return this.rule.header_features;
452571
this.rule.header_features = m;
453572
return this;
454573
}
@@ -459,13 +578,13 @@ FrameRule.prototype.header = function(m){
459578
return this;
460579
}
461580

462-
FrameRule.prototype.feature_renderers = function(m){
581+
FrameRule.prototype.featureRenderers = function(m){
463582
if(!m) return this.rule.feature_renderers;
464583
this.rule.feature_renderers = m;
465584
return this;
466585
}
467586

468-
FrameRule.prototype.show_empty = function(m){
587+
FrameRule.prototype.showEmpty = function(m){
469588
if(!m) return this.rule.show_empty;
470589
this.rule.show_empty = m;
471590
return this;
@@ -477,10 +596,4 @@ FrameRule.prototype.dataviewer = function(m){
477596
return this;
478597
}
479598

480-
FrameRule.prototype.dataviewer_options = function(m){
481-
if(!m) return this.rule.dataviewer_options;
482-
this.rule.dataviewer_options = m;
483-
return this;
484-
}
485-
486599
module.exports = {FramePatternMatcher, FramePattern, FrameRule } ;

lib/objectFrame.js

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ ObjectFrame.prototype.getPropertyClassFrame = function (prop, instance) {
197197
/*
198198
* Returns a list of properties - type can be filled|missing|all
199199
*/
200-
ObjectFrame.prototype.properties = function (type) {
201-
if(type == "filled"){
200+
ObjectFrame.prototype.getProperties = function (type) {
201+
if(type == "filled" || !this.classframes){
202202
return Object.keys(this.properties);
203203
}
204204
if(type == "missing"){
@@ -221,7 +221,7 @@ ObjectFrame.prototype.properties = function (type) {
221221
* for this to work we need to load the frame with the associated classframe
222222
*/
223223
ObjectFrame.prototype.getMissingPropertyList = function () {
224-
var missing = this.properties("missing");
224+
var missing = this.getProperties("missing");
225225
const nmissing = [];
226226
for(var i = 0; i<missing.length; i++){
227227
const cframe = this.getPropertyClassFrame(missing[i]);
@@ -235,7 +235,7 @@ ObjectFrame.prototype.getMissingPropertyList = function () {
235235
* List of properties that are filled in the object
236236
*/
237237
ObjectFrame.prototype.getFilledPropertyList = function () {
238-
var props = this.properties("filled");
238+
var props = this.getProperties("filled");
239239
const filled = [];
240240
for(var i = 0; i<props.length; i++){
241241
const cframe = this.getPropertyClassFrame(props[i]);
@@ -435,6 +435,46 @@ ObjectFrame.prototype.standardCompare = function(a, b, doc){
435435
return 0;
436436
}
437437

438+
ObjectFrame.prototype.cardControlAllows = function(action){
439+
if(!this.parent) return true;
440+
if(this.parent.cframe.hasRestriction()){
441+
var rest = this.parent.cframe.restriction;
442+
var currentnum = this.parent.values.length;
443+
if(action == "add" || action == "clone"){
444+
if(rest.max && currentnum >= rest.max){
445+
return false;
446+
}
447+
}
448+
if(action == "delete" && (rest.min && currentnum <= rest.min)){
449+
return false;
450+
}
451+
}
452+
return true;
453+
}
454+
455+
ObjectFrame.prototype.isUpdated = function(){
456+
var i = 0;
457+
for(var prop in this.properties){
458+
if(this.originalFrames[i] != prop) return true;
459+
if(this.properties[prop].isUpdated()) return true;
460+
i++;
461+
}
462+
if(i != this.originalFrames.length) return true;
463+
return false;
464+
}
465+
466+
467+
ObjectFrame.prototype.getSummary = function(){
468+
var ret = { status: "ok" };
469+
if(this.isUpdated()) ret.status = "updated";
470+
if(this.isNew()) ret.status = "new";
471+
ret.propcount = 0;
472+
for(var prop in this.properties){
473+
ret.propcount++;
474+
}
475+
ret.long = ret.propcount + " properties";
476+
return ret;
477+
}
438478

439479
function PropertyFrame(property, cframe, parent){
440480
this.predicate = property;
@@ -602,6 +642,44 @@ PropertyFrame.prototype.sortValues = function(){
602642
return this.values;
603643
}
604644

645+
PropertyFrame.prototype.cardControlAllows = function(action){
646+
if(this.cframe.hasRestriction()){
647+
var rest = this.cframe.restriction;
648+
var currentnum = this.values.length;
649+
if(action == "add" || action == "clone"){
650+
if(rest.max && currentnum >= rest.max){
651+
return false;
652+
}
653+
}
654+
if(action == "delete" && (rest.min)){
655+
return false;
656+
}
657+
}
658+
return true;
659+
}
660+
661+
PropertyFrame.prototype.isUpdated = function(){
662+
return true;
663+
if(this.values.length != this.originalValues.length) return true;
664+
for(var i = 0 ; i < this.values.length; i++){
665+
if(this.cframe && this.cframe.isData()){
666+
if(this.values[i].value() != this.originalValues[i]){
667+
return true;
668+
}
669+
}
670+
else {
671+
if(this.values[i].subject() != this.originalValues[i]) {
672+
return true;
673+
}
674+
if(this.values[i].isUpdated()) {
675+
return true;
676+
}
677+
}
678+
}
679+
return false;
680+
}
681+
682+
605683
function DataFrame(frame, parent, index) {
606684
this.err = false;
607685
this.parent = parent;
@@ -879,6 +957,23 @@ DataFrame.prototype.clear = function () {
879957
}
880958
};
881959

960+
DataFrame.prototype.cardControlAllows = function(action){
961+
if(this.parent.cframe.hasRestriction()){
962+
var rest = this.parent.cframe.restriction;
963+
var currentnum = this.parent.values.length;
964+
if(action == "add" || action == "clone"){
965+
if(rest.max && currentnum >= rest.max){
966+
return false;
967+
}
968+
}
969+
if(action == "delete" && (rest.min && currentnum <= rest.min)){
970+
return false;
971+
}
972+
}
973+
return true;
974+
}
975+
976+
882977
/*
883978
* Class frames represent the archetypal version of a property frame as returned by the class frame api
884979
*/

0 commit comments

Comments
 (0)