aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/documents/Documents.ts1
-rw-r--r--src/client/views/collections/CollectionPivotView.tsx18
-rw-r--r--src/client/views/collections/CollectionTreeView.tsx7
-rw-r--r--src/new_fields/Doc.ts30
4 files changed, 41 insertions, 15 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 91085cd0f..6cb3f604e 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -129,6 +129,7 @@ export interface DocumentOptions {
isExpanded?: boolean; // is linear view expanded
textTransform?: string; // is linear view expanded
letterSpacing?: string; // is linear view expanded
+ treeViewChecked?: ScriptField; // computes whether or not the checkbox for this facet is checked
}
class EmptyBox {
diff --git a/src/client/views/collections/CollectionPivotView.tsx b/src/client/views/collections/CollectionPivotView.tsx
index 816939a41..546fa3744 100644
--- a/src/client/views/collections/CollectionPivotView.tsx
+++ b/src/client/views/collections/CollectionPivotView.tsx
@@ -10,7 +10,7 @@ import { CollectionTreeView } from "./CollectionTreeView";
import { Cast, StrCast, NumCast } from "../../../new_fields/Types";
import { Docs } from "../../documents/Documents";
import { ScriptField } from "../../../new_fields/ScriptField";
-import { CompileScript } from "../../util/Scripting";
+import { CompileScript, Scripting } from "../../util/Scripting";
import { anchorPoints, Flyout } from "../TemplateMenu";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { List } from "../../../new_fields/List";
@@ -43,9 +43,8 @@ export class CollectionPivotView extends CollectionSubView(doc => doc) {
(childDetailed) =>
DocCastAsync(childDetailed).then(childDetailed => {
if (childDetailed instanceof Doc) {
- const targetKey = "childDetailed";
const captured: { [name: string]: Field } = {};
- captured[targetKey] = new PrefetchProxy(childDetailed);
+ captured.childDetailed = new PrefetchProxy(childDetailed);
const openDocText = "const alias = getAlias(this); Doc.ApplyTemplateTo(childDetailed, alias, 'layout_detailed'); useRightSplit(alias); ";
const openDocScript = CompileScript(openDocText, {
params: { this: Doc.name, heading: "boolean", context: Doc.name },
@@ -76,6 +75,9 @@ export class CollectionPivotView extends CollectionSubView(doc => doc) {
return facets.toArray();
}
+ /**
+ * Responds to clicking the check box in the flyout menu
+ */
facetClick = (facet: string) => {
const facetCollection = this.props.Document.facetCollection;
if (facetCollection instanceof Doc) {
@@ -84,15 +86,9 @@ export class CollectionPivotView extends CollectionSubView(doc => doc) {
//Doc.RemoveDocFromList(facetCollection, "data", DocListCast(facetCollection.data)[found]);
(facetCollection.data as List<Doc>).splice(found, 1);
} else {
- const facetValues = new Set<string>();
- this.childDocs.forEach(child => {
- Object.keys(Doc.GetProto(child)).forEach(key => child[key] instanceof Doc && facetValues.add((child[key] as Doc)[facet]?.toString() || "(null)"));
- facetValues.add(child[facet]?.toString() || "(null)");
- });
-
- const newFacetVals = facetValues.toArray().sort().map(val => Docs.Create.TextDocument({ title: val.toString() }));
- const newFacet = Docs.Create.FreeformDocument(newFacetVals, { title: facet, treeViewOpen: true, isFacetFilter: true });
+ const newFacet = Docs.Create.FreeformDocument([], { title: facet, treeViewOpen: true, isFacetFilter: true });
Doc.AddDocToList(facetCollection, "data", newFacet);
+ newFacet.data = ScriptField.MakeFunction("readFacetData()", { params: {} });
}
}
}
diff --git a/src/client/views/collections/CollectionTreeView.tsx b/src/client/views/collections/CollectionTreeView.tsx
index 4a6dffc1c..2e9f0379c 100644
--- a/src/client/views/collections/CollectionTreeView.tsx
+++ b/src/client/views/collections/CollectionTreeView.tsx
@@ -373,12 +373,12 @@ class TreeView extends React.Component<TreeViewProps> {
@action
bulletClick = (e: React.MouseEvent) => {
if (this.props.onCheckedClick && this.props.document.type !== DocumentType.COL) {
- this.props.document.treeViewChecked = this.props.document.treeViewChecked === "check" ? "x" : this.props.document.treeViewChecked === "x" ? undefined : "check";
+ // this.props.document.treeViewChecked = this.props.document.treeViewChecked === "check" ? "x" : this.props.document.treeViewChecked === "x" ? undefined : "check";
ScriptCast(this.props.onCheckedClick).script.run({
this: this.props.document.isTemplateField && this.props.dataDoc ? this.props.dataDoc : this.props.document,
heading: this.props.containingCollection.title,
checked: this.props.document.treeViewChecked === "check" ? false : this.props.document.treeViewChecked === "x" ? "x" : "none",
- context: this.props.treeViewId
+ context: this.props.treeViewId,
}, console.log);
} else {
this.treeViewOpen = !this.treeViewOpen;
@@ -634,12 +634,11 @@ export class CollectionTreeView extends CollectionSubView(Document) {
}
ContextMenu.Instance.addItem({
description: "Buxton Layout", icon: "eye", event: () => {
- const { TextDocument, ImageDocument, MulticolumnDocument } = Docs.Create;
+ const { TextDocument, ImageDocument } = Docs.Create;
const { Document } = this.props;
const fallback = "http://www.cs.brown.edu/~bcz/face.gif";
const wrapper = Docs.Create.StackingDocument([
ImageDocument(fallback, { title: "hero" }),
- MulticolumnDocument([], { title: "data", height: 100 }),
...["short_description", "year", "company", "degrees_of_freedom"].map(key => TextDocument({ title: key }))
], { autoHeight: true, chromeStatus: "disabled" });
wrapper.disableLOD = true;
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index fa5ca1489..74b8df1a0 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -16,6 +16,7 @@ import { deleteProperty, getField, getter, makeEditable, makeReadOnly, setter, u
import { intersectRect } from "../Utils";
import { UndoManager } from "../client/util/UndoManager";
import { computedFn } from "mobx-utils";
+import { Docs } from "../client/documents/Documents";
export namespace Field {
export function toKeyValueString(doc: Doc, key: string): string {
@@ -823,4 +824,33 @@ Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: an
}
const docFilterText = Doc.MakeDocFilter(docFilters);
container.viewSpecScript = docFilterText ? ScriptField.MakeFunction(docFilterText, { doc: Doc.name }) : undefined;
+});
+
+Scripting.addGlobal(function readFacetData(target: Doc, facet: string) {
+ const facetValues = new Set<string>();
+ DocListCast(target.dataField).forEach(child => {
+ Object.keys(Doc.GetProto(child)).forEach(key => child[key] instanceof Doc && facetValues.add((child[key] as Doc)[facet]?.toString() || "(null)"));
+ facetValues.add(child[facet]?.toString() || "(null)");
+ });
+ return Array.from(facetValues).sort().map(val => {
+ const capturedVariables: { [name: string]: Field } = {};
+ capturedVariables.facet = val;
+ capturedVariables.container = target;
+ return Docs.Create.TextDocument({
+ title: val.toString(),
+ treeViewChecked: ScriptField.MakeFunction("readCheckedState(container, facetValue)", { capturedVariables })
+ });
+ });
+});
+
+Scripting.addGlobal(function readCheckedState(container: Doc, facetValue: string) {
+ const docFilters = Cast(container.docFilter, listSpec("string"), []);
+ for (let i = 0; i < docFilters.length; i += 3) {
+ const key = docFilters[i];
+ const value = docFilters[i + 1];
+ if (key === facetValue) {
+ return value;
+ }
+ }
+ return false;
}); \ No newline at end of file