From d8c065935a0cb5a89b6d76407b7729f8584424eb Mon Sep 17 00:00:00 2001
From: Sam Wilkins <samwilkins333@gmail.com>
Date: Tue, 6 Aug 2019 22:03:59 -0400
Subject: pivot view

---
 .../collectionFreeForm/CollectionFreeFormView.tsx  | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 7ba13e961..17c4e83b0 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -37,6 +37,7 @@ import "./CollectionFreeFormView.scss";
 import { MarqueeView } from "./MarqueeView";
 import React = require("react");
 import { DocumentType, Docs } from "../../../documents/Documents";
+import { RouteStore } from "../../../../server/RouteStore";
 
 library.add(faEye as any, faTable, faPaintBrush, faExpandArrowsAlt, faCompressArrowsAlt, faCompass, faUpload, faBraille, faChalkboard);
 
@@ -48,6 +49,20 @@ export const panZoomSchema = createSchema({
     arrangeInit: ScriptField,
 });
 
+export namespace PivotView {
+
+    export let arrangeInit: string;
+    export let arrangeScript: string;
+
+    export async function loadLayouts() {
+        let response = await fetch(Utils.prepend("/layoutscripts"));
+        let scripts = JSON.parse(await response.text());
+        arrangeInit = scripts[0];
+        arrangeScript = scripts[1];
+    }
+
+}
+
 type PanZoomDocument = makeInterface<[typeof panZoomSchema, typeof positionSchema, typeof pageSchema]>;
 const PanZoomDocument = makeInterface(panZoomSchema, positionSchema, pageSchema);
 
@@ -787,6 +802,23 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
         };
     }
 
+    public static SetPivotLayout = (target: Doc) => {
+        let setSpecifiedLayoutField = (originalText: string, key: string, params: Record<string, string>, requiredType?: string) => {
+            const script = CompileScript(originalText, {
+                params,
+                requiredType,
+                typecheck: false
+            });
+            if (!script.compiled) {
+                console.log(script.errors.map(error => error.messageText).join("\n"));
+                return;
+            }
+            target[key] = new ScriptField(script);
+        };
+        setSpecifiedLayoutField(PivotView.arrangeInit, "arrangeInit", { collection: "Doc", docs: "Doc[]" }, undefined);
+        setSpecifiedLayoutField(PivotView.arrangeScript, "arrangeScript", { doc: "Doc", index: "number", collection: "Doc", state: "any", docs: "Doc[]" }, "{x: number, y: number, width?: number, height?: number}");
+    }
+
     render() {
         const easing = () => this.props.Document.panTransformType === "Ease";
         Doc.UpdateDocumentExtensionForField(this.props.DataDoc ? this.props.DataDoc : this.props.Document, this.props.fieldKey);
-- 
cgit v1.2.3-70-g09d2

