@zeedhi/teknisa-components-common 1.79.0 → 1.79.1

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.
@@ -1011,6 +1011,7 @@
1011
1011
  {
1012
1012
  name: `${this.grid.name}-filter-title`,
1013
1013
  component: 'ZdText',
1014
+ cssStyle: `color: ${'var(--v-primary-base);'}`,
1014
1015
  text: `${mergeModalFilterProps.title}`,
1015
1016
  tag: 'h3',
1016
1017
  },
@@ -1651,13 +1652,13 @@
1651
1652
  OR: true,
1652
1653
  };
1653
1654
 
1654
- class TekRestDatasource extends core.RestDatasource {
1655
+ class TekMemoryDatasource extends core.MemoryDatasource {
1655
1656
  /**
1656
1657
  * Create new datasource
1657
1658
  * @param props Datasource properties
1658
1659
  */
1659
1660
  constructor(props) {
1660
- super(Object.assign(Object.assign({}, props), { lazyLoad: true }));
1661
+ super(props);
1661
1662
  /**
1662
1663
  * Dynamic Filter Operations
1663
1664
  */
@@ -1674,13 +1675,10 @@
1674
1675
  this.dynamicFilter = this.getInitValue('dynamicFilter', props.dynamicFilter, {});
1675
1676
  this.searchJoin = this.getInitValue('searchJoin', props.searchJoin, {});
1676
1677
  }
1677
- this.lazyLoad = this.getInitValue('lazyLoad', props.lazyLoad, this.lazyLoad);
1678
1678
  this.createAccessors();
1679
1679
  this.createObjAccessors(this.dynamicFilter, 'dynamicFilter');
1680
1680
  this.createObjAccessors(this.searchJoin, 'searchJoin');
1681
- if (!this.lazyLoad) {
1682
- this.get();
1683
- }
1681
+ this.get();
1684
1682
  }
1685
1683
  updateReservedKeys() {
1686
1684
  this.reservedKeys.dynamic_filter = true;
@@ -1809,37 +1807,124 @@
1809
1807
  && this.dynamicFilterRelations[filterValue.relation]
1810
1808
  && filterValue.value !== '' && filterValue.value !== null);
1811
1809
  }
1810
+ clone() {
1811
+ return Object.assign(Object.assign({}, super.clone()), { dynamicFilter: this.dynamicFilter, searchJoin: this.searchJoin, type: 'tek-memory' });
1812
+ }
1812
1813
  /**
1813
- * Retrieves request params
1814
+ * Updates filtered data
1814
1815
  */
1815
- getRequestParams() {
1816
- const requestParams = super.getRequestParams();
1817
- const isNotEmptyObj = (obj) => !!(obj && Object.keys(obj).length);
1818
- const isValid = this.dynamicFilter && Object.keys(this.dynamicFilter).every((column) => {
1819
- const value = this.dynamicFilter[column];
1820
- return value && value.length > 0 && this.isValidDynamicFilterValue(column, value);
1821
- });
1822
- if (isNotEmptyObj(this.dynamicFilter) && isValid) {
1823
- requestParams.dynamic_filter = btoa(JSON.stringify(this.dynamicFilter));
1816
+ updateFilteredData() {
1817
+ // first apply filters (simple and dynamic)
1818
+ this.filteredData = Object.keys(this.filter).length
1819
+ ? this.allData.filter((row) => this.getRowByFilter(row))
1820
+ : Array.from(this.allData);
1821
+ if (this.dynamicFilter && Object.keys(this.dynamicFilter).length) {
1822
+ this.filteredData = this.filteredData.filter((row) => this.getRowByDynamicFilter(row));
1824
1823
  }
1825
- if (isNotEmptyObj(this.searchJoin)) {
1826
- requestParams.search_join = btoa(JSON.stringify(this.searchJoin));
1824
+ const searchWithoutSearchJoin = (row) => {
1825
+ const searchRow = Object.assign({}, row);
1826
+ if (this.searchJoin) {
1827
+ // do not search on columns with searchJoin
1828
+ Object.keys(this.searchJoin).forEach((key) => delete searchRow[key]);
1829
+ }
1830
+ return this.getRowBySearch(searchRow);
1831
+ };
1832
+ // only after do the search
1833
+ const searchData = this.search
1834
+ ? this.filteredData.filter(searchWithoutSearchJoin)
1835
+ : this.filteredData;
1836
+ let searchIds = searchData.map((row) => row[this.uniqueKey]);
1837
+ if (this.searchJoin && Object.keys(this.searchJoin).length) {
1838
+ const searchJoinData = this.filteredData.filter((row) => this.getRowBySearchJoin(row));
1839
+ // get the ids from search and searchJoin
1840
+ searchIds = searchIds
1841
+ .concat(searchJoinData.map((row) => row[this.uniqueKey]))
1842
+ .sort();
1827
1843
  }
1828
- return requestParams;
1844
+ // filter filteredData using searchIds
1845
+ this.filteredData = this.allData.filter((row) => searchIds.indexOf(row[this.uniqueKey]) !== -1);
1829
1846
  }
1830
- clone() {
1831
- return Object.assign(Object.assign({}, super.clone()), { dynamicFilter: this.dynamicFilter, searchJoin: this.searchJoin, type: 'tek-rest' });
1847
+ getRowByDynamicFilter(row) {
1848
+ let filtered;
1849
+ try {
1850
+ Object.keys(this.dynamicFilter).forEach((key) => {
1851
+ const filterItems = this.dynamicFilter[key];
1852
+ filterItems.forEach((item) => {
1853
+ if (filtered === false && item.relation === 'AND')
1854
+ return;
1855
+ if (filtered === true && item.relation === 'OR')
1856
+ return;
1857
+ const columnValue = core.Utils.normalize(row[key].toString());
1858
+ let value = '';
1859
+ if (Array.isArray(item.value)) {
1860
+ value = item.value.map((val) => core.Utils.normalize(val.toString()));
1861
+ switch (item.operation) {
1862
+ case 'IN':
1863
+ filtered = value.includes(columnValue);
1864
+ break;
1865
+ case 'NOT_IN':
1866
+ filtered = !value.includes(columnValue);
1867
+ break;
1868
+ case 'BETWEEN':
1869
+ filtered = (Number(columnValue) || columnValue) >= (Number(value[0]) || value[0])
1870
+ && (Number(columnValue) || columnValue) <= (Number(value[1]) || value[1]);
1871
+ break;
1872
+ default:
1873
+ break;
1874
+ }
1875
+ }
1876
+ else {
1877
+ value = core.Utils.normalize(item.value.toString());
1878
+ switch (item.operation) {
1879
+ case 'CONTAINS':
1880
+ filtered = columnValue.indexOf(value) !== -1;
1881
+ break;
1882
+ case 'NOT_CONTAINS':
1883
+ filtered = columnValue.indexOf(value) === -1;
1884
+ break;
1885
+ case 'EQUALS':
1886
+ filtered = columnValue === value;
1887
+ break;
1888
+ case 'NOT_EQUALS':
1889
+ filtered = columnValue !== value;
1890
+ break;
1891
+ case 'GREATER_THAN':
1892
+ filtered = (Number(columnValue) || columnValue) > (Number(value) || value);
1893
+ break;
1894
+ case 'LESS_THAN':
1895
+ filtered = (Number(columnValue) || columnValue) < (Number(value) || value);
1896
+ break;
1897
+ case 'GREATER_THAN_EQUALS':
1898
+ filtered = (Number(columnValue) || columnValue) >= (Number(value) || value);
1899
+ break;
1900
+ case 'LESS_THAN_EQUALS':
1901
+ filtered = (Number(columnValue) || columnValue) <= (Number(value) || value);
1902
+ break;
1903
+ default:
1904
+ break;
1905
+ }
1906
+ }
1907
+ });
1908
+ });
1909
+ }
1910
+ catch (_a) {
1911
+ // do nothing
1912
+ }
1913
+ return filtered;
1914
+ }
1915
+ getRowBySearchJoin(row) {
1916
+ return Object.keys(this.searchJoin).some((key) => this.searchJoin[key].includes(row[key]));
1832
1917
  }
1833
1918
  }
1834
- core.DatasourceFactory.register('tek-rest', TekRestDatasource);
1919
+ core.DatasourceFactory.register('tek-memory', TekMemoryDatasource);
1835
1920
 
1836
- class TekMemoryDatasource extends core.MemoryDatasource {
1921
+ class TekRestDatasource extends core.RestDatasource {
1837
1922
  /**
1838
1923
  * Create new datasource
1839
1924
  * @param props Datasource properties
1840
1925
  */
1841
1926
  constructor(props) {
1842
- super(props);
1927
+ super(Object.assign(Object.assign({}, props), { lazyLoad: true }));
1843
1928
  /**
1844
1929
  * Dynamic Filter Operations
1845
1930
  */
@@ -1856,10 +1941,13 @@
1856
1941
  this.dynamicFilter = this.getInitValue('dynamicFilter', props.dynamicFilter, {});
1857
1942
  this.searchJoin = this.getInitValue('searchJoin', props.searchJoin, {});
1858
1943
  }
1944
+ this.lazyLoad = this.getInitValue('lazyLoad', props.lazyLoad, this.lazyLoad);
1859
1945
  this.createAccessors();
1860
1946
  this.createObjAccessors(this.dynamicFilter, 'dynamicFilter');
1861
1947
  this.createObjAccessors(this.searchJoin, 'searchJoin');
1862
- this.get();
1948
+ if (!this.lazyLoad) {
1949
+ this.get();
1950
+ }
1863
1951
  }
1864
1952
  updateReservedKeys() {
1865
1953
  this.reservedKeys.dynamic_filter = true;
@@ -1988,116 +2076,29 @@
1988
2076
  && this.dynamicFilterRelations[filterValue.relation]
1989
2077
  && filterValue.value !== '' && filterValue.value !== null);
1990
2078
  }
1991
- clone() {
1992
- return Object.assign(Object.assign({}, super.clone()), { dynamicFilter: this.dynamicFilter, searchJoin: this.searchJoin, type: 'tek-memory' });
1993
- }
1994
2079
  /**
1995
- * Updates filtered data
2080
+ * Retrieves request params
1996
2081
  */
1997
- updateFilteredData() {
1998
- // first apply filters (simple and dynamic)
1999
- this.filteredData = Object.keys(this.filter).length
2000
- ? this.allData.filter((row) => this.getRowByFilter(row))
2001
- : Array.from(this.allData);
2002
- if (this.dynamicFilter && Object.keys(this.dynamicFilter).length) {
2003
- this.filteredData = this.filteredData.filter((row) => this.getRowByDynamicFilter(row));
2004
- }
2005
- const searchWithoutSearchJoin = (row) => {
2006
- const searchRow = Object.assign({}, row);
2007
- if (this.searchJoin) {
2008
- // do not search on columns with searchJoin
2009
- Object.keys(this.searchJoin).forEach((key) => delete searchRow[key]);
2010
- }
2011
- return this.getRowBySearch(searchRow);
2012
- };
2013
- // only after do the search
2014
- const searchData = this.search
2015
- ? this.filteredData.filter(searchWithoutSearchJoin)
2016
- : this.filteredData;
2017
- let searchIds = searchData.map((row) => row[this.uniqueKey]);
2018
- if (this.searchJoin && Object.keys(this.searchJoin).length) {
2019
- const searchJoinData = this.filteredData.filter((row) => this.getRowBySearchJoin(row));
2020
- // get the ids from search and searchJoin
2021
- searchIds = searchIds
2022
- .concat(searchJoinData.map((row) => row[this.uniqueKey]))
2023
- .sort();
2024
- }
2025
- // filter filteredData using searchIds
2026
- this.filteredData = this.allData.filter((row) => searchIds.indexOf(row[this.uniqueKey]) !== -1);
2027
- }
2028
- getRowByDynamicFilter(row) {
2029
- let filtered;
2030
- try {
2031
- Object.keys(this.dynamicFilter).forEach((key) => {
2032
- const filterItems = this.dynamicFilter[key];
2033
- filterItems.forEach((item) => {
2034
- if (filtered === false && item.relation === 'AND')
2035
- return;
2036
- if (filtered === true && item.relation === 'OR')
2037
- return;
2038
- const columnValue = core.Utils.normalize(row[key].toString());
2039
- let value = '';
2040
- if (Array.isArray(item.value)) {
2041
- value = item.value.map((val) => core.Utils.normalize(val.toString()));
2042
- switch (item.operation) {
2043
- case 'IN':
2044
- filtered = value.includes(columnValue);
2045
- break;
2046
- case 'NOT_IN':
2047
- filtered = !value.includes(columnValue);
2048
- break;
2049
- case 'BETWEEN':
2050
- filtered = (Number(columnValue) || columnValue) >= (Number(value[0]) || value[0])
2051
- && (Number(columnValue) || columnValue) <= (Number(value[1]) || value[1]);
2052
- break;
2053
- default:
2054
- break;
2055
- }
2056
- }
2057
- else {
2058
- value = core.Utils.normalize(item.value.toString());
2059
- switch (item.operation) {
2060
- case 'CONTAINS':
2061
- filtered = columnValue.indexOf(value) !== -1;
2062
- break;
2063
- case 'NOT_CONTAINS':
2064
- filtered = columnValue.indexOf(value) === -1;
2065
- break;
2066
- case 'EQUALS':
2067
- filtered = columnValue === value;
2068
- break;
2069
- case 'NOT_EQUALS':
2070
- filtered = columnValue !== value;
2071
- break;
2072
- case 'GREATER_THAN':
2073
- filtered = (Number(columnValue) || columnValue) > (Number(value) || value);
2074
- break;
2075
- case 'LESS_THAN':
2076
- filtered = (Number(columnValue) || columnValue) < (Number(value) || value);
2077
- break;
2078
- case 'GREATER_THAN_EQUALS':
2079
- filtered = (Number(columnValue) || columnValue) >= (Number(value) || value);
2080
- break;
2081
- case 'LESS_THAN_EQUALS':
2082
- filtered = (Number(columnValue) || columnValue) <= (Number(value) || value);
2083
- break;
2084
- default:
2085
- break;
2086
- }
2087
- }
2088
- });
2089
- });
2082
+ getRequestParams() {
2083
+ const requestParams = super.getRequestParams();
2084
+ const isNotEmptyObj = (obj) => !!(obj && Object.keys(obj).length);
2085
+ const isValid = this.dynamicFilter && Object.keys(this.dynamicFilter).every((column) => {
2086
+ const value = this.dynamicFilter[column];
2087
+ return value && value.length > 0 && this.isValidDynamicFilterValue(column, value);
2088
+ });
2089
+ if (isNotEmptyObj(this.dynamicFilter) && isValid) {
2090
+ requestParams.dynamic_filter = btoa(JSON.stringify(this.dynamicFilter));
2090
2091
  }
2091
- catch (_a) {
2092
- // do nothing
2092
+ if (isNotEmptyObj(this.searchJoin)) {
2093
+ requestParams.search_join = btoa(JSON.stringify(this.searchJoin));
2093
2094
  }
2094
- return filtered;
2095
+ return requestParams;
2095
2096
  }
2096
- getRowBySearchJoin(row) {
2097
- return Object.keys(this.searchJoin).some((key) => this.searchJoin[key].includes(row[key]));
2097
+ clone() {
2098
+ return Object.assign(Object.assign({}, super.clone()), { dynamicFilter: this.dynamicFilter, searchJoin: this.searchJoin, type: 'tek-rest' });
2098
2099
  }
2099
2100
  }
2100
- core.DatasourceFactory.register('tek-memory', TekMemoryDatasource);
2101
+ core.DatasourceFactory.register('tek-rest', TekRestDatasource);
2101
2102
 
2102
2103
  /**
2103
2104
  * Base class for TekGrid column
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/teknisa-components-common",
3
- "version": "1.79.0",
3
+ "version": "1.79.1",
4
4
  "description": "Teknisa Components Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -31,5 +31,5 @@
31
31
  "peerDependencies": {
32
32
  "@zeedhi/core": "*"
33
33
  },
34
- "gitHead": "21ab64d9a9f50082961702e29e6df8114d5f62cd"
34
+ "gitHead": "3dbfc60f316134f249bb4c65429623dfb93b0696"
35
35
  }
@@ -2,7 +2,7 @@ import { GridEditable, IComponentRender } from '@zeedhi/common';
2
2
  import { Datasource, IDictionary } from '@zeedhi/core';
3
3
  import { ITekGridAtoms } from '../../utils';
4
4
  import { TekGridColumn } from './grid-column';
5
- import { ITekGrid, ITekGridColumn, ITekGridEvents, ITekGridExportConfig, IModalFilterProps } from './interfaces';
5
+ import { IModalFilterProps, ITekGrid, ITekGridColumn, ITekGridEvents, ITekGridExportConfig } from './interfaces';
6
6
  import { TekGridLayoutOptions } from './layout-options';
7
7
  export declare class TekGrid extends GridEditable implements ITekGrid {
8
8
  title: string;