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

Commit b7473e1

Browse files
committed
first version working
1 parent 92b9d62 commit b7473e1

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

src/DatabaseView.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,18 @@ export class DatabaseView extends TextFileView implements HoverParent {
5757
super(leaf);
5858
this.plugin = plugin;
5959
this.emitter = createEmitter();
60-
this.file = file;
61-
this.register(
62-
this.containerEl.onWindowMigrated(() => {
63-
this.plugin.removeView(this);
64-
this.plugin.addView(this, this.data);
65-
})
66-
);
60+
if (file) {
61+
this.file = file;
62+
this.plugin.removeView(this);
63+
this.plugin.addView(this, this.data);
64+
} else {
65+
this.register(
66+
this.containerEl.onWindowMigrated(() => {
67+
this.plugin.removeView(this);
68+
this.plugin.addView(this, this.data);
69+
})
70+
);
71+
}
6772
}
6873

6974
/**

src/api/obsidian-projects-api.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
} from 'DatabaseView';
77
import { LOGGER } from "services/Logger";
88
import { DataQueryResult, ProjectView, ProjectViewProps } from "obsidian-projects-types";
9-
import { createDatabaseFile, resolve_tfile } from "helpers/FileManagement";
9+
import { resolve_tfile, resolve_tfolder } from "helpers/FileManagement";
10+
import { generateDbConfiguration, generateNewDatabase } from "helpers/CommandsHelper";
1011

1112
class ProjectAPI extends ProjectView {
1213
private plugin: DBFolderPlugin;
@@ -46,9 +47,11 @@ class ProjectAPI extends ProjectView {
4647
const { path } = project;
4748
let filePath = config.filepath;
4849
if (!filePath) {
49-
// If the config is empty, we need to create a Default
50-
filePath = await createDatabaseFile(path, `${viewId}_db`, this.plugin.settings.local_settings);
51-
saveConfig({ filepath: filePath });
50+
const folder = resolve_tfolder(path);
51+
// If the config is empty, we need to create a Default
52+
const dbConfig = generateDbConfiguration(this.plugin.settings.local_settings);
53+
await generateNewDatabase(dbConfig, folder, `${viewId}_db`, false);
54+
saveConfig({ filepath: `${path}/${viewId}_db.md` });
5255
}
5356
const leaf = app.workspace.getLeaf();
5457
const file = resolve_tfile(filePath);

src/helpers/CommandsHelper.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Notice, TFile, TFolder } from "obsidian";
33
import { LOGGER } from "services/Logger";
44
import { DatabaseCore, DatabaseFrontmatterOptions, DATABASE_CONFIG, DEFAULT_SETTINGS, YAML_INDENT } from "helpers/Constants";
55

6-
export async function generateNewDatabase(ddbbConfig: string, folder?: TFolder, ddbbName?: string) {
6+
export async function generateNewDatabase(ddbbConfig: string, folder?: TFolder, ddbbName?: string, autoOpen = true) {
77
const targetFolder = folder
88
?? app.fileManager.getNewFileParent(
99
app.workspace.getActiveFile()?.path || ''
@@ -22,10 +22,13 @@ export async function generateNewDatabase(ddbbConfig: string, folder?: TFolder,
2222
.concat('\n')
2323
.concat(DATABASE_CONFIG.END_CENTINEL)
2424
);
25-
await app.workspace.getMostRecentLeaf().setViewState({
26-
type: DatabaseCore.FRONTMATTER_KEY,
27-
state: { file: database.path },
28-
});
25+
// Open the new database file
26+
if (autoOpen) {
27+
await app.workspace.getMostRecentLeaf().setViewState({
28+
type: DatabaseCore.FRONTMATTER_KEY,
29+
state: { file: database.path },
30+
});
31+
}
2932
} catch (e) {
3033
LOGGER.error('Error creating database folder:', e);
3134
new Notice(`Error creating database folder: ${e}`, 5000);

src/helpers/FileManagement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const resolveNewFilePath = ({
166166
* @param ddbbConfig
167167
* @returns
168168
*/
169-
export async function createDatabaseFile(
169+
export async function create_row_file(
170170
folderPath: string,
171171
filename: string,
172172
ddbbConfig: LocalSettings

src/stateManagement/data/handlers/AddRowHandlerAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RowDataType, TableColumn } from "cdm/FolderModel";
22
import { LocalSettings } from "cdm/SettingsModel";
33
import { DataState, TableActionResponse } from "cdm/TableStateInterface";
4-
import { createDatabaseFile, destination_folder } from "helpers/FileManagement";
4+
import { create_row_file, destination_folder } from "helpers/FileManagement";
55
import { DateTime } from "luxon";
66
import { Link } from "obsidian-dataview";
77
import NoteInfo from "services/NoteInfo";
@@ -12,7 +12,7 @@ export default class AddRowlHandlerAction extends AbstractTableAction<DataState>
1212
const { view, set, implementation } = tableActionResponse;
1313
implementation.actions.addRow = async (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => {
1414
const folderPath = destination_folder(view, ddbbConfig);
15-
const filepath = await createDatabaseFile(folderPath, filename, ddbbConfig);
15+
const filepath = await create_row_file(folderPath, filename, ddbbConfig);
1616

1717
const newNote = new NoteInfo({
1818
file: {

0 commit comments

Comments
 (0)