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

Commit 4c5418c

Browse files
committed
demo rollup summatory
1 parent 35eda32 commit 4c5418c

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/automations/Rollup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ROLLUP_ACTIONS } from "helpers/Constants";
12
import { Link, Literal } from "obsidian-dataview";
23
import { DataviewService } from "services/DataviewService";
34
import { LOGGER } from "services/Logger";
@@ -17,7 +18,7 @@ class Rollup {
1718
}
1819
public dispatch(): string {
1920
switch (this.action) {
20-
case "sum":
21+
case ROLLUP_ACTIONS.SUM:
2122
return this.sum();
2223
default:
2324
// No valid action found

src/components/modals/columnSettings/handlers/automations/RollupInputHandler.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AbstractHandlerClass } from "patterns/AbstractHandler";
33
import { Setting } from "obsidian";
44
import { add_toggle } from "settings/SettingsComponents";
55
import { StringSuggest } from "settings/suggesters/StringSuggester";
6-
import { InputType } from "helpers/Constants";
6+
import { InputType, ROLLUP_ACTIONS } from "helpers/Constants";
77
export class RollupInputHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
88
settingTitle: string = 'rollup properties';
99
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
@@ -45,7 +45,30 @@ export class RollupInputHandler extends AbstractHandlerClass<ColumnSettingsHandl
4545
.setValue(column.config.asociated_relation_id)
4646
.onChange(relation_selector_promise);
4747
});
48-
// TODO select rollup action
48+
// select rollup action
49+
const rollup_action_options: Record<string, string> = {};
50+
Object.entries(ROLLUP_ACTIONS).forEach(([key, value]) => {
51+
rollup_action_options[key] = value;
52+
});
53+
const rollup_action_promise = async (value: string): Promise<void> => {
54+
// Persist on disk
55+
await view.diskConfig.updateColumnConfig(column.id, {
56+
rollup_action: value
57+
});
58+
columnSettingsManager.modal.enableReset = true;
59+
};
60+
new Setting(containerEl)
61+
.setName("Select action")
62+
.setDesc('Select the action to perform on the rollup')
63+
.addSearch((cb) => {
64+
new StringSuggest(
65+
cb.inputEl,
66+
rollup_action_options
67+
);
68+
cb.setPlaceholder("Select action...")
69+
.setValue(column.config.rollup_action)
70+
.onChange(rollup_action_promise);
71+
});
4972
// TODO select key column (if action allows it)
5073
// Enable persist rollup toggle
5174
add_toggle(

src/helpers/Constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ export const DatabaseFrontmatterOptions = Object.freeze({
418418
' conditions:'
419419
].join('\n')
420420
});
421+
421422
/******************************************************************************
422423
* SUGGESTER REGEX
423424
******************************************************************************/
@@ -439,3 +440,7 @@ export const DB_ICONS = Object.freeze({
439440
NAME: 'database-folder-icon',
440441
ICON: `<g transform="matrix(0.06 0 0 0.05 52 52)"><path stroke="currentColor" fill="#fff" vector-effect="non-scaling-stroke" transform=" translate(-896, -896)" d="M 896 768 q 237 0 443 -43 t 325 -127 v 170 q 0 69 -103 128 t -280 93.5 t -385 34.5 t -385 -34.5 t -280 -93.5 t -103 -128 v -170 q 119 84 325 127 t 443 43 z m 0 768 q 237 0 443 -43 t 325 -127 v 170 q 0 69 -103 128 t -280 93.5 t -385 34.5 t -385 -34.5 t -280 -93.5 t -103 -128 v -170 q 119 84 325 127 t 443 43 z m 0 -384 q 237 0 443 -43 t 325 -127 v 170 q 0 69 -103 128 t -280 93.5 t -385 34.5 t -385 -34.5 t -280 -93.5 t -103 -128 v -170 q 119 84 325 127 t 443 43 z m 0 -1152 q 208 0 385 34.5 t 280 93.5 t 103 128 v 128 q 0 69 -103 128 t -280 93.5 t -385 34.5 t -385 -34.5 t -280 -93.5 t -103 -128 v -128 q 0 -69 103 -128 t 280 -93.5 t 385 -34.5 z" stroke-linecap="round" /></g>`
441442
});
443+
444+
export const ROLLUP_ACTIONS = Object.freeze({
445+
SUM: 'sum',
446+
});

0 commit comments

Comments
 (0)