aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-12-21 14:56:03 -0500
committerbobzel <zzzman@gmail.com>2023-12-21 14:56:03 -0500
commit6693adb16545cc932fe9d244a15c658288adadc7 (patch)
tree952b10edff955579da90a096532bd6a45defa400 /src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
parent1caba64ee0f32ee8af79263cd4ef2a8bc5d5146e (diff)
fixes post-merge for dataViz-annotations
Diffstat (limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 1f4688729..88cdd51ff 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -52,6 +52,7 @@ import { CollectionFreeFormPannableContents } from './CollectionFreeFormPannable
import { CollectionFreeFormRemoteCursors } from './CollectionFreeFormRemoteCursors';
import './CollectionFreeFormView.scss';
import { MarqueeView } from './MarqueeView';
+import { SchemaCSVPopUp } from '../../nodes/DataVizBox/SchemaCSVPopUp';
export type collectionFreeformViewProps = {
NativeWidth?: () => number;
@@ -1982,3 +1983,40 @@ ScriptingGlobals.add(function bringToFront() {
ScriptingGlobals.add(function sendToBack(doc: Doc) {
SelectionManager.Views.forEach(view => view.CollectionFreeFormView?.bringToFront(view.Document, true));
});
+ScriptingGlobals.add(function datavizFromSchema(doc: Doc) {
+ SelectionManager.Views.forEach(view => {
+ if (!view.layoutDoc.schema_columnKeys){
+ view.layoutDoc.schema_columnKeys = new List<string>(['title', 'type', 'author', 'author_date'])
+ }
+ const keys = Cast(view.layoutDoc.schema_columnKeys, listSpec('string'))?.filter(key => key!="text");
+ if (!keys) return;
+
+ const children = DocListCast(view.Document[Doc.LayoutFieldKey(view.Document)]);
+ let csvRows = [];
+ csvRows.push(keys.join(','));
+ for (let i=0; i < children.length; i++) {
+ let eachRow = [];
+ for (let j=0; j<keys.length; j++){
+ var cell = children[i][keys[j]];
+ if (cell && cell as string) cell = cell.toString().replace(/\,/g, '');
+ eachRow.push(cell);
+ }
+ csvRows.push(eachRow);
+ }
+ const blob = new Blob([csvRows.join('\n')], { type: 'text/csv' });
+ const options = { x:0, y:-300, title: 'schemaTable', _width: 300, _height: 100, type: 'text/csv' };
+ const file = new File([blob], 'schemaTable', options);
+ const loading = Docs.Create.LoadingDocument(file, options);
+ loading.presentation_openInLightbox = true;
+ DocUtils.uploadFileToDoc(file, {}, loading);
+
+ if (view.ComponentView?.addDocument) {
+ // loading.dataViz_fromSchema = true;
+ loading.dataViz_asSchema = view.layoutDoc;
+ SchemaCSVPopUp.Instance.setView(view);
+ SchemaCSVPopUp.Instance.setTarget(view.layoutDoc);
+ SchemaCSVPopUp.Instance.setDataVizDoc(loading);
+ SchemaCSVPopUp.Instance.setVisible(true);
+ }
+ })
+});