aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/Doc.ts
diff options
context:
space:
mode:
authorTyler Schicke <tschicke@gmail.com>2020-01-11 14:10:59 -0800
committerTyler Schicke <tschicke@gmail.com>2020-01-11 14:10:59 -0800
commitf24fcf4df595542d47ec9b98e173979656db68bd (patch)
treedaf32c16ac99add88460980a6f19925806eb51da /src/new_fields/Doc.ts
parenta2f423fa31e649805e7dd087037a5fe262c44a4a (diff)
parent54a241ff71abc07a5dbdebce1b614f1024a767e6 (diff)
Merge branch 'master' of github.com:browngraphicslab/Dash-Web into no_db
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r--src/new_fields/Doc.ts8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 8e0b28606..8117453e7 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -10,7 +10,7 @@ import { ObjectField } from "./ObjectField";
import { PrefetchProxy, ProxyField } from "./Proxy";
import { FieldId, RefField } from "./RefField";
import { listSpec } from "./Schema";
-import { ComputedField } from "./ScriptField";
+import { ComputedField, ScriptField } from "./ScriptField";
import { BoolCast, Cast, FieldValue, NumCast, PromiseValue, StrCast, ToConstructor } from "./Types";
import { deleteProperty, getField, getter, makeEditable, makeReadOnly, setter, updateFunction } from "./util";
import { intersectRect } from "../Utils";
@@ -760,4 +760,10 @@ Scripting.addGlobal(function selectDoc(doc: any) { Doc.UserDoc().SelectedDocs =
Scripting.addGlobal(function selectedDocs(container: Doc, excludeCollections: boolean, prevValue: any) {
const docs = DocListCast(Doc.UserDoc().SelectedDocs).filter(d => !Doc.AreProtosEqual(d, container) && !d.annotationOn && d.type !== DocumentType.DOCUMENT && d.type !== DocumentType.KVP && (!excludeCollections || !Cast(d.data, listSpec(Doc), null)));
return docs.length ? new List(docs) : prevValue;
+});
+Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, type: string, contains: boolean = true) {
+ const scriptText = `${contains ? "" : "!"}(((doc.${key} && (doc.${key} as ${type})${type === "string" ? ".includes" : "<="}(${value}))) ||
+ ((doc.data_ext && doc.data_ext.${key}) && (doc.data_ext.${key} as ${type})${type === "string" ? ".includes" : "<="}(${value}))))`;
+ container.docFilter = scriptText;
+ container.viewSpecScript = ScriptField.MakeFunction(scriptText, { doc: Doc.name });
}); \ No newline at end of file