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

Commit d1713e8

Browse files
committed
Merge branch 'settings-adjustments'
2 parents d24e103 + 756cf43 commit d1713e8

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

src/settings/ColumnsSection.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { SettingHandlerResponse } from 'settings/handlers/AbstractSettingHandler
33
import { GroupFolderColumnDropDownHandler } from 'settings/handlers/columns/GroupFolderColumnDropDownHandler';
44
import { RemoveFieldsWhenDeleteToggleHandler } from 'settings/handlers/columns/RemoveFieldsWhenDeleteToggleHandler';
55
import { MetadataToggleGroupHandler } from 'settings/handlers/columns/MetadataToggleGroupHandler';
6-
import { UseFileFieldsAsTemplateColumnsHandler } from 'settings/handlers/columns/UseFileFieldsAsTemplateColumnsHandler';
7-
import { AddAllPossibleColumnsHandler } from 'settings/handlers/columns/AddAllPossibleColumnsHandler';
6+
import { TemplateColumnsHandler } from 'settings/handlers/columns/TemplateColumnsHandler';
87
import { AbstractChain, AbstractHandler } from 'patterns/AbstractFactoryChain';
98

109
class ColumnSetttingsSection extends AbstractChain<SettingHandlerResponse> {
@@ -19,8 +18,7 @@ class ColumnSetttingsSection extends AbstractChain<SettingHandlerResponse> {
1918
return [
2019
new GroupFolderColumnDropDownHandler(),
2120
new RemoveFieldsWhenDeleteToggleHandler(),
22-
new UseFileFieldsAsTemplateColumnsHandler(),
23-
new AddAllPossibleColumnsHandler(),
21+
new TemplateColumnsHandler(),
2422
new MetadataToggleGroupHandler(),
2523
];
2624
}

src/settings/handlers/columns/AddAllPossibleColumnsHandler.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/settings/handlers/columns/UseFileFieldsAsTemplateColumnsHandler.ts renamed to src/settings/handlers/columns/TemplateColumnsHandler.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import { RowDataType } from "cdm/FolderModel";
2-
import { obtainColumnsFromFile } from "components/Columns";
2+
import { obtainColumnsFromFile, obtainColumnsFromRows } from "components/Columns";
33
import { Notice, Setting } from "obsidian";
44
import { VaultManagerDB } from "services/FileManagerService";
55
import { AbstractSettingsHandler, SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
6+
import { add_setting_header } from "settings/SettingsComponents";
67

7-
export class UseFileFieldsAsTemplateColumnsHandler extends AbstractSettingsHandler {
8-
settingTitle: string = 'Select file as columns template';
8+
export class TemplateColumnsHandler extends AbstractSettingsHandler {
9+
settingTitle: string = 'Header templates';
910
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
1011
const { local, containerEl, view } = settingHandlerResponse;
11-
let selected_file: string = "";
12+
const template_section = containerEl.createDiv("configuration-section-container-columns-template");
1213
// Local exclusivey
1314
if (local) {
15+
// title of the section
16+
add_setting_header(template_section, this.settingTitle, 'h4');
17+
/***************************
18+
* TEMPLATE OF SELECTED FILE
19+
***************************/
20+
let selected_file: string = "";
1421
const filePaths: Record<string, string> = {};
1522
view.rows.forEach((row: RowDataType) => {
1623
if (row.__note__) {
1724
filePaths[row.__note__.getFile().path] = row.__note__.getFile().basename;
1825
}
1926
});
20-
new Setting(containerEl)
21-
.setName(this.settingTitle)
27+
new Setting(template_section)
28+
.setName('Select file as columns template')
2229
.setDesc('Select file to use as template for database columns. Click the button to apply the template.')
2330
.addDropdown((dropdown) => {
2431
dropdown
@@ -38,6 +45,23 @@ export class UseFileFieldsAsTemplateColumnsHandler extends AbstractSettingsHandl
3845
new Notice(`${Object.keys(columns).length} Columns were loaded from file "${tfile.basename}"! Close this dialog to show the database changes`);
3946
});
4047
});
48+
49+
/*********************************
50+
* TEMPLATE OF ALL POSSIBLE FIELDS
51+
*********************************/
52+
new Setting(template_section)
53+
.setName('Use all fields')
54+
.setDesc('Add all possible columns of your actual source of the database')
55+
.addButton((button) => {
56+
button.setIcon("create-new")
57+
.setTooltip("Load columns from file")
58+
.onClick(async (): Promise<void> => {
59+
const columns = obtainColumnsFromRows(view.rows);
60+
view.diskConfig.yaml.columns = columns;
61+
view.diskConfig.saveOnDisk();
62+
new Notice(`${Object.keys(columns).length} Columns were loaded from all fields avaliable in the current source! Close this dialog to show the database changes`);
63+
});
64+
});
4165
}
4266
return this.goNext(settingHandlerResponse);
4367
}

styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@
464464
background-color: var(--background-modifier-error);
465465
}
466466

467+
.configuration-section-container-columns-template {
468+
background-color: var(--background-modifier-box-shadow);
469+
}
470+
467471
/*
468472
* React-datepicker styles
469473
*/

0 commit comments

Comments
 (0)