@wavemaker/app-ng-runtime 11.4.2-next.25743 → 11.4.2-next.25744

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -346,17 +346,17 @@
346
346
  var defaultTreeIconClass = 'plus-minus';
347
347
  var TreeComponent = /** @class */ (function (_super) {
348
348
  __extends(TreeComponent, _super);
349
- function TreeComponent(inj, bindnodeid) {
349
+ function TreeComponent(inj, binddatavalue, bindnodelabel, bindnodeicon, bindnodechildren, bindnodeid) {
350
350
  var _this = _super.call(this, inj, WIDGET_INFO) || this;
351
+ _this.binddatavalue = binddatavalue;
352
+ _this.bindnodelabel = bindnodelabel;
353
+ _this.bindnodeicon = bindnodeicon;
354
+ _this.bindnodechildren = bindnodechildren;
351
355
  _this.bindnodeid = bindnodeid;
352
356
  _this.setting = {
353
357
  data: {
354
358
  simpleData: {
355
359
  enable: false
356
- },
357
- key: {
358
- children: 'children',
359
- name: 'label'
360
360
  }
361
361
  },
362
362
  view: {
@@ -370,46 +370,46 @@
370
370
  callback: {}
371
371
  };
372
372
  base.styler(_this.nativeElement, _this, base.APPLY_STYLES_TYPE.CONTAINER);
373
+ _this.setting.view['nodeClasses'] = _this.setNodeClasses;
374
+ _this.setting.callback["onClick"] = _this.onClick.bind(_this);
375
+ _this.setting.callback["onExpand"] = _this.onExpand.bind(_this);
376
+ _this.setting.callback["onCollapse"] = _this.onCollapse.bind(_this);
373
377
  return _this;
374
378
  }
375
379
  TreeComponent.prototype.onPropertyChange = function (key, nv, ov) {
376
380
  switch (key) {
377
381
  case 'dataset':
378
382
  this.nodes = this.getNodes(nv);
379
- if (this.level > 0) {
380
- this.expandTree(this.level, this.nodes, 0);
381
- }
382
383
  this.renderTree();
383
384
  break;
384
385
  case 'levels':
385
- if (nv > 0) {
386
- this.level = nv;
387
- }
386
+ this.level = nv;
388
387
  this.renderTree();
389
388
  break;
390
- case 'treeicons':
391
- this.treeicon = nv;
389
+ case 'nodeicon':
390
+ this.nodeicon = nv;
392
391
  this.renderTree();
393
392
  break;
394
393
  case 'nodelabel':
395
- this.setting.data.key.name = this.labelKey;
394
+ this.nodelabel = nv;
396
395
  this.renderTree();
397
396
  break;
398
397
  case 'nodechildren':
399
- this.setting.data.key.children = this.childrenKey;
398
+ this.nodechildren = nv;
400
399
  this.renderTree();
401
400
  break;
402
- case 'nodeicon':
403
- this.nodeicon = this.iconKey;
401
+ case 'orderby':
402
+ this.orderby = nv;
404
403
  this.renderTree();
405
404
  break;
406
- case 'orderby':
405
+ case 'treeicons':
406
+ this.treeicons = nv;
407
407
  this.renderTree();
408
408
  break;
409
409
  case 'class':
410
410
  this.treeClass = nv;
411
+ this.setTreeTemplate(this.treeClass);
411
412
  this.renderTree();
412
- break;
413
413
  default:
414
414
  _super.prototype.onPropertyChange.call(this, key, nv, ov);
415
415
  break;
@@ -419,9 +419,9 @@
419
419
  TreeComponent.prototype.expandTree = function (level, node, childLevel) {
420
420
  var _this = this;
421
421
  node.map(function (childNode) {
422
- var children = _this.getChildren(childNode);
423
- if (children && !("open" in childNode) && childLevel < level) {
424
- childNode["open"] = true;
422
+ var children = childNode.children;
423
+ if (children && childLevel < level) {
424
+ childNode.open = true;
425
425
  _this.expandTree(level, children, childLevel + 1);
426
426
  }
427
427
  else {
@@ -432,14 +432,15 @@
432
432
  };
433
433
  // sets the template for the tree based on the property selected.
434
434
  TreeComponent.prototype.setTreeTemplate = function (value) {
435
- if (value === 'Classic') {
435
+ var classList = value.split(" ");
436
+ if (classList.includes('Classic')) {
436
437
  this.setting.check["enable"] = false;
437
438
  }
438
- else if (value === 'Checkbox') {
439
+ else if (classList.includes('Checkbox')) {
439
440
  this.setting.check["enable"] = true;
440
441
  this.setting.check["chkStyle"] = 'checkbox';
441
442
  }
442
- else if (value === 'Radio') {
443
+ else if (classList.includes('Radio')) {
443
444
  this.setting.check["enable"] = true;
444
445
  this.setting.check["chkStyle"] = 'radio';
445
446
  this.setting.check["radioType"] = "all";
@@ -471,53 +472,10 @@
471
472
  return nodes;
472
473
  };
473
474
  // adds class to the nodes inorder to add icons to respective node.
474
- TreeComponent.prototype.setNodeclasses = function (treeId, treeNode) {
475
+ TreeComponent.prototype.setNodeClasses = function (treeId, treeNode) {
475
476
  return treeNode.icon ? { add: ["" + treeNode.icon] } : '';
476
477
  };
477
478
  ;
478
- // Sets the node label with any icon if bound to
479
- TreeComponent.prototype.setNodeData = function (nodes, depth, level, parentNode, type) {
480
- var _this = this;
481
- if (depth === 0) {
482
- nodes.map(function (node) {
483
- var children = _this.getChildren(node);
484
- if (children) {
485
- _this.setNodeData(children, depth, level, parentNode, type);
486
- }
487
- if (node.icon && _this.nodelabel == 'icon') {
488
- node[type] = node.icon;
489
- }
490
- else if (node.name && _this.nodelabel == 'name') {
491
- node[type] = node.name;
492
- }
493
- else {
494
- return;
495
- }
496
- });
497
- }
498
- else {
499
- nodes.map(function (node) {
500
- var children = _this.getChildren(node);
501
- if (children && level > 1) {
502
- if (depth === level) {
503
- parentNode = node;
504
- }
505
- _this.setNodeData(children, depth, level - 1, parentNode, type);
506
- }
507
- if (level === 1 && (type === "name" ? _this.nodelabel.includes("label") || _this.nodelabel.includes("name") : _this.nodeicon.includes("label") || _this.nodeicon.includes("name"))) {
508
- parentNode[type] = node.name || node.label;
509
- return;
510
- }
511
- else if (level === 1 && (node.icon !== undefined) && (type === "name" ? _this.nodelabel.includes("icon") : _this.nodeicon.includes("icon"))) {
512
- parentNode[type] = node.icon;
513
- return;
514
- }
515
- else {
516
- return;
517
- }
518
- });
519
- }
520
- };
521
479
  // adds tree icons to the nodes on load of the tree
522
480
  TreeComponent.prototype.changeTreeIcons = function (nv) {
523
481
  var eleClose = $('ul[name="' + this.name + '"] li span.button.switch');
@@ -530,19 +488,20 @@
530
488
  });
531
489
  });
532
490
  };
491
+ // Returns the node path
533
492
  TreeComponent.prototype.getPath = function (treeNode, path) {
534
493
  if (treeNode.getParentNode() === null) {
535
- path = "/" + treeNode[this.labelKey] + path;
494
+ path = "/" + treeNode.name + path;
536
495
  }
537
496
  else {
538
- path = this.getPath(treeNode.getParentNode(), path) + "/" + treeNode[this.labelKey];
497
+ path = this.getPath(treeNode.getParentNode(), path) + "/" + treeNode.name;
539
498
  }
540
499
  return path;
541
500
  };
542
501
  // binds the click event to all nodes to open the child nodes
543
502
  TreeComponent.prototype.onClick = function (event, treeId, treeNode, clickFlag) {
544
503
  if (this.nodeclick === "expand") {
545
- var nodes = this.treeObj.getSelectedNodes();
504
+ var nodes = this.zTree.getSelectedNodes();
546
505
  if (nodes.length > 0) {
547
506
  this.expandNode(nodes[0], !nodes[0].open, true);
548
507
  }
@@ -555,18 +514,18 @@
555
514
  var path = this.getPath(treeNode, "");
556
515
  var eventParams = {
557
516
  '$event': event,
558
- "$item": treeNode,
517
+ "$item": core.getClonedObject(treeNode.data),
559
518
  "$path": path
560
519
  };
561
520
  this.invokeEventCallback('expand', eventParams);
562
- var children = this.getChildren(treeNode);
521
+ var children = treeNode.children;
563
522
  children === null || children === void 0 ? void 0 : children.map(function (el) {
564
523
  if (el.isParent) {
565
524
  var ele_1 = $("#" + el.tId + "_switch");
566
- $(ele_1).addClass(self.treeicon || defaultTreeIconClass);
525
+ $(ele_1).addClass(self.treeicons || defaultTreeIconClass);
567
526
  $(ele_1).on("click", function (e) {
568
527
  setTimeout(function () {
569
- $(ele_1).addClass(self.treeicon || defaultTreeIconClass);
528
+ $(ele_1).addClass(self.treeicons || defaultTreeIconClass);
570
529
  }, 0);
571
530
  });
572
531
  }
@@ -576,151 +535,56 @@
576
535
  var path = this.getPath(treeNode, "");
577
536
  var eventParams = {
578
537
  '$event': event,
579
- "$item": treeNode,
538
+ "$item": core.getClonedObject(treeNode.data),
580
539
  "$path": path
581
540
  };
582
541
  this.invokeEventCallback('collapse', eventParams);
583
542
  };
584
- TreeComponent.prototype.getChildren = function (node) {
585
- return node[this.childrenKey];
586
- };
587
- Object.defineProperty(TreeComponent.prototype, "childrenKey", {
588
- get: function () {
589
- if (!this.nodechildren) {
590
- return 'children';
591
- }
592
- var depth = this.countDepth(this.nodechildren);
593
- return depth ? this.nodechildren.split('.').pop() : this.nodechildren;
594
- },
595
- enumerable: false,
596
- configurable: true
597
- });
598
- Object.defineProperty(TreeComponent.prototype, "labelKey", {
599
- get: function () {
600
- if (!this.nodelabel) {
601
- return 'label';
602
- }
603
- var depth = this.countDepth(this.nodelabel);
604
- return depth ? this.nodelabel.split('.').pop() : this.nodelabel;
605
- },
606
- enumerable: false,
607
- configurable: true
608
- });
609
- Object.defineProperty(TreeComponent.prototype, "iconKey", {
610
- get: function () {
611
- if (!this.nodeicon) {
612
- return 'icon';
613
- }
614
- var depth = this.countDepth(this.nodeicon);
615
- return depth ? this.nodeicon.split('.').pop() : this.nodeicon;
616
- },
617
- enumerable: false,
618
- configurable: true
619
- });
620
- Object.defineProperty(TreeComponent.prototype, "treeObj", {
621
- get: function () {
622
- return $.fn.zTree.getZTreeObj("" + this.name);
623
- },
624
- enumerable: false,
625
- configurable: true
626
- });
627
543
  // function to support backward compatibility of objects
628
- TreeComponent.prototype.modifyObjects = function (array) {
544
+ TreeComponent.prototype.constructZTreeData = function (data, zTreeData) {
629
545
  var _this = this;
630
- array.forEach(function (obj) {
631
- obj.icon = obj[_this.nodeicon];
632
- var children = _this.getChildren(obj);
633
- if (children === null || children === void 0 ? void 0 : children.length) {
634
- _this.modifyObjects(children);
546
+ data.forEach(function (node) {
547
+ var zNode = {};
548
+ var name = base.getEvaluatedData(node, { field: _this.nodelabel, bindExpression: _this.bindnodelabel }, _this.viewParent) || node.label;
549
+ var icon = base.getEvaluatedData(node, { field: _this.nodeicon, bindExpression: _this.bindnodeicon }, _this.viewParent) || node.icon;
550
+ var nodeId = base.getEvaluatedData(node, { field: _this.nodeid, bindExpression: _this.bindnodeid }, _this.viewParent);
551
+ var children = base.getEvaluatedData(node, { field: _this.nodechildren, bindExpression: _this.bindnodechildren }, _this.viewParent) || node.children;
552
+ zNode['name'] = name;
553
+ zNode['icon'] = icon;
554
+ zNode['nodeId'] = nodeId;
555
+ zNode['data'] = core.getClonedObject(node);
556
+ if (_.isArray(children) && children.length) {
557
+ zNode['children'] = [];
558
+ _this.constructZTreeData(children, zNode['children']);
635
559
  }
560
+ zTreeData.push(zNode);
636
561
  });
637
562
  };
638
- // sets the node children property to parent nodes
639
- TreeComponent.prototype.setNodeChildren = function (nodes, depth, level, parentNode) {
640
- var _this = this;
641
- if (depth <= 0) {
642
- return nodes;
643
- }
644
- for (var i = 0; i < nodes.length; i++) {
645
- var node = nodes[i];
646
- if (depth === level) {
647
- parentNode = nodes[i];
648
- }
649
- var children = this.getChildren(node);
650
- if (children === null || children === void 0 ? void 0 : children.length) {
651
- if (level === 1) {
652
- parentNode[this.childrenKey] = children.map(function (child) {
653
- var _a;
654
- return (_a = {}, _a[_this.labelKey] = child[_this.labelKey], _a[_this.childrenKey] = _this.getChildren(child), _a.icon = child[_this.iconKey], _a);
655
- });
656
- return;
657
- }
658
- else {
659
- this.setNodeChildren(children, depth, level - 1, parentNode);
660
- }
661
- }
662
- }
663
- return nodes;
664
- };
665
- TreeComponent.prototype.countDepth = function (str) {
666
- var e_1, _a;
667
- var regex = /\[.*?\]/g;
668
- var matches = str.match(regex);
669
- var count = 1;
670
- if (matches === null)
671
- return count;
672
- try {
673
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
674
- var match = matches_1_1.value;
675
- count++;
676
- }
677
- }
678
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
679
- finally {
680
- try {
681
- if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
682
- }
683
- finally { if (e_1) throw e_1.error; }
684
- }
685
- return count;
686
- };
687
563
  // Renders the tree on to the dom
688
564
  TreeComponent.prototype.renderTree = function () {
689
- if (this.nodes) {
565
+ var _a;
566
+ this.zTreeNodes = [];
567
+ if ((_a = this.nodes) === null || _a === void 0 ? void 0 : _a.length) {
690
568
  this.nativeElement.setAttribute('id', this.name);
691
- if (this.nodeicon && this.nodeicon !== 'icon') {
692
- this.modifyObjects(this.nodes);
693
- }
694
- this.setTreeTemplate(this.treeClass);
695
- if (this.nodelabel) {
696
- var depth = 0;
697
- if (this.nodelabel.includes("children")) {
698
- depth = this.countDepth(this.nodelabel);
699
- }
700
- this.setNodeData(this.nodes, depth, depth, null, "name");
701
- }
702
- if (this.nodeicon) {
703
- var depth = 0;
704
- if (this.nodeicon.includes("children")) {
705
- depth = this.countDepth(this.nodeicon);
706
- }
707
- this.setNodeData(this.nodes, depth, depth, null, "icon");
708
- }
709
- if (this.nodechildren) {
710
- var depth = this.countDepth(this.nodechildren);
711
- if (depth > 1) {
712
- this.nodes = this.setNodeChildren(this.nodes, depth, depth, null);
713
- }
569
+ this.constructZTreeData(this.nodes, this.zTreeNodes);
570
+ if (this.level > 0) {
571
+ this.expandTree(this.level, this.zTreeNodes, 0);
714
572
  }
715
573
  }
716
- this.setting.view['nodeClasses'] = this.setNodeclasses;
717
- this.setting.callback["onClick"] = this.onClick.bind(this);
718
- this.setting.callback["onExpand"] = this.onExpand.bind(this);
719
- this.setting.callback["onCollapse"] = this.onCollapse.bind(this);
720
- var zTree = $.fn.zTree.init($('ul[name="' + this.name + '"]'), this.setting, this.nodes);
721
- $.fn.zTreeKeyboardNavigation(zTree, $('ul[name="' + this.name + '"]'), null, this.treeicon || defaultTreeIconClass);
574
+ this.zTree = $.fn.zTree.init($('ul[name="' + this.name + '"]'), this.setting, this.zTreeNodes);
575
+ $.fn.zTreeKeyboardNavigation(this.zTree, $('ul[name="' + this.name + '"]'), null, this.treeicons || defaultTreeIconClass);
722
576
  this.postRenderTree();
723
577
  };
578
+ TreeComponent.prototype.setChecked = function (zNode, node) {
579
+ var _this = this;
580
+ node.checked = zNode.checked;
581
+ var children = base.getEvaluatedData(node, { field: this.nodechildren, bindExpression: this.bindnodechildren }, this.viewParent) || node.children;
582
+ if (children === null || children === void 0 ? void 0 : children.length) {
583
+ children.forEach(function (node, index) {
584
+ _this.setChecked(zNode.children[index], node);
585
+ });
586
+ }
587
+ };
724
588
  TreeComponent.prototype.selectNode = function (event, node) {
725
589
  var deSelectElm = $(".app-tree[name=" + this.name + "] li[treenode].selected");
726
590
  deSelectElm.removeClass('selected');
@@ -729,27 +593,36 @@
729
593
  }
730
594
  var selectElm = $("#" + node.tId + ":has(.curSelectedNode)");
731
595
  selectElm.addClass('selected');
596
+ var classList = (this.treeClass || "").split(" ");
597
+ if (classList.includes('Checkbox') || classList.includes('Radio')) {
598
+ this.setChecked(node, node.data);
599
+ }
732
600
  var path = this.getPath(node, "");
733
- this.selecteditem = core.getClonedObject(node) || {};
601
+ this.selecteditem = core.getClonedObject(node.data) || {};
734
602
  this.selecteditem.path = path;
735
603
  var eventParams = {
736
604
  '$event': event,
737
- "$item": node,
605
+ "$item": core.getClonedObject(node.data),
738
606
  "$path": path
739
607
  };
608
+ //[Todo-CSP]: this data will be dynamic, can not generate function upfront
609
+ var nodeAction = node.data[this.nodeaction || 'action'];
610
+ if (nodeAction) {
611
+ core.$parseEvent(nodeAction)(this);
612
+ }
740
613
  this.invokeEventCallback('select', eventParams);
741
614
  };
742
615
  TreeComponent.prototype.expandNode = function (node, expand, eventFlag) {
743
- this.treeObj.expandNode(node, expand, false, false, eventFlag);
616
+ this.zTree.expandNode(node, expand, false, false, eventFlag);
744
617
  var el = $("#" + node.tId + "_switch");
745
- $(el).addClass(this.treeicon || defaultTreeIconClass);
618
+ $(el).addClass(this.treeicons || defaultTreeIconClass);
746
619
  };
747
620
  TreeComponent.prototype.postRenderTree = function () {
748
621
  var _this = this;
749
622
  setTimeout(function () {
750
- _this.changeTreeIcons(_this.treeicon || defaultTreeIconClass);
623
+ _this.changeTreeIcons(_this.treeicons || defaultTreeIconClass);
751
624
  if (_this.datavalue && !_this.selecteditem) {
752
- var nodes = _this.treeObj.getNodes();
625
+ var nodes = _this.zTree.getNodes();
753
626
  var node = void 0;
754
627
  if (nodes.length) {
755
628
  if (_this.datavalue === 'FirstNode') {
@@ -760,7 +633,7 @@
760
633
  }
761
634
  }
762
635
  if (node) {
763
- _this.treeObj.selectNode(node, false);
636
+ _this.zTree.selectNode(node, false);
764
637
  _this.selectNode(undefined, node);
765
638
  _this.expandNode(node, true, false);
766
639
  }
@@ -768,11 +641,11 @@
768
641
  }, 200);
769
642
  };
770
643
  TreeComponent.prototype.selectById = function (value) {
771
- var _this = this;
772
- var simpleNodes = this.treeObj.transformToArray(this.treeObj.getNodes());
773
- var node = simpleNodes.find(function (node) { return value === base.getEvaluatedData(node, { field: _this.nodeid, bindExpression: _this.bindnodeid }, _this.viewParent); });
644
+ var _a;
645
+ var simpleNodes = (_a = this.zTree) === null || _a === void 0 ? void 0 : _a.transformToArray(this.zTree.getNodes());
646
+ var node = simpleNodes === null || simpleNodes === void 0 ? void 0 : simpleNodes.find(function (node) { return value === node.nodeId; });
774
647
  if (node) {
775
- this.treeObj.selectNode(node, false);
648
+ this.zTree.selectNode(node, false);
776
649
  this.selectNode(undefined, node);
777
650
  }
778
651
  };
@@ -795,6 +668,10 @@
795
668
  ];
796
669
  TreeComponent.ctorParameters = function () { return [
797
670
  { type: core$1.Injector },
671
+ { type: undefined, decorators: [{ type: core$1.Attribute, args: ['datavalue.bind',] }] },
672
+ { type: undefined, decorators: [{ type: core$1.Attribute, args: ['nodelabel.bind',] }] },
673
+ { type: undefined, decorators: [{ type: core$1.Attribute, args: ['nodeicon.bind',] }] },
674
+ { type: undefined, decorators: [{ type: core$1.Attribute, args: ['nodechildren.bind',] }] },
798
675
  { type: undefined, decorators: [{ type: core$1.Attribute, args: ['nodeid.bind',] }] }
799
676
  ]; };
800
677