From cc6b30d2824ad5ff686fe728587d89d17aa3c8b2 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Wed, 22 Jan 2020 01:00:09 -0500 Subject: fixed pivot viewer to not have multiple columns with the same value. fixed imagebox to show fade views. cleaned up makeMetadataFieldTemplate --- .../CollectionFreeFormLayoutEngines.tsx | 4 +- src/client/views/nodes/ImageBox.tsx | 2 +- src/new_fields/Doc.ts | 76 +++++++++++----------- 3 files changed, 42 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx index 5924c3afb..5c6336248 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx @@ -8,7 +8,6 @@ import { emptyFunction } from "../../../../Utils"; import React = require("react"); import { ObservableMap, runInAction } from "mobx"; import { Id, ToString } from "../../../../new_fields/FieldSymbols"; -import { DateField } from "../../../../new_fields/DateField"; import { ObjectField } from "../../../../new_fields/ObjectField"; import { RefField } from "../../../../new_fields/RefField"; @@ -47,8 +46,9 @@ export function computePivotLayout(poolData: ObservableMap, pivotDo const pivotAxisWidth = NumCast(pivotDoc.pivotWidth, 200); const pivotColumnGroups = new Map, Doc[]>(); + const pivotFieldKey = toLabel(pivotDoc.pivotField); for (const doc of childDocs) { - const val = doc[StrCast(pivotDoc.pivotField, "title")]; + const val = Field.toString(doc[pivotFieldKey] as Field); if (val) { !pivotColumnGroups.get(val) && pivotColumnGroups.set(val, []); pivotColumnGroups.get(val)!.push(doc); diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index 634555012..4b2a1c1cb 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -319,7 +319,7 @@ export class ImageBox extends DocAnnotatableComponent - {fadepath === srcpath ? (null) :
+ {fadepath === srcpath ? (null) :
{ - !templateDataDoc[metadataFieldName] && data instanceof ObjectField && (Doc.GetProto(templateDataDoc)[metadataFieldName] = ObjectField.MakeCopy(data)); - const layout = StrCast(fieldLayoutDoc.layout).replace(/fieldKey={'[^']*'}/, `fieldKey={'${metadataFieldName}'}`); - const layoutDelegate = Doc.Layout(fieldTemplate); - layoutDelegate[metadataFieldName + "_ext"] = fieldLayoutExt; - layoutDelegate.layout = layout; - fieldTemplate.layout = layoutDelegate !== fieldTemplate ? layoutDelegate : layout; - if (fieldTemplate.backgroundColor !== templateDataDoc.defaultBackgroundColor) fieldTemplate.defaultBackgroundColor = fieldTemplate.backgroundColor; - fieldTemplate.proto = templateDataDoc; - // }), 0); + // + // This function converts a generic field layout display into a field layout that displays a specific + // metadata field indicated by the title of the template field (not the default field that it was rendering) + // + export function MakeMetadataFieldTemplate(templateField: Doc, templateDoc: Doc, suppressTitle: boolean = false): boolean { + + // find the metadata field key that this template field doc will display (indicated by its title) + const metadataFieldKey = StrCast(templateField.title).replace(/^-/, ""); + + // update the original template to mark it as a template + templateField.templateField = metadataFieldKey; + templateField.isTemplateField = true; + templateField.title = metadataFieldKey; + templateField.showTitle = suppressTitle ? undefined : "title"; + + // move any data that the template field had been rendering over to the template doc so that things will + // appear the same after the conversion to a template has completed. (otherwise, there would be no data for the template to render) + // note: this will not overwrite any field that already exists on the template doc at the field key + if (!templateDoc[metadataFieldKey] && templateField.data instanceof ObjectField) { + (Doc.GetProto(templateDoc)[metadataFieldKey] = ObjectField.MakeCopy(templateField.data)); + } + + // get the layout string that the template uses to specify its layout + const templateFieldLayoutString = StrCast(Doc.LayoutField(Doc.Layout(templateField))); + + // change itto render the target metadata field instead of what it was rendering before and assign it to the template field layout document. + Doc.Layout(templateField).layout = templateFieldLayoutString.replace(/fieldKey={'[^']*'}/, `fieldKey={'${metadataFieldKey}'}`); + + // assign the template field doc a delegate of any extension document that was previously used to render the template field (since extension doc's carry rendering informatino) + Doc.Layout(templateField)[metadataFieldKey + "_ext"] = Doc.MakeDelegate(templateField[templateFieldLayoutString?.split("'")[1] + "_ext"] as Doc); + + if (templateField.backgroundColor !== templateDoc.defaultBackgroundColor) { + templateField.defaultBackgroundColor = templateField.backgroundColor; + } + + // finally, make the templateField be a delegate of the templateDoc so that it can find all the fields needed to render itselt + // (note that this is only useful to see the template doc itself which may not be necessary for many use cases) + templateField.proto = templateDoc; return true; } -- cgit v1.2.3-70-g09d2