From 92a5efa6876db1a497640aeb13fef5c8d99b102d Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Tue, 4 Feb 2020 10:38:14 -0500
Subject: fixing layout stuff

---
 src/client/views/collections/CollectionTimeView.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

diff --git a/src/client/views/collections/CollectionTimeView.tsx b/src/client/views/collections/CollectionTimeView.tsx
index 253dfa890..d1e2844df 100644
--- a/src/client/views/collections/CollectionTimeView.tsx
+++ b/src/client/views/collections/CollectionTimeView.tsx
@@ -43,7 +43,7 @@ export class CollectionTimeView extends CollectionSubView(doc => doc) {
 
     @computed get _allFacets() {
         const facets = new Set<string>();
-        this.childDocs.forEach(child => Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key)));
+        //this.childDocs.forEach(child => Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key)));
         return facets.toArray();
     }
 
-- 
cgit v1.2.3-70-g09d2


From ccedb9302632fcdbc75292b90942a34b98bebcee Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Fri, 7 Feb 2020 13:58:24 -0500
Subject: restored things that cause problems.

---
 src/client/views/MetadataEntryMenu.tsx              | 18 +++++++++++++++++-
 src/client/views/TemplateMenu.tsx                   | 18 +++++++++---------
 src/client/views/collections/CollectionTimeView.tsx |  2 +-
 3 files changed, 27 insertions(+), 11 deletions(-)

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

diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx
index ac152bf67..23b21ae0c 100644
--- a/src/client/views/MetadataEntryMenu.tsx
+++ b/src/client/views/MetadataEntryMenu.tsx
@@ -133,7 +133,23 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
     }
 
     getKeySuggestions = async (value: string): Promise<string[]> => {
-        return [];
+        value = value.toLowerCase();
+        let docs = this.props.docs;
+        if (typeof docs === "function") {
+            if (this.props.suggestWithFunction) {
+                docs = docs();
+            } else {
+                return [];
+            }
+        }
+        docs = await docs;
+        if (docs instanceof Doc) {
+            return Object.keys(docs).filter(key => key.toLowerCase().startsWith(value));
+        } else {
+            const keys = new Set<string>();
+            docs.forEach(doc => Doc.allKeys(doc).forEach(key => keys.add(key)));
+            return Array.from(keys).filter(key => key.toLowerCase().startsWith(value));
+        }
     }
     getSuggestionValue = (suggestion: string) => suggestion;
 
diff --git a/src/client/views/TemplateMenu.tsx b/src/client/views/TemplateMenu.tsx
index 9b0199eac..f61eb9cd0 100644
--- a/src/client/views/TemplateMenu.tsx
+++ b/src/client/views/TemplateMenu.tsx
@@ -94,15 +94,15 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> {
         }
     }
     componentDidMount() {
-        // !this._addedKeys && (this._addedKeys = new ObservableSet());
-        // Array.from(Object.keys(Doc.GetProto(this.props.docViews[0].props.Document))).
-        //     filter(key => key.startsWith("layout_")).
-        //     map(key => runInAction(() => this._addedKeys.add(key.replace("layout_", ""))));
-        // DocListCast(Cast(CurrentUserUtils.UserDocument.expandingButtons, Doc, null)?.data)?.map(btnDoc => {
-        //     if (StrCast(Cast(btnDoc?.dragFactory, Doc, null)?.title)) {
-        //         runInAction(() => this._addedKeys.add(StrCast(Cast(btnDoc?.dragFactory, Doc, null)?.title)));
-        //     }
-        // });
+        !this._addedKeys && (this._addedKeys = new ObservableSet());
+        Array.from(Object.keys(Doc.GetProto(this.props.docViews[0].props.Document))).
+            filter(key => key.startsWith("layout_")).
+            map(key => runInAction(() => this._addedKeys.add(key.replace("layout_", ""))));
+        DocListCast(Cast(CurrentUserUtils.UserDocument.expandingButtons, Doc, null)?.data)?.map(btnDoc => {
+            if (StrCast(Cast(btnDoc?.dragFactory, Doc, null)?.title)) {
+                runInAction(() => this._addedKeys.add(StrCast(Cast(btnDoc?.dragFactory, Doc, null)?.title)));
+            }
+        });
     }
 
     _addedKeys = new ObservableSet();
diff --git a/src/client/views/collections/CollectionTimeView.tsx b/src/client/views/collections/CollectionTimeView.tsx
index d1e2844df..253dfa890 100644
--- a/src/client/views/collections/CollectionTimeView.tsx
+++ b/src/client/views/collections/CollectionTimeView.tsx
@@ -43,7 +43,7 @@ export class CollectionTimeView extends CollectionSubView(doc => doc) {
 
     @computed get _allFacets() {
         const facets = new Set<string>();
-        //this.childDocs.forEach(child => Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key)));
+        this.childDocs.forEach(child => Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key)));
         return facets.toArray();
     }
 
-- 
cgit v1.2.3-70-g09d2


From d310058e80f0896e2724f8723d5b95e1077296c1 Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Fri, 7 Feb 2020 15:06:46 -0500
Subject: fixed __LAYOUT__ and added action() to pivot-in action

---
 src/client/views/collections/CollectionTimeView.tsx | 10 ++++++----
 src/new_fields/Doc.ts                               | 15 +++++++++++----
 src/new_fields/util.ts                              | 15 +++++++--------
 3 files changed, 24 insertions(+), 16 deletions(-)

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

diff --git a/src/client/views/collections/CollectionTimeView.tsx b/src/client/views/collections/CollectionTimeView.tsx
index 0c1f93829..4983acbc2 100644
--- a/src/client/views/collections/CollectionTimeView.tsx
+++ b/src/client/views/collections/CollectionTimeView.tsx
@@ -1,6 +1,6 @@
 import { faEdit } from "@fortawesome/free-solid-svg-icons";
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { action, computed, observable, trace } from "mobx";
+import { action, computed, observable, trace, runInAction } from "mobx";
 import { observer } from "mobx-react";
 import { Set } from "typescript-collections";
 import { Doc, DocListCast, Field } from "../../../new_fields/Doc";
@@ -323,7 +323,9 @@ Scripting.addGlobal(function pivotColumnClick(pivotDoc: Doc, bounds: ViewDefBoun
     let pfilterIndex = NumCast(pivotDoc._pfilterIndex);
     pivotDoc["_pfilter" + pfilterIndex] = ObjectField.MakeCopy(pivotDoc._docFilter as ObjectField);
     pivotDoc._pfilterIndex = ++pfilterIndex;
-    pivotDoc._docFilter = new List();
-    (bounds.payload as string[]).map(filterVal =>
-        Doc.setDocFilter(pivotDoc, StrCast(pivotDoc._pivotField), filterVal, "check"));
+    runInAction(() => {
+        pivotDoc._docFilter = new List();
+        (bounds.payload as string[]).map(filterVal =>
+            Doc.setDocFilter(pivotDoc, StrCast(pivotDoc._pivotField), filterVal, "check"));
+    });
 });
\ No newline at end of file
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 69717e612..3abd6aaa4 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -112,8 +112,11 @@ export class Doc extends RefField {
             get: getter,
             // getPrototypeOf: (target) => Cast(target[SelfProxy].proto, Doc) || null, // TODO this might be able to replace the proto logic in getter
             has: (target, key) => key in target.__fields,
-            ownKeys: target => Object.keys(target.__fields),
+            ownKeys: target => Object.keys(target.__allfields),
             getOwnPropertyDescriptor: (target, prop) => {
+                if (prop.toString() === "__LAYOUT__") {
+                    return Reflect.getOwnPropertyDescriptor(target, prop);
+                }
                 if (prop in target.__fields) {
                     return {
                         configurable: true,//TODO Should configurable be true?
@@ -140,6 +143,12 @@ export class Doc extends RefField {
     private get __fields() {
         return this.___fields;
     }
+    private get __allfields() {
+        let obj = this.___fields;
+        obj.__LAYOUT__ = this.__LAYOUT__;
+        return obj;
+    }
+
 
     private set __fields(value) {
         this.___fields = value;
@@ -173,10 +182,8 @@ export class Doc extends RefField {
         const layoutKey = StrCast(this[SelfProxy].layoutKey);
         const resolvedLayout = Cast(this[SelfProxy][layoutKey], Doc);
         if (resolvedLayout instanceof Doc) {
-            let x = resolvedLayout[Id];
             let layout = (resolvedLayout.layout as string).split("'")[1];
-            const layoutDoc = this[SelfProxy][layout + "-layout[" + x + "]"];
-            return layoutDoc || this[SelfProxy];
+            return this[SelfProxy][layout + "-layout[" + resolvedLayout[Id] + "]"];
         }
         return undefined;
     }
diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts
index 26c10525e..52bb7afcd 100644
--- a/src/new_fields/util.ts
+++ b/src/new_fields/util.ts
@@ -110,15 +110,16 @@ export function setter(target: any, in_prop: string | symbol | number, value: an
             console.log(prop + " is deprecated - switch to _" + prop);
             prop = "_" + prop;
         }
-        const self = target[Self];
-        const layoutDoc = (self || target).__LAYOUT__;
-        if (layoutDoc) layoutDoc[prop] = value;
+        if (target.__LAYOUT__) {
+            target.__LAYOUT__[prop] = value;
+            return true;
+        }
         // const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver);
         // if (resolvedLayout instanceof Doc) {
         //     let x = resolvedLayout[Id];
         //     let layout = (resolvedLayout.layout as string).split("'")[1];
         //     let expanded = getFieldImpl(target, layout + "-layout[" + x + "]", receiver);
-        //     expanded && (expanded[prop] = value);
+        //     //expanded && (expanded[prop] = value);
         //     // resolvedLayout[prop] = value;
         //     return true;
         // }
@@ -134,15 +135,13 @@ export function getter(target: any, in_prop: string | symbol | number, receiver:
             console.log(prop + " is deprecated - switch to _" + prop);
             prop = "_" + prop;
         }
-        const self = target[Self];
-        const layoutDoc = (self || target).__LAYOUT__;
-        if (layoutDoc) return layoutDoc[prop];
+        if (target.__LAYOUT__) return target.__LAYOUT__[prop];
         // const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver);
         // if (resolvedLayout instanceof Doc) {
         //     let x = resolvedLayout[Id];
         //     let layout = (resolvedLayout.layout as string).split("'")[1];
         //     let expanded = getFieldImpl(target, layout + "-layout[" + x + "]", receiver);
-        //     return (expanded || resolvedLayout)?.[prop];
+        //     return (expanded)?.[prop];
         //     //return resolvedLayout[prop];
         // }
     }
-- 
cgit v1.2.3-70-g09d2

