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

Commit 1bbe9c3

Browse files
committed
Merge branch '59-fr-create-db-from-dataview-query'
2 parents 8608b6d + 0a69b0f commit 1bbe9c3

File tree

14 files changed

+189
-17
lines changed

14 files changed

+189
-17
lines changed

docs/docs/changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 1.6.0
2+
### Shiny new things
3+
- Another kind of data sources of dataview are added(current folder will be avaliable too, of course) [ISSUE#59](https://github.com/RafaelGB/obsidian-db-folder/issues/59):
4+
- TAGs: select a tag from a list of all tags
5+
- INCOMING_LINKS: select a file from a list of all files
6+
- OUTGOING_LINKS: select a file from a list of all files
7+
8+
### No longer broken
9+
- Filters of type "contains", "starts with" & "ends with" are fixed. A bug appears when original data was empty. [ISSUE#72](https://github.com/RafaelGB/obsidian-db-folder/issues/72)
110
## 1.5.1
211
*Published on 2022/05/29*
312
### Shiny new things

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "dbfolder",
33
"name": "DB Folder",
4-
"version": "1.5.1",
4+
"version": "1.6.0",
55
"minAppVersion": "0.14.6",
66
"description": "Folder with the capability to store and retrieve data from a folder like database",
77
"author": "RafaelGB",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-dbfolder",
3-
"version": "1.5.1",
3+
"version": "1.6.0",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {

src/DatabaseView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class DatabaseView extends TextFileView implements HoverParent {
132132
const rows = await adapterTFilesToRows(
133133
this.file.parent.path,
134134
columns,
135-
this.diskConfig.yaml.filters
135+
this.diskConfig.yaml
136136
);
137137
const initialState: InitialState = obtainInitialState(columns, rows);
138138
// Define table properties

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ 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+
OUTGOING_LINK: 'outgoing_link',
182+
INCOMING_LINK: 'incoming_link',
183+
});
184+
178185
export const WidthVariables = Object.freeze({
179186
ICON_SPACING: 17,
180187
MAGIC_SPACING: 10

src/helpers/VaultManagement.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { ActionType } from 'react-table';
44
import { VaultManagerDB } from 'services/FileManagerService';
55
import { LOGGER } from "services/Logger";
66
import NoteInfo from 'services/NoteInfo';
7-
import { DatabaseCore, UpdateRowOptions } from "helpers/Constants";
7+
import { DatabaseCore, SourceDataTypes, UpdateRowOptions } from "helpers/Constants";
88
import obtainRowDatabaseFields from 'parsers/FileToRowDatabaseFields';
99
import { parseFrontmatterFieldsToString } from 'parsers/RowDatabaseFieldsToFile';
1010
import { DataviewService } from 'services/DataviewService';
11-
import { FilterCondition } from 'cdm/DatabaseModel';
11+
import { DatabaseYaml } from 'cdm/DatabaseModel';
12+
import { Literal } from 'obsidian-dataview/lib/data-model/value';
13+
import { DataArray } from 'obsidian-dataview/lib/api/data-array';
1214

1315
const noBreakSpace = /\u00A0/g;
1416

@@ -62,16 +64,16 @@ export function getNormalizedPath(path: string): NormalizedPath {
6264
* @param folderPath
6365
* @returns
6466
*/
65-
export async function adapterTFilesToRows(folderPath: string, columns: TableColumn[], filters: FilterCondition[]): Promise<Array<RowDataType>> {
67+
export async function adapterTFilesToRows(folderPath: string, columns: TableColumn[], dbYaml: DatabaseYaml): Promise<Array<RowDataType>> {
6668
LOGGER.debug(`=> adapterTFilesToRows. folderPath:${folderPath}`);
6769
const rows: Array<RowDataType> = [];
6870
let id = 0;
6971

70-
let folderFiles = DataviewService.getDataviewAPI().pages(`"${folderPath}"`)
72+
let folderFiles = sourceDataviewPages(folderPath, dbYaml)
7173
.where(p => !p[DatabaseCore.FRONTMATTER_KEY]);
7274
// Config filters asociated with the database
73-
if (filters) {
74-
folderFiles = folderFiles.where(p => DataviewService.filter(filters, p));
75+
if (dbYaml.filters) {
76+
folderFiles = folderFiles.where(p => DataviewService.filter(dbYaml.filters, p));
7577
}
7678

7779
folderFiles.map(async (page) => {
@@ -83,6 +85,18 @@ export async function adapterTFilesToRows(folderPath: string, columns: TableColu
8385
return rows;
8486
}
8587

88+
export function sourceDataviewPages(folderPath: string, dbYaml: DatabaseYaml): DataArray<Record<string, Literal>> {
89+
switch (dbYaml.config.source_data) {
90+
case SourceDataTypes.TAG:
91+
return DataviewService.getDataviewAPI().pages(`#${dbYaml.config.source_form_result}`);
92+
case SourceDataTypes.INCOMING_LINK:
93+
return DataviewService.getDataviewAPI().pages(`[[${dbYaml.config.source_form_result}]]`);
94+
case SourceDataTypes.OUTGOING_LINK:
95+
return DataviewService.getDataviewAPI().pages(`outgoing([[${dbYaml.config.source_form_result}]])`);
96+
default:
97+
return DataviewService.getDataviewAPI().pages(`"${folderPath}"`);
98+
}
99+
}
86100
export async function updateRowFileProxy(file: TFile, columnId: string, newValue: string, state: TableDataType, option: string): Promise<void> {
87101
await updateRowFile(file, columnId, newValue, state, option).catch(e => {
88102
LOGGER.error(`updateRowFileProxy. Error:${e}`);

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/services/DataviewService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ class DataviewProxy {
4646
if (p[c.field] > c.value) return false;
4747
break;
4848
case OperatorFilter.CONTAINS:
49-
if (!p[c.field].includes(c.value)) return false;
49+
if (p[c.field] !== undefined && !p[c.field].includes(c.value)) return false;
5050
break;
5151
case OperatorFilter.STARTS_WITH:
52-
if (!p[c.field].startsWith(c.value)) return false;
52+
if (p[c.field] !== undefined && !p[c.field].startsWith(c.value)) return false;
5353
break;
5454
case OperatorFilter.ENDS_WITH:
55-
if (!p[c.field].endsWith(c.value)) return false;
55+
if (p[c.field] !== undefined && !p[c.field].endsWith(c.value)) return false;
5656
break;
5757
default:
5858
throw new Error(`Unknown operator: ${c.operator}`);

src/services/MarkdownPostProcessorService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class PreviewDatabaseModeService {
137137
const rows = await adapterTFilesToRows(
138138
dbFile.parent.path,
139139
columns,
140-
databaseDisk.yaml.filters
140+
databaseDisk.yaml
141141
);
142142
const dataviewCols: string[] = columns
143143
.filter((col) => !col.skipPersist)

0 commit comments

Comments
 (0)