Skip to content

Commit a04bb4f

Browse files
authored
Simple table 01 (#8)
* Initial SimpleTable - read only * show different values for readOnly vs Editable, some styling * For editable value, show initial value if there is one
1 parent 3c52392 commit a04bb4f

File tree

8 files changed

+741
-2
lines changed

8 files changed

+741
-2
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "SimpleTable",
3+
"description": "Datatype List Template",
4+
"type": "Template",
5+
"subtype": "DATAVIEW",
6+
"icon": "EditableTable.svg",
7+
"hideTemplatePicker": true,
8+
"hideFromTemplatePicker": true,
9+
"editing": true,
10+
"properties": [
11+
{
12+
"name": "parameters",
13+
"label": "",
14+
"format": "PARAMETERS"
15+
},
16+
{
17+
"name": "renderMode",
18+
"label": "Mode",
19+
"format": "RENDERMODE"
20+
},
21+
{
22+
"name": "Columns",
23+
"label": "Columns",
24+
"format": "CONTENTPICKER",
25+
"addTypeList": ["Fields", "Associations"],
26+
"hideModifyIcons": false,
27+
"modifyPanelOverrideProp": "renderMode",
28+
"modifyPanelOverride": {
29+
"ReadOnly": "ListField"
30+
}
31+
},
32+
{
33+
"name": "fillAvailableSpace",
34+
"label": "Column to take up remaining width",
35+
"format": "FILLCOLUMNWIDTH"
36+
},
37+
{
38+
"label": "Conditions",
39+
"format": "GROUP",
40+
"properties": [
41+
{
42+
"name": "required",
43+
"label": "Required",
44+
"format": "REQUIRED",
45+
"saveToReference": true
46+
},
47+
{
48+
"name": "disabled",
49+
"label": "Disabled",
50+
"format": "DISABLED",
51+
"saveToReference": true
52+
},
53+
{
54+
"name": "visibility",
55+
"label": "Visibility",
56+
"format": "VISIBILITY",
57+
"saveToReference": true
58+
}
59+
]
60+
}
61+
]
62+
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
declare var PCore;
2+
3+
export const TABLE_CELL = "SdkRenderer";
4+
export const DELETE_ICON = "DeleteIcon";
5+
6+
// BUG-615253: Workaround for autosize in table with lazy loading components
7+
/* istanbul ignore next */
8+
function getFiledWidth(field, label) {
9+
let width;
10+
switch (field.type) {
11+
case "Time":
12+
width = 150;
13+
break;
14+
case "Date":
15+
width = 160;
16+
break;
17+
case "DateTime":
18+
width = 205;
19+
break;
20+
case "AutoComplete":
21+
case "TextArea":
22+
width = 190;
23+
break;
24+
case "Currency":
25+
case "TextInput":
26+
width = 182;
27+
break;
28+
case "Checkbox":
29+
// eslint-disable-next-line no-case-declarations
30+
const text = document.createElement("span");
31+
document.body.appendChild(text);
32+
text.style.fontSize = "13px";
33+
text.style.position = "absolute";
34+
text.innerHTML = label;
35+
width = Math.ceil(text.clientWidth) + 30;
36+
document.body.removeChild(text);
37+
break;
38+
default:
39+
width = 180;
40+
}
41+
return width;
42+
}
43+
44+
export const getContext = (thePConn) => {
45+
const contextName = thePConn.getContextName();
46+
const pageReference = thePConn.getPageReference();
47+
let { referenceList } = thePConn.getStateProps().config;
48+
const pageReferenceForRows = referenceList.startsWith(".")
49+
? `${pageReference}.${referenceList.substring(1)}`
50+
: referenceList;
51+
52+
// removing "caseInfo.content" prefix to avoid setting it as a target while preparing pageInstructions
53+
referenceList = pageReferenceForRows.replace(
54+
PCore.getConstants().CASE_INFO.CASE_INFO_CONTENT,
55+
""
56+
);
57+
58+
return {
59+
contextName,
60+
referenceListStr: referenceList,
61+
pageReferenceForRows
62+
};
63+
};
64+
65+
export const populateRowKey = (rawData) => {
66+
return rawData.map((row, index) => {
67+
return { ...row, index };
68+
});
69+
};
70+
71+
export const getApiContext = (processedData, pConnect, reorderCB) => {
72+
return {
73+
fetchData: () => {
74+
return new Promise((resolve) => {
75+
resolve({
76+
data: processedData,
77+
filteredRecordCount: processedData.length,
78+
totalRecordCount: processedData.length
79+
});
80+
});
81+
},
82+
fetchPersonalizations: () => {
83+
return Promise.resolve({});
84+
},
85+
applyRowReorder: (sourceKey, destinationKey) => {
86+
// indexes are keys for simple table so, it should work.
87+
reorderCB();
88+
return Promise.resolve(
89+
pConnect
90+
.getListActions()
91+
.reorder(parseInt(sourceKey, 10), parseInt(destinationKey, 10))
92+
);
93+
}
94+
};
95+
};
96+
97+
export const buildMetaForListView = (
98+
fieldMetadata,
99+
fields,
100+
type,
101+
ruleClass,
102+
name,
103+
propertyLabel,
104+
parameters
105+
) => {
106+
return {
107+
name,
108+
config: {
109+
type,
110+
referenceList: fieldMetadata.datasource.name,
111+
parameters: parameters ?? fieldMetadata.datasource.parameters,
112+
personalization: false,
113+
grouping: true,
114+
globalSearch: true,
115+
reorderFields: true,
116+
toggleFieldVisibility: true,
117+
personalizationId: "" /* TODO */,
118+
template: "ListView",
119+
presets: [
120+
{
121+
name: "presets",
122+
template: "Table",
123+
config: {},
124+
children: [
125+
{
126+
name: "Columns",
127+
type: "Region",
128+
children: fields
129+
}
130+
],
131+
label: propertyLabel,
132+
id: "P_" /* TODO */
133+
}
134+
],
135+
ruleClass
136+
}
137+
};
138+
};
139+
140+
export const buildFieldsForTable = (configFields, fields, bReadOnly) => {
141+
const fieldDefs = configFields.map((field, index) => {
142+
return {
143+
type: "text",
144+
label: fields[index].config.label || fields[index].config.caption,
145+
fillAvailableSpace: !!field.config.fillAvailableSpace,
146+
id: index,
147+
name: field.config.value.substr(4),
148+
cellRenderer: TABLE_CELL,
149+
sort: false,
150+
noContextMenu: true,
151+
showMenu: false,
152+
meta: {
153+
...field
154+
},
155+
// BUG-615253: Workaround for autosize in table with lazy loading components
156+
width: getFiledWidth(field, fields[index].config.label)
157+
};
158+
});
159+
160+
// ONLY add DELETE_ICON to fields when the table is requested as EDITABLE
161+
if (!bReadOnly) {
162+
fieldDefs.push({
163+
type: "text",
164+
id: fieldDefs.length,
165+
cellRenderer: DELETE_ICON,
166+
sort: false,
167+
noContextMenu: true,
168+
showMenu: false,
169+
// BUG-615253: Workaround for autosize in table with lazy loading components
170+
width: 46
171+
});
172+
}
173+
174+
return fieldDefs;
175+
};
176+
177+
export const createMetaForTable = (fields, renderMode) => {
178+
return {
179+
height: {
180+
minHeight: "auto",
181+
fitHeightToElement: "fitHeightToElement",
182+
deltaAdjustment: "deltaAdjustment",
183+
autoSize: true
184+
},
185+
fieldDefs: fields,
186+
itemKey: "index",
187+
grouping: false,
188+
reorderFields: false,
189+
reorderItems: renderMode === "Editable",
190+
dragHandle: renderMode === "Editable",
191+
globalSearch: false,
192+
personalization: false,
193+
toggleFieldVisibility: false,
194+
toolbar: false,
195+
footer: false,
196+
filterExpression: null,
197+
editing: false,
198+
timezone: PCore.getEnvironmentInfo().getTimeZone()
199+
};
200+
};
201+
202+
/**
203+
* This method returns a callBack function for Add action.
204+
* @param {object} pConnect - PConnect object
205+
* @param {number} index - index of the page list to add
206+
*/
207+
export const getAddRowCallback = (pConnect, index) => {
208+
return () => pConnect.getListActions().insert({}, index);
209+
};
210+
211+
/**
212+
* This method creates a PConnect object with proper options for Add and Delete actions
213+
* @param {string} contextName - contextName
214+
* @param {string} referenceList - referenceList
215+
* @param {string} pageReference - pageReference
216+
*/
217+
export const createPConnect = (contextName, referenceList, pageReference) => {
218+
const options = {
219+
context: contextName,
220+
pageReference,
221+
referenceList
222+
};
223+
224+
// create PConnect object
225+
const config = { meta: {}, options };
226+
const { getPConnect } = PCore.createPConnect(config);
227+
228+
return getPConnect();
229+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="psdk-data-readonly">
2+
<strong>simple-table-component</strong> not complete in the Angular SDK. This is a work in progress.
3+
<div *ngIf="requestedReadOnlyMode">
4+
Table is readOnly.
5+
</div>
6+
<div *ngIf="!requestedReadOnlyMode">
7+
You have requested an editable table which is not yet supported. Displaying in a modified readOnly mode.
8+
</div>
9+
</div>
10+
11+
<div class="simple-table-wrapper">
12+
<table mat-table [dataSource]="rowData" class="mat-elevation-z8">
13+
14+
<ng-container *ngFor="let dCol of processedFields" [matColumnDef]="dCol.config.name">
15+
<th mat-header-cell *matHeaderCellDef> {{ dCol.config.label }}</th>
16+
<td mat-cell *matCellDef="let element"> {{ element[dCol.config.name] }} </td>
17+
</ng-container>
18+
19+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
20+
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
21+
</table>
22+
</div>

0 commit comments

Comments
 (0)