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

Commit d53d0b3

Browse files
committed
checkpoint
1 parent 19bac29 commit d53d0b3

File tree

12 files changed

+124
-79
lines changed

12 files changed

+124
-79
lines changed

src/Settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class SettingsManager {
103103

104104
const settingBody = containerEl.createDiv();
105105
settingBody.addClass(StyleClasses.SETTINGS_MODAL_BODY);
106-
containerEl.setAttribute("id", StyleClasses.SETTINGS_MODAL_BODY);
106+
settingBody.setAttribute("id", StyleClasses.SETTINGS_MODAL_BODY);
107107
const settingHandlerResponse: SettingHandlerResponse = {
108108
settingsManager: this,
109109
containerEl: settingBody,

src/cdm/DatabaseModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ export type CalendarProps = {
4444
intialState: TableDataType;
4545
column: TableColumn;
4646
cellProperties: Cell;
47-
};
47+
};

src/cdm/ModalSettingsModel.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { TableColumn } from "cdm/FolderModel";
2+
import { ColumnSettingsManager } from "components/modals/ColumnModal";
3+
import { DatabaseView } from "DatabaseView";
4+
5+
export type ColumnHandlerResponse = {
6+
containerEl: HTMLElement,
7+
view: DatabaseView,
8+
column: TableColumn,
9+
columnSettingsManager: ColumnSettingsManager
10+
}

src/components/Cell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function DefaultCell(cellProperties: Cell) {
5858
//TODO - this is a hack. find why is layout effect called twice
5959
containerCellRef.current.innerHTML = "";
6060
renderMarkdown(
61-
(cellProperties as any).initialState.view,
61+
cellProperties,
6262
contextValue.value,
6363
containerCellRef.current
6464
);

src/components/markdown/MarkdownRenderer.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { NormalizedPath } from "cdm/FolderModel";
1+
import { DatabaseColumn } from "cdm/DatabaseModel";
22
import { DatabaseView } from "DatabaseView";
33
import { MediaExtensions } from "helpers/Constants";
44
import { getNormalizedPath } from "helpers/VaultManagement";
55
import { MarkdownRenderer, TFile } from "obsidian";
6+
import { Cell } from "react-table";
67
import { LOGGER } from "services/Logger";
78

89
export async function renderMarkdown(
9-
view: DatabaseView,
10+
cell: Cell,
1011
markdownString: string,
1112
domElement: HTMLDivElement
1213
): Promise<HTMLDivElement> {
1314
try {
14-
if (isValidHttpUrl(markdownString, view)) {
15+
const view = (cell as any).initialState.view;
16+
const column = cell.column as unknown as DatabaseColumn;
17+
if (isValidHttpUrl(markdownString, column)) {
1518
const { height, width } = view.diskConfig.yaml.config.media_settings;
1619
// TODO option to generate Iframes
1720
//markdownString = `<div class=iframe-container> <iframe width="427" height="240" src="${markdownString}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div>`;
@@ -127,7 +130,7 @@ function handleVideo(el: HTMLElement, file: TFile, view: DatabaseView) {
127130
el.addClasses(["media-embed", "is-loaded"]);
128131
}
129132

130-
function isValidHttpUrl(urlCandidate: string, view: DatabaseView) {
133+
function isValidHttpUrl(urlCandidate: string, column: DatabaseColumn) {
131134
let url;
132135

133136
try {
@@ -138,6 +141,6 @@ function isValidHttpUrl(urlCandidate: string, view: DatabaseView) {
138141

139142
return (
140143
(url.protocol === "http:" || url.protocol === "https:") &&
141-
view.diskConfig.yaml.config.media_settings.enable_media_view
144+
column.config.enable_media_view
142145
);
143146
}

src/components/modals/ColumnModal.ts

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,79 @@ import { TableColumn } from "cdm/FolderModel";
22
import { DatabaseView } from "DatabaseView";
33
import { Modal } from "obsidian";
44
import { add_setting_header } from "settings/SettingsComponents";
5-
import { ColumnHandler, ColumnHandlerResponse } from "components/modals/handlers/AbstractColumnHandler";
5+
import { ColumnHandler } from "components/modals/handlers/AbstractColumnHandler";
66
import { MediaDimensionsHandler } from "components/modals/handlers/MediaDimensionsHandler";
77
import { MediaToggleHandler } from "components/modals/handlers/MediaToggleHandler";
8+
import { StyleClasses } from "helpers/Constants";
9+
import { ColumnHandlerResponse } from "cdm/ModalSettingsModel";
810

911
export class ColumnModal extends Modal {
1012
view: DatabaseView;
1113
column: TableColumn;
14+
columnSettingsManager: ColumnSettingsManager;
1215
constructor(
1316
view: DatabaseView,
1417
column: TableColumn
1518
) {
1619
super(view.app);
1720
this.view = view;
1821
this.column = column;
22+
this.columnSettingsManager = new ColumnSettingsManager(this.view, this.column);
1923
}
2024

2125
onOpen() {
22-
const { contentEl, modalEl } = this;
26+
const { contentEl } = this;
2327
contentEl.empty();
28+
this.columnSettingsManager.constructUI(contentEl);
29+
}
30+
31+
reset(columnHandlerResponse: ColumnHandlerResponse) {
32+
33+
}
34+
35+
onClose() {
36+
const { contentEl } = this;
37+
contentEl.empty();
38+
}
39+
}
40+
export class ColumnSettingsManager {
41+
view: DatabaseView;
42+
column: TableColumn;
43+
constructor(
44+
view: DatabaseView,
45+
column: TableColumn
46+
) {
47+
this.view = view;
48+
this.column = column;
49+
}
50+
constructUI(containerEl: HTMLElement) {
51+
/** Common modal headings */
52+
containerEl.addClass(StyleClasses.COLUMN_MODAL);
53+
add_setting_header(containerEl, `Settings of ${this.column.label} column`, 'h2');
54+
55+
const settingBody = containerEl.createDiv();
56+
settingBody.addClass(StyleClasses.COLUMN_MODAL_BODY);
57+
settingBody.setAttribute("id", StyleClasses.COLUMN_MODAL_BODY);
2458
const initialResponse: ColumnHandlerResponse = {
25-
containerEl: contentEl,
59+
containerEl: containerEl,
2660
view: this.view,
2761
column: this.column,
62+
columnSettingsManager: this
2863
};
29-
folder_settings_section(initialResponse);
64+
this.constructBody(initialResponse);
3065
}
3166

32-
onClose() {
33-
const { contentEl } = this;
34-
contentEl.empty();
67+
constructBody(settingHandlerResponse: ColumnHandlerResponse) {
68+
/** Columns section */
69+
folder_settings_section(settingHandlerResponse);
70+
}
71+
72+
reset(response: ColumnHandlerResponse) {
73+
const columnElement = document.getElementById(StyleClasses.COLUMN_MODAL_BODY);
74+
// remove all sections
75+
columnElement.empty();
76+
response.containerEl = columnElement;
77+
this.constructBody(response);
3578
}
3679
}
3780

src/components/modals/handlers/AbstractColumnHandler.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import { TableColumn } from "cdm/FolderModel";
2-
import { DatabaseView } from "DatabaseView";
3-
4-
export type ColumnHandlerResponse = {
5-
containerEl: HTMLElement,
6-
view: DatabaseView,
7-
column: TableColumn,
8-
}
1+
import { ColumnHandlerResponse } from "cdm/ModalSettingsModel";
92

103
export interface ColumnHandler {
114
setNext(handler: ColumnHandler): ColumnHandler;
@@ -32,4 +25,4 @@ export abstract class AbstractColumnHandler implements ColumnHandler {
3225

3326

3427
abstract handle(settingHandlerResponse: ColumnHandlerResponse): ColumnHandlerResponse;
35-
}
28+
}

src/components/modals/handlers/MediaDimensionsHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Setting } from "obsidian";
2-
import { AbstractColumnHandler, ColumnHandlerResponse } from "components/modals/handlers/AbstractColumnHandler";
2+
import { AbstractColumnHandler } from "components/modals/handlers/AbstractColumnHandler";
3+
import { ColumnHandlerResponse } from "cdm/ModalSettingsModel";
34

45
export class MediaDimensionsHandler extends AbstractColumnHandler {
56
settingTitle: string = 'Choose dimensions of embeded media';

src/components/modals/handlers/MediaToggleHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { add_toggle } from "settings/SettingsComponents";
2-
import { AbstractColumnHandler, ColumnHandlerResponse } from "components/modals/handlers/AbstractColumnHandler";
2+
import { AbstractColumnHandler } from "components/modals/handlers/AbstractColumnHandler";
3+
import { ColumnHandlerResponse } from "cdm/ModalSettingsModel";
34
export class MediaToggleHandler extends AbstractColumnHandler {
45
settingTitle: string = 'Enable media links';
56
handle(settingHandlerResponse: ColumnHandlerResponse): ColumnHandlerResponse {

src/helpers/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ export const StyleClasses = Object.freeze({
145145
TABLE_CONTAINER: 'dbfolder-table-container',
146146
SETTINGS_MODAL: 'database-settings-modal',
147147
SETTINGS_MODAL_BODY: 'database-settings-body',
148+
COLUMN_MODAL: 'database-column-modal',
149+
COLUMN_MODAL_BODY: 'database-column-body',
148150
});
149151

150152
export const StyleVariables = Object.freeze({

0 commit comments

Comments
 (0)