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

Commit cb0134f

Browse files
committed
skeleton config done
1 parent 8608b6d commit cb0134f

File tree

8 files changed

+129
-4
lines changed

8 files changed

+129
-4
lines changed

src/Settings.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { LOGGER } from "services/Logger";
66
import { developer_settings_section } from "settings/DeveloperSection";
77
import { columns_settings_section } from "settings/ColumnsSection";
88
import { folder_settings_section } from "settings/FolderSection";
9-
import { DEFAULT_COLUMN_CONFIG, StyleClasses } from "helpers/Constants";
9+
import { DEFAULT_COLUMN_CONFIG, SourceDataTypes, StyleClasses } from "helpers/Constants";
1010
import { SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
1111
import { media_settings_section } from "settings/MediaSection";
12+
import { source_settings_section } from "settings/SourceSection";
1213

1314
export interface MediaSettings {
1415
enable_media_view: boolean;
@@ -30,6 +31,8 @@ export interface LocalSettings {
3031
show_metadata_created: boolean;
3132
show_metadata_modified: boolean;
3233
show_metadata_tasks: boolean;
34+
source_data: string;
35+
source_form_result: string;
3336
}
3437

3538
export interface DatabaseSettings {
@@ -53,7 +56,9 @@ export const DEFAULT_SETTINGS: DatabaseSettings = {
5356
group_folder_column: '',
5457
show_metadata_created: false,
5558
show_metadata_modified: false,
56-
show_metadata_tasks: false
59+
show_metadata_tasks: false,
60+
source_data: SourceDataTypes.CURRENT_FOLDER,
61+
source_form_result: 'root'
5762
}
5863
};
5964

@@ -118,6 +123,8 @@ export class SettingsManager {
118123

119124
constructSettingBody(settingHandlerResponse: SettingHandlerResponse) {
120125
if (settingHandlerResponse.local) {
126+
/** Source section */
127+
source_settings_section(settingHandlerResponse);
121128
/** Folder section */
122129
folder_settings_section(settingHandlerResponse);
123130
}

src/helpers/Constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ export const StyleVariables = Object.freeze({
175175
TEXT_NORMAL: 'var(--text-normal)',
176176
});
177177

178+
export const SourceDataTypes = Object.freeze({
179+
CURRENT_FOLDER: 'current_folder',
180+
TAG: 'tag',
181+
});
182+
178183
export const WidthVariables = Object.freeze({
179184
ICON_SPACING: 17,
180185
MAGIC_SPACING: 10

src/parsers/handlers/marshall/MarshallConfigHandler.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { YamlHandlerResponse } from 'cdm/MashallModel';
2+
import { SourceDataTypes } from 'helpers/Constants';
23
import { AbstractYamlHandler } from 'parsers/handlers/marshall/AbstractYamlPropertyHandler';
34

45
export class MarshallConfigHandler extends AbstractYamlHandler {
@@ -14,7 +15,7 @@ export class MarshallConfigHandler extends AbstractYamlHandler {
1415
yaml.config.enable_show_state = false;
1516
}
1617

17-
// if group_folder_column is not defined, load default
18+
// if group_folder_column is not defined, load empty (optional)
1819
if (checkNullable(yaml.config.group_folder_column)) {
1920
yaml.config.group_folder_column = '';
2021
}
@@ -36,6 +37,17 @@ export class MarshallConfigHandler extends AbstractYamlHandler {
3637
this.addError(`There was not show_metadata_modified key in yaml. Default will be loaded`);
3738
yaml.config.show_metadata_modified = false;
3839
}
40+
41+
// if source_data is not defined, load default
42+
if (checkNullable(yaml.config.source_data)) {
43+
this.addError(`There was not source_data key in yaml. Default will be loaded`);
44+
yaml.config.source_data = SourceDataTypes.CURRENT_FOLDER;
45+
}
46+
47+
// if source_form_result is not defined, load empty (optional)
48+
if (checkNullable(yaml.config.source_form_result)) {
49+
yaml.config.source_form_result = '';
50+
}
3951
}
4052
handlerResponse.yaml = yaml;
4153
return this.goNext(handlerResponse);

src/parsers/handlers/unmarshall/UnmarshallConfigHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class UnmarshallConfigHandler extends AbstractDiskHandler {
99
const { config } = handlerResponse.yaml;
1010
// Lvl1: config
1111
this.localDisk.push(`${this.handlerName}:`);
12+
console.log(`${this.handlerName}:`);
1213
Object.entries(config).forEach(([key, value]) => {
1314
if (typeof value === 'object') {
1415
this.localDisk.push(`${YAML_INDENT.repeat(1)}${key}:`);

src/settings/SettingsComponents.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { OperatorFilter } from "helpers/Constants";
21
import { ButtonComponent, Setting } from "obsidian";
32

43
/**

src/settings/SourceSection.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { add_setting_header } from 'settings/SettingsComponents';
2+
import { SettingHandler, SettingHandlerResponse } from 'settings/handlers/AbstractSettingHandler';
3+
import { SourceDropDownHandler } from 'settings/handlers/source/SourceDropDownHandler';
4+
import { SourceFormHandler } from 'settings/handlers/source/SourceFormHandler';
5+
6+
/**
7+
* developer settings section
8+
*/
9+
export function source_settings_section(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
10+
const columns_section = settingHandlerResponse.containerEl.createDiv("configuration-section-container-source");
11+
// title of the section
12+
add_setting_header(columns_section, "Source of database", 'h3');
13+
// section settings
14+
const handlers = getHandlers();
15+
let i = 1;
16+
while (i < handlers.length) {
17+
handlers[i - 1].setNext(handlers[i]);
18+
i++;
19+
}
20+
settingHandlerResponse.containerEl = columns_section;
21+
return handlers[0].handle(settingHandlerResponse);
22+
}
23+
24+
/**
25+
* Obtain all classes than extends from AbstractHandler
26+
*/
27+
function getHandlers(): SettingHandler[] {
28+
return [
29+
new SourceDropDownHandler(),
30+
new SourceFormHandler()
31+
];
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { SourceDataTypes } from "helpers/Constants";
2+
import { AbstractSettingsHandler, SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
3+
import { add_dropdown } from "settings/SettingsComponents";
4+
5+
export class SourceDropDownHandler extends AbstractSettingsHandler {
6+
settingTitle: string = 'Select the source of database data';
7+
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
8+
const { settingsManager, containerEl, view } = settingHandlerResponse;
9+
const source_dropdown_promise = async (value: string): Promise<void> => {
10+
// update settings
11+
view.diskConfig.updateConfig('source_data', value);
12+
// Force refresh of settings
13+
settingsManager.reset(settingHandlerResponse);
14+
};
15+
// render dropdown inside container
16+
add_dropdown(
17+
containerEl,
18+
this.settingTitle,
19+
'Select from which source you want to get the data to be displayed in the table.',
20+
view.diskConfig.yaml.config.source_data,
21+
{
22+
current_folder: SourceDataTypes.CURRENT_FOLDER,
23+
tag: SourceDataTypes.TAG,
24+
},
25+
source_dropdown_promise
26+
);
27+
return this.goNext(settingHandlerResponse);
28+
}
29+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { SourceDataTypes } from "helpers/Constants";
2+
import { getAllTags } from "obsidian";
3+
import { DataviewService } from "services/DataviewService";
4+
import { LOGGER } from "services/Logger";
5+
import { AbstractSettingsHandler, SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
6+
import { add_dropdown } from "settings/SettingsComponents";
7+
8+
export class SourceFormHandler extends AbstractSettingsHandler {
9+
settingTitle: string = 'Form in function of source data';
10+
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
11+
const { containerEl, view } = settingHandlerResponse;
12+
switch (view.diskConfig.yaml.config.source_data) {
13+
case SourceDataTypes.TAG:
14+
const tagArray: Record<string, number> = (app.metadataCache as unknown as any).getTags();
15+
if (tagArray) {
16+
const tagRecords: Record<string, string> = {};
17+
Object.keys(tagArray).forEach((tag) => {
18+
tagRecords[tag] = tag;
19+
});
20+
const source_form_promise = async (value: string): Promise<void> => {
21+
// update settings
22+
view.diskConfig.updateConfig('source_form_result', value.slice(1));
23+
};
24+
25+
add_dropdown(
26+
containerEl,
27+
'Select a tag',
28+
'Select tag to get data from',
29+
`#${view.diskConfig.yaml.config.source_form_result}`,
30+
tagRecords,
31+
source_form_promise
32+
);
33+
}
34+
default:
35+
//Current folder
36+
}
37+
38+
return this.goNext(settingHandlerResponse);
39+
}
40+
}

0 commit comments

Comments
 (0)