@wavemaker/app-ng-runtime 11.4.0-next.28701 → 11.4.0-rc.5342

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.
Files changed (92) hide show
  1. app-ng-runtime/build-task/basic/tree/tree.build.d.ts +1 -2
  2. app-ng-runtime/build-task/bundles/index.umd.js +7 -9
  3. app-ng-runtime/build-task/bundles/index.umd.js.map +1 -1
  4. app-ng-runtime/build-task/esm2015/basic/tree/tree.build.js +3 -4
  5. app-ng-runtime/build-task/esm2015/navigation/popover/popover.build.js +3 -3
  6. app-ng-runtime/build-task/fesm2015/index.js +7 -9
  7. app-ng-runtime/build-task/fesm2015/index.js.map +1 -1
  8. app-ng-runtime/components/base/bundles/index.umd.js +7 -4
  9. app-ng-runtime/components/base/bundles/index.umd.js.map +1 -1
  10. app-ng-runtime/components/base/esm2015/utils/widget-utils.js +7 -4
  11. app-ng-runtime/components/base/esm2015/widgets/common/dialog/dialog.service.js +3 -3
  12. app-ng-runtime/components/base/fesm2015/index.js +8 -5
  13. app-ng-runtime/components/base/fesm2015/index.js.map +1 -1
  14. app-ng-runtime/components/base/utils/widget-utils.d.ts +1 -1
  15. app-ng-runtime/components/basic/tree/bundles/index.umd.js +280 -256
  16. app-ng-runtime/components/basic/tree/bundles/index.umd.js.map +1 -1
  17. app-ng-runtime/components/basic/tree/esm2015/public_api.js +2 -2
  18. app-ng-runtime/components/basic/tree/esm2015/tree.component.js +322 -0
  19. app-ng-runtime/components/basic/tree/esm2015/tree.module.js +3 -3
  20. app-ng-runtime/components/basic/tree/fesm2015/index.js +260 -248
  21. app-ng-runtime/components/basic/tree/fesm2015/index.js.map +1 -1
  22. app-ng-runtime/components/basic/tree/index.metadata.json +1 -1
  23. app-ng-runtime/components/basic/tree/public_api.d.ts +1 -1
  24. app-ng-runtime/components/basic/tree/tree.component.d.ts +34 -0
  25. app-ng-runtime/components/containers/tabs/bundles/index.umd.js +39 -23
  26. app-ng-runtime/components/containers/tabs/bundles/index.umd.js.map +1 -1
  27. app-ng-runtime/components/containers/tabs/esm2015/tab-pane/tab-pane.component.js +8 -1
  28. app-ng-runtime/components/containers/tabs/esm2015/tabs.animator.js +33 -13
  29. app-ng-runtime/components/containers/tabs/fesm2015/index.js +40 -13
  30. app-ng-runtime/components/containers/tabs/fesm2015/index.js.map +1 -1
  31. app-ng-runtime/components/containers/tabs/tabs.animator.d.ts +5 -1
  32. app-ng-runtime/components/data/list/bundles/index.umd.js +51 -42
  33. app-ng-runtime/components/data/list/bundles/index.umd.js.map +1 -1
  34. app-ng-runtime/components/data/list/esm2015/list.component.js +51 -42
  35. app-ng-runtime/components/data/list/fesm2015/index.js +50 -41
  36. app-ng-runtime/components/data/list/fesm2015/index.js.map +1 -1
  37. app-ng-runtime/components/data/list/index.metadata.json +1 -1
  38. app-ng-runtime/components/data/pagination/bundles/index.umd.js +21 -4
  39. app-ng-runtime/components/data/pagination/bundles/index.umd.js.map +1 -1
  40. app-ng-runtime/components/data/pagination/esm2015/pagination.component.js +22 -5
  41. app-ng-runtime/components/data/pagination/fesm2015/index.js +21 -4
  42. app-ng-runtime/components/data/pagination/fesm2015/index.js.map +1 -1
  43. app-ng-runtime/components/data/pagination/index.metadata.json +1 -1
  44. app-ng-runtime/components/data/pagination/pagination.component.d.ts +1 -0
  45. app-ng-runtime/components/data/table/bundles/index.umd.js +7 -0
  46. app-ng-runtime/components/data/table/bundles/index.umd.js.map +1 -1
  47. app-ng-runtime/components/data/table/esm2015/table.component.js +8 -1
  48. app-ng-runtime/components/data/table/fesm2015/index.js +7 -0
  49. app-ng-runtime/components/data/table/fesm2015/index.js.map +1 -1
  50. app-ng-runtime/components/data/table/index.metadata.json +1 -1
  51. app-ng-runtime/components/dialogs/default/base-dialog.d.ts +1 -0
  52. app-ng-runtime/components/dialogs/default/bundles/index.umd.js +13 -4
  53. app-ng-runtime/components/dialogs/default/bundles/index.umd.js.map +1 -1
  54. app-ng-runtime/components/dialogs/default/esm2015/base-dialog.js +14 -6
  55. app-ng-runtime/components/dialogs/default/fesm2015/index.js +13 -5
  56. app-ng-runtime/components/dialogs/default/fesm2015/index.js.map +1 -1
  57. app-ng-runtime/components/dialogs/default/index.metadata.json +1 -1
  58. app-ng-runtime/components/input/epoch/bundles/index.umd.js +66 -29
  59. app-ng-runtime/components/input/epoch/bundles/index.umd.js.map +1 -1
  60. app-ng-runtime/components/input/epoch/date-time/date-time-picker.component.d.ts +1 -0
  61. app-ng-runtime/components/input/epoch/esm2015/base-date-time.component.js +43 -25
  62. app-ng-runtime/components/input/epoch/esm2015/date/date.component.js +3 -3
  63. app-ng-runtime/components/input/epoch/esm2015/date-time/date-time-picker.component.js +31 -11
  64. app-ng-runtime/components/input/epoch/esm2015/date-time/date-time.component.js +2 -2
  65. app-ng-runtime/components/input/epoch/fesm2015/index.js +75 -37
  66. app-ng-runtime/components/input/epoch/fesm2015/index.js.map +1 -1
  67. app-ng-runtime/components/input/epoch/index.metadata.json +1 -1
  68. app-ng-runtime/components/navigation/popover/bundles/index.umd.js +3 -4
  69. app-ng-runtime/components/navigation/popover/bundles/index.umd.js.map +1 -1
  70. app-ng-runtime/components/navigation/popover/esm2015/popover.component.js +5 -6
  71. app-ng-runtime/components/navigation/popover/fesm2015/index.js +4 -5
  72. app-ng-runtime/components/navigation/popover/fesm2015/index.js.map +1 -1
  73. app-ng-runtime/mobile/components/page/default/bundles/index.umd.js +24 -6
  74. app-ng-runtime/mobile/components/page/default/bundles/index.umd.js.map +1 -1
  75. app-ng-runtime/mobile/components/page/default/esm2015/page.directive.js +20 -3
  76. app-ng-runtime/mobile/components/page/default/fesm2015/index.js +19 -2
  77. app-ng-runtime/mobile/components/page/default/fesm2015/index.js.map +1 -1
  78. app-ng-runtime/mobile/components/page/default/index.metadata.json +1 -1
  79. app-ng-runtime/mobile/components/page/default/page.directive.d.ts +4 -1
  80. app-ng-runtime/package.json +1 -1
  81. app-ng-runtime/scripts/datatable/datatable.js +23 -23
  82. app-ng-runtime/scripts/tree-keyboard-navigation/keyboard-navigation.js +251 -0
  83. app-ng-runtime/variables/bundles/index.umd.js +14 -4
  84. app-ng-runtime/variables/bundles/index.umd.js.map +1 -1
  85. app-ng-runtime/variables/esm2015/manager/action/notification-action.manager.js +5 -6
  86. app-ng-runtime/variables/esm2015/service/variables.service.js +8 -1
  87. app-ng-runtime/variables/fesm2015/index.js +11 -5
  88. app-ng-runtime/variables/fesm2015/index.js.map +1 -1
  89. app-ng-runtime/variables/index.metadata.json +1 -1
  90. app-ng-runtime/variables/service/variables.service.d.ts +4 -0
  91. app-ng-runtime/components/basic/tree/esm2015/tree.directive.js +0 -310
  92. app-ng-runtime/components/basic/tree/tree.directive.d.ts +0 -35
@@ -1,7 +1,6 @@
1
- import { Directive, Injector, Attribute, NgModule } from '@angular/core';
1
+ import { Component, ViewEncapsulation, Injector, NgModule } from '@angular/core';
2
2
  import { CommonModule } from '@angular/common';
3
- import { register, PROP_STRING, PROP_ANY, PROP_NUMBER, PROP_BOOLEAN, StylableComponent, styler, APPLY_STYLES_TYPE, getEvaluatedData, getOrderedDataset, provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
4
- import { $parseExpr, getClonedObject, $appDigest, $parseEvent } from '@wm/core';
3
+ import { register, PROP_STRING, PROP_ANY, PROP_NUMBER, PROP_BOOLEAN, StylableComponent, styler, APPLY_STYLES_TYPE, getOrderedDataset, provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
5
4
 
6
5
  const registerProps = () => {
7
6
  register('wm-tree', new Map([
@@ -23,314 +22,327 @@ const registerProps = () => {
23
22
  ]));
24
23
  };
25
24
 
26
- const defaultTreeIconClass = 'plus-minus';
27
- const ICON_CLASSES = {
28
- 'folder': {
29
- 'expanded': 'wi-folder-open',
30
- 'collapsed': 'wi-folder'
31
- },
32
- 'circle-plus-minus': {
33
- 'expanded': 'wi-remove-circle-outline',
34
- 'collapsed': 'wi-add-circle-outline'
35
- },
36
- 'chevron': {
37
- 'expanded': 'wi-keyboard-arrow-down',
38
- 'collapsed': 'wi-keyboard-arrow-right'
39
- },
40
- 'menu': {
41
- 'expanded': 'wi-arrow-down',
42
- 'collapsed': 'wi-arrow-right'
43
- },
44
- 'triangle': {
45
- 'expanded': 'wi-arrow-drop-down-circle',
46
- 'collapsed': 'wi-play-circle-filled'
47
- },
48
- 'expand-collapse': {
49
- 'expanded': 'wi-expand-less',
50
- 'collapsed': 'wi-expand-more'
51
- },
52
- 'plus-minus': {
53
- 'expanded': 'wi-minus',
54
- 'collapsed': 'wi-plus'
55
- }
56
- };
57
25
  const WIDGET_INFO = { widgetType: 'wm-tree', hostClass: 'app-tree' };
58
- class TreeDirective extends StylableComponent {
59
- constructor(inj, binddatavalue, bindnodelabel, bindnodeicon, bindnodechildren, bindnodeid) {
26
+ const defaultTreeIconClass = 'plus-minus';
27
+ class TreeComponent extends StylableComponent {
28
+ constructor(inj) {
60
29
  super(inj, WIDGET_INFO);
61
- this.binddatavalue = binddatavalue;
62
- this.bindnodelabel = bindnodelabel;
63
- this.bindnodeicon = bindnodeicon;
64
- this.bindnodechildren = bindnodechildren;
65
- this.bindnodeid = bindnodeid;
30
+ this.setting = {
31
+ data: {
32
+ simpleData: {
33
+ enable: true
34
+ },
35
+ },
36
+ view: {
37
+ dblClickExpand: false,
38
+ fontCss: {
39
+ 'font-awesome': true
40
+ },
41
+ switchIcon: {},
42
+ },
43
+ check: {},
44
+ callback: {}
45
+ };
66
46
  styler(this.nativeElement, this, APPLY_STYLES_TYPE.CONTAINER);
67
- this.bindEvents();
68
47
  }
69
48
  onPropertyChange(key, nv, ov) {
70
49
  switch (key) {
71
50
  case 'dataset':
72
51
  this.nodes = this.getNodes(nv);
73
- this._selectNode = undefined;
52
+ if (this.level > 0) {
53
+ this.expandTree(this.level, this.nodes, 0);
54
+ }
74
55
  this.renderTree();
75
56
  break;
76
- case 'nodeicon':
57
+ case 'levels':
58
+ if (nv > 0) {
59
+ this.level = nv;
60
+ }
61
+ break;
62
+ case 'treeicons':
63
+ this.treeicon = nv;
64
+ break;
77
65
  case 'nodelabel':
78
- case 'nodechildren':
66
+ this.nodelabel = nv;
67
+ break;
68
+ case 'icon':
69
+ this.nodeicon = nv;
79
70
  case 'orderby':
80
71
  this.renderTree();
81
72
  break;
82
- case 'treeicons':
83
- this.changeTreeIcons(nv, ov);
84
- break;
85
- case 'datavalue':
86
- this.selectById(nv);
73
+ case 'class':
74
+ this.treeClass = nv;
87
75
  break;
88
76
  default:
89
77
  super.onPropertyChange(key, nv, ov);
78
+ break;
90
79
  }
91
80
  }
92
- constructNodes(nodes, parent, levels, deep, _evalDataValue) {
93
- const $ul = $('<ul></ul>');
94
- const _iconClses = ICON_CLASSES[this.treeicons || defaultTreeIconClass];
95
- const _expr = (this.binddatavalue || this.datavalue);
96
- let _iconCls, _cls;
97
- _cls = levels > 0 ? ' expanded ' : ' collapsed ';
98
- _iconCls = _cls + (levels > 0 ? _iconClses.expanded : _iconClses.collapsed);
99
- deep = deep || 0;
100
- parent.append($ul);
101
- nodes.forEach((node, idx) => {
102
- const $li = $('<li></li>'), $iconNode = $('<i></i>'), nodeLabel = getEvaluatedData(node, { field: this.nodelabel, bindExpression: this.bindnodelabel }, this.viewParent) || node.label, nodeIcon = getEvaluatedData(node, { field: this.nodeicon, bindExpression: this.bindnodeicon }, this.viewParent) || node.icon, nodeChildren = getEvaluatedData(node, { field: this.nodechildren, bindExpression: this.bindnodechildren }, this.viewParent) || node.children;
103
- let nodeIdValue = getEvaluatedData(node, { field: this.nodeid, bindExpression: this.bindnodeid }, this.viewParent);
104
- if (nodeIdValue === undefined) {
105
- nodeIdValue = node.children;
106
- }
107
- let isNodeMatched = false, expandCollapseIcon;
108
- $li.data('nodedata', node)
109
- .append($iconNode)
110
- .append(`<span class="title">${nodeLabel}</span>`)
111
- .appendTo($ul);
112
- // if datavalue(ie, expr) is provided select the tree node accordingly
113
- // if datavalue === 'FirstNode' -- select the FirstNode at level 0
114
- // if datavalue === 'LastNode' -- select the LastNode at level 0
115
- // if datavalue is a bind expression evaluate the expression for each node of the tree till the condition is satisfied.
116
- // if node identifier is present then verify the datavalue is bound expr or static value and compare with the node model
117
- if (this.bindnodeid || this.nodeid) {
118
- isNodeMatched = this.binddatavalue ? nodeIdValue === _evalDataValue : nodeIdValue === _expr;
119
- if (nodeIdValue !== undefined) {
120
- $li.attr('id', nodeIdValue);
121
- }
122
- }
123
- else if (this.binddatavalue) { // evaluate the expression only if it is bound (useExpression)
124
- isNodeMatched = !!$parseExpr(_expr)(this, node);
125
- }
126
- // Perform LastNode check only at level 0.(ie, deep = 0);
127
- if (!this._selectNode) {
128
- if ((_expr === 'FirstNode' && idx === 0)
129
- || (!deep && _expr === 'LastNode' && idx === nodes.length - 1)
130
- || isNodeMatched) {
131
- // save a reference of the node to be selected in `_selectNode`
132
- this._selectNode = $li;
133
- this.datavalue = nodeIdValue;
134
- }
135
- }
136
- if (nodeIcon) {
137
- $iconNode.addClass(nodeIcon);
138
- }
139
- if (nodeChildren && nodeChildren.length) { // parent node
140
- $li.addClass(`parent-node ${_cls}`);
141
- expandCollapseIcon = $(`<i class="wi ${_iconCls}"></i>`);
142
- if (nodeIcon) {
143
- $iconNode.addClass(nodeIcon);
144
- }
145
- $li.prepend(expandCollapseIcon);
146
- this.constructNodes(nodeChildren, $li, levels - 1, deep + 1, _evalDataValue);
81
+ // expands the tree nodes if the property is selected.
82
+ expandTree(level, node, childLevel) {
83
+ node.map(childNode => {
84
+ if ("children" in childNode && !("open" in childNode) && childLevel < level) {
85
+ childNode["open"] = true;
86
+ this.expandTree(level, childNode.children, childLevel + 1);
147
87
  }
148
88
  else {
149
- if (!nodeIcon) {
150
- $iconNode.addClass('leaf-node');
151
- }
152
- $li.addClass('leaf-node');
89
+ childLevel = 0;
90
+ return;
153
91
  }
154
92
  });
155
93
  }
94
+ // sets the template for the tree based on the property selected.
95
+ setTreeTemplate(value) {
96
+ if (value === 'Classic') {
97
+ this.setting.check["enable"] = false;
98
+ }
99
+ else if (value === 'Checkbox') {
100
+ this.setting.check["enable"] = true;
101
+ this.setting.check["chkStyle"] = 'checkbox';
102
+ }
103
+ else if (value === 'Radio') {
104
+ this.setting.check["enable"] = true;
105
+ this.setting.check["chkStyle"] = 'radio';
106
+ this.setting.check["radioType"] = "all";
107
+ }
108
+ }
109
+ // extracts nodes from string format
156
110
  getNodesFromString(value) {
157
111
  return value.split(',').map((item) => {
158
112
  return {
159
- 'label': item && item.trim()
113
+ 'name': item && item.trim()
160
114
  };
161
115
  });
162
116
  }
117
+ // gets the nodes and orders the nodes if required
163
118
  getNodes(newVal) {
164
119
  let nodes;
165
- if (_.isString(newVal) && !_.isEmpty(newVal)) {
120
+ if (_.isArray(newVal)) {
121
+ nodes = getOrderedDataset(newVal, this.orderby);
122
+ }
123
+ else if (_.isObject(newVal)) {
124
+ nodes = [newVal];
125
+ }
126
+ else if (_.isString(newVal) && !_.isEmpty(newVal)) {
166
127
  newVal = newVal.trim();
167
128
  if (newVal) {
168
129
  nodes = this.getNodesFromString(newVal);
169
130
  }
170
131
  }
171
- else if (_.isArray(newVal)) {
172
- newVal = getOrderedDataset(newVal, this.orderby);
173
- nodes = newVal;
174
- }
175
- else if (_.isObject(newVal)) {
176
- nodes = [newVal];
177
- }
178
132
  return nodes;
179
133
  }
180
- changeTreeIcons(nv, ov) {
181
- const $el = $(this.nativeElement);
182
- nv = nv || defaultTreeIconClass;
183
- ov = ov || defaultTreeIconClass;
184
- $el.find('i.expanded').removeClass(ICON_CLASSES[ov].expanded).addClass(ICON_CLASSES[nv].expanded);
185
- $el.find('i.collapsed').removeClass(ICON_CLASSES[ov].collapsed).addClass(ICON_CLASSES[nv].collapsed);
134
+ // adds class to the nodes inorder to add icons to respective node.
135
+ setNodeclasses(treeId, treeNode) {
136
+ return treeNode.icon ? { add: [`${treeNode.icon}`] } : '';
186
137
  }
187
- toggleExpandCollapseNode($event, $i, $li) {
188
- const treeIcons = ICON_CLASSES[this.treeicons || defaultTreeIconClass];
189
- const $liPath = this.findSelectedNodeParent($li);
190
- let path = '';
191
- // construct the path of the node
192
- $liPath
193
- .each((i, el) => {
194
- const current = $(el).children('.title').text();
195
- path = `/${current + path}`;
196
- });
197
- const eventParams = {
198
- '$event': $event,
199
- "$item": $li.data('nodedata'),
200
- "$path": path
201
- };
202
- if ($i.hasClass('collapsed')) {
203
- $i.removeClass(`collapsed ${treeIcons.collapsed}`).addClass(`expanded ${treeIcons.expanded}`);
204
- $li.removeClass('collapsed').addClass('expanded');
205
- this.invokeEventCallback('expand', eventParams);
138
+ ;
139
+ // Sets the node label with any icon if bound to
140
+ setNodeData(nodes, depth, level, parentNode, type) {
141
+ if (depth === 0) {
142
+ nodes.map(node => {
143
+ if (node.children) {
144
+ this.setNodeData(node.children, depth, level, parentNode, type);
145
+ }
146
+ if (node.icon && this.nodelabel == 'icon') {
147
+ node[type] = node.icon;
148
+ }
149
+ else if (node.name && this.nodelabel == 'name') {
150
+ node[type] = node.name;
151
+ }
152
+ else {
153
+ return;
154
+ }
155
+ });
206
156
  }
207
- else if ($i.hasClass('expanded')) {
208
- $i.removeClass(`expanded ${treeIcons.expanded}`).addClass(`collapsed ${treeIcons.collapsed}`);
209
- $li.removeClass('expanded').addClass('collapsed');
210
- this.invokeEventCallback('collapse', eventParams);
157
+ else {
158
+ nodes.map(node => {
159
+ if (node.children && level > 1) {
160
+ if (depth === level) {
161
+ parentNode = node;
162
+ }
163
+ this.setNodeData(node.children, depth, level - 1, parentNode, type);
164
+ }
165
+ if (level === 1 && (type === "name" ? this.nodelabel.includes("label") || this.nodelabel.includes("name") : this.nodeicon.includes("label") || this.nodeicon.includes("name"))) {
166
+ parentNode[type] = node.name || node.label;
167
+ return;
168
+ }
169
+ else if (level === 1 && (node.icon !== undefined) && (type === "name" ? this.nodelabel.includes("icon") : this.nodeicon.includes("icon"))) {
170
+ parentNode[type] = node.icon;
171
+ return;
172
+ }
173
+ else {
174
+ return;
175
+ }
176
+ });
211
177
  }
212
178
  }
213
- renderTree(forceRender) {
214
- let docFrag, $li, $liPath, data, path = '';
215
- const levels = +this.nativeElement.getAttribute('levels') || 0, $el = $(this.nativeElement);
216
- $el.empty();
217
- if (forceRender) {
218
- this._selectNode = undefined;
179
+ // adds tree icons to the nodes on load of the tree
180
+ changeTreeIcons(nv) {
181
+ let eleClose = $('ul[name="' + this.name + '"] li span.button.switch');
182
+ $(eleClose).map((idx, ele) => {
183
+ $(ele).addClass(nv);
184
+ $(ele).on("click", function (e) {
185
+ setTimeout(() => {
186
+ $(ele).addClass(nv);
187
+ }, 0);
188
+ });
189
+ });
190
+ }
191
+ getPath(treeNode, path) {
192
+ if (treeNode.getParentNode() === null) {
193
+ path = "/" + treeNode.name + path;
219
194
  }
220
- if (this.nodes && this.nodes.length) {
221
- docFrag = document.createDocumentFragment();
222
- this.constructNodes(this.nodes, $(docFrag), levels, 0, this.datavalue);
223
- $el.append(docFrag);
195
+ else {
196
+ path = this.getPath(treeNode.getParentNode(), path) + "/" + treeNode.name;
224
197
  }
225
- if (this._selectNode) {
226
- $li = this._selectNode;
227
- $li.addClass('selected');
228
- data = $li.data('nodedata');
229
- $liPath = this.findSelectedNodeParent($li);
230
- if (!$liPath.length) {
231
- $liPath = $li;
198
+ return path;
199
+ }
200
+ // binds the click event to all nodes to open the child nodes
201
+ onClick(event, treeId, treeNode, clickFlag) {
202
+ var treeObj = $.fn.zTree.getZTreeObj(`${this.name}`);
203
+ let path = this.getPath(treeNode, "");
204
+ const eventParams = {
205
+ '$event': event,
206
+ "$item": treeNode,
207
+ "$path": path
208
+ };
209
+ this.invokeEventCallback('select', eventParams);
210
+ }
211
+ // Adds tree icon classes to child nodes when expanded
212
+ onExpand(event, treeId, treeNode) {
213
+ let self = this;
214
+ let path = this.getPath(treeNode, "");
215
+ const eventParams = {
216
+ '$event': event,
217
+ "$item": treeNode,
218
+ "$path": path
219
+ };
220
+ this.invokeEventCallback('expand', eventParams);
221
+ treeNode.children ? treeNode.children.map((el) => {
222
+ if (el.isParent) {
223
+ let ele = $(`#${el.tId}_switch`);
224
+ $(ele).addClass(self.treeicon || defaultTreeIconClass);
225
+ $(ele).on("click", function (e) {
226
+ setTimeout(() => {
227
+ $(ele).addClass(self.treeicon || defaultTreeIconClass);
228
+ }, 0);
229
+ });
232
230
  }
233
- $liPath
234
- .each((i, el) => {
235
- const $current = $(el), $i = $current.children('i.collapsed'), $title = $current.children('.title');
236
- this.toggleExpandCollapseNode(undefined, $i, $current);
237
- path = `/${$title.text() + path}`;
238
- });
239
- this.selecteditem = getClonedObject(data) || {};
240
- this.selecteditem.path = path;
241
- this.invokeEventCallback('select', { $event: undefined, $item: data, $path: path });
242
- $appDigest();
243
- }
231
+ }) : '';
244
232
  }
245
- selectNode(evt, value) {
246
- const target = evt && $(evt.target), $el = $(this.nativeElement), $li = _.isObject(value) ? value : $el.find(`li[id="${value}"]`).first();
247
- let data, path = '', $liPath, nodeAction;
248
- $el.find('.selected').removeClass('selected');
249
- if (!$li.length) {
250
- return;
251
- }
252
- $li.addClass('selected');
253
- data = $li.data('nodedata');
254
- nodeAction = data[this.nodeaction || 'action'];
255
- // if the selectNode is initiated by click event then use the nativeElement target from event
256
- $liPath = target ? target.parents('.app-tree li') : this.findSelectedNodeParent($li);
257
- // construct the path of the node
258
- $liPath
259
- .each((i, el) => {
260
- const current = $(el).children('.title').text();
261
- path = `/${current + path}`;
262
- });
263
- // expand the current node till the viewParent level which is collapsed
264
- $li.parentsUntil($el, 'li.parent-node.collapsed')
265
- .each((index, el) => {
266
- const $current = $(el), $i = $current.children('i.collapsed');
267
- this.toggleExpandCollapseNode(undefined, $i, $current);
268
- });
269
- this.selecteditem = getClonedObject(data) || {};
270
- this.selecteditem.path = path;
271
- if (target) {
272
- if (this.nodeid || this.bindnodeid) {
273
- this.datavalue = getEvaluatedData(data, { field: this.nodeid, bindExpression: this.bindnodeid }, this.viewParent);
233
+ onCollapse(event, treeId, treeNode) {
234
+ let path = this.getPath(treeNode, "");
235
+ const eventParams = {
236
+ '$event': event,
237
+ "$item": treeNode,
238
+ "$path": path
239
+ };
240
+ this.invokeEventCallback('collapse', eventParams);
241
+ }
242
+ // function to support backward compatibility of objects
243
+ modifyObjects(array) {
244
+ array.forEach(obj => {
245
+ if (obj.label !== undefined) {
246
+ obj.name = obj.label;
247
+ delete obj.label;
274
248
  }
275
- else {
276
- this.datavalue = getClonedObject(data) || {};
249
+ if (obj.children !== undefined) {
250
+ this.modifyObjects(obj.children);
277
251
  }
252
+ });
253
+ return array;
254
+ }
255
+ // sets the node children property to parent nodes
256
+ setNodeChildren(nodes, depth, level, parentNode) {
257
+ if (depth <= 0) {
258
+ return nodes;
278
259
  }
279
- else {
280
- this.datavalue = value;
260
+ for (let i = 0; i < nodes.length; i++) {
261
+ const node = nodes[i];
262
+ if (depth === level) {
263
+ parentNode = nodes[i];
264
+ }
265
+ if (node.children && node.children.length > 0) {
266
+ if (level === 1) {
267
+ parentNode.children = node.children.map(child => ({ name: child.name, children: child === null || child === void 0 ? void 0 : child.children }));
268
+ return;
269
+ }
270
+ else {
271
+ this.setNodeChildren(node.children, depth, level - 1, parentNode);
272
+ }
273
+ }
281
274
  }
282
- //[Todo-CSP]: this data will be dynamic, can not generate function upfront
283
- if (nodeAction) {
284
- $parseEvent(nodeAction)(this);
275
+ return nodes;
276
+ }
277
+ countDepth(str) {
278
+ const regex = /\[.*?\]/g;
279
+ let matches = str.match(regex);
280
+ let count = 1;
281
+ if (matches === null)
282
+ return count;
283
+ for (let match of matches) {
284
+ count++;
285
285
  }
286
- this.invokeEventCallback('select', { $event: evt, $item: data, $path: path });
287
- $appDigest();
286
+ return count;
288
287
  }
289
- // click event is added on the host nativeElement
290
- bindEvents() {
291
- $(this.nativeElement).on('click', (evt) => {
292
- const target = $(evt.target), li = target.closest('li'), $i = target.is('i') ? target : target.siblings('i.collapsed,i.expanded');
293
- evt.stopPropagation();
294
- if (target.is('span.title')) { // select the node only if it is nodelabel
295
- this.selecteditem = {};
296
- this.selectNode(evt, li);
288
+ // Renders the tree on to the dom
289
+ renderTree() {
290
+ console.log(this.nodes, 'this.nodes');
291
+ if (this.nodes) {
292
+ this.nativeElement.setAttribute('id', this.name);
293
+ this.nodes = this.modifyObjects(this.nodes);
294
+ this.setTreeTemplate(this.treeClass);
295
+ if (this.nodelabel) {
296
+ let depth = 0;
297
+ if (this.nodelabel.includes("children")) {
298
+ depth = this.countDepth(this.nodelabel);
299
+ }
300
+ this.setNodeData(this.nodes, depth, depth, null, "name");
297
301
  }
298
- if (target.is('i') || (target.is('span.title') && this.nodeclick === 'expand')) {
299
- this.toggleExpandCollapseNode(evt, $i, li);
302
+ if (this.nodeicon) {
303
+ let depth = 0;
304
+ if (this.nodeicon.includes("children")) {
305
+ depth = this.countDepth(this.nodeicon);
306
+ }
307
+ this.setNodeData(this.nodes, depth, depth, null, "icon");
300
308
  }
301
- });
302
- }
303
- findSelectedNodeParent($li) {
304
- return $li.find('> span.title').parents('.app-tree li');
305
- }
306
- selectById(value) {
307
- this.selectNode(undefined, value);
309
+ if (this.nodechildren) {
310
+ let depth = this.countDepth(this.nodechildren);
311
+ if (depth > 1) {
312
+ this.nodes = this.setNodeChildren(this.nodes, depth, depth, null);
313
+ }
314
+ }
315
+ }
316
+ this.setting.view['nodeClasses'] = this.setNodeclasses;
317
+ this.setting.callback["onClick"] = this.onClick.bind(this);
318
+ this.setting.callback["onExpand"] = this.onExpand.bind(this);
319
+ this.setting.callback["onCollapse"] = this.onCollapse.bind(this);
320
+ let zTree = $.fn.zTree.init($('ul[name="' + this.name + '"]'), this.setting, this.nodes);
321
+ $.fn.zTreeKeyboardNavigation(zTree, $('ul[name="' + this.name + '"]'), null, this.treeicon || defaultTreeIconClass);
308
322
  }
309
- deselectById(value) {
310
- this.selecteditem = {};
311
- this.selectById();
323
+ ngAfterViewInit() {
324
+ setTimeout(() => {
325
+ this.changeTreeIcons(this.treeicon || defaultTreeIconClass);
326
+ }, 200);
312
327
  }
313
328
  }
314
- TreeDirective.initializeProps = registerProps();
315
- TreeDirective.decorators = [
316
- { type: Directive, args: [{
317
- selector: 'div[wmTree]',
329
+ TreeComponent.initializeProps = registerProps();
330
+ TreeComponent.decorators = [
331
+ { type: Component, args: [{
332
+ selector: 'ul[wmTree]',
333
+ template: "<ul #wmTree class=\"ztree\" id=\"ztree\"></ul> ",
318
334
  providers: [
319
- provideAsWidgetRef(TreeDirective)
320
- ]
335
+ provideAsWidgetRef(TreeComponent)
336
+ ],
337
+ encapsulation: ViewEncapsulation.None
321
338
  },] }
322
339
  ];
323
- TreeDirective.ctorParameters = () => [
324
- { type: Injector },
325
- { type: undefined, decorators: [{ type: Attribute, args: ['datavalue.bind',] }] },
326
- { type: undefined, decorators: [{ type: Attribute, args: ['nodelabel.bind',] }] },
327
- { type: undefined, decorators: [{ type: Attribute, args: ['nodeicon.bind',] }] },
328
- { type: undefined, decorators: [{ type: Attribute, args: ['nodechildren.bind',] }] },
329
- { type: undefined, decorators: [{ type: Attribute, args: ['nodeid.bind',] }] }
340
+ TreeComponent.ctorParameters = () => [
341
+ { type: Injector }
330
342
  ];
331
343
 
332
344
  const components = [
333
- TreeDirective
345
+ TreeComponent
334
346
  ];
335
347
  class TreeModule {
336
348
  }
@@ -350,5 +362,5 @@ TreeModule.decorators = [
350
362
  * Generated bundle index. Do not edit.
351
363
  */
352
364
 
353
- export { TreeDirective, TreeModule, registerProps as ɵa };
365
+ export { TreeComponent, TreeModule, registerProps as ɵa };
354
366
  //# sourceMappingURL=index.js.map