Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit df70042

Browse files
committed
fordocumentation for option formulas
1 parent af60cd9 commit df70042

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

docs/docs/features/Formulas.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ If you are using a column formula, you can also use the following variables:
2525
In case you are using a footer formula, you can also use the following variables:
2626
- `values` : An Array of cell values in the column
2727

28+
#### Options Formula
29+
The options formula is a special case. It is used to generate the options for a column with the type `select` or `tag`. The formula must return an array of objects with the following structure:
30+
31+
```javascript
32+
{
33+
value: "value",
34+
label: "label"
35+
color: "color" // HSL, RGB, HEX, or color name but with string representation
36+
}
37+
```
38+
Due the nature of the formula, the variables are called directly instead of using the `${}` syntax. For example, to get a value of the `db`, you can use `db.js.myOptionsFormula()`.
39+
40+
You can also use the following variables:
41+
- `column` : Object with the column information
42+
43+
2844
### Exposed Functions
2945

3046
The root object `db` has the following functions:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Generate a list of options in function of the tags of Obsidian
3+
*
4+
* Formula: ${db.js.tagsAsOptions(db)}
5+
*/
6+
function tagsAsOptions(db) {
7+
options = [];
8+
tagArray = app.metadataCache.getTags(); // Record<string, number>
9+
Object.keys(tagArray).forEach(tag => {
10+
options.push({
11+
value: tag,
12+
label: tag.slice(1),
13+
color: db.colors.randomColor()
14+
})
15+
});
16+
return options;
17+
}
18+
19+
module.exports = tagsAsOptions

src/components/modals/columnSettings/handlers/selects/FormulaColumnOptionsHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { c } from "helpers/StylesHelper";
44
import { t } from "lang/helpers";
55
import { Notice, Setting } from "obsidian";
66
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
7+
import { Db } from "services/CoreService";
78
import { FormulaService } from "services/FormulaService";
89

910
export class FormulaColumnOptionsHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
@@ -36,6 +37,7 @@ export class FormulaColumnOptionsHandler extends AbstractHandlerClass<ColumnSett
3637
.setTooltip("column_settings_modal_formula_option_source_placeholder")
3738
.onClick(async (): Promise<void> => {
3839
try {
40+
column.config.formula_option_source = currentFormula;
3941
columnHandlerResponse.column.options = FormulaService.evalOptionsWith(column, automationState.info.getFormulas());
4042
} catch (e) {
4143
new Notice("Error in formula: " + e);
@@ -79,6 +81,7 @@ export class FormulaColumnOptionsHandler extends AbstractHandlerClass<ColumnSett
7981
const tr = tbody.createEl("tr");
8082
tr.addClass(c("center-cell"));
8183
tr.style.backgroundColor = option.color;
84+
tr.style.color = Db.coreFns.colors.getContrast(option.color);
8285
// td centering text
8386
tr.createEl("td", {
8487
text: option.label,

src/services/CoreService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CoreService {
3333

3434
/**
3535
* Singleton instance
36-
* @returns {VaultManager}
36+
* @returns {CoreService}
3737
*/
3838
public static getInstance(): CoreService {
3939
if (!this.instance) {

0 commit comments

Comments
 (0)