@oat-sa/tao-core-ui 3.2.2 → 3.3.0

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.
@@ -31,7 +31,7 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
31
31
  if (helper = helpers.childrenLimit) { stack1 = helper.call(depth0, {hash:{},data:data}); }
32
32
  else { helper = (depth0 && depth0.childrenLimit); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
33
33
  buffer += escapeExpression(stack1)
34
- + "\">\n ";
34
+ + "\"\n data-level=\"0\"\n style=\"--tree-level: 0;\">\n ";
35
35
  if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
36
36
  else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
37
37
  buffer += escapeExpression(stack1)
@@ -73,7 +73,15 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
73
73
  if (helper = helpers.childrenLimit) { stack1 = helper.call(depth0, {hash:{},data:data}); }
74
74
  else { helper = (depth0 && depth0.childrenLimit); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
75
75
  buffer += escapeExpression(stack1)
76
- + "\"\n href=\"#\">\n ";
76
+ + "\"\n data-level=\"";
77
+ if (helper = helpers.level) { stack1 = helper.call(depth0, {hash:{},data:data}); }
78
+ else { helper = (depth0 && depth0.level); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
79
+ buffer += escapeExpression(stack1)
80
+ + "\"\n style=\"--tree-level: ";
81
+ if (helper = helpers.level) { stack1 = helper.call(depth0, {hash:{},data:data}); }
82
+ else { helper = (depth0 && depth0.level); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
83
+ buffer += escapeExpression(stack1)
84
+ + ";\"\n href=\"#\">\n ";
77
85
  if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
78
86
  else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
79
87
  buffer += escapeExpression(stack1)
@@ -179,6 +187,8 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
179
187
 
180
188
  //load the content of the ROOT
181
189
  getFolderContent(fileTree, rootPath, function (content) {
190
+ indexTree(content);
191
+
182
192
  //create the tree node for the ROOT folder by default once the initial content loaded
183
193
  $folderContainer.append(rootFolderTpl(content));
184
194
  const $rootNode = $$1('.root-folder', $folderContainer);
@@ -209,6 +219,7 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
209
219
 
210
220
  //get the folder content
211
221
  getFolderContent(subTree, fullPath, function (content) {
222
+ indexTree(fileTree);
212
223
  if (content) {
213
224
  //either create the inner list of the content is new or just show it
214
225
  let $innerList = $selected.siblings('ul');
@@ -326,6 +337,22 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
326
337
  }
327
338
  }
328
339
 
340
+ /**
341
+ * Sets the tree level for each node in the tree.
342
+ * @param {object} tree - the tree model
343
+ * @param {number} level - the root level
344
+ */
345
+ function indexTree(tree) {
346
+ let level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
347
+ if (!tree) {
348
+ return;
349
+ }
350
+ tree.level = level;
351
+ if (tree.children) {
352
+ _.forEach(tree.children, child => indexTree(child, level + 1));
353
+ }
354
+ }
355
+
329
356
  /**
330
357
  * Get a subTree from a path
331
358
  * @param {Object} tree - the tree model
@@ -488,6 +515,7 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
488
515
 
489
516
  //get the folder content
490
517
  getFolderContent(subTree, selectedClass.path, function (content) {
518
+ indexTree(fileTree);
491
519
  if (content) {
492
520
  //internal event to set the file-selector content
493
521
  $container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oat-sa/tao-core-ui",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "displayName": "TAO Core UI",
5
5
  "description": "UI libraries of TAO",
6
6
  "scripts": {
@@ -43,6 +43,8 @@ export default function (options) {
43
43
 
44
44
  //load the content of the ROOT
45
45
  getFolderContent(fileTree, rootPath, function (content) {
46
+ indexTree(content);
47
+
46
48
  //create the tree node for the ROOT folder by default once the initial content loaded
47
49
  $folderContainer.append(rootFolderTpl(content));
48
50
 
@@ -81,6 +83,8 @@ export default function (options) {
81
83
 
82
84
  //get the folder content
83
85
  getFolderContent(subTree, fullPath, function (content) {
86
+ indexTree(fileTree);
87
+
84
88
  if (content) {
85
89
  //either create the inner list of the content is new or just show it
86
90
  let $innerList = $selected.siblings('ul');
@@ -204,6 +208,21 @@ export default function (options) {
204
208
  }
205
209
  }
206
210
 
211
+ /**
212
+ * Sets the tree level for each node in the tree.
213
+ * @param {object} tree - the tree model
214
+ * @param {number} level - the root level
215
+ */
216
+ function indexTree(tree, level = 0) {
217
+ if (!tree) {
218
+ return;
219
+ }
220
+ tree.level = level;
221
+ if (tree.children) {
222
+ _.forEach(tree.children, child => indexTree(child, level + 1));
223
+ }
224
+ }
225
+
207
226
  /**
208
227
  * Get a subTree from a path
209
228
  * @param {Object} tree - the tree model
@@ -372,6 +391,8 @@ export default function (options) {
372
391
 
373
392
  //get the folder content
374
393
  getFolderContent(subTree, selectedClass.path, function (content) {
394
+ indexTree(fileTree);
395
+
375
396
  if (content) {
376
397
  //internal event to set the file-selector content
377
398
  $container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path]);
@@ -4,6 +4,8 @@
4
4
  data-path="{{path}}"
5
5
  data-display="{{relPath}}"
6
6
  data-children-limit="{{childrenLimit}}"
7
+ data-level="{{level}}"
8
+ style="--tree-level: {{level}};"
7
9
  href="#">
8
10
  {{label}}
9
11
  </a>
@@ -5,7 +5,9 @@
5
5
  href="#"
6
6
  data-path="{{path}}"
7
7
  data-display="{{relPath}}"
8
- data-children-limit="{{childrenLimit}}">
8
+ data-children-limit="{{childrenLimit}}"
9
+ data-level="0"
10
+ style="--tree-level: 0;">
9
11
  {{label}}
10
12
  </a>
11
13
  <ul></ul>