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 | 93x 93x 93x 93x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 10x 9x 1x 3x 3x 3x 10x 10x 10x 9x 7x 1x 3x 1x | import { IDictionary } from '@zeedhi/core';
import get from 'lodash.get';
import { IComponentRender } from '../zd-component/interfaces';
import { Column } from '../zd-iterable/column';
import { IColumn } from '../zd-iterable/interfaces';
import { Iterable } from '../zd-iterable/iterable';
import { IIterableComponentRender, IIterableComponentRenderProps } from './interfaces';
/**
* Base class for IterableComponentRender component.
* This component uses every row returned by Iterable.datasource to render
* components defined by componentMetadata property.
* If the data inside the datasource is changed you should perform
* a datasource.get() to force updating the rendered components.
*/
export class IterableComponentRender extends Iterable implements IIterableComponentRender {
/**
* Components that will be rendered on toolbar slot
*/
public toolbarSlot: IComponentRender[] = [];
/**
* Components that will be rendered on footer slot
*/
public footerSlot: IComponentRender[] = [];
/**
* Component item definition
*/
public componentMetadata!: IComponentRender;
/**
* Row property name
*/
public rowPropName = 'row';
/**
* Components that will be rendered in no-data case
*/
public noDataSlot: IComponentRender[] = [
{
name: '<<NAME>>_no-data',
component: 'ZdText',
cssClass: 'no-data',
text: 'NO_DATA',
},
];
/**
* Components that will be rendered in no-result case
*/
public noResultSlot: IComponentRender[] = [
{
name: '<<NAME>>_no-result',
component: 'ZdText',
cssClass: 'no-result',
text: 'NO_RESULT',
},
];
/**
* Defines the component height. Possible values for this property can be
* <samp>'auto', '100%', '400px' or 400</samp>
*/
public height: string | number = 'auto';
/**
* Defines the component min height. Possible values for this property can be
* <samp>'auto', '100%', '400px' or 400</samp>
*/
public minHeight: string | number = 'auto';
/**
* Defines the component max height. Possible values for this property can be
* <samp>'auto', '100%', '400px' or 400</samp>
*/
public maxHeight: string | number = 'none';
/**
* Set component height to fill all space available
*/
public fillHeight = false;
/**
* Defines the component width. Possible values for this property can be
* <samp>'auto', '100%', '400px' or 400</samp>
*/
public width: string | number = '100%';
/**
* Defines the component min width. Possible values for this property can be
* <samp>'auto', '100%', '400px' or 400</samp>
*/
public minWidth: string | number = 'auto';
/**
* Defines the component max height. Possible values for this property can be
* <samp>'auto', '100%', '400px' or 400</samp>
*/
public maxWidth: string | number = 'none';
/**
* Components that will be rendered in error case
*/
public errorSlot: IComponentRender[] = [];
public constructor(props: IIterableComponentRenderProps) {
super(props);
this.toolbarSlot = props.toolbarSlot || this.toolbarSlot;
this.footerSlot = props.footerSlot || this.footerSlot;
this.componentMetadata = this.getInitValue('componentMetadata', props.componentMetadata, this.componentMetadata);
this.rowPropName = this.getInitValue('rowPropName', props.rowPropName, this.rowPropName);
this.noDataSlot = props.noDataSlot || this.noDataSlot;
this.noResultSlot = props.noResultSlot || this.noResultSlot;
this.errorSlot = props.errorSlot || this.errorSlot;
this.noDataSlot = this.changeDefaultSlotNames(this.noDataSlot);
this.noResultSlot = this.changeDefaultSlotNames(this.noResultSlot);
this.height = this.getInitValue('height', props.height, this.height);
this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
this.fillHeight = this.getInitValue('fillHeight', props.fillHeight, this.fillHeight);
this.width = this.getInitValue('width', props.width, this.width);
this.minWidth = this.getInitValue('minWidth', props.minWidth, this.minWidth);
this.maxWidth = this.getInitValue('maxWidth', props.maxWidth, this.maxWidth);
this.createAccessors();
}
private addSlashes(value: any) {
if (typeof value === 'string') {
return value
.replace(/\\/g, '\\\\')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\f/g, '\\f')
.replace(/\r/g, '\\r')
.replace(/"/g, '\\"');
}
return value;
}
/**
* Returns the iterable component metadata based on row data
*/
public getComponentMetadata(row: IDictionary<any>) {
const exp = new RegExp(`<<${this.rowPropName}.(.[A-z]+?)>>|"<<${this.rowPropName}.(.[A-z]+?)>>"`, 'g');
const rowExp = new RegExp(`"<<${this.rowPropName}>>"`, 'g');
const metadata = JSON.stringify(this.componentMetadata)
.replace(rowExp, JSON.stringify(row))
.replace(exp, (match) => {
const propPath = match
.replace(/<<|>>|"/g, '')
.split('.')
.splice(1)
.join('.');
const value = this.addSlashes(get(row, propPath));
if (typeof value === 'string') {
if (match.startsWith('"') && match.endsWith('"')) return `"${value}"`;
return value;
}
return value;
});
return JSON.parse(metadata);
}
public createColumn(column: IColumn): Column {
return new Column(column);
}
}
|