From c3ca0179b8a5672037d27af59faf64a50fe4f097 Mon Sep 17 00:00:00 2001 From: srichman333 Date: Mon, 27 Nov 2023 02:05:29 -0500 Subject: schema to dataviz --- src/client/util/CurrentUserUtils.ts | 1 + .../collectionFreeForm/CollectionFreeFormView.tsx | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index ac506e2d6..1068e26bb 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -688,6 +688,7 @@ export class CurrentUserUtils { return [ {title: "Preview", toolTip: "Show selection preview", btnType: ButtonType.ToggleButton, icon: "portrait", scripts:{ onClick: '{ return toggleSchemaPreview(_readOnly_); }'} }, {title: "1 Line",toolTip: "Single Line Rows", btnType: ButtonType.ToggleButton, icon: "eye", scripts:{ onClick: '{ return toggleSingleLineSchema(_readOnly_); }'} }, + {title: "DataViz",toolTip: "Turn Schema Table into Data Visualization Doc", btnType: ButtonType.ClickButton, icon: "chart-bar", scripts:{ onClick: '{ datavizFromSchema()'} }, ]; } diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index e350c35cc..04e5ebb2c 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -1973,3 +1973,27 @@ ScriptingGlobals.add(function bringToFront() { ScriptingGlobals.add(function sendToBack(doc: Doc) { SelectionManager.Views().forEach(view => view.CollectionFreeFormView?.bringToFront(view.rootDoc, true)); }); +ScriptingGlobals.add(function datavizFromSchema(doc: Doc) { + SelectionManager.Views().forEach(view => { + const keys = Cast(view.rootDoc.schema_columnKeys, listSpec('string'))?.filter(key => key!="text"); + + if (!keys) return; + const children = DocListCast(view.rootDoc[Doc.LayoutFieldKey(view.rootDoc)]); + let csvRows = []; + csvRows.push(keys.join(',')); + for (let i=0; i < children.length; i++) { + let eachRow = []; + for (let j=0; j