-
Notifications
You must be signed in to change notification settings - Fork 2
/
DropdownEditorSetup.tsx
138 lines (130 loc) · 4.47 KB
/
DropdownEditorSetup.tsx
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
import { DropdownColumnDrivers, DropdownDataTable } from "modules/Editors/DropdownEditor/DropdownTableModel";
import { IDriverState } from "modules/Editors/DropdownEditor/Cells/IDriverState";
import { findStopping } from "xmlInterpreters/xmlUtils";
import { getMomentFormat } from "xmlInterpreters/getMomentFormat";
import { TextCellDriver } from "modules/Editors/DropdownEditor/Cells/TextCellDriver";
import { NumberCellDriver } from "modules/Editors/DropdownEditor/Cells/NumberCellDriver";
import { BooleanCellDriver } from "modules/Editors/DropdownEditor/Cells/BooleanCellDriver";
import { DateCellDriver } from "modules/Editors/DropdownEditor/Cells/DateCellDriver";
import { DefaultHeaderCellDriver } from "modules/Editors/DropdownEditor/Cells/HeaderCell";
export class DropdownEditorSetup {
constructor(
public propertyId: string,
public lookupId: string,
public columnNames: string[],
public visibleColumnNames: string[],
public columnNameToIndex: Map<string, number>,
public showUniqueValues: boolean,
public identifier: string,
public identifierIndex: number,
public parameters: { [key: string]: any },
public dropdownType: string,
public cached: boolean,
public searchByFirstColumnOnly: boolean,
public columnDrivers: DropdownColumnDrivers,
public isLink?: boolean,
) {
}
}
export function DropdownEditorSetupFromXml(
xmlNode: any,
dropdownEditorDataTable: DropdownDataTable,
dropdownEditorBehavior: IDriverState,
customStyle: {[key: string]: string} | undefined,
isLink: boolean | undefined
): DropdownEditorSetup {
const attributes = xmlNode.attributes;
const lookupId = attributes.LookupId;
const propertyId = attributes.Id;
const showUniqueValues = attributes.DropDownShowUniqueValues === "true";
const identifier = attributes.Identifier;
let identifierIndex = 0;
const dropdownType = attributes.DropDownType;
const cached = attributes.Cached === "true";
const searchByFirstColumnOnly = attributes.SearchByFirstColumnOnly === "true";
const columnNames: string[] = [identifier];
const visibleColumnNames: string[] = [];
const columnNameToIndex = new Map<string, number>([[identifier, identifierIndex]]);
let index = 0;
const drivers = new DropdownColumnDrivers();
drivers.customFieldStyle = customStyle;
if (attributes.SuppressEmptyColumns === "true") {
drivers.driversFilter = (driver) => {
return dropdownEditorDataTable.columnIdsWithNoData.indexOf(driver.columnId) < 0;
};
}
for (let propertyXml of findStopping(xmlNode, (n) => n.name === "Property")) {
index++;
const attributes = propertyXml.attributes;
const id = attributes.Id;
columnNames.push(id);
columnNameToIndex.set(id, index);
const formatterPattern = attributes.FormatterPattern
? getMomentFormat(propertyXml)
: "";
visibleColumnNames.push(id);
const name = attributes.Name;
const column = attributes.Column;
let bodyCellDriver;
switch (column) {
case "Text":
bodyCellDriver = new TextCellDriver(
index,
dropdownEditorDataTable,
dropdownEditorBehavior,
index == 1 ? customStyle : undefined
);
break;
case "Number":
bodyCellDriver = new NumberCellDriver(
index,
dropdownEditorDataTable,
dropdownEditorBehavior
);
break;
case "CheckBox":
bodyCellDriver = new BooleanCellDriver(
index,
dropdownEditorDataTable,
dropdownEditorBehavior
);
break;
case "Date":
bodyCellDriver = new DateCellDriver(
index,
dropdownEditorDataTable,
dropdownEditorBehavior,
formatterPattern
);
break;
default:
throw new Error("Unknown column type " + column);
}
drivers.allDrivers.push({
columnId: id,
headerCellDriver: new DefaultHeaderCellDriver(name, index == 1 ? customStyle : undefined),
bodyCellDriver,
});
}
const parameters: { [k: string]: any } = {};
for (let ddp of findStopping(xmlNode, (n) => n.name === "ComboBoxParameterMapping")) {
const pat = ddp.attributes;
parameters[pat.ParameterName] = pat.FieldName;
}
return new DropdownEditorSetup(
propertyId,
lookupId,
columnNames,
visibleColumnNames,
columnNameToIndex,
showUniqueValues,
identifier,
identifierIndex,
parameters,
dropdownType,
cached,
searchByFirstColumnOnly,
drivers,
isLink
);
}