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

Commit eac4553

Browse files
committed
rollup better manage
1 parent 9651b78 commit eac4553

File tree

6 files changed

+159
-109
lines changed

6 files changed

+159
-109
lines changed

src/components/modals/columnSettings/ColumnSections.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import { AlignmentSelectorHandler } from "components/modals/columnSettings/handl
1111
import { ToggleWrapContentHandler } from "components/modals/columnSettings/handlers/styles/ToggleWrapContentHandler";
1212
import { ColumnIdInputHandler } from "components/modals/columnSettings/handlers/ColumnIdInputHandler";
1313
import { DatabaseSelectorHandler } from "components/modals/columnSettings/handlers/dropdowns/DatabaseSelectorHandler";
14-
import { RollupInputHandler } from "components/modals/columnSettings/handlers/automations/RollupInputHandler";
14+
import { RollupAsociatedRelationHandler } from "components/modals/columnSettings/handlers/rollups/RollupAsociatedRelationHandler";
15+
import { RollupActionHandler } from "components/modals/columnSettings/handlers/rollups/RollupActionHandler";
16+
import { RollupKeyHandler } from "components/modals/columnSettings/handlers/rollups/RollupKeyHandler";
17+
import { RollupPersistToggleHandler } from "components/modals/columnSettings/handlers/rollups/RollupPersistToggleHandler";
1518
import { InputType } from "helpers/Constants";
1619
import { AbstractChain } from "patterns/AbstractFactoryChain";
1720
import { AbstractHandler } from "patterns/AbstractHandler";
1821

22+
1923
class StyleSetttingsSection extends AbstractChain<ColumnSettingsHandlerResponse> {
2024
private input: string = InputType.TEXT;
2125
protected runBefore(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
@@ -116,7 +120,10 @@ class ParticularSetttingsSection extends AbstractChain<ColumnSettingsHandlerResp
116120
particularHandlers.push(new DatabaseSelectorHandler());
117121
break;
118122
case InputType.ROLLUP:
119-
particularHandlers.push(new RollupInputHandler());
123+
particularHandlers.push(new RollupAsociatedRelationHandler());
124+
particularHandlers.push(new RollupActionHandler())
125+
particularHandlers.push(new RollupKeyHandler());
126+
particularHandlers.push(new RollupPersistToggleHandler());
120127
break;
121128
default:
122129
break;

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

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
2+
import { AbstractHandlerClass } from "patterns/AbstractHandler";
3+
import { Setting } from "obsidian";
4+
import { StringSuggest } from "settings/suggesters/StringSuggester";
5+
import { ROLLUP_ACTIONS } from "helpers/Constants";
6+
export class RollupActionHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
7+
settingTitle: string = 'Select action';
8+
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
9+
const { column, containerEl, columnSettingsManager } = columnHandlerResponse;
10+
const { view } = columnSettingsManager.modal;
11+
// select rollup action
12+
const rollup_action_options: Record<string, string> = {};
13+
Object.values(ROLLUP_ACTIONS).forEach((action) => {
14+
rollup_action_options[action] = action;
15+
});
16+
17+
const rollup_action_promise = async (value: string): Promise<void> => {
18+
// Persist on disk
19+
await view.diskConfig.updateColumnConfig(column.id, {
20+
rollup_action: value
21+
});
22+
columnSettingsManager.modal.enableReset = true;
23+
};
24+
25+
new Setting(containerEl)
26+
.setName(this.settingTitle)
27+
.setDesc('Select the action to perform on the rollup')
28+
.addSearch((cb) => {
29+
new StringSuggest(
30+
cb.inputEl,
31+
rollup_action_options
32+
);
33+
cb.setPlaceholder("Select action...")
34+
.setValue(column.config.rollup_action)
35+
.onChange(rollup_action_promise);
36+
});
37+
return this.goNext(columnHandlerResponse);
38+
}
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
2+
import { AbstractHandlerClass } from "patterns/AbstractHandler";
3+
import { Setting } from "obsidian";
4+
import { StringSuggest } from "settings/suggesters/StringSuggester";
5+
import { InputType } from "helpers/Constants";
6+
export class RollupAsociatedRelationHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
7+
settingTitle: string = 'Select relation column';
8+
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
9+
const { column, containerEl, columnSettingsManager } = columnHandlerResponse;
10+
const { view, columnsState } = columnSettingsManager.modal;
11+
const { config } = column
12+
const allColumns = columnsState.info.getAllColumns();
13+
// Select relation from existing columns
14+
const avaliableRelations: Record<string, string> = {};
15+
allColumns
16+
.filter((col) => col.input === InputType.RELATION && col.config.related_note_path)
17+
.forEach((col) => {
18+
avaliableRelations[col.id] = col.label;
19+
});
20+
const relation_selector_promise = async (value: string): Promise<void> => {
21+
config.asociated_relation_id = value;
22+
// Persist value
23+
await view.diskConfig.updateColumnConfig(column.id, {
24+
rollup_relation: value
25+
});
26+
columnSettingsManager.modal.enableReset = true;
27+
};
28+
new Setting(containerEl)
29+
.setName(this.settingTitle)
30+
.setDesc('Select from the existing columns to rollup')
31+
.addSearch((cb) => {
32+
new StringSuggest(
33+
cb.inputEl,
34+
avaliableRelations
35+
);
36+
cb.setPlaceholder("Search Relation...")
37+
.setValue(column.config.asociated_relation_id)
38+
.onChange(relation_selector_promise);
39+
});
40+
return this.goNext(columnHandlerResponse);
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
2+
import { AbstractHandlerClass } from "patterns/AbstractHandler";
3+
import { Setting } from "obsidian";
4+
import { StringSuggest } from "settings/suggesters/StringSuggester";
5+
import { recordFieldsFromRelation } from "helpers/RelationHelper";
6+
export class RollupKeyHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
7+
settingTitle: string = 'Select property of relation';
8+
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
9+
const { column, containerEl, columnSettingsManager } = columnHandlerResponse;
10+
const { view, columnsState, configState } = columnSettingsManager.modal;
11+
const { config } = column
12+
const allColumns = columnsState.info.getAllColumns();
13+
// TODO select key column (if action allows it)
14+
const relationColumn = allColumns.find((col) => col.id === config.asociated_relation_id);
15+
const rollup_key_promise = async (value: string): Promise<void> => {
16+
// Persist on disk
17+
await view.diskConfig.updateColumnConfig(column.id, {
18+
rollup_key: value
19+
});
20+
columnSettingsManager.modal.enableReset = true;
21+
};
22+
recordFieldsFromRelation(
23+
relationColumn.config.related_note_path,
24+
configState.info.getLocalSettings()
25+
).then((fields) => {
26+
new Setting(containerEl)
27+
.setName(this.settingTitle)
28+
.setDesc('Select the property to rollup from the relation')
29+
.addSearch((cb) => {
30+
new StringSuggest(
31+
cb.inputEl,
32+
fields
33+
);
34+
cb.setPlaceholder("Select property...")
35+
.setValue(column.config.rollup_key)
36+
.onChange(rollup_key_promise);
37+
});
38+
return this.goNext(columnHandlerResponse);
39+
});
40+
return null;
41+
}
42+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
2+
import { AbstractHandlerClass } from "patterns/AbstractHandler";
3+
import { add_toggle } from "settings/SettingsComponents";
4+
5+
export class RollupPersistToggleHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
6+
settingTitle: string = 'Persist rollup output';
7+
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
8+
const { column, containerEl, columnSettingsManager } = columnHandlerResponse;
9+
const { view } = columnSettingsManager.modal;
10+
const { config } = column;
11+
const persist_rollup_toggle_promise = async (value: boolean): Promise<void> => {
12+
// Persist value
13+
await view.diskConfig.updateColumnConfig(column.id, {
14+
persist_rollup: value
15+
});
16+
columnSettingsManager.modal.enableReset = true;
17+
}
18+
add_toggle(
19+
containerEl,
20+
this.settingTitle,
21+
"Enable/disable to persist rollup output on your notes (Only persisted rollups could be searchable and sortable)",
22+
config.persist_rollup,
23+
persist_rollup_toggle_promise
24+
);
25+
return this.goNext(columnHandlerResponse);
26+
}
27+
}

0 commit comments

Comments
 (0)