This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register formula dependencies and listen for chnge
- Loading branch information
Vic van Cooten
committed
Sep 30, 2021
1 parent
4340d2e
commit 04b4a05
Showing
5 changed files
with
282 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Formula from "../index"; | ||
|
||
/* | ||
* AND(...arg1, etc) | ||
* returns true if ALL children are true | ||
*/ | ||
|
||
export default { | ||
execute: (fArguments, data, formula: Formula) => | ||
new Promise(async (resolve, reject) => { | ||
let isTrue = true; | ||
for (let x = 0; x < fArguments.length; x++) { | ||
if (fArguments[x] !== true) isTrue = false; | ||
} | ||
|
||
resolve(isTrue); | ||
}), | ||
onCompile: (fArguments) => { | ||
const deps = []; | ||
|
||
// For each argument, check if their type is string (so not a "string", but a string). If so, it refers to a field and is a dependency. | ||
for (let x = 0; x < fArguments.length; x++) { | ||
if (typeof fArguments[x] === "string") deps.push(fArguments[x]); | ||
} | ||
|
||
return deps; | ||
}, | ||
// Give a sample result so it's parent functions know what we will return on execute and can perform the right precompiling. | ||
returnPreview: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import and from "./and"; | ||
|
||
const functions = { | ||
and, | ||
}; | ||
|
||
export default functions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Collection } from "mongodb"; | ||
|
||
/* Server technical types */ | ||
export interface DBCollectionsType { | ||
models: Collection; | ||
objects: Collection; | ||
usersettings: Collection; | ||
} | ||
|
||
/* Model */ | ||
export interface ModelType { | ||
_id: string; | ||
key: string; | ||
key_plural: string; | ||
label: string; | ||
label_plural: string; | ||
app: string; | ||
primary: string; | ||
icon: string; | ||
locked?: boolean; | ||
fields: { [key: string]: ModelFieldType }; | ||
layouts: { [key: string]: ModelLayoutType }; | ||
lists: { [key: string]: ModelListType }; | ||
permissions: { | ||
create: string[]; | ||
read: string[]; | ||
read_own: string[]; | ||
update: string[]; | ||
update_own: string[]; | ||
delete: string[]; | ||
delete_own: string[]; | ||
}; | ||
} | ||
|
||
// Field | ||
export interface ModelFieldType { | ||
label: string; | ||
type?: "text" | "number" | "relationship" | "formula" | "options"; | ||
required?: boolean; | ||
unique?: boolean; | ||
// Options | ||
selectMultiple?: boolean; | ||
optionsDisplayAs?: "dropdown" | "list" | string; | ||
options?: { label: string; value: string }[]; | ||
// Relationship | ||
relationshipTo?: string; | ||
// Formula | ||
formula?: string; | ||
} | ||
|
||
// Layout | ||
export interface ModelLayoutType { | ||
label: string; | ||
layout: LayoutItemType[]; | ||
} | ||
export interface LayoutItemType { | ||
key?: string; | ||
label: string; | ||
type: string; | ||
items?: LayoutItemType[]; | ||
args?: { [key: string]: any }; | ||
} | ||
|
||
// List | ||
export interface ModelListType { | ||
label?: string; | ||
filter?: {}; | ||
fields?: string[]; | ||
} | ||
|
||
/* Object types */ | ||
export interface ObjectType { | ||
_id: string; | ||
meta: { | ||
model: string; | ||
createdOn: Date; | ||
lastModifiedOn: Date; | ||
createdBy: string; | ||
lastModifiedBy: string; | ||
owner: string; | ||
team?: string; | ||
}; | ||
[key: string]: any; | ||
} | ||
|
||
export interface UserObjectType extends ObjectType { | ||
username: string; | ||
first_name: string; | ||
last_name: string; | ||
email: string; | ||
password: string; | ||
roles: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters