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

Commit dd248e0

Browse files
committed
inline properties working
1 parent 104d625 commit dd248e0

File tree

6 files changed

+110
-23
lines changed

6 files changed

+110
-23
lines changed

src/helpers/FileManagement.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LocalSettings } from "cdm/SettingsModel";
22
import { DatabaseView } from "DatabaseView";
33
import HelperException from "errors/HelperException";
44
import { normalizePath, TAbstractFile, TFile, TFolder, Vault } from "obsidian";
5-
import { SourceDataTypes } from "helpers/Constants";
5+
import { INLINE_POSITION, SourceDataTypes } from "helpers/Constants";
66

77
export function resolve_tfile(file_str: string): TFile {
88
file_str = normalizePath(file_str);
@@ -69,3 +69,15 @@ export function destination_folder(view: DatabaseView, ddbbConfig: LocalSettings
6969
}
7070
return destination_folder;
7171
}
72+
73+
export function inline_regex_target_in_function_of(position: string, columnId: string, newValue: string) {
74+
let regex_target = "";
75+
switch (position) {
76+
case INLINE_POSITION.BOTTOM:
77+
regex_target = `$1$2${columnId}:: ${newValue}`;
78+
break;
79+
default:
80+
regex_target = `$1${columnId}:: ${newValue}\n$2`;
81+
}
82+
return regex_target;
83+
}

src/helpers/VaultManagement.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DataArray } from 'obsidian-dataview/lib/api/data-array';
1313
import { EditionError } from 'errors/ErrorTypes';
1414
import { FilterSettings, LocalSettings } from 'cdm/SettingsModel';
1515
import { NoteInfoPage } from 'cdm/DatabaseModel';
16+
import { inline_regex_target_in_function_of } from './FileManagement';
1617

1718
const noBreakSpace = /\u00A0/g;
1819

@@ -301,12 +302,16 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
301302
}
302303

303304
async function inlineAddColumn(): Promise<void> {
304-
const inlineAddRegex = new RegExp(`(^---[\\s\\S]+?---\\n)+(.*)`, 'g');
305+
const inlineAddRegex = new RegExp(`(^---[\\s\\S]+?---\\n)+([\\s\\S]+?$)`, 'g');
305306
const noteObject = {
306307
action: 'replace',
307308
file: file,
308309
regexp: inlineAddRegex,
309-
newValue: `$1${columnId}:: ${newValue}\n$2`
310+
newValue: inline_regex_target_in_function_of(
311+
ddbbConfig.inline_new_position,
312+
columnId,
313+
DataviewService.parseLiteral(newValue, InputType.MARKDOWN, ddbbConfig).toString()
314+
)
310315
};
311316
await persistFrontmatter();
312317
await VaultManagerDB.editNoteContent(noteObject);

src/settings/ColumnsSection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GroupFolderColumnDropDownHandler } from 'settings/handlers/columns/Grou
44
import { RemoveFieldsWhenDeleteToggleHandler } from 'settings/handlers/columns/RemoveFieldsWhenDeleteToggleHandler';
55
import { MetadataToggleGroupHandler } from 'settings/handlers/columns/MetadataToggleGroupHandler';
66
import { TemplateColumnsHandler } from 'settings/handlers/columns/TemplateColumnsHandler';
7+
import { InlineFieldsOptionsHandler } from 'settings/handlers/columns/InlineFieldsOptionsHandler';
78
import { AbstractChain } from 'patterns/AbstractFactoryChain';
89
import { AbstractHandler } from 'patterns/AbstractHandler';
910

@@ -21,6 +22,7 @@ class ColumnSetttingsSection extends AbstractChain<SettingHandlerResponse> {
2122
new RemoveFieldsWhenDeleteToggleHandler(),
2223
new TemplateColumnsHandler(),
2324
new MetadataToggleGroupHandler(),
25+
new InlineFieldsOptionsHandler()
2426
];
2527
}
2628
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { add_dropdown, add_setting_header, add_toggle } from "settings/SettingsComponents";
2+
import { AbstractSettingsHandler, SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
3+
import { INLINE_POSITION } from "helpers/Constants";
4+
export class InlineFieldsOptionsHandler extends AbstractSettingsHandler {
5+
settingTitle: string = 'Inline fields options';
6+
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
7+
const { settingsManager, containerEl, local, view } = settingHandlerResponse;
8+
const inline_section = containerEl.createDiv("configuration-section-container-columns-inline");
9+
// title of the section
10+
add_setting_header(inline_section, this.settingTitle, 'h4');
11+
/*********************************
12+
* TOGGLE INLINE FIELDS AS DEFAULT
13+
* *******************************/
14+
const logger_togle_promise = async (value: boolean): Promise<void> => {
15+
if (local) {
16+
// Persist value
17+
view.diskConfig.updateConfig({ inline_default: value });
18+
} else {
19+
// set debug mode
20+
const update_local_settings = settingsManager.plugin.settings.local_settings;
21+
update_local_settings.inline_default = value;
22+
// update settings
23+
await settingsManager.plugin.updateSettings({
24+
local_settings: update_local_settings
25+
});
26+
}
27+
}
28+
add_toggle(
29+
containerEl,
30+
"Enable inline fields as default",
31+
"New columns will be created as inline fields by default",
32+
local ? view.diskConfig.yaml.config.inline_default : settingsManager.plugin.settings.local_settings.inline_default,
33+
logger_togle_promise
34+
);
35+
36+
/************************************
37+
* DROPDOWN POSITION OF INLINE FIELDS
38+
* **********************************/
39+
const inline_position_dropdown_promise = async (value: string): Promise<void> => {
40+
if (local) {
41+
// Persist value
42+
view.diskConfig.updateConfig({ inline_new_position: value });
43+
} else {
44+
// set dropdown value
45+
const update_local_settings = settingsManager.plugin.settings.local_settings;
46+
update_local_settings.inline_new_position = value;
47+
// update settings
48+
settingsManager.plugin.updateSettings({ local_settings: update_local_settings });
49+
}
50+
};
51+
// render dropdown inside container
52+
const options: Record<string, string> = {};
53+
Object.entries(INLINE_POSITION).forEach(([key, value]) => {
54+
options[value] = value;
55+
});
56+
add_dropdown(
57+
containerEl,
58+
'Select position of new inline fields',
59+
'New inline fields will be created in the selected position on your notes',
60+
local ? view.diskConfig.yaml.config.inline_new_position : settingsManager.plugin.settings.local_settings.inline_new_position,
61+
options,
62+
inline_position_dropdown_promise
63+
);
64+
return this.goNext(settingHandlerResponse);
65+
}
66+
}

src/settings/handlers/developer/TableStateToggleHandler.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@ export class TableStateToggleHandler extends AbstractSettingsHandler {
44
settingTitle: string = 'Show state of table';
55
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
66
const { settingsManager, containerEl } = settingHandlerResponse;
7-
if (settingsManager.plugin.settings.global_settings.enable_debug_mode) {
8-
const table_state_togle_promise = async (value: boolean): Promise<void> => {
9-
// Check context to define correct promise
7+
const table_state_togle_promise = async (value: boolean): Promise<void> => {
8+
// Check context to define correct promise
109

11-
// switch table state on/off
12-
const update_global_settings = settingsManager.plugin.settings.global_settings;
13-
update_global_settings.enable_show_state = value;
14-
// update settings
15-
await settingsManager.plugin.updateSettings({
16-
global_settings: update_global_settings
17-
});
18-
}
19-
20-
add_toggle(
21-
containerEl,
22-
this.settingTitle,
23-
"This will show/hide properties of the table on the bottom of the view",
24-
settingsManager.plugin.settings.global_settings.enable_show_state,
25-
table_state_togle_promise
26-
);
10+
// switch table state on/off
11+
const update_global_settings = settingsManager.plugin.settings.global_settings;
12+
update_global_settings.enable_show_state = value;
13+
// update settings
14+
await settingsManager.plugin.updateSettings({
15+
global_settings: update_global_settings
16+
});
2717
}
18+
19+
add_toggle(
20+
containerEl,
21+
this.settingTitle,
22+
"This will show/hide properties of the table on the bottom of the view",
23+
settingsManager.plugin.settings.global_settings.enable_show_state,
24+
table_state_togle_promise
25+
);
26+
2827
return this.goNext(settingHandlerResponse);
2928
}
3029
}

src/stateManagement/columns/handlers/NewColumnAction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export default class InsertColumnHandlerAction extends AbstractTableAction<Colum
5555
key: columnInfo.name,
5656
label: columnInfo.label,
5757
position: columnInfo.position,
58-
config: DEFAULT_COLUMN_CONFIG,
58+
config: {
59+
...DEFAULT_COLUMN_CONFIG,
60+
isInline: view.diskConfig.yaml.config.inline_default
61+
},
5962
};
6063
view.diskConfig.addColumn(columnInfo.name, newColumn);
6164

0 commit comments

Comments
 (0)