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

Commit de69f61

Browse files
committed
Merge branch 'bug-persisting-data'
2 parents 1bbe9c3 + 61ac909 commit de69f61

File tree

12 files changed

+132
-107
lines changed

12 files changed

+132
-107
lines changed

src/Settings.ts

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,7 @@ import { DEFAULT_COLUMN_CONFIG, SourceDataTypes, StyleClasses } from "helpers/Co
1010
import { SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
1111
import { media_settings_section } from "settings/MediaSection";
1212
import { source_settings_section } from "settings/SourceSection";
13-
14-
export interface MediaSettings {
15-
enable_media_view: boolean;
16-
width: number;
17-
height: number;
18-
}
19-
/**
20-
* Options that affects the behavior of the plugin and defines default values with some fields
21-
*/
22-
interface GlobalSettings {
23-
enable_debug_mode: boolean;
24-
logger_level_info: string;
25-
media_settings: MediaSettings;
26-
}
27-
export interface LocalSettings {
28-
enable_show_state: boolean;
29-
group_folder_column: string;
30-
remove_field_when_delete_column: boolean;
31-
show_metadata_created: boolean;
32-
show_metadata_modified: boolean;
33-
show_metadata_tasks: boolean;
34-
source_data: string;
35-
source_form_result: string;
36-
}
37-
38-
export interface DatabaseSettings {
39-
global_settings: GlobalSettings;
40-
local_settings: LocalSettings;
41-
}
42-
43-
export const DEFAULT_SETTINGS: DatabaseSettings = {
44-
global_settings: {
45-
enable_debug_mode: false,
46-
logger_level_info: 'error',
47-
media_settings: {
48-
enable_media_view: DEFAULT_COLUMN_CONFIG.enable_media_view,
49-
width: DEFAULT_COLUMN_CONFIG.media_height,
50-
height: DEFAULT_COLUMN_CONFIG.media_height
51-
}
52-
},
53-
local_settings: {
54-
enable_show_state: false,
55-
remove_field_when_delete_column: false,
56-
group_folder_column: '',
57-
show_metadata_created: false,
58-
show_metadata_modified: false,
59-
show_metadata_tasks: false,
60-
source_data: SourceDataTypes.CURRENT_FOLDER,
61-
source_form_result: 'root'
62-
}
63-
};
13+
import { DatabaseSettings } from "cdm/SettingsModel";
6414

6515
export type SettingRetriever = <K extends keyof DatabaseSettings>(
6616
key: K,

src/StateManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { DatabaseSettings } from "cdm/SettingsModel";
12
import { DatabaseView } from "DatabaseView";
23
import { App, TFile } from 'obsidian';
3-
import { LOGGER } from "services/Logger";
4-
import { DatabaseSettings } from 'Settings';
54
export default class StateManager {
65
private onEmpty: () => void;
76
private getGlobalSettings: () => DatabaseSettings;

src/api/plugin-api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FolderModel, } from 'cdm/FolderModel';
2+
import { DatabaseSettings } from 'cdm/SettingsModel';
23
import { App } from 'obsidian';
3-
import { DatabaseSettings } from 'Settings';
44
import { Schema } from 'services/BaseService';
55
import { DbfAPIInterface } from 'typings/api';
66

@@ -9,15 +9,15 @@ export class DBFolderAPI implements DbfAPIInterface {
99
settings: DatabaseSettings;
1010

1111
public constructor(
12-
app: App,
12+
app: App,
1313
settings: DatabaseSettings
1414
) {
1515
this.app = app;
1616
this.settings = settings;
1717
}
18-
18+
1919
obtainFolderModel(key: string): FolderModel {
20-
const model:FolderModel = Schema.getInstance().getModel(key);
20+
const model: FolderModel = Schema.getInstance().getModel(key);
2121
return model;
2222
}
2323
}

src/cdm/DatabaseModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RowType } from "cdm/RowTypeModel"
2+
import { LocalSettings } from "cdm/SettingsModel";
23
import { Literal } from "obsidian-dataview/lib/data-model/value";
34
import { Cell } from "react-table";
4-
import { LocalSettings } from "Settings"
55
import { BaseColumn, TableColumn, TableDataType } from "cdm/FolderModel";
66
import { RowSelectOption } from "cdm/RowSelectModel";
77

src/cdm/SettingsModel.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export interface MediaSettings {
2+
enable_media_view: boolean;
3+
width: number;
4+
height: number;
5+
}
6+
/**
7+
* Options that affects the behavior of the plugin and defines default values with some fields
8+
*/
9+
interface GlobalSettings {
10+
enable_debug_mode: boolean;
11+
logger_level_info: string;
12+
media_settings: MediaSettings;
13+
}
14+
export interface LocalSettings {
15+
enable_show_state: boolean;
16+
group_folder_column: string;
17+
remove_field_when_delete_column: boolean;
18+
show_metadata_created: boolean;
19+
show_metadata_modified: boolean;
20+
show_metadata_tasks: boolean;
21+
source_data: string;
22+
source_form_result: string;
23+
}
24+
25+
export interface DatabaseSettings {
26+
global_settings: GlobalSettings;
27+
local_settings: LocalSettings;
28+
}

src/components/Columns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { TableColumn } from "cdm/FolderModel";
77
import { LOGGER } from "services/Logger";
88
import { DatabaseColumn } from "cdm/DatabaseModel";
99
import { RowSelectOption } from "cdm/RowSelectModel";
10+
import { LocalSettings } from "cdm/SettingsModel";
1011
import { dbTrim } from "helpers/StylesHelper";
11-
import { LocalSettings } from "Settings";
1212

1313
/**
1414
* Add mandatory columns to the table

src/components/RelationShip.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import React from "react";
22
import { grey } from "helpers/Colors";
33
import { RelationshipProps } from "cdm/FolderModel";
4+
import { c } from "helpers/StylesHelper";
45

56
export default function Relationship(relationShipProps: RelationshipProps) {
67
const { value, backgroundColor } = relationShipProps;
78
return (
89
<span
10+
className={c("relationship")}
911
style={{
10-
boxSizing: "border-box",
1112
backgroundColor: backgroundColor,
1213
color: grey(800),
13-
fontWeight: 400,
14-
padding: "2px 6px",
15-
borderRadius: 4,
16-
display: "inline-block",
1714
}}
1815
>
1916
{value}

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import update from "immutability-helper";
33
import {
44
ActionTypes,
55
DataTypes,
6+
DEFAULT_COLUMN_CONFIG,
67
MetadataColumns,
78
TableColumnsTemplate,
89
UpdateRowOptions,
@@ -27,9 +28,7 @@ import { Literal } from "obsidian-dataview/lib/data-model/value";
2728
import { DateTime } from "luxon";
2829

2930
export function databaseReducer(state: TableDataType, action: ActionType) {
30-
LOGGER.debug(
31-
`<=>databaseReducer action: ${action.type} value: ${action.value}`
32-
);
31+
LOGGER.debug(`<=>databaseReducer action: ${action.type}`, action);
3332
/** database configuration */
3433
const dbconfig = state.view.diskConfig.yaml.config;
3534
// Check if action exists
@@ -114,23 +113,25 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
114113
(column: any) => column.id === action.columnId
115114
);
116115
// Update configuration & row files on disk
117-
state.view.diskConfig
118-
.updateColumnKey(action.columnId, action.newKey, action.label)
119-
.then(async () => {
120-
// Once the column is updated, update the rows in case the key is changed
121-
122-
await Promise.all(
123-
state.data.map(async (row: RowDataType) => {
124-
await updateRowFileProxy(
125-
row.note.getFile(),
126-
action.columnId,
127-
action.newKey,
128-
state,
129-
UpdateRowOptions.COLUMN_KEY
130-
);
131-
})
132-
);
133-
});
116+
state.view.diskConfig.updateColumnKey(
117+
action.columnId,
118+
action.newKey,
119+
action.label
120+
);
121+
async () => {
122+
// Update the rows in case the key is changed
123+
await Promise.all(
124+
state.data.map(async (row: RowDataType) => {
125+
await updateRowFileProxy(
126+
row.note.getFile(),
127+
action.columnId,
128+
action.newKey,
129+
state,
130+
UpdateRowOptions.COLUMN_KEY
131+
);
132+
})
133+
);
134+
};
134135
return update(state, {
135136
skipReset: { $set: true },
136137
// Modify column visually with the new label
@@ -158,6 +159,14 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
158159
return row;
159160
}),
160161
},
162+
// Update view yaml state
163+
view: {
164+
diskConfig: {
165+
yaml: {
166+
$set: state.view.diskConfig.yaml,
167+
},
168+
},
169+
},
161170
});
162171

163172
/**
@@ -256,12 +265,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
256265
key: action.columnInfo.name,
257266
label: action.columnInfo.label,
258267
position: action.columnInfo.position,
259-
config: {
260-
isInline: false,
261-
media_height: 100,
262-
media_width: 100,
263-
enable_media_view: false,
264-
},
268+
config: DEFAULT_COLUMN_CONFIG,
265269
};
266270
// Update configuration on disk
267271
state.view.diskConfig.addColumn(action.columnInfo.name, newLeftColumn);
@@ -285,6 +289,14 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
285289
...state.columns.slice(leftIndex, state.columns.length),
286290
],
287291
},
292+
// Update view yaml
293+
view: {
294+
diskConfig: {
295+
yaml: {
296+
$set: state.view.diskConfig.yaml,
297+
},
298+
},
299+
},
288300
});
289301
/**
290302
* Add new column to the table to the right of the column with the given id
@@ -301,12 +313,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
301313
key: action.columnInfo.name,
302314
label: action.columnInfo.label,
303315
position: action.columnInfo.position,
304-
config: {
305-
isInline: false,
306-
media_height: 100,
307-
media_width: 100,
308-
enable_media_view: false,
309-
},
316+
config: DEFAULT_COLUMN_CONFIG,
310317
};
311318
// Update configuration on disk
312319
state.view.diskConfig.addColumn(action.columnInfo.name, newRIghtColumn);
@@ -331,6 +338,14 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
331338
...state.columns.slice(rightIndex + 1, state.columns.length),
332339
],
333340
},
341+
// Update view yaml
342+
view: {
343+
diskConfig: {
344+
yaml: {
345+
$set: state.view.diskConfig.yaml,
346+
},
347+
},
348+
},
334349
});
335350
case ActionTypes.DELETE_COLUMN:
336351
const deleteIndex = state.columns.findIndex(

src/helpers/Constants.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TableColumn } from "cdm/FolderModel";
2+
import { DatabaseSettings } from "cdm/SettingsModel";
23

34
/** Table Actions */
45
export const ActionTypes = Object.freeze({
@@ -54,7 +55,8 @@ export const DEFAULT_COLUMN_CONFIG = Object.freeze({
5455
enable_media_view: true,
5556
media_width: 100,
5657
media_height: 100,
57-
isInline: false
58+
isInline: false,
59+
source_data: 'current_folder',
5860
});
5961

6062
export const MetadataDatabaseColumns = Object.freeze({
@@ -146,6 +148,7 @@ export const DatabaseFrontmatterOptions = Object.freeze({
146148
' media_width: 100',
147149
' media_height: 100',
148150
' isInline: false',
151+
' source_data: current_folder',
149152
'filters:',
150153
].join('\n')
151154
});
@@ -165,6 +168,7 @@ export const StyleClasses = Object.freeze({
165168
COLUMN_MODAL_BODY: 'database-column-body',
166169
});
167170

171+
168172
export const StyleVariables = Object.freeze({
169173
BACKGROUND_MODIFIER_ERROR: 'var(--background-modifier-error)',
170174
BACKGROUND_PRIMARY: 'var(--background-primary)',
@@ -212,4 +216,29 @@ export const MediaExtensions = Object.freeze({
212216
AUDIO: ['mp3', 'wav', 'm4a', '3gp', 'flac', 'ogg', 'oga']
213217
});
214218

215-
export const YAML_INDENT = Object.freeze(" ");
219+
export const YAML_INDENT = Object.freeze(" ");
220+
221+
/******************************************************************************
222+
* SETTINGS CONSTANTS
223+
******************************************************************************/
224+
export const DEFAULT_SETTINGS: DatabaseSettings = {
225+
global_settings: {
226+
enable_debug_mode: false,
227+
logger_level_info: 'error',
228+
media_settings: {
229+
enable_media_view: DEFAULT_COLUMN_CONFIG.enable_media_view,
230+
width: DEFAULT_COLUMN_CONFIG.media_height,
231+
height: DEFAULT_COLUMN_CONFIG.media_height
232+
}
233+
},
234+
local_settings: {
235+
enable_show_state: false,
236+
remove_field_when_delete_column: false,
237+
group_folder_column: '',
238+
show_metadata_created: false,
239+
show_metadata_modified: false,
240+
show_metadata_tasks: false,
241+
source_data: SourceDataTypes.CURRENT_FOLDER,
242+
source_form_result: 'root'
243+
}
244+
};

src/main.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
} from 'DatabaseView';
1616

1717
import {
18-
DEFAULT_SETTINGS,
19-
DatabaseSettings,
2018
DBFolderSettingTab,
2119
loadServicesThatRequireSettings
2220
} from 'Settings';
@@ -28,11 +26,12 @@ import {
2826
import {
2927
DBFolderAPI
3028
} from 'api/plugin-api';
29+
import { DatabaseSettings } from 'cdm/SettingsModel';
3130

3231
import StateManager from 'StateManager';
3332
import { around } from 'monkey-around';
3433
import { LOGGER } from 'services/Logger';
35-
import { DatabaseCore, DatabaseFrontmatterOptions } from 'helpers/Constants';
34+
import { DatabaseCore, DatabaseFrontmatterOptions, DEFAULT_SETTINGS } from 'helpers/Constants';
3635
import { PreviewDatabaseModeService } from 'services/MarkdownPostProcessorService';
3736

3837
export default class DBFolderPlugin extends Plugin {

0 commit comments

Comments
 (0)