Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | 93x 93x 93x 93x 392x 1x 1x 31x 4x 5x 3x 3x 2x 2x 5x 5x 6x 5x 1x 4x 3x 3x 1x 1x 4x 93x 30x 29x 29x 29x 29x 28x 28x 8x 8x 12x 12x 8x 8x 20x 10x 10x 10x 10x 15x 15x 15x 10x 10x 29x 26x 26x 8x 4x 4x 8x 8x 26x 26x 25x 11x 14x 14x 93x 11x 8x 8x 8x 16x 16x 16x 6x 6x 8x 8x 6x 10x 8x 8x 4x 4x 8x 8x 8x 12x 8x 16x 8x 93x 8x 8x 8x 8x 4x 4x 4x 4x 93x 93x | import { FormatterParserProvider, I18n, IDictionary, Utils } from '@zeedhi/core';
import isUndefined from 'lodash.isundefined';
import { Column } from '../zd-iterable/column';
import { IChildrenActionColumn, IGridColumn } from './interfaces';
/**
* Base class for Grid column
*/
export class GridColumn extends Column implements IGridColumn {
/* Children components to be rendered on action columns */
public children: IChildrenActionColumn[] = [];
/* istanbul ignore next */
/**
* Creates a new Grid Column.
* @param props Grid column properties
*/
constructor(props: IGridColumn) {
super(props);
this.children = this.getInitValue('children', props.children, this.children);
if (!this.componentProps.component) {
this.componentProps.mask = this.componentProps.mask || this.mask;
this.componentProps.component = 'ZdTextInput';
}
this.createAccessors();
}
/**
* Children props without grid system.
*/
get childrenProps() {
return this.children.map(({ conditions, ...otherAttrs }) => otherAttrs);
}
/**
* Get the Column without the conditions object
* @param component Column component
*/
public getColumnWithoutConditions(component: any) {
return { ...component, conditions: undefined };
}
/**
* checkOutValues
*/
public checkOutValues(component: any, row: IDictionary<any>, newRow: IDictionary<any>) {
if (this.componentProps.dataValueOut && component.datasource?.currentRow) {
this.componentProps.dataValueOut.forEach((dataOutColumn: any) => {
let column: string;
let columnOnGrid: string;
if (typeof dataOutColumn === 'string') {
column = dataOutColumn;
columnOnGrid = this.componentProps.foreignColumns?.[column] || column;
} else {
column = dataOutColumn.column;
columnOnGrid = dataOutColumn.columnOnGrid;
}
let currentValue = component.datasource.currentRow[column];
if (Array.isArray(component.value)) {
currentValue = component.selectedValue.map((item: IDictionary) => item[column]);
}
if (
Utils.isEqual(newRow[`${columnOnGrid}_original`], newRow.originalRow[columnOnGrid]) &&
Utils.isEqual(newRow[columnOnGrid], currentValue)
) {
return;
}
if (!Utils.isEqual(newRow.originalRow[columnOnGrid], currentValue)) {
newRow[`${columnOnGrid}_original`] = newRow.originalRow[columnOnGrid];
newRow[columnOnGrid] = currentValue;
} else {
delete newRow[`${columnOnGrid}_original`];
delete newRow[columnOnGrid];
}
row[columnOnGrid] = currentValue;
});
}
}
}
FormatterParserProvider.registerFormatter('column_ZdSelect', ({ column, value, row, componentProps }: any) => {
if (value === null || value === undefined) return '';
const { dataText, formatterDataText, dataTextSeparator, dataValue, dataTextDiscrete, foreignColumns } =
componentProps;
let currentRow = row;
const dataTextColumns = Array.isArray(dataText) ? dataText : [dataText];
if (dataValue) {
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
if (foreignColumns) {
const loopkupRow: IDictionary = {};
dataTextColumns.forEach((item) => {
const dataTextName = typeof item === 'string' ? item : item.name;
loopkupRow[dataTextName] = currentRow[foreignColumns[dataTextName] || dataTextName];
});
loopkupRow[dataValue] = currentRow[column.name];
column.lookupData[currentRow[column.name]] = loopkupRow;
} else if (!formatterDataText) {
currentRow = column.getLookupData(dataValue, value[dataValue] || value);
} else if (columns.length === dataTextColumns.length) {
const loopkupRow: IDictionary = {};
columns.forEach((item, index) => {
const dataTextValue = dataTextColumns[index];
const dataTextName = typeof dataTextValue === 'string' ? dataTextValue : dataTextValue.name;
loopkupRow[dataTextName] = currentRow[typeof item === 'string' ? item : item.name];
});
loopkupRow[dataValue] = currentRow[column.name];
column.lookupData[currentRow[column.name]] = loopkupRow;
}
}
if (!Object.keys(currentRow).length) return typeof value === 'object' ? '' : value;
let dataTextForeign: any = dataText;
if (dataText && foreignColumns) {
if (typeof dataText === 'string') {
dataTextForeign = foreignColumns[dataText] || dataText;
} else {
dataTextForeign = dataTextColumns.map((item: any) => {
const itemName = typeof item === 'string' ? item : item.name;
return foreignColumns[itemName] || itemName;
});
}
}
const textColumn = formatterDataText || dataTextDiscrete || dataTextForeign;
if (!textColumn) return value;
if (typeof textColumn === 'string') {
return currentRow[textColumn] || value;
}
const formatterFn = FormatterParserProvider.getFormatter('ZdSelect');
return formatterFn(currentRow, { dataText: textColumn, dataTextSeparator });
});
FormatterParserProvider.registerFormatter('column_ZdSelectMultiple', ({ column, value, row, componentProps }: any) => {
if (!value || !Array.isArray(value) || value.length === 0) return '';
const { formatterDataText, foreignColumns, dataText } = componentProps;
const formatterFn = FormatterParserProvider.getFormatter('column_ZdSelect');
const result = value.map((item: string | number | IDictionary, index: number) => {
let formatterRow = { ...row };
const rowOverride: IDictionary = {};
if (formatterDataText && formatterDataText.length > 0) {
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
columns.forEach((col) => {
const textName = typeof col === 'string' ? col : col.name;
rowOverride[textName] = row[textName][index];
});
formatterRow = { ...row, ...rowOverride };
} else if (foreignColumns && dataText) {
let dataTextForeign: any = dataText;
if (typeof dataText === 'string') {
dataTextForeign = [foreignColumns[dataText] || dataText];
} else {
dataTextForeign = dataText.map((col: any) => {
const colName = typeof col === 'string' ? col : col.name;
return foreignColumns[colName] || colName;
});
}
dataTextForeign.forEach((col: string) => {
rowOverride[col] = row[col][index];
});
formatterRow = { ...row, ...rowOverride };
}
return formatterFn({
column,
value: item,
row: formatterRow,
componentProps,
});
});
return result.join(', ');
});
const toggleableFormatter = ({ value, componentProps }: any) => {
const { trueValue, falseValue, trueIcon, falseIcon, trueDisplayValue, falseDisplayValue } = componentProps;
const trueDefined = isUndefined(trueValue) ? true : trueValue;
const falseDefined = isUndefined(falseValue) ? false : falseValue;
if (value === trueDefined) {
const display = trueDisplayValue ? I18n.translate(trueDisplayValue) : trueDisplayValue;
return trueIcon || display || trueDefined;
}
const display = falseDisplayValue ? I18n.translate(falseDisplayValue) : falseDisplayValue;
return falseIcon || display || falseDefined;
};
FormatterParserProvider.registerFormatter('column_ZdCheckbox', toggleableFormatter);
FormatterParserProvider.registerFormatter('column_ZdSwitch', toggleableFormatter);
|