Mike's patch plus some fixes.
Signed-off-by: Bill Erickson <berickxx@gmail.com>
switch (datatype) {
+ case 'link':
+ if (typeof value !== 'object') {
+ return value + ''; // no fleshed value here
+ }
+
+ if (!params.idlClass || !params.idlField) {
+ // Without a full accounting of the field data,
+ // we can't determine the display value.
+ return value + '';
+ }
+
+ const localClass = this.idl.classes[params.idlClass];
+
+ if (!localClass) {
+ console.warn(`No such IDL class ${params.idlClass}`);
+ return value + '';
+ }
+
+ if (!localClass.field_map[params.idlField]) {
+ console.warn(`IDL class ${params.idlClass} ` +
+ `has no field named "${params.idlField}"`);
+ return value + '';
+ }
+
+ const linkType = localClass.field_map[params.idlField]['reltype'];
+ if (linkType !== 'has_a') {
+ return value + ''; // eh?
+ }
+
+ const localField = localClass.field_map[params.idlField];
+ const remoteKey = localField['key'];
+
+ const remoteClass = this.idl.classes[localField['class']];
+ const remoteField = remoteClass.field_map[remoteKey];
+ const remoteSelector = remoteField.selector || remoteField.name;
+
+ return value[remoteSelector]() + '';
+
case 'org_unit':
const orgField = params.orgField || 'shortname';
const org = this.org.get(value);
hidden: boolean;
visible: boolean;
sort: number;
+ // IDL class of the object which contains this field.
+ // Not to be confused with the class of a linked object.
idlClass: string;
idlFieldDef: any;
datatype: string;
const idlInfo = this.idlInfoFromDotpath(col.path);
if (idlInfo) {
col.idlFieldDef = idlInfo.idlField;
+ col.idlClass = idlInfo.idlClass.name;
if (!col.label) {
col.label = col.idlFieldDef.label || col.idlFieldDef.name;
col.datatype = col.idlFieldDef.datatype;
return this.format.transform({
value: val,
+ idlClass: col.idlClass,
+ idlField: col.idlFieldDef ? col.idlFieldDef.name : col.name,
datatype: col.datatype,
datePlusTime: Boolean(col.datePlusTime)
});
if (!col.datatype) {
col.datatype = idlField.datatype;
}
+ if (!col.idlFieldDef) {
+ idlField = col.idlFieldDef;
+ }
+ if (!col.idlClass) {
+ col.idlClass = idlClassDef.name;
+ }
if (!col.label) {
col.label = idlField.label || idlField.name;
}
col.name = field.name;
col.label = field.label || field.name;
col.idlFieldDef = field;
+ col.idlClass = this.columnSet.idlClass;
col.datatype = field.datatype;
col.isIndex = (field.name === pkeyField);
col.isAuto = true;
this.dataSource.getRows = (pager: Pager, sort: any[]) => {
const orderBy: any = {};
+ const fleshList: any = {};
if (sort.length) {
// Sort specified from grid
orderBy[this.idlClass] = this.sortField;
}
+ fleshList[this.idlClass] = [];
+ this.idlClassDef.fields.forEach(field => {
+ if (field['datatype'] === 'link'
+ && field['reltype'] === 'has_a'
+ && field['class'] !== 'aou'
+ ) { // Ignore aou, that's handled separately via cached data
+
+ const remoteClass = this.idl.classes[field['class']];
+ const remoteKey = remoteClass.pkey || 'id';
+ const remoteField = remoteClass.field_map[remoteKey];
+
+ if (remoteField.selector) { // only flesh fields with a selector
+ fleshList[this.idlClass].push(field['name']);
+ }
+ }
+ });
+
const searchOps = {
offset: pager.offset,
limit: pager.limit,
- order_by: orderBy
+ order_by: orderBy,
+ flesh_fields: fleshList,
+ flesh: 1
};
if (this.contextOrg) {