From 44aa6fe49de97998fd84a6d6331501c8a1d7a775 Mon Sep 17 00:00:00 2001
From: Tyler Schicke <tyler_schicke@brown.edu>
Date: Sun, 7 Apr 2019 01:14:31 -0400
Subject: Refactored scripting to seperate compilation and execution

---
 src/client/views/collections/CollectionSchemaView.tsx | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

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

diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx
index 0ff6c3b40..afe530c1a 100644
--- a/src/client/views/collections/CollectionSchemaView.tsx
+++ b/src/client/views/collections/CollectionSchemaView.tsx
@@ -87,11 +87,13 @@ export class CollectionSchemaView extends CollectionViewBase {
         let reference = React.createRef<HTMLDivElement>();
         let onItemDown = setupDrag(reference, () => props.doc, (containingCollection: CollectionView) => this.props.removeDocument(props.doc));
         let applyToDoc = (doc: Document, value: string) => {
-            let script = CompileScript(value, { this: doc }, true);
+            let script = CompileScript(value, { addReturn: true, params: { this: "Document" } });
             if (!script.compiled) {
                 return false;
             }
-            let field = script();
+            const res = script.run({ this: doc });
+            if (!res.success) return false;
+            const field = res.result;
             if (field instanceof Field) {
                 doc.Set(props.fieldKey, field);
                 return true;
@@ -121,6 +123,7 @@ export class CollectionSchemaView extends CollectionViewBase {
                         return applyToDoc(props.doc, value);
                     }}
                     OnFillDown={(value: string) => {
+                        //TODO This should be able to be refactored to compile the script once
                         this.props.Document.GetTAsync<ListField<Document>>(this.props.fieldKey, ListField).then((val) => {
                             if (val) {
                                 val.Data.forEach(doc => applyToDoc(doc, value));
-- 
cgit v1.2.3-70-g09d2


From bf05eac7677997075bc58d2b70c3e101e2e87560 Mon Sep 17 00:00:00 2001
From: Tyler Schicke <tyler_schicke@brown.edu>
Date: Sun, 7 Apr 2019 17:39:23 -0400
Subject: Refactored schema scripting Changed tree view style to not be global

---
 .../views/collections/CollectionSchemaView.tsx     | 21 ++++--
 .../views/collections/CollectionTreeView.scss      | 86 +++++++++++-----------
 2 files changed, 55 insertions(+), 52 deletions(-)

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

diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx
index afe530c1a..b10aaba98 100644
--- a/src/client/views/collections/CollectionSchemaView.tsx
+++ b/src/client/views/collections/CollectionSchemaView.tsx
@@ -86,12 +86,8 @@ export class CollectionSchemaView extends CollectionViewBase {
         )
         let reference = React.createRef<HTMLDivElement>();
         let onItemDown = setupDrag(reference, () => props.doc, (containingCollection: CollectionView) => this.props.removeDocument(props.doc));
-        let applyToDoc = (doc: Document, value: string) => {
-            let script = CompileScript(value, { addReturn: true, params: { this: "Document" } });
-            if (!script.compiled) {
-                return false;
-            }
-            const res = script.run({ this: doc });
+        let applyToDoc = (doc: Document, run: (args?: { [name: string]: any }) => any) => {
+            const res = run({ this: doc });
             if (!res.success) return false;
             const field = res.result;
             if (field instanceof Field) {
@@ -120,13 +116,22 @@ export class CollectionSchemaView extends CollectionViewBase {
                         return field || "";
                     }}
                     SetValue={(value: string) => {
-                        return applyToDoc(props.doc, value);
+                        let script = CompileScript(value, { addReturn: true, params: { this: "Document" } });
+                        if (!script.compiled) {
+                            return false;
+                        }
+                        return applyToDoc(props.doc, script.run);
                     }}
                     OnFillDown={(value: string) => {
+                        let script = CompileScript(value, { addReturn: true, params: { this: "Document" } });
+                        if (!script.compiled) {
+                            return;
+                        }
+                        const run = script.run;
                         //TODO This should be able to be refactored to compile the script once
                         this.props.Document.GetTAsync<ListField<Document>>(this.props.fieldKey, ListField).then((val) => {
                             if (val) {
-                                val.Data.forEach(doc => applyToDoc(doc, value));
+                                val.Data.forEach(doc => applyToDoc(doc, run));
                             }
                         })
                     }}>
diff --git a/src/client/views/collections/CollectionTreeView.scss b/src/client/views/collections/CollectionTreeView.scss
index 5a14aa54d..f2affbf55 100644
--- a/src/client/views/collections/CollectionTreeView.scss
+++ b/src/client/views/collections/CollectionTreeView.scss
@@ -1,64 +1,62 @@
 @import "../global_variables";
-#body {
+
+.collectionTreeView-dropTarget {
+    border: 0px solid transparent;
+    border-radius: $border-radius;
+    box-sizing: border-box;
+    height: 100%;
     padding: 20px;
     padding-left: 10px;
     padding-right: 0px;
     background: $light-color-secondary;
     font-size: 13px;
     overflow: scroll;
-}
 
-ul {
-    list-style: none;
-    padding-left: 20px;
-}
+    ul {
+        list-style: none;
+        padding-left: 20px;
+    }
 
-li {
-    margin: 5px 0;
-}
+    li {
+        margin: 5px 0;
+    }
 
-.collection-child {
-    margin-top: 10px;
-    margin-bottom: 10px;
-}
+    .collection-child {
+        margin-top: 10px;
+        margin-bottom: 10px;
+    }
 
-.no-indent {
-    padding-left: 0;
-}
+    .no-indent {
+        padding-left: 0;
+    }
 
-.bullet {
-    width: 1.5em;
-    display: inline-block;
-    color: $intermediate-color;
-}
+    .bullet {
+        width: 1.5em;
+        display: inline-block;
+        color: $intermediate-color;
+    }
 
-.coll-title {
-    font-size: 24px;
-    margin-bottom: 20px;
-}
+    .coll-title {
+        font-size: 24px;
+        margin-bottom: 20px;
+    }
 
-.collectionTreeView-dropTarget {
-    border: 0px solid transparent;
-    border-radius: $border-radius;
-    box-sizing: border-box;
-    height: 100%;
-}
+    .docContainer {
+        display: inline-table;
+    }
 
-.docContainer {
-    display: inline-table;
-}
+    .docContainer:hover {
+        .delete-button {
+            display: inline;
+            width: auto;
+        }
+    }
 
-.docContainer:hover {
     .delete-button {
+        color: $intermediate-color;
+        float: right;
+        margin-left: 15px;
+        margin-top: 3px;
         display: inline;
-        width: auto;
     }
-}
-
-.delete-button {
-    color: $intermediate-color;
-    float: right;
-    margin-left: 15px;
-    margin-top: 3px;
-    display: inline;
 }
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

