reneco-hierarchized-picker 0.4.0-beta.1 → 0.4.0-beta.11

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.
@@ -14,7 +14,7 @@ const patchEsm = () => {
14
14
  const defineCustomElements = (win, options) => {
15
15
  if (typeof window === 'undefined') return Promise.resolve();
16
16
  return patchEsm().then(() => {
17
- return index.bootstrapLazy([["reneco-hierarchized-picker_2.cjs",[[0,"reneco-hierarchized-picker",{"options":[16],"valueChangeCallback":[16],"disabled":[4],"newoptions":[1],"newfilter":[1],"isDisabled":[32],"componentID":[32],"rawData":[32],"pickerClass":[32],"displayedValue":[32],"value":[32],"shownTree":[32],"searchResultData":[32],"hasFocus":[32],"errorToLog":[32],"getValue":[64],"refreshPicker":[64],"setOptions":[64],"getSearchResult":[64],"filterTree":[64],"clearPicker":[64],"showSelectedNodes":[64]}],[0,"search-input",{"placeholder":[1],"setFocus":[64]}]]]], options);
17
+ return index.bootstrapLazy([["reneco-hierarchized-picker_2.cjs",[[0,"reneco-hierarchized-picker",{"options":[1],"valueChangeCallback":[16],"disabled":[4],"newoptions":[1],"newfilter":[1],"isDisabled":[32],"componentID":[32],"rawData":[32],"pickerClass":[32],"displayedValue":[32],"value":[32],"shownTree":[32],"searchResultData":[32],"hasFocus":[32],"errorToLog":[32],"getValue":[64],"refreshPicker":[64],"setOptions":[64],"getSearchResult":[64],"filterTree":[64],"clearPicker":[64],"showSelectedNodes":[64]}],[0,"search-input",{"placeholder":[1],"setFocus":[64]}]]]], options);
18
18
  });
19
19
  };
20
20
 
@@ -17,7 +17,7 @@ const patchBrowser = () => {
17
17
  };
18
18
 
19
19
  patchBrowser().then(options => {
20
- return index.bootstrapLazy([["reneco-hierarchized-picker_2.cjs",[[0,"reneco-hierarchized-picker",{"options":[16],"valueChangeCallback":[16],"disabled":[4],"newoptions":[1],"newfilter":[1],"isDisabled":[32],"componentID":[32],"rawData":[32],"pickerClass":[32],"displayedValue":[32],"value":[32],"shownTree":[32],"searchResultData":[32],"hasFocus":[32],"errorToLog":[32],"getValue":[64],"refreshPicker":[64],"setOptions":[64],"getSearchResult":[64],"filterTree":[64],"clearPicker":[64],"showSelectedNodes":[64]}],[0,"search-input",{"placeholder":[1],"setFocus":[64]}]]]], options);
20
+ return index.bootstrapLazy([["reneco-hierarchized-picker_2.cjs",[[0,"reneco-hierarchized-picker",{"options":[1],"valueChangeCallback":[16],"disabled":[4],"newoptions":[1],"newfilter":[1],"isDisabled":[32],"componentID":[32],"rawData":[32],"pickerClass":[32],"displayedValue":[32],"value":[32],"shownTree":[32],"searchResultData":[32],"hasFocus":[32],"errorToLog":[32],"getValue":[64],"refreshPicker":[64],"setOptions":[64],"getSearchResult":[64],"filterTree":[64],"clearPicker":[64],"showSelectedNodes":[64]}],[0,"search-input",{"placeholder":[1],"setFocus":[64]}]]]], options);
21
21
  });
22
22
 
23
23
  exports.setNonce = index.setNonce;
@@ -242,7 +242,7 @@ Tree.prototype.bindEvent = function (ele) {
242
242
  this.options.rawDataManager
243
243
  .getFromClassification(this.options.parentApi.theOptions.url, Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId }))
244
244
  .then(data => {
245
- this.options.completeCurrentTreeWithTree(this, data);
245
+ this.options.completeCurrentTreeWithTree(this, data, this.options.parentApi.theOptions);
246
246
  });
247
247
  }
248
248
  else {
@@ -254,7 +254,7 @@ Tree.prototype.bindEvent = function (ele) {
254
254
  IsDeprecated: this.options.parentApi.theOptions.options.IsDeprecated,
255
255
  })
256
256
  .then(data => {
257
- this.options.completeCurrentTreeWithTree(this, data);
257
+ this.options.completeCurrentTreeWithTree(this, data, this.options.parentApi.theOptions);
258
258
  });
259
259
  }
260
260
  }
@@ -18068,12 +18068,25 @@ class RawDataManager {
18068
18068
  }
18069
18069
  // Fetch data from classification
18070
18070
  async getFromClassification(endpoint, options, loader) {
18071
- console.log("getFromClassification", options);
18072
- const urlParams = new URLSearchParams(options);
18073
- await this.makeRequest('GET', `${endpoint}/?${urlParams.toString()}`, null, loader).then((data) => {
18074
- this.loadData(data);
18075
- });
18076
- return;
18071
+ let pathSegment = '';
18072
+ const queryParams = [];
18073
+ for (const key in options) {
18074
+ if (!options.hasOwnProperty(key))
18075
+ continue;
18076
+ const value = options[key];
18077
+ const lowerKey = key.toLowerCase();
18078
+ if ((lowerKey === 'startnode' || lowerKey === 'startnodeid') && !pathSegment) {
18079
+ pathSegment = encodeURIComponent(value);
18080
+ continue; // Skip adding this to the query string
18081
+ }
18082
+ // Add other keys to query string
18083
+ queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
18084
+ }
18085
+ const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
18086
+ const newUrl = pathSegment
18087
+ ? `${endpoint}/${pathSegment}/${queryString}`
18088
+ : `${endpoint}/${queryString}`;
18089
+ return await this.makeRequest('GET', newUrl, null, loader);
18077
18090
  }
18078
18091
  // Fetch data from a generic source
18079
18092
  async getFromSource(endpoint, options, loader) {
@@ -18267,13 +18280,27 @@ function findNodeById(tree, nodeId) {
18267
18280
  /**
18268
18281
  * Fills the tree with nodes based on the provided object.
18269
18282
  */
18270
- function fillTreeWithObject(tree, myObject, searched, searchResultPresentsUnMatched = false, depth = 0) {
18283
+ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
18284
+ const searchResultPresentsUnMatched = options.searchResultPresentsUnMatched;
18271
18285
  if (myObject && myObject.length) {
18272
18286
  myObject.forEach(value => {
18273
- const keyPropFromNode = getPropertyFromNode(value, 'key');
18274
- const valueTranslatedPropFromNode = getPropertyFromNode(value, 'valueTranslated');
18275
- const fullpathPropFromNode = getPropertyFromNode(value, 'fullpath');
18276
- const fullpathTranslatedPropFromNode = getPropertyFromNode(value, 'fullpathTranslated');
18287
+ var _a, _b, _c;
18288
+ let keyPropFromNode = null;
18289
+ let valueTranslatedPropFromNode = null;
18290
+ let fullpathPropFromNode = null;
18291
+ let fullpathTranslatedPropFromNode = null;
18292
+ if (options.origin == "classification") {
18293
+ keyPropFromNode = getPropertyFromNode(value, 'ID');
18294
+ valueTranslatedPropFromNode = (_a = getPropertyFromNode(value, 'Translations')[options.language]) === null || _a === void 0 ? void 0 : _a.translated_name;
18295
+ fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_Fullpath;
18296
+ fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'Translations')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
18297
+ }
18298
+ else {
18299
+ keyPropFromNode = getPropertyFromNode(value, 'key');
18300
+ valueTranslatedPropFromNode = getPropertyFromNode(value, 'valueTranslated');
18301
+ fullpathPropFromNode = getPropertyFromNode(value, 'fullpath');
18302
+ fullpathTranslatedPropFromNode = getPropertyFromNode(value, 'fullpathTranslated');
18303
+ }
18277
18304
  const childrenPropFromNode = getPropertyFromNode(value, 'children', false);
18278
18305
  const deprecated = getPropertyFromNode(value, 'deprecated', false);
18279
18306
  const objToPush = {
@@ -18287,14 +18314,7 @@ function fillTreeWithObject(tree, myObject, searched, searchResultPresentsUnMatc
18287
18314
  isDesaturated: false,
18288
18315
  searchMatch: false,
18289
18316
  };
18290
- // const childTree = fillTreeWithObject(objToPush.children, childrenPropFromNode, searched, depth + 1);
18291
- // const matched = searched ? searchValue(objToPush, false, searched) : true;
18292
- // if (matched) {
18293
- // objToPush.searchMatch = true;
18294
- // objToPush.children = childTree;
18295
- // tree.push(objToPush);
18296
- // }
18297
- const childTree = fillTreeWithObject(objToPush.children, childrenPropFromNode, searched, searchResultPresentsUnMatched, depth + 1);
18317
+ const childTree = fillTreeWithObject(objToPush.children, childrenPropFromNode, searched, options, depth + 1);
18298
18318
  let pushMe = false;
18299
18319
  if (searched) {
18300
18320
  const matched = searchValue(objToPush, false, searched);
@@ -18316,7 +18336,7 @@ function fillTreeWithObject(tree, myObject, searched, searchResultPresentsUnMatc
18316
18336
  /**
18317
18337
  * Updates the current tree with new nodes.
18318
18338
  */
18319
- function completeCurrentTreeWithTree(treeJsInstance, newTree) {
18339
+ function completeCurrentTreeWithTree(treeJsInstance, newTree, options) {
18320
18340
  var _a;
18321
18341
  const ElmID = newTree.key || newTree.id || newTree.ID;
18322
18342
  const targetNode = findNodeById(treeJsInstance, ElmID);
@@ -18327,7 +18347,7 @@ function completeCurrentTreeWithTree(treeJsInstance, newTree) {
18327
18347
  ulElem = treeJsInstance.createUlEle();
18328
18348
  treeJsInstance.liElementsById[ElmID].appendChild(ulElem);
18329
18349
  }
18330
- const filledTree = fillTreeWithObject([], newTree.children, null);
18350
+ const filledTree = fillTreeWithObject([], newTree.children, null, options);
18331
18351
  ulElem.innerHTML = '';
18332
18352
  filledTree.forEach(item => {
18333
18353
  const liElm = treeJsInstance.createLiEle(item, true);
@@ -18546,6 +18566,11 @@ const HierarchizedPickerComponent = class {
18546
18566
  async setOptions(newOptions) {
18547
18567
  this.setNewOption(newOptions);
18548
18568
  }
18569
+ getOptionsAsIConf(options) {
18570
+ if (typeof options == 'string')
18571
+ return JSON.parse(options);
18572
+ return options;
18573
+ }
18549
18574
  setSearchResults(tree) {
18550
18575
  let searchCount = 0;
18551
18576
  const queue = [...tree];
@@ -18598,9 +18623,11 @@ const HierarchizedPickerComponent = class {
18598
18623
  // });
18599
18624
  // ---------------------------------------
18600
18625
  // this.theOptions = newValue;
18626
+ if (typeof newValue == 'string')
18627
+ newValue = JSON.parse(newValue);
18601
18628
  this.optionsManager.updateOptions(newValue);
18602
18629
  this.setDisplayedValue(this.value);
18603
- const originOrNodeIdAreDifferent = (newValue.origin != oldValue.origin || newValue.options.StartNodeID != oldValue.options.StartNodeID);
18630
+ const originOrNodeIdAreDifferent = !oldValue || (newValue.origin != oldValue.origin || newValue.options.StartNodeID != oldValue.options.StartNodeID);
18604
18631
  if (this.optionsManager.getOptions().source != 'file' && (!oldValue || (oldValue && originOrNodeIdAreDifferent))) {
18605
18632
  this.rawData = null;
18606
18633
  }
@@ -18643,6 +18670,8 @@ const HierarchizedPickerComponent = class {
18643
18670
  }
18644
18671
  isChangeInOptions(newV, oldV) {
18645
18672
  const isEqual = lodash.isEqual(newV, oldV);
18673
+ if (!newV.defaultValue && !oldV.defaultValue)
18674
+ return;
18646
18675
  const changeDefaultValue = !(newV.defaultValue.length == oldV.defaultValue.length && newV.defaultValue.every(value => oldV.defaultValue.includes(value)));
18647
18676
  if (!isEqual && changeDefaultValue) {
18648
18677
  return changeDefaultValue;
@@ -18701,7 +18730,7 @@ const HierarchizedPickerComponent = class {
18701
18730
  }
18702
18731
  async componentWillLoad() {
18703
18732
  this.isDisabled = this.disabled;
18704
- this.optionsManager = new OptionsManager(this.options);
18733
+ this.optionsManager = new OptionsManager(this.getOptionsAsIConf(this.options));
18705
18734
  this.rawDataManager = new RawDataManager(() => this.getToken(), this.optionsManager);
18706
18735
  await this.loadHierarchizedPicker();
18707
18736
  this.setDisplayedValueFromDefault();
@@ -18878,13 +18907,13 @@ const HierarchizedPickerComponent = class {
18878
18907
  }
18879
18908
  async getToken() {
18880
18909
  var _a;
18881
- if (typeof this.options.token === 'string') {
18882
- return this.options.token.length > 200
18883
- ? this.options.token
18884
- : (_a = window.localStorage.getItem(this.options.token)) !== null && _a !== void 0 ? _a : null;
18910
+ if (typeof this.getOptionsAsIConf(this.options).token === 'string') {
18911
+ return this.getOptionsAsIConf(this.options).token.length > 200
18912
+ ? this.getOptionsAsIConf(this.options).token
18913
+ : (_a = window.localStorage.getItem(this.getOptionsAsIConf(this.options).token)) !== null && _a !== void 0 ? _a : null;
18885
18914
  }
18886
- if (typeof this.options.token === 'function') {
18887
- const token = await this.options.token();
18915
+ if (typeof this.getOptionsAsIConf(this.options).token === 'function') {
18916
+ const token = await this.getOptionsAsIConf(this.options).token();
18888
18917
  return typeof token === 'string' ? token : null;
18889
18918
  }
18890
18919
  return null;
@@ -18945,7 +18974,7 @@ const HierarchizedPickerComponent = class {
18945
18974
  if (this.searchToDisplay > -1) { // TODO > Not working anymore after refact, prevents issues in displaying results when running multiple researchs at the same time && searchID == this.searchToDisplay) {
18946
18975
  this.rawDataManager.mergeData(newtree);
18947
18976
  newtree.children.forEach((value, index) => {
18948
- completeCurrentTreeWithTree(this.loadedTreeJs, value);
18977
+ completeCurrentTreeWithTree(this.loadedTreeJs, value, this.optionsManager.getOptions());
18949
18978
  });
18950
18979
  this.triggerTreeDisplay(this.rawData, searched);
18951
18980
  displayAutocompleteWithResults(this.rawDataManager.getData(), searched, this.optionsManager, this.editValue.bind(this), this.showTree.bind(this));
@@ -18965,7 +18994,7 @@ const HierarchizedPickerComponent = class {
18965
18994
  if (this.theOptions.source == 'webservice') {
18966
18995
  if (this.theOptions.origin == 'classification') {
18967
18996
  // WS Call
18968
- console.log("FLAG 01");
18997
+ console.log("FLAG 01", this.theOptions);
18969
18998
  this.rawDataManager.getFromClassification(this.getApiSearchURL(), {
18970
18999
  search: {
18971
19000
  StartNodeID: this.theOptions.options.startNode,
@@ -19013,12 +19042,12 @@ const HierarchizedPickerComponent = class {
19013
19042
  else {
19014
19043
  if (this.searchToDisplay > -1 && searchID == this.searchToDisplay) {
19015
19044
  this.rawDataManager.getData().children.forEach((value, _) => {
19016
- completeCurrentTreeWithTree(this.loadedTreeJs, value);
19045
+ completeCurrentTreeWithTree(this.loadedTreeJs, value, this.optionsManager.getOptions());
19017
19046
  });
19018
19047
  displayAutocompleteWithResults(this.rawDataManager.getData(), searched, this.optionsManager, this.editValue.bind(this), this.showTree.bind(this));
19019
19048
  }
19020
19049
  const data = !this.optionsManager.getOptions().displayRootNode ? this.rawDataManager.getData().children : [this.rawDataManager.getData()];
19021
- const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions().searchResultPresentsUnMatched);
19050
+ const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions());
19022
19051
  if (searched) {
19023
19052
  this.setSearchResults(treeToDisplay);
19024
19053
  }
@@ -19030,7 +19059,7 @@ const HierarchizedPickerComponent = class {
19030
19059
  return;
19031
19060
  this.mylog(`Translate from ${this.optionsManager.getOptions().origin} ! (${this.optionsManager.getOptions().source})`, dataToLoad);
19032
19061
  const data = !this.optionsManager.getOptions().displayRootNode ? dataToLoad.children : [dataToLoad];
19033
- const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions().searchResultPresentsUnMatched);
19062
+ const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions());
19034
19063
  if (searched) {
19035
19064
  this.setSearchResults(treeToDisplay);
19036
19065
  }
@@ -19315,8 +19344,22 @@ const HierarchizedPickerComponent = class {
19315
19344
  loadDataForTree(init, loader) {
19316
19345
  if (this.optionsManager.getOptions().source == 'webservice') {
19317
19346
  if (this.optionsManager.getOptions().origin == 'classification') {
19318
- console.log("FLAG 02", this.optionsManager.getOptions().options);
19319
- this.rawDataManager.getFromClassification(this.optionsManager.getOptions().url, this.optionsManager.getOptions().options, loader);
19347
+ console.log("FLAG 02", this.optionsManager.getOptions());
19348
+ this.rawDataManager.getFromClassification(this.optionsManager.getOptions().url, this.optionsManager.getOptions().options, loader).then((data) => {
19349
+ this.rawData = data;
19350
+ if (init) {
19351
+ this.formatDefaultValue();
19352
+ this.showSelectedNodes();
19353
+ }
19354
+ })
19355
+ .catch(error => {
19356
+ try {
19357
+ this.errorToLog = 'getDataFromSource 3 classification rejected:' + JSON.stringify(error, replacer, 2);
19358
+ }
19359
+ catch (_a) {
19360
+ console.error('getDataFromSource 4 classification rejected:', JSON.stringify(error, replacer, 2));
19361
+ }
19362
+ });
19320
19363
  }
19321
19364
  else {
19322
19365
  this.rawDataManager.getFromSource(this.optionsManager.getOptions().url, this.optionsManager.getOptions().options, loader)
@@ -19329,10 +19372,10 @@ const HierarchizedPickerComponent = class {
19329
19372
  })
19330
19373
  .catch(error => {
19331
19374
  try {
19332
- this.errorToLog = 'getDataFromSource 3 rejected:' + JSON.stringify(error, replacer, 2);
19375
+ this.errorToLog = 'getDataFromSource 3 legacy rejected:' + JSON.stringify(error, replacer, 2);
19333
19376
  }
19334
19377
  catch (_a) {
19335
- console.error('getDataFromSource 4 rejected:', JSON.stringify(error, replacer, 2));
19378
+ console.error('getDataFromSource 4 legacy rejected:', JSON.stringify(error, replacer, 2));
19336
19379
  }
19337
19380
  });
19338
19381
  }
@@ -46,6 +46,11 @@ export class HierarchizedPickerComponent {
46
46
  async setOptions(newOptions) {
47
47
  this.setNewOption(newOptions);
48
48
  }
49
+ getOptionsAsIConf(options) {
50
+ if (typeof options == 'string')
51
+ return JSON.parse(options);
52
+ return options;
53
+ }
49
54
  setSearchResults(tree) {
50
55
  let searchCount = 0;
51
56
  const queue = [...tree];
@@ -98,9 +103,11 @@ export class HierarchizedPickerComponent {
98
103
  // });
99
104
  // ---------------------------------------
100
105
  // this.theOptions = newValue;
106
+ if (typeof newValue == 'string')
107
+ newValue = JSON.parse(newValue);
101
108
  this.optionsManager.updateOptions(newValue);
102
109
  this.setDisplayedValue(this.value);
103
- const originOrNodeIdAreDifferent = (newValue.origin != oldValue.origin || newValue.options.StartNodeID != oldValue.options.StartNodeID);
110
+ const originOrNodeIdAreDifferent = !oldValue || (newValue.origin != oldValue.origin || newValue.options.StartNodeID != oldValue.options.StartNodeID);
104
111
  if (this.optionsManager.getOptions().source != 'file' && (!oldValue || (oldValue && originOrNodeIdAreDifferent))) {
105
112
  this.rawData = null;
106
113
  }
@@ -143,6 +150,8 @@ export class HierarchizedPickerComponent {
143
150
  }
144
151
  isChangeInOptions(newV, oldV) {
145
152
  const isEqual = _.isEqual(newV, oldV);
153
+ if (!newV.defaultValue && !oldV.defaultValue)
154
+ return;
146
155
  const changeDefaultValue = !(newV.defaultValue.length == oldV.defaultValue.length && newV.defaultValue.every(value => oldV.defaultValue.includes(value)));
147
156
  if (!isEqual && changeDefaultValue) {
148
157
  return changeDefaultValue;
@@ -196,7 +205,7 @@ export class HierarchizedPickerComponent {
196
205
  }
197
206
  async componentWillLoad() {
198
207
  this.isDisabled = this.disabled;
199
- this.optionsManager = new OptionsManager(this.options);
208
+ this.optionsManager = new OptionsManager(this.getOptionsAsIConf(this.options));
200
209
  this.rawDataManager = new RawDataManager(() => this.getToken(), this.optionsManager);
201
210
  await this.loadHierarchizedPicker();
202
211
  this.setDisplayedValueFromDefault();
@@ -376,13 +385,13 @@ export class HierarchizedPickerComponent {
376
385
  }
377
386
  async getToken() {
378
387
  var _a;
379
- if (typeof this.options.token === 'string') {
380
- return this.options.token.length > 200
381
- ? this.options.token
382
- : (_a = window.localStorage.getItem(this.options.token)) !== null && _a !== void 0 ? _a : null;
388
+ if (typeof this.getOptionsAsIConf(this.options).token === 'string') {
389
+ return this.getOptionsAsIConf(this.options).token.length > 200
390
+ ? this.getOptionsAsIConf(this.options).token
391
+ : (_a = window.localStorage.getItem(this.getOptionsAsIConf(this.options).token)) !== null && _a !== void 0 ? _a : null;
383
392
  }
384
- if (typeof this.options.token === 'function') {
385
- const token = await this.options.token();
393
+ if (typeof this.getOptionsAsIConf(this.options).token === 'function') {
394
+ const token = await this.getOptionsAsIConf(this.options).token();
386
395
  return typeof token === 'string' ? token : null;
387
396
  }
388
397
  return null;
@@ -443,7 +452,7 @@ export class HierarchizedPickerComponent {
443
452
  if (this.searchToDisplay > -1) { // TODO > Not working anymore after refact, prevents issues in displaying results when running multiple researchs at the same time && searchID == this.searchToDisplay) {
444
453
  this.rawDataManager.mergeData(newtree);
445
454
  newtree.children.forEach((value, index) => {
446
- completeCurrentTreeWithTree(this.loadedTreeJs, value);
455
+ completeCurrentTreeWithTree(this.loadedTreeJs, value, this.optionsManager.getOptions());
447
456
  });
448
457
  this.triggerTreeDisplay(this.rawData, searched);
449
458
  displayAutocompleteWithResults(this.rawDataManager.getData(), searched, this.optionsManager, this.editValue.bind(this), this.showTree.bind(this));
@@ -463,7 +472,7 @@ export class HierarchizedPickerComponent {
463
472
  if (this.theOptions.source == 'webservice') {
464
473
  if (this.theOptions.origin == 'classification') {
465
474
  // WS Call
466
- console.log("FLAG 01");
475
+ console.log("FLAG 01", this.theOptions);
467
476
  this.rawDataManager.getFromClassification(this.getApiSearchURL(), {
468
477
  search: {
469
478
  StartNodeID: this.theOptions.options.startNode,
@@ -511,12 +520,12 @@ export class HierarchizedPickerComponent {
511
520
  else {
512
521
  if (this.searchToDisplay > -1 && searchID == this.searchToDisplay) {
513
522
  this.rawDataManager.getData().children.forEach((value, _) => {
514
- completeCurrentTreeWithTree(this.loadedTreeJs, value);
523
+ completeCurrentTreeWithTree(this.loadedTreeJs, value, this.optionsManager.getOptions());
515
524
  });
516
525
  displayAutocompleteWithResults(this.rawDataManager.getData(), searched, this.optionsManager, this.editValue.bind(this), this.showTree.bind(this));
517
526
  }
518
527
  const data = !this.optionsManager.getOptions().displayRootNode ? this.rawDataManager.getData().children : [this.rawDataManager.getData()];
519
- const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions().searchResultPresentsUnMatched);
528
+ const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions());
520
529
  if (searched) {
521
530
  this.setSearchResults(treeToDisplay);
522
531
  }
@@ -528,7 +537,7 @@ export class HierarchizedPickerComponent {
528
537
  return;
529
538
  this.mylog(`Translate from ${this.optionsManager.getOptions().origin} ! (${this.optionsManager.getOptions().source})`, dataToLoad);
530
539
  const data = !this.optionsManager.getOptions().displayRootNode ? dataToLoad.children : [dataToLoad];
531
- const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions().searchResultPresentsUnMatched);
540
+ const treeToDisplay = fillTreeWithObject([], data, searched, this.optionsManager.getOptions());
532
541
  if (searched) {
533
542
  this.setSearchResults(treeToDisplay);
534
543
  }
@@ -813,8 +822,22 @@ export class HierarchizedPickerComponent {
813
822
  loadDataForTree(init, loader) {
814
823
  if (this.optionsManager.getOptions().source == 'webservice') {
815
824
  if (this.optionsManager.getOptions().origin == 'classification') {
816
- console.log("FLAG 02", this.optionsManager.getOptions().options);
817
- this.rawDataManager.getFromClassification(this.optionsManager.getOptions().url, this.optionsManager.getOptions().options, loader);
825
+ console.log("FLAG 02", this.optionsManager.getOptions());
826
+ this.rawDataManager.getFromClassification(this.optionsManager.getOptions().url, this.optionsManager.getOptions().options, loader).then((data) => {
827
+ this.rawData = data;
828
+ if (init) {
829
+ this.formatDefaultValue();
830
+ this.showSelectedNodes();
831
+ }
832
+ })
833
+ .catch(error => {
834
+ try {
835
+ this.errorToLog = 'getDataFromSource 3 classification rejected:' + JSON.stringify(error, replacer, 2);
836
+ }
837
+ catch (_a) {
838
+ console.error('getDataFromSource 4 classification rejected:', JSON.stringify(error, replacer, 2));
839
+ }
840
+ });
818
841
  }
819
842
  else {
820
843
  this.rawDataManager.getFromSource(this.optionsManager.getOptions().url, this.optionsManager.getOptions().options, loader)
@@ -827,10 +850,10 @@ export class HierarchizedPickerComponent {
827
850
  })
828
851
  .catch(error => {
829
852
  try {
830
- this.errorToLog = 'getDataFromSource 3 rejected:' + JSON.stringify(error, replacer, 2);
853
+ this.errorToLog = 'getDataFromSource 3 legacy rejected:' + JSON.stringify(error, replacer, 2);
831
854
  }
832
855
  catch (_a) {
833
- console.error('getDataFromSource 4 rejected:', JSON.stringify(error, replacer, 2));
856
+ console.error('getDataFromSource 4 legacy rejected:', JSON.stringify(error, replacer, 2));
834
857
  }
835
858
  });
836
859
  }
@@ -975,11 +998,11 @@ export class HierarchizedPickerComponent {
975
998
  static get properties() {
976
999
  return {
977
1000
  "options": {
978
- "type": "unknown",
1001
+ "type": "string",
979
1002
  "mutable": false,
980
1003
  "complexType": {
981
- "original": "IConf",
982
- "resolved": "IConf",
1004
+ "original": "string | IConf",
1005
+ "resolved": "IConf | string",
983
1006
  "references": {
984
1007
  "IConf": {
985
1008
  "location": "import",
@@ -992,7 +1015,9 @@ export class HierarchizedPickerComponent {
992
1015
  "docs": {
993
1016
  "tags": [],
994
1017
  "text": "The component's options as described in the IConf interface"
995
- }
1018
+ },
1019
+ "attribute": "options",
1020
+ "reflect": false
996
1021
  },
997
1022
  "valueChangeCallback": {
998
1023
  "type": "unknown",
@@ -208,7 +208,7 @@ Tree.prototype.bindEvent = function (ele) {
208
208
  this.options.rawDataManager
209
209
  .getFromClassification(this.options.parentApi.theOptions.url, Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId }))
210
210
  .then(data => {
211
- this.options.completeCurrentTreeWithTree(this, data);
211
+ this.options.completeCurrentTreeWithTree(this, data, this.options.parentApi.theOptions);
212
212
  });
213
213
  }
214
214
  else {
@@ -220,7 +220,7 @@ Tree.prototype.bindEvent = function (ele) {
220
220
  IsDeprecated: this.options.parentApi.theOptions.options.IsDeprecated,
221
221
  })
222
222
  .then(data => {
223
- this.options.completeCurrentTreeWithTree(this, data);
223
+ this.options.completeCurrentTreeWithTree(this, data, this.options.parentApi.theOptions);
224
224
  });
225
225
  }
226
226
  }
@@ -42,12 +42,25 @@ export class RawDataManager {
42
42
  }
43
43
  // Fetch data from classification
44
44
  async getFromClassification(endpoint, options, loader) {
45
- console.log("getFromClassification", options);
46
- const urlParams = new URLSearchParams(options);
47
- await this.makeRequest('GET', `${endpoint}/?${urlParams.toString()}`, null, loader).then((data) => {
48
- this.loadData(data);
49
- });
50
- return;
45
+ let pathSegment = '';
46
+ const queryParams = [];
47
+ for (const key in options) {
48
+ if (!options.hasOwnProperty(key))
49
+ continue;
50
+ const value = options[key];
51
+ const lowerKey = key.toLowerCase();
52
+ if ((lowerKey === 'startnode' || lowerKey === 'startnodeid') && !pathSegment) {
53
+ pathSegment = encodeURIComponent(value);
54
+ continue; // Skip adding this to the query string
55
+ }
56
+ // Add other keys to query string
57
+ queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
58
+ }
59
+ const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
60
+ const newUrl = pathSegment
61
+ ? `${endpoint}/${pathSegment}/${queryString}`
62
+ : `${endpoint}/${queryString}`;
63
+ return await this.makeRequest('GET', newUrl, null, loader);
51
64
  }
52
65
  // Fetch data from a generic source
53
66
  async getFromSource(endpoint, options, loader) {
@@ -46,13 +46,27 @@ export function getNodesFromSearch(data, searched) {
46
46
  /**
47
47
  * Fills the tree with nodes based on the provided object.
48
48
  */
49
- export function fillTreeWithObject(tree, myObject, searched, searchResultPresentsUnMatched = false, depth = 0) {
49
+ export function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
50
+ const searchResultPresentsUnMatched = options.searchResultPresentsUnMatched;
50
51
  if (myObject && myObject.length) {
51
52
  myObject.forEach(value => {
52
- const keyPropFromNode = getPropertyFromNode(value, 'key');
53
- const valueTranslatedPropFromNode = getPropertyFromNode(value, 'valueTranslated');
54
- const fullpathPropFromNode = getPropertyFromNode(value, 'fullpath');
55
- const fullpathTranslatedPropFromNode = getPropertyFromNode(value, 'fullpathTranslated');
53
+ var _a, _b, _c;
54
+ let keyPropFromNode = null;
55
+ let valueTranslatedPropFromNode = null;
56
+ let fullpathPropFromNode = null;
57
+ let fullpathTranslatedPropFromNode = null;
58
+ if (options.origin == "classification") {
59
+ keyPropFromNode = getPropertyFromNode(value, 'ID');
60
+ valueTranslatedPropFromNode = (_a = getPropertyFromNode(value, 'Translations')[options.language]) === null || _a === void 0 ? void 0 : _a.translated_name;
61
+ fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_Fullpath;
62
+ fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'Translations')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
63
+ }
64
+ else {
65
+ keyPropFromNode = getPropertyFromNode(value, 'key');
66
+ valueTranslatedPropFromNode = getPropertyFromNode(value, 'valueTranslated');
67
+ fullpathPropFromNode = getPropertyFromNode(value, 'fullpath');
68
+ fullpathTranslatedPropFromNode = getPropertyFromNode(value, 'fullpathTranslated');
69
+ }
56
70
  const childrenPropFromNode = getPropertyFromNode(value, 'children', false);
57
71
  const deprecated = getPropertyFromNode(value, 'deprecated', false);
58
72
  const objToPush = {
@@ -66,14 +80,7 @@ export function fillTreeWithObject(tree, myObject, searched, searchResultPresent
66
80
  isDesaturated: false,
67
81
  searchMatch: false,
68
82
  };
69
- // const childTree = fillTreeWithObject(objToPush.children, childrenPropFromNode, searched, depth + 1);
70
- // const matched = searched ? searchValue(objToPush, false, searched) : true;
71
- // if (matched) {
72
- // objToPush.searchMatch = true;
73
- // objToPush.children = childTree;
74
- // tree.push(objToPush);
75
- // }
76
- const childTree = fillTreeWithObject(objToPush.children, childrenPropFromNode, searched, searchResultPresentsUnMatched, depth + 1);
83
+ const childTree = fillTreeWithObject(objToPush.children, childrenPropFromNode, searched, options, depth + 1);
77
84
  let pushMe = false;
78
85
  if (searched) {
79
86
  const matched = searchValue(objToPush, false, searched);
@@ -95,7 +102,7 @@ export function fillTreeWithObject(tree, myObject, searched, searchResultPresent
95
102
  /**
96
103
  * Updates the current tree with new nodes.
97
104
  */
98
- export function completeCurrentTreeWithTree(treeJsInstance, newTree) {
105
+ export function completeCurrentTreeWithTree(treeJsInstance, newTree, options) {
99
106
  var _a;
100
107
  const ElmID = newTree.key || newTree.id || newTree.ID;
101
108
  const targetNode = findNodeById(treeJsInstance, ElmID);
@@ -106,7 +113,7 @@ export function completeCurrentTreeWithTree(treeJsInstance, newTree) {
106
113
  ulElem = treeJsInstance.createUlEle();
107
114
  treeJsInstance.liElementsById[ElmID].appendChild(ulElem);
108
115
  }
109
- const filledTree = fillTreeWithObject([], newTree.children, null);
116
+ const filledTree = fillTreeWithObject([], newTree.children, null, options);
110
117
  ulElem.innerHTML = '';
111
118
  filledTree.forEach(item => {
112
119
  const liElm = treeJsInstance.createLiEle(item, true);