@dev-tcloud/tcloud-ui 0.0.35 → 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.
@@ -2034,6 +2034,10 @@ class TCloudUiSearchInObjectService {
2034
2034
  }
2035
2035
  return false;
2036
2036
  }
2037
+ normalize(text) {
2038
+ const v = (((`${text}`).normalize('NFD').replace(/[\u0300-\u036f]/g, "")).trim()).toLowerCase();
2039
+ return v;
2040
+ }
2037
2041
  /**
2038
2042
  * meet - Procura em object - filtro utilizado para busca em tabelas
2039
2043
  * @param valor texto a ser procurado
@@ -2054,7 +2058,7 @@ class TCloudUiSearchInObjectService {
2054
2058
  if (camposDebusca.length < 1) {
2055
2059
  return emObject;
2056
2060
  }
2057
- valor = valor.toLowerCase();
2061
+ valor = this.normalize(valor);
2058
2062
  var result = [];
2059
2063
  for (const key in emObject) {
2060
2064
  var oObject = emObject[key];
@@ -2064,14 +2068,14 @@ class TCloudUiSearchInObjectService {
2064
2068
  if (this.isADate(dt) && typeof ((dt).getMonth) === 'function') {
2065
2069
  const data1 = this.datepipe.transform(dt, 'dd/MM/yyyy hh:mm');
2066
2070
  const data2 = this.datepipe.transform(dt, 'medium');
2067
- const strToTest = (data1 + " " + data2 + " " + oObject[objectvalue]).toLowerCase();
2071
+ const strToTest = this.normalize(data1 + " " + data2 + " " + oObject[objectvalue]);
2068
2072
  if ((strToTest.indexOf(valor) >= 0) && (result).indexOf(oObject) == -1) {
2069
2073
  result.push(oObject);
2070
2074
  break;
2071
2075
  }
2072
2076
  }
2073
2077
  else {
2074
- const strToTest = (this.statusinfo.transform(oObject[objectvalue], 'ALL') + "").toLowerCase();
2078
+ const strToTest = this.normalize(this.statusinfo.transform(oObject[objectvalue], 'ALL') + "");
2075
2079
  if ((strToTest.indexOf(valor) >= 0) && (result).indexOf(oObject) == -1) {
2076
2080
  result.push(oObject);
2077
2081
  break;
@@ -2082,9 +2086,9 @@ class TCloudUiSearchInObjectService {
2082
2086
  }
2083
2087
  if (emObject && typeof emObject === 'object' && Array.isArray(emObject)) {
2084
2088
  // is array
2085
- const v = (`${valor}`).toUpperCase();
2089
+ const v = this.normalize(`${valor}`);
2086
2090
  for (let i = 0; i < (emObject).length; i++) {
2087
- const item = (`${emObject[i]}`).toUpperCase();
2091
+ const item = this.normalize(`${emObject[i]}`);
2088
2092
  if (item.includes(v) || item === v) {
2089
2093
  result.push(emObject[i]);
2090
2094
  }
@@ -2786,15 +2790,44 @@ class TCloudUiFiltersComponent {
2786
2790
  const v = (((`${text}`).normalize('NFD').replace(/[\u0300-\u036f]/g, "")).trim()).toLowerCase();
2787
2791
  return v;
2788
2792
  }
2789
- fetchFromObject(obj, prop) {
2790
- if (typeof obj === 'undefined') {
2791
- return false;
2792
- }
2793
- var _index = `${prop}`.indexOf('.');
2794
- if (_index > -1) {
2795
- 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
+ }
2796
2829
  }
2797
- return obj[prop];
2830
+ return current;
2798
2831
  }
2799
2832
  searchIn(item, event) {
2800
2833
  if (typeof event === 'boolean') {
@@ -2814,7 +2847,7 @@ class TCloudUiFiltersComponent {
2814
2847
  const filter_item = this.filters[j];
2815
2848
  if (filter_item.searchText && typeof (filter_item.searchText) === 'string' && filter_item.searchText !== '') {
2816
2849
  filter_item.searchText = this.normalize(filter_item.searchText);
2817
- let item_value = this.fetchFromObject(this.data[i], filter_item.searchIn);
2850
+ let item_value = this.collectionFind(this.data[i], filter_item.searchIn);
2818
2851
  if (item_value) {
2819
2852
  item_value = this.normalize(item_value);
2820
2853
  if (!(item_value.includes(filter_item.searchText) || item_value === filter_item.searchText)) {
@@ -2822,9 +2855,21 @@ class TCloudUiFiltersComponent {
2822
2855
  }
2823
2856
  }
2824
2857
  }
2825
- if (typeof (filter_item.searchText) === 'boolean') {
2826
- let item_value = this.fetchFromObject(this.data[i], filter_item.searchIn);
2827
- 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 {
2828
2873
  if (!(item_value === filter_item.searchText)) {
2829
2874
  this.data[i]['tc_filter_accept'] = false;
2830
2875
  }