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

Commit 1140404

Browse files
committed
Merge branch '457-fr-new-option-to-enabledisable-formula-scripts-load'
2 parents 29c0fb0 + e792e5c commit 1140404

File tree

11 files changed

+138
-102
lines changed

11 files changed

+138
-102
lines changed

src/automations/formula_functions/FormulaFunctions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class FormulaFunctions implements IGenerateObject {
1414
): Promise<Record<string, unknown>> {
1515
let user_script_functions = {};
1616

17-
if (config.formula_folder_path) {
17+
if (config.enable_js_formulas && config.formula_folder_path) {
1818
user_script_functions =
1919
await this.js_script_functions.generate_object();
2020
}

src/cdm/SettingsModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface LocalSettings {
4949
source_data: string;
5050
sticky_first_column: boolean;
5151
row_templates_folder: string;
52+
enable_js_formulas: boolean;
5253
formula_folder_path: string;
5354
inline_default: boolean;
5455
inline_new_position: string;

src/components/NavBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import { c } from "helpers/StylesHelper";
1616
import EditFiltersButton from "components/reducers/DataviewFilters";
1717
import { MenuButtonStyle } from "components/styles/NavBarStyles";
1818
import { SettingsModal } from "Settings";
19-
import CsvReader from "./navbar/CsvReader";
19+
import CsvReader from "components/navbar/CsvReader";
2020
import { t } from "lang/helpers";
2121
import AppBar from "@mui/material/AppBar";
2222
import ButtonGroup from "@mui/material/ButtonGroup";
2323
import ToggleFiltersButton from "components/reducers/ToggleFiltersButton";
2424
import Paper from "@mui/material/Paper";
25-
import QuickFilters from "./reducers/QuickFilters";
25+
import QuickFilters from "components/reducers/QuickFilters";
2626

2727
export function NavBar(navBarProps: NavBarProps) {
2828
const { table } = navBarProps;

src/components/Table.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import TableHeader from "components/TableHeader";
3333
import TableRow from "components/TableRow";
3434
import getInitialColumnSizing from "components/behavior/InitialColumnSizeRecord";
3535
import { globalDatabaseFilterFn } from "components/reducers/TableFilterFlavours";
36-
import dbfolderColumnSortingFn from "./reducers/CustomSortingFn";
36+
import dbfolderColumnSortingFn from "components/reducers/CustomSortingFn";
3737
import { useCallback, useState } from "react";
38-
import { AddRow } from "./AddRow";
38+
import { AddRow } from "components/AddRow";
3939

4040
const defaultColumn: Partial<ColumnDef<RowDataType>> = {
4141
minSize: DatabaseLimits.MIN_COLUMN_HEIGHT,

src/helpers/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ export const DEFAULT_SETTINGS: DatabaseSettings = {
380380
row_templates_folder: '/',
381381
current_row_template: '',
382382
pagination_size: 10,
383+
enable_js_formulas: false,
383384
formula_folder_path: '/',
384385
inline_default: false,
385386
inline_new_position: INLINE_POSITION.TOP,

src/services/FileGroupingService.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Notice } from "obsidian";
2-
import { LOGGER } from "./Logger";
2+
import { LOGGER } from "services/Logger";
33
import pLimit from "p-limit";
44
import { RowDataType } from "cdm/FolderModel";
55
import { LocalSettings } from "cdm/SettingsModel";
@@ -89,14 +89,13 @@ export class FileGroupingService {
8989
throw error;
9090
}
9191
}
92-
if (movedRows.length > 0) {
92+
if (movedRows.length > 0) {
9393
new Notice(
94-
`Moved ${movedRows.length} file${
95-
movedRows.length > 1 ? "s" : ""
94+
`Moved ${movedRows.length} file${movedRows.length > 1 ? "s" : ""
9695
} into subfolders`,
9796
1500
9897
);
99-
}
98+
}
10099
return movedRows;
101100
});
102101

src/settings/AutomationSection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SettingHandlerResponse } from 'settings/handlers/AbstractSettingHandler
33
import { AbstractChain } from 'patterns/AbstractFactoryChain';
44
import { AbstractHandler } from 'patterns/AbstractHandler';
55
import { FormulaJSFolderHandler } from 'settings/handlers/automation/FormulaJSFolderHandler';
6+
import { FormulaJSToggleHandler } from 'settings/handlers/automation/FormulaJSToggleHandler';
67

78
class AutomationSetttingsSection extends AbstractChain<SettingHandlerResponse> {
89
protected customHandle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
@@ -14,6 +15,7 @@ class AutomationSetttingsSection extends AbstractChain<SettingHandlerResponse> {
1415
}
1516
protected getHandlers(): AbstractHandler<SettingHandlerResponse>[] {
1617
return [
18+
new FormulaJSToggleHandler(),
1719
new FormulaJSFolderHandler()
1820
];
1921
}

src/settings/handlers/automation/FormulaJSFolderHandler.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,35 @@ export class FormulaJSFolderHandler extends AbstractSettingsHandler {
66
settingTitle: string = 'Select the source of your formula JS files';
77
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
88
const { settingsManager, containerEl, view, local } = settingHandlerResponse;
9+
if (view.diskConfig.yaml.config.enable_js_formulas) {
10+
const formula_folder_promise = async (value: string): Promise<void> => {
11+
if (local) {
12+
// update settings
13+
view.diskConfig.updateConfig({ formula_folder_path: value });
14+
} else {
15+
// switch show created on/off
16+
const update_local_settings = settingsManager.plugin.settings.local_settings;
17+
update_local_settings.formula_folder_path = value;
18+
// update settings
19+
await settingsManager.plugin.updateSettings({
20+
local_settings: update_local_settings
21+
});
22+
}
923

10-
const formula_folder_promise = async (value: string): Promise<void> => {
11-
if (local) {
12-
// update settings
13-
view.diskConfig.updateConfig({ formula_folder_path: value });
14-
} else {
15-
// switch show created on/off
16-
const update_local_settings = settingsManager.plugin.settings.local_settings;
17-
update_local_settings.formula_folder_path = value;
18-
// update settings
19-
await settingsManager.plugin.updateSettings({
20-
local_settings: update_local_settings
24+
};
25+
// render dropdown inside container
26+
new Setting(containerEl)
27+
.setName('Select the formula JS folder')
28+
.setDesc('Select the destination of the formula JS files.')
29+
.addSearch((cb) => {
30+
new FolderSuggest(
31+
cb.inputEl
32+
);
33+
cb.setPlaceholder("Example: path/to/folder")
34+
.setValue(local ? view.diskConfig.yaml.config.formula_folder_path : settingsManager.plugin.settings.local_settings.formula_folder_path)
35+
.onChange(formula_folder_promise);
2136
});
22-
}
23-
24-
};
25-
// render dropdown inside container
26-
new Setting(containerEl)
27-
.setName('Select the formula JS folder')
28-
.setDesc('Select the destination of the formula JS files.')
29-
.addSearch((cb) => {
30-
new FolderSuggest(
31-
cb.inputEl
32-
);
33-
cb.setPlaceholder("Example: path/to/folder")
34-
.setValue(local ? view.diskConfig.yaml.config.formula_folder_path : settingsManager.plugin.settings.local_settings.formula_folder_path)
35-
.onChange(formula_folder_promise);
36-
});
37+
}
3738
return this.goNext(settingHandlerResponse);
3839
}
3940
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { add_toggle } from "settings/SettingsComponents";
2+
import { AbstractSettingsHandler, SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
3+
export class FormulaJSToggleHandler extends AbstractSettingsHandler {
4+
settingTitle: string = 'Enable JavaScript formulas';
5+
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
6+
const { settingsManager, containerEl, view, local } = settingHandlerResponse;
7+
// pass if modal opened from local settings
8+
const formulas_togle_promise = async (value: boolean): Promise<void> => {
9+
if (local) {
10+
// update settings
11+
view.diskConfig.updateConfig({ enable_js_formulas: value });
12+
} else {
13+
const update_local_settings = settingsManager.plugin.settings.local_settings;
14+
update_local_settings.enable_js_formulas = value;
15+
// update settings
16+
await settingsManager.plugin.updateSettings({
17+
local_settings: update_local_settings
18+
});
19+
}
20+
// Force refresh of settings
21+
settingsManager.reset(settingHandlerResponse);
22+
}
23+
add_toggle(
24+
containerEl,
25+
this.settingTitle,
26+
"Enable JavaScript formulas to be used in your database.",
27+
local ? view.diskConfig.yaml.config.enable_js_formulas : settingsManager.plugin.settings.local_settings.enable_js_formulas,
28+
formulas_togle_promise
29+
);
30+
31+
return this.goNext(settingHandlerResponse);
32+
}
33+
}

src/settings/handlers/columns/GroupFolderColumnTextInputHandler.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,60 @@ import { destination_folder } from "helpers/FileManagement";
33
import { FileGroupingService } from "services/FileGroupingService";
44
import { AbstractSettingsHandler, SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
55
import { add_toggle } from "settings/SettingsComponents";
6-
import { FileGroupingColumnsSetting } from "./FileGroupingColumnsSetting";
6+
import { FileGroupingColumnsSetting } from "settings/handlers/columns/FileGroupingColumnsSetting";
77

88
export class GroupFolderColumnTextInputHandler extends AbstractSettingsHandler {
99
settingTitle: string = 'Define a schema to group files into folders';
10-
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
11-
const { containerEl, local, view,settingsManager } = settingHandlerResponse;
12-
if (local) {
13-
const columns = view.diskConfig.yaml.columns;
14-
const allowedColumns = new Set(
15-
Object.keys(columns)
16-
.filter( (f) => columns[f].input === InputType.SELECT)
17-
.map((key) => columns[key].label),
18-
);
19-
20-
settingsManager.cleanupFns.push(async () => {
21-
const config = view.diskConfig.yaml.config;
22-
if (config.automatically_group_files) {
23-
const folderPath = destination_folder(view, config);
24-
await FileGroupingService.organizeNotesIntoSubfolders( folderPath, view.rows, config);
25-
await FileGroupingService.removeEmptyFolders(folderPath, config);
26-
view.reloadDatabase();
27-
}
28-
});
29-
30-
new FileGroupingColumnsSetting(view, allowedColumns).init(containerEl);
10+
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
11+
const { containerEl, local, view, settingsManager } = settingHandlerResponse;
12+
if (local) {
13+
const columns = view.diskConfig.yaml.columns;
14+
const allowedColumns = new Set(
15+
Object.keys(columns)
16+
.filter((f) => columns[f].input === InputType.SELECT)
17+
.map((key) => columns[key].label),
18+
);
3119

32-
add_toggle(
33-
containerEl,
34-
"Group all files into folders automatically",
35-
"By default, files are groupped individually, after a value is updated",
36-
view.diskConfig.yaml.config.automatically_group_files,
37-
async (value) => {
38-
view.diskConfig.updateConfig({ automatically_group_files: value });
39-
}
40-
)
41-
add_toggle(
42-
containerEl,
43-
"Remove empty folders",
44-
"Automatically remove empty folders after grouping files.",
45-
view.diskConfig.yaml.config.remove_empty_folders,
46-
async (value) => {
47-
view.diskConfig.updateConfig({ remove_empty_folders: value });
48-
}
49-
)
20+
settingsManager.cleanupFns.push(async () => {
21+
const config = view.diskConfig.yaml.config;
22+
if (config.automatically_group_files) {
23+
const folderPath = destination_folder(view, config);
24+
await FileGroupingService.organizeNotesIntoSubfolders(folderPath, view.rows, config);
25+
await FileGroupingService.removeEmptyFolders(folderPath, config);
26+
view.reloadDatabase();
27+
}
28+
});
5029

51-
add_toggle(
52-
containerEl,
53-
"Hoist files with missing attributes to root folder",
54-
"By default, files with missing attributes are hoisted to the lowest possible folder",
55-
view.diskConfig.yaml.config.hoist_files_with_empty_attributes,
56-
async (value) => {
57-
view.diskConfig.updateConfig({ hoist_files_with_empty_attributes: value});
58-
}
59-
)
30+
new FileGroupingColumnsSetting(view, allowedColumns).init(containerEl);
31+
32+
add_toggle(
33+
containerEl,
34+
"Group all files into folders automatically",
35+
"By default, files are groupped individually, after a value is updated",
36+
view.diskConfig.yaml.config.automatically_group_files,
37+
async (value) => {
38+
view.diskConfig.updateConfig({ automatically_group_files: value });
39+
}
40+
)
41+
add_toggle(
42+
containerEl,
43+
"Remove empty folders",
44+
"Automatically remove empty folders after grouping files.",
45+
view.diskConfig.yaml.config.remove_empty_folders,
46+
async (value) => {
47+
view.diskConfig.updateConfig({ remove_empty_folders: value });
48+
}
49+
)
50+
51+
add_toggle(
52+
containerEl,
53+
"Hoist files with missing attributes to root folder",
54+
"By default, files with missing attributes are hoisted to the lowest possible folder",
55+
view.diskConfig.yaml.config.hoist_files_with_empty_attributes,
56+
async (value) => {
57+
view.diskConfig.updateConfig({ hoist_files_with_empty_attributes: value });
58+
}
59+
)
6060
}
6161
return this.goNext(settingHandlerResponse);
6262
}

0 commit comments

Comments
 (0)