Appearance
Schema
The active schema is edited directly in CMS interface (if permission is given), and is stored as a single document in Firestore.
Having the schema as a Firestore document, gives great flexibility in real-time syncing and allows for easy backups and replication.
Collections
Collections correspond directly to your Firestore collections, and will read/write documents directly from it.
Additional settings
Property | Type | Description |
---|---|---|
key | string | Name of the collection as used in Firestore. |
label | string | Alias of collection used in overview. |
fields | array | List of defined fields. See fields. |
singleton | boolean | Make singleton collection. See singletons. |
create | boolean | Determine if creation should be permitted. |
delete | boolean | Determine if deletion should be permitted. |
export | boolean | Fields to index for inline search. |
timestamps | boolean | Adds timestamps if enabled. |
docLabel | string | Key of the field used as label for the document. |
search | string | Key of the field used for search in references. |
sortBy | string | Default key to sort by. |
asc | boolean | If sort order should be assending. |
dashboard | object | Defined dashboard for collection. See dashboards. |
functions | array | List of functions to extend form. See functions. |
Fields
Your documents are defined using an array of fields of these types.
Field | Example | Description |
---|---|---|
Text | "Hello world" | Simple text field. |
Textarea | "Long text" | Long text field that adapt height to content. |
Date | "16-15-2004" | Single date as string. |
Time | "13:37" | Hours and minutes. |
Timestamp | 16-15-2004-13:37 | Firestore timestamp. |
Location | {lat:"1", lng:"2", hash:"3"} | Location object with calculated geo hash. |
Geopoint | [55.69° N, 13.37° E] | Native Firestore geopoint. |
Number | 666 | Number with optional step count. |
"asd@asd.dk" | Validated email. | |
Select | "val1" | Value from defined slect options. |
Color | "#b4d455" | Native colorpicker with hex value. |
Tags | ["yo", "wyd"] | Array of uniqe stings. |
HTML | <p>hello</p> | HTML content. |
Image | "https://storage.path/hash" | Public URL from Firebase Storage. |
Boolean | false | Boolean toggle. |
Object | {} | Object that can contain individual fiels. Can also be colapsed. |
File | "https://storage.path/hash" | Public URL from Firebase Storage. |
References | ["path/to/doc"] | Path to Firestore document. |
Markup | N/A | HTML only rendered in form. |
Telephone | "+45 33 99 88 22" | String with formatted telephone number. |
Sub collections
Sub collections are identical to collections, but are neasted under each document of the parent collection.
And yes, sub collections can have sub collections can have sub... etc.
Example
- myCollection
- doc1
- mySubCollection
- doc2
- mySubCollection
- doc3
- mySubCollection
- subDoc 1
- mySubSybCollection
- subDoc 2
- mySubSybCollection
Singletons
If a collection is marked as a singleton, each of it's children will corespond to a unique document instead of a collection.
This is ideal for creating f.ex. a settings
collection.
Example
settings (singleton collection)
- colors (with uniqe fields)
- translations (with other uniqe fields)
Functions
Each collection form can be extended with custom callable cloud functions. These will appear at the bottom next to the save button.
An example of such function can be seen here:
js
import functions from 'firebase-functions'
import admin from 'firebase-admin'
export const getBTC = functions.region('europe-west1').https.onCall(async (docs, context) => {
const btcPrice = await fetch('https://api.coinbase.com/v2/prices/btc-eur/buy').then((res) => res.json())
for (let path of docs) {
const doc = await admin.firestore().doc(path)
doc.update({
notes: `BTC is worth ${btcPrice.data.amount}${btcPrice.data.currency}`
})
}
return {
message: 'Doc has been updated with latest price!'
}
})
Request
The function will get a request containing an array of document paths: ['collection/mydoc1']
.
Currently this will only contain a single path to the document from where the function is called from. In the future this might be called on entire quries or collections.
Response
Multiple instructions can be sent as response.
js
// This will display an alert on the client
return {
message: 'Thanks'
}
// This will redirect to a internal or external link
return {
redirect: 'http://grid.ws'
}