@dev-tcloud/tcloud-ui 0.0.36 → 0.0.37

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.
@@ -2790,15 +2790,44 @@ class TCloudUiFiltersComponent {
2790
2790
  const v = (((`${text}`).normalize('NFD').replace(/[\u0300-\u036f]/g, "")).trim()).toLowerCase();
2791
2791
  return v;
2792
2792
  }
2793
- fetchFromObject(obj, prop) {
2794
- if (typeof obj === 'undefined') {
2795
- return false;
2796
- }
2797
- var _index = `${prop}`.indexOf('.');
2798
- if (_index > -1) {
2799
- return this.fetchFromObject(obj[prop.substring(0, _index)], prop.substr(_index + 1));
2793
+ collectionFind(obj, path) {
2794
+ const pathArray = path.split(".");
2795
+ let current = obj;
2796
+ for (let i = 0; i < pathArray.length; i++) {
2797
+ const key = pathArray[i];
2798
+ if (key.includes('[') && key.includes(']')) {
2799
+ const nextKeys = pathArray.slice(i + 1);
2800
+ const index = key.substring(key.indexOf('[') + 1, key.indexOf(']'));
2801
+ const arrayKey = key.substring(0, key.indexOf('['));
2802
+ if (current[arrayKey][index]) {
2803
+ console.log('current[arrayKey][index]', current[arrayKey][index]);
2804
+ return this.collectionFind(current[arrayKey][index], nextKeys.join("."));
2805
+ }
2806
+ }
2807
+ if (key.includes("[]")) {
2808
+ const arrayKey = key.replace("[]", "");
2809
+ current = current[arrayKey] || [];
2810
+ const nextKeys = pathArray.slice(i + 1);
2811
+ const results = [];
2812
+ for (let j = 0; j < current.length; j++) {
2813
+ let result = this.collectionFind(current[j], nextKeys.join("."));
2814
+ if (result !== undefined) {
2815
+ results.push(result);
2816
+ }
2817
+ }
2818
+ if (results.length === 0) {
2819
+ return undefined;
2820
+ }
2821
+ return results;
2822
+ }
2823
+ else {
2824
+ current = current[key];
2825
+ if (current === undefined) {
2826
+ return undefined;
2827
+ }
2828
+ }
2800
2829
  }
2801
- return obj[prop];
2830
+ return current;
2802
2831
  }
2803
2832
  searchIn(item, event) {
2804
2833
  if (typeof event === 'boolean') {
@@ -2818,7 +2847,7 @@ class TCloudUiFiltersComponent {
2818
2847
  const filter_item = this.filters[j];
2819
2848
  if (filter_item.searchText && typeof (filter_item.searchText) === 'string' && filter_item.searchText !== '') {
2820
2849
  filter_item.searchText = this.normalize(filter_item.searchText);
2821
- let item_value = this.fetchFromObject(this.data[i], filter_item.searchIn);
2850
+ let item_value = this.collectionFind(this.data[i], filter_item.searchIn);
2822
2851
  if (item_value) {
2823
2852
  item_value = this.normalize(item_value);
2824
2853
  if (!(item_value.includes(filter_item.searchText) || item_value === filter_item.searchText)) {
@@ -2826,9 +2855,21 @@ class TCloudUiFiltersComponent {
2826
2855
  }
2827
2856
  }
2828
2857
  }
2829
- if (typeof (filter_item.searchText) === 'boolean') {
2830
- let item_value = this.fetchFromObject(this.data[i], filter_item.searchIn);
2831
- if (filter_item.searchText) {
2858
+ if (typeof (filter_item.searchText) === 'boolean' && filter_item.searchText) {
2859
+ let item_value = this.collectionFind(this.data[i], filter_item.searchIn);
2860
+ if (item_value && (item_value).length > 0) {
2861
+ let qtd_is_true = 0;
2862
+ for (let i = 0; i < ((item_value).length); i++) {
2863
+ const item = item_value[i];
2864
+ if (item === filter_item.searchText) {
2865
+ qtd_is_true++;
2866
+ }
2867
+ }
2868
+ if (qtd_is_true === 0) {
2869
+ this.data[i]['tc_filter_accept'] = false;
2870
+ }
2871
+ }
2872
+ else {
2832
2873
  if (!(item_value === filter_item.searchText)) {
2833
2874
  this.data[i]['tc_filter_accept'] = false;
2834
2875
  }