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

Commit c3b6378

Browse files
committed
Merge branch 'issue126'
2 parents b72e267 + 1822bbd commit c3b6378

File tree

5 files changed

+71
-23
lines changed

5 files changed

+71
-23
lines changed

src/cdm/SettingsModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface LocalSettings {
3131
show_metadata_modified: boolean;
3232
show_metadata_tasks: boolean;
3333
source_form_result: string;
34+
source_destination_path: string;
3435
source_data: string;
3536
sticky_first_column: boolean;
3637
row_templates_folder: string;

src/helpers/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ export const DEFAULT_SETTINGS: DatabaseSettings = {
312312
show_metadata_tasks: false,
313313
source_data: SourceDataTypes.CURRENT_FOLDER,
314314
source_form_result: 'root',
315+
source_destination_path: '/',
315316
frontmatter_quote_wrap: false,
316317
row_templates_folder: '/',
317318
current_row_template: '',

src/settings/handlers/source/SourceFormHandler.ts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { Notice, Setting } from "obsidian";
66
import { DataviewService } from "services/DataviewService";
77
import { AbstractSettingsHandler, SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
88
import { add_dropdown } from "settings/SettingsComponents";
9-
import { FileSuggest } from "settings/suggesters/FileSuggester";
9+
import { filePathsRecordSuggester, FileSuggest } from "settings/suggesters/FileSuggester";
10+
import { FolderSuggest } from "settings/suggesters/FolderSuggester";
1011

1112
export class SourceFormHandler extends AbstractSettingsHandler {
1213
settingTitle: string = 'Form in function of source data';
@@ -18,24 +19,7 @@ export class SourceFormHandler extends AbstractSettingsHandler {
1819
break;
1920
case SourceDataTypes.OUTGOING_LINK:
2021
case SourceDataTypes.INCOMING_LINK:
21-
const filePaths: Record<string, string> = {}
22-
app.vault.getMarkdownFiles().forEach(file => { filePaths[file.path] = file.basename });
23-
const source_form_promise = async (value: string): Promise<void> => {
24-
// update settings
25-
view.diskConfig.updateConfig({ source_form_result: value });
26-
};
27-
new Setting(containerEl)
28-
.setName('Select a file')
29-
.setDesc('Select file from vault to be used as source of data.')
30-
.addSearch((cb) => {
31-
new FileSuggest(
32-
cb.inputEl,
33-
view.file.parent.path
34-
);
35-
cb.setPlaceholder("Example: folder1/template_file")
36-
.setValue(view.diskConfig.yaml.config.source_form_result)
37-
.onChange(source_form_promise);
38-
});
22+
outgoingAndIncomingHandler(view, containerEl);
3923
break;
4024
case SourceDataTypes.QUERY:
4125
queryHandler(view, containerEl, columns);
@@ -70,9 +54,30 @@ function tagHandler(view: DatabaseView, containerEl: HTMLElement) {
7054
tagRecords,
7155
source_form_promise
7256
);
57+
destinationFolderHandler(view, containerEl);
7358
}
7459
}
7560

61+
function outgoingAndIncomingHandler(view: DatabaseView, containerEl: HTMLElement) {
62+
const source_form_promise = async (value: string): Promise<void> => {
63+
// update settings
64+
view.diskConfig.updateConfig({ source_form_result: value });
65+
};
66+
new Setting(containerEl)
67+
.setName('Select a file')
68+
.setDesc('Select file from vault to be used as source of data.')
69+
.addSearch((cb) => {
70+
new FileSuggest(
71+
cb.inputEl,
72+
view.file.parent.path
73+
);
74+
cb.setPlaceholder("Example: folder1/template_file")
75+
.setValue(view.diskConfig.yaml.config.source_form_result)
76+
.onChange(source_form_promise);
77+
});
78+
destinationFolderHandler(view, containerEl);
79+
}
80+
7681
function queryHandler(view: DatabaseView, containerEl: HTMLElement, columns: TableColumn[]) {
7782
const query_promise = async (value: string): Promise<void> => {
7883
// update settings
@@ -104,4 +109,23 @@ function queryHandler(view: DatabaseView, containerEl: HTMLElement, columns: Tab
104109
}
105110
});
106111
});
112+
destinationFolderHandler(view, containerEl);
113+
}
114+
115+
function destinationFolderHandler(view: DatabaseView, containerEl: HTMLElement) {
116+
const source_form_promise = async (value: string): Promise<void> => {
117+
// update settings
118+
view.diskConfig.updateConfig({ source_destination_path: value });
119+
};
120+
new Setting(containerEl)
121+
.setName('Select destination folder')
122+
.setDesc('Select the destination of new entries for this source')
123+
.addSearch((cb) => {
124+
new FolderSuggest(
125+
cb.inputEl
126+
);
127+
cb.setPlaceholder("Example: path/to/folder")
128+
.setValue(view.diskConfig.yaml.config.source_destination_path)
129+
.onChange(source_form_promise);
130+
});
107131
}

src/settings/suggesters/FileSuggester.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ export class FileSuggest extends TextInputSuggest<TFile> {
5252
this.inputEl.trigger("input");
5353
this.close();
5454
}
55+
}
56+
57+
export function filePathsRecordSuggester(): Record<string, string> {
58+
const filePaths: Record<string, string> = {}
59+
app.vault.getMarkdownFiles().forEach(file => { filePaths[file.path] = file.basename });
60+
return filePaths;
5561
}

src/stateManagement/data/handlers/AddRowHandlerAction.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { RowDatabaseFields } from "cdm/DatabaseModel";
22
import { RowDataType, TableColumn } from "cdm/FolderModel";
33
import { LocalSettings } from "cdm/SettingsModel";
44
import { DataState, TableActionResponse } from "cdm/TableStateInterface";
5-
import { MetadataColumns } from "helpers/Constants";
5+
import { DatabaseView } from "DatabaseView";
6+
import { MetadataColumns, SourceDataTypes } from "helpers/Constants";
7+
import { resolve_tfolder } from "helpers/FileManagement";
68
import { DateTime } from "luxon";
79
import { Literal } from "obsidian-dataview";
810
import { VaultManagerDB } from "services/FileManagerService";
@@ -13,13 +15,14 @@ export default class AddRowlHandlerAction extends AbstractTableAction<DataState>
1315
handle(tableActionResponse: TableActionResponse<DataState>): TableActionResponse<DataState> {
1416
const { view, set, implementation } = tableActionResponse;
1517
implementation.actions.addRow = (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => set((state) => {
18+
const destination_folder = this.destination_folder(view, ddbbConfig);
1619
let trimedFilename = filename.replace(/\.[^/.]+$/, "").trim();
17-
let filepath = `${view.file.parent.path}/${trimedFilename}.md`;
20+
let filepath = `${destination_folder}/${trimedFilename}.md`;
1821
// Validate possible duplicates
1922
let sufixOfDuplicate = 0;
2023
while (state.rows.find((row) => row.__note__.filepath === filepath)) {
2124
sufixOfDuplicate++;
22-
filepath = `${view.file.parent.path}/${trimedFilename}-${sufixOfDuplicate}.md`;
25+
filepath = `${destination_folder}/${trimedFilename}-${sufixOfDuplicate}.md`;
2326
}
2427
if (sufixOfDuplicate > 0) {
2528
trimedFilename = `${trimedFilename}-${sufixOfDuplicate}`;
@@ -37,7 +40,7 @@ export default class AddRowlHandlerAction extends AbstractTableAction<DataState>
3740
});
3841
// Add note to persist row
3942
VaultManagerDB.create_markdown_file(
40-
view.file.parent,
43+
resolve_tfolder(destination_folder),
4144
trimedFilename,
4245
rowRecord,
4346
ddbbConfig
@@ -62,4 +65,17 @@ export default class AddRowlHandlerAction extends AbstractTableAction<DataState>
6265
tableActionResponse.implementation = implementation;
6366
return this.goNext(tableActionResponse);
6467
}
68+
destination_folder(view: DatabaseView, ddbbConfig: LocalSettings): string {
69+
let destination_folder = view.file.parent.path;
70+
switch (ddbbConfig.source_data) {
71+
case SourceDataTypes.TAG:
72+
case SourceDataTypes.OUTGOING_LINK:
73+
case SourceDataTypes.INCOMING_LINK:
74+
destination_folder = ddbbConfig.source_destination_path;
75+
break;
76+
default:
77+
//Current folder
78+
}
79+
return destination_folder;
80+
}
6581
}

0 commit comments

Comments
 (0)