@zeedhi/teknisa-components-common 1.44.0 → 1.47.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.
@@ -1,5 +1,5 @@
1
- import { KeyMap, I18n, FormatterParserProvider, Messages, Metadata, DatasourceFactory, RestDatasource, URL, MemoryDatasource, Utils, Loader, dayjs, Config } from '@zeedhi/core';
2
- import { Form, Button, Tooltip, GridEditable, Grid, ComponentRender, Iterable, Carousel, ModalService, GridColumnEditable, Report, IterableColumnsButtonController, IterableColumnsButton, TreeGridEditable } from '@zeedhi/common';
1
+ import { KeyMap, I18n, FormatterParserProvider, Messages, Metadata, DatasourceFactory, RestDatasource, URL, MemoryDatasource, Utils, Loader, DateHelper } from '@zeedhi/core';
2
+ import { Form, Button, Tooltip, GridEditable, Grid, ComponentRender, Iterable, Carousel, Loading as Loading$1, ModalService, GridColumnEditable, Report, IterableColumnsButtonController, IterableColumnsButton, TreeGridEditable } from '@zeedhi/common';
3
3
  import get from 'lodash.get';
4
4
  import debounce from 'lodash.debounce';
5
5
  import merge from 'lodash.merge';
@@ -584,7 +584,7 @@ const loading = 'data:image/gif;base64,R0lGODlhlgCWAPf/AC1oxPa+ADarUdmsFEB/m0yTc
584
584
  /**
585
585
  * Teknisa component
586
586
  */
587
- class Loading extends ComponentRender {
587
+ class Loading extends Loading$1 {
588
588
  /**
589
589
  * Creates a new instance of TekLoading
590
590
  * @param props Image Link props
@@ -1134,9 +1134,11 @@ class GridBase {
1134
1134
  columnComponentName = `${this.grid.name}-filter-AND-CONTAINS-${column.name}-${index}`;
1135
1135
  }
1136
1136
  this.filterFormInputs[column.name].push(columnComponentName);
1137
- let newColumnComponent = Object.assign(Object.assign(Object.assign({ label: column.label }, column.componentProps), filterItem), { name: columnComponentName });
1137
+ const newColumnComponent = Object.assign(Object.assign(Object.assign({ label: column.label }, column.componentProps), filterItem), { name: columnComponentName });
1138
1138
  if (filterItem.helperOptions) {
1139
- newColumnComponent = this.getHelperValueComponent(newColumnComponent, filterItem.helperOptions, column);
1139
+ if (!newColumnComponent.events)
1140
+ newColumnComponent.events = {};
1141
+ newColumnComponent.events.change = this.changeHelperEvent.bind(this, column);
1140
1142
  }
1141
1143
  filterColumns.push(newColumnComponent);
1142
1144
  });
@@ -1144,54 +1146,9 @@ class GridBase {
1144
1146
  });
1145
1147
  return filterColumns;
1146
1148
  }
1147
- getHelperValueComponent(component, helperValues, column) {
1148
- return {
1149
- name: `${component.name}_helperspan`,
1150
- component: 'ZdTag',
1151
- tag: 'span',
1152
- cssClass: 'zd-display-flex',
1153
- grid: component.grid,
1154
- children: [
1155
- Object.assign(Object.assign({}, component), { persistentHint: true, events: {
1156
- onMounted: this.registerFilterComponentToForm.bind(this),
1157
- change: this.clearFilterHelperValue.bind(this, column),
1158
- } }),
1159
- {
1160
- name: `${component.name}_helperdropdown`,
1161
- component: 'ZdDropdown',
1162
- offsetY: true,
1163
- activator: {
1164
- name: `${component.name}_helperbutton`,
1165
- component: 'ZdButton',
1166
- iconName: 'magnify',
1167
- icon: true,
1168
- small: true,
1169
- cssClass: `filter-helper-values-button ${component.showLabel !== false ? 'with-label' : ''}`,
1170
- },
1171
- children: this.createHelperValueOptions(component, helperValues, column),
1172
- },
1173
- ],
1174
- };
1175
- }
1176
- createHelperValueOptions(component, helperValues, column) {
1177
- return helperValues.map((value) => ({
1178
- name: `${component.name}_helpervalue_${value}`,
1179
- component: 'ZdText',
1180
- cssClass: 'filter-helper-values-option',
1181
- text: TekFilterHelper.getLabel(value),
1182
- events: {
1183
- click: this.helperValuesOptionClick.bind(this, component, value, column),
1184
- },
1185
- }));
1186
- }
1187
- helperValuesOptionClick(component, helperValue, column) {
1188
- const value = TekFilterHelper.getValue(helperValue, column);
1189
- const componentObject = Metadata.getInstance(component.name);
1190
- componentObject.value = value;
1191
- componentObject.hint = TekFilterHelper.getLabel(helperValue);
1192
- this.setFilterPropsHelperValue(column, component.name, helperValue);
1193
- }
1194
- setFilterPropsHelperValue(column, componentName, helperValue) {
1149
+ changeHelperEvent(column, { component }) {
1150
+ const { helperValue } = component;
1151
+ const componentName = component.name;
1195
1152
  if (!Array.isArray(column.filterProps)) {
1196
1153
  column.filterProps.helperValue = helperValue;
1197
1154
  }
@@ -1205,14 +1162,6 @@ class GridBase {
1205
1162
  });
1206
1163
  }
1207
1164
  }
1208
- registerFilterComponentToForm({ component }) {
1209
- const form = Metadata.getInstance(`${this.grid.name}-filter-form`);
1210
- form.registerInput(component);
1211
- }
1212
- clearFilterHelperValue(column, { component }) {
1213
- this.setFilterPropsHelperValue(column, component.name, '');
1214
- component.hint = '';
1215
- }
1216
1165
  loadFilterValues({ component }) {
1217
1166
  const { datasource } = this.grid;
1218
1167
  if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
@@ -1687,6 +1636,8 @@ class TekRestDatasource extends RestDatasource {
1687
1636
  }
1688
1637
  this.lazyLoad = this.getInitValue('lazyLoad', props.lazyLoad, this.lazyLoad);
1689
1638
  this.createAccessors();
1639
+ this.createObjAccessors(this.dynamicFilter, 'dynamicFilter');
1640
+ this.createObjAccessors(this.searchJoin, 'searchJoin');
1690
1641
  if (!this.lazyLoad) {
1691
1642
  this.get();
1692
1643
  }
@@ -1866,6 +1817,8 @@ class TekMemoryDatasource extends MemoryDatasource {
1866
1817
  this.searchJoin = this.getInitValue('searchJoin', props.searchJoin, {});
1867
1818
  }
1868
1819
  this.createAccessors();
1820
+ this.createObjAccessors(this.dynamicFilter, 'dynamicFilter');
1821
+ this.createObjAccessors(this.searchJoin, 'searchJoin');
1869
1822
  this.get();
1870
1823
  }
1871
1824
  updateReservedKeys() {
@@ -2012,61 +1965,70 @@ class TekMemoryDatasource extends MemoryDatasource {
2012
1965
  }
2013
1966
  getRowByDynamicFilter(row) {
2014
1967
  let filtered;
2015
- Object.keys(this.dynamicFilter).forEach((key) => {
2016
- const filterItems = this.dynamicFilter[key];
2017
- filterItems.forEach((item) => {
2018
- if (filtered === false && item.relation === 'AND')
2019
- return;
2020
- if (filtered === true && item.relation === 'OR')
2021
- return;
2022
- const columnValue = Utils.normalize(row[key].toString());
2023
- let value = '';
2024
- if (Array.isArray(item.value)) {
2025
- value = item.value.map((val) => Utils.normalize(val.toString()));
2026
- switch (item.operation) {
2027
- case 'IN':
2028
- filtered = value.includes(columnValue);
2029
- break;
2030
- case 'NOT_IN':
2031
- filtered = !value.includes(columnValue);
2032
- break;
2033
- case 'BETWEEN':
2034
- filtered = (Number(columnValue) || columnValue) >= (Number(value[0]) || value[0])
2035
- && (Number(columnValue) || columnValue) <= (Number(value[1]) || value[1]);
2036
- break;
1968
+ try {
1969
+ Object.keys(this.dynamicFilter).forEach((key) => {
1970
+ const filterItems = this.dynamicFilter[key];
1971
+ filterItems.forEach((item) => {
1972
+ if (filtered === false && item.relation === 'AND')
1973
+ return;
1974
+ if (filtered === true && item.relation === 'OR')
1975
+ return;
1976
+ const columnValue = Utils.normalize(row[key].toString());
1977
+ let value = '';
1978
+ if (Array.isArray(item.value)) {
1979
+ value = item.value.map((val) => Utils.normalize(val.toString()));
1980
+ switch (item.operation) {
1981
+ case 'IN':
1982
+ filtered = value.includes(columnValue);
1983
+ break;
1984
+ case 'NOT_IN':
1985
+ filtered = !value.includes(columnValue);
1986
+ break;
1987
+ case 'BETWEEN':
1988
+ filtered = (Number(columnValue) || columnValue) >= (Number(value[0]) || value[0])
1989
+ && (Number(columnValue) || columnValue) <= (Number(value[1]) || value[1]);
1990
+ break;
1991
+ default:
1992
+ break;
1993
+ }
2037
1994
  }
2038
- }
2039
- else {
2040
- value = Utils.normalize(item.value.toString());
2041
- switch (item.operation) {
2042
- case 'CONTAINS':
2043
- filtered = columnValue.indexOf(value) !== -1;
2044
- break;
2045
- case 'NOT_CONTAINS':
2046
- filtered = columnValue.indexOf(value) === -1;
2047
- break;
2048
- case 'EQUALS':
2049
- filtered = columnValue === value;
2050
- break;
2051
- case 'NOT_EQUALS':
2052
- filtered = columnValue !== value;
2053
- break;
2054
- case 'GREATER_THAN':
2055
- filtered = (Number(columnValue) || columnValue) > (Number(value) || value);
2056
- break;
2057
- case 'LESS_THAN':
2058
- filtered = (Number(columnValue) || columnValue) < (Number(value) || value);
2059
- break;
2060
- case 'GREATER_THAN_EQUALS':
2061
- filtered = (Number(columnValue) || columnValue) >= (Number(value) || value);
2062
- break;
2063
- case 'LESS_THAN_EQUALS':
2064
- filtered = (Number(columnValue) || columnValue) <= (Number(value) || value);
2065
- break;
1995
+ else {
1996
+ value = Utils.normalize(item.value.toString());
1997
+ switch (item.operation) {
1998
+ case 'CONTAINS':
1999
+ filtered = columnValue.indexOf(value) !== -1;
2000
+ break;
2001
+ case 'NOT_CONTAINS':
2002
+ filtered = columnValue.indexOf(value) === -1;
2003
+ break;
2004
+ case 'EQUALS':
2005
+ filtered = columnValue === value;
2006
+ break;
2007
+ case 'NOT_EQUALS':
2008
+ filtered = columnValue !== value;
2009
+ break;
2010
+ case 'GREATER_THAN':
2011
+ filtered = (Number(columnValue) || columnValue) > (Number(value) || value);
2012
+ break;
2013
+ case 'LESS_THAN':
2014
+ filtered = (Number(columnValue) || columnValue) < (Number(value) || value);
2015
+ break;
2016
+ case 'GREATER_THAN_EQUALS':
2017
+ filtered = (Number(columnValue) || columnValue) >= (Number(value) || value);
2018
+ break;
2019
+ case 'LESS_THAN_EQUALS':
2020
+ filtered = (Number(columnValue) || columnValue) <= (Number(value) || value);
2021
+ break;
2022
+ default:
2023
+ break;
2024
+ }
2066
2025
  }
2067
- }
2026
+ });
2068
2027
  });
2069
- });
2028
+ }
2029
+ catch (_a) {
2030
+ // do nothing
2031
+ }
2070
2032
  return filtered;
2071
2033
  }
2072
2034
  getRowBySearchJoin(row) {
@@ -2836,6 +2798,12 @@ class TekGridColumnsButtonController extends IterableColumnsButtonController {
2836
2798
  }
2837
2799
  column.aggregation = newValue;
2838
2800
  }
2801
+ showHideTekColumn(column, { component, event, element }) {
2802
+ if (!component.value && column.grouped)
2803
+ column.grouped = false;
2804
+ column.isVisible = component.value;
2805
+ this.iterableComponent.changeLayout(event, element);
2806
+ }
2839
2807
  }
2840
2808
 
2841
2809
  /**
@@ -3025,88 +2993,19 @@ class TekGridLayoutOptions extends ComponentRender {
3025
2993
  }
3026
2994
 
3027
2995
  class TekFilterHelper {
3028
- static formatDate(date, column) {
3029
- if (column.componentProps.dateFormat) {
3030
- return dayjs(date).format(column.componentProps.dateFormat);
3031
- }
3032
- return dayjs(date).format(Config.dateFormat);
3033
- }
3034
2996
  static getLabel(name) {
3035
- return I18n.translate(this.values[name].label);
2997
+ return DateHelper.getLabel(name);
3036
2998
  }
3037
2999
  static getValue(name, column) {
3038
- if (!this.values[name])
3039
- return '';
3040
- const value = this.values[name].fn();
3041
- if (Array.isArray(value)) {
3042
- return value.map((item) => this.formatDate(item, column));
3043
- }
3044
- return this.formatDate(value, column);
3000
+ return DateHelper.getValue(name, column.componentProps.dateFormat);
3045
3001
  }
3046
3002
  static register(name, label, fn) {
3047
- this.values[name] = {
3048
- label,
3049
- fn,
3050
- };
3003
+ DateHelper.register(name, label, fn);
3051
3004
  }
3052
3005
  static unregister(name) {
3053
- delete this.values[name];
3006
+ DateHelper.unregister(name);
3054
3007
  }
3055
- }
3056
- TekFilterHelper.values = {
3057
- TODAY: {
3058
- label: 'TEKGRID_HELPERVALUE_TODAY',
3059
- fn: () => dayjs().toDate(),
3060
- },
3061
- TOMORROW: {
3062
- label: 'TEKGRID_HELPERVALUE_TOMORROW',
3063
- fn: () => dayjs().add(1, 'day').toDate(),
3064
- },
3065
- YESTERDAY: {
3066
- label: 'TEKGRID_HELPERVALUE_YESTERDAY',
3067
- fn: () => dayjs().subtract(1, 'day').toDate(),
3068
- },
3069
- LAST_7_DAYS: {
3070
- label: 'TEKGRID_HELPERVALUE_LAST_7_DAYS',
3071
- fn: () => {
3072
- const end = dayjs().toDate();
3073
- const start = dayjs().subtract(7, 'day').toDate();
3074
- return [start, end];
3075
- },
3076
- },
3077
- NEXT_7_DAYS: {
3078
- label: 'TEKGRID_HELPERVALUE_NEXT_7_DAYS',
3079
- fn: () => {
3080
- const start = dayjs().toDate();
3081
- const end = dayjs().add(7, 'day').toDate();
3082
- return [start, end];
3083
- },
3084
- },
3085
- CURRENT_WEEK: {
3086
- label: 'TEKGRID_HELPERVALUE_CURRENT_WEEK',
3087
- fn: () => {
3088
- const start = dayjs().startOf('week').toDate();
3089
- const end = dayjs().endOf('week').toDate();
3090
- return [start, end];
3091
- },
3092
- },
3093
- CURRENT_MONTH: {
3094
- label: 'TEKGRID_HELPERVALUE_CURRENT_MONTH',
3095
- fn: () => {
3096
- const start = dayjs().startOf('month').toDate();
3097
- const end = dayjs().endOf('month').toDate();
3098
- return [start, end];
3099
- },
3100
- },
3101
- CURRENT_YEAR: {
3102
- label: 'TEKGRID_HELPERVALUE_CURRENT_YEAR',
3103
- fn: () => {
3104
- const start = dayjs().startOf('year').toDate();
3105
- const end = dayjs().endOf('year').toDate();
3106
- return [start, end];
3107
- },
3108
- },
3109
- };
3008
+ }
3110
3009
 
3111
3010
  /* TekTreeGrid Class */
3112
3011
  class TekTreeGrid extends TreeGridEditable {