finish some command coding

This commit is contained in:
Jiaxin Peng
2023-12-27 00:27:32 +00:00
parent 59c15f1206
commit fb5f7b502d
8 changed files with 235 additions and 194 deletions

View File

@@ -1,8 +1,9 @@
import { i18nConfig } from "src/lang/I18n"; import { i18nConfig } from "src/lang/I18n";
import { Editor, MarkdownView } from "obsidian"; import {Editor, MarkdownView, setTooltip} from "obsidian";
import { FuzzySuggester, DatabaseList } from "./FuzzySuggester"; import { FuzzySuggester, DatabaseList } from "./FuzzySuggester";
import { uploadCommandGeneral, uploadCommandNext } from "../upload/uploadCommand"; import { uploadCommandGeneral, uploadCommandNext } from "../upload/uploadCommand";
import ObsidianSyncNotionPlugin from "src/main"; import ObsidianSyncNotionPlugin from "src/main";
import {DatabaseDetails} from "../ui/settingTabs";
interface Command { interface Command {
@@ -21,26 +22,11 @@ export default class RibbonCommands {
constructor(plugin: ObsidianSyncNotionPlugin) { constructor(plugin: ObsidianSyncNotionPlugin) {
this.plugin = plugin; this.plugin = plugin;
// Check if NextButton is true, then include the corresponding command // iterate through the database detail
if (this.plugin.settings.NextButton) {
this.Ncommand.push({
id: "share-to-notionnext",
name: i18nConfig.CommandName, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app);
}
});
}
// Check if GeneralButton is true, then include the corresponding command for (let key in this.plugin.settings.databaseDetails) {
if (this.plugin.settings.GeneralButton) { let dbDetails = this.plugin.settings.databaseDetails[key];
this.Ncommand.push({ this.addCommandForDatabase(dbDetails);
id: "share-to-notion",
name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app);
}
});
} }
// Register all the commands // Register all the commands
@@ -77,24 +63,9 @@ export default class RibbonCommands {
this.Ncommand = []; this.Ncommand = [];
if (this.plugin.settings.NextButton) { for (let key in this.plugin.settings.databaseDetails) {
this.Ncommand.push({ let dbDetails = this.plugin.settings.databaseDetails[key];
id: "share-to-notionnext", this.addCommandForDatabase(dbDetails);
name: i18nConfig.CommandName, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app);
}
});
}
if (this.plugin.settings.GeneralButton) {
this.Ncommand.push({
id: "share-to-notion",
name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig
editorCallback: async (editor: Editor, view: MarkdownView) => {
await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app);
}
});
} }
this.Ncommand.forEach(command => { this.Ncommand.forEach(command => {
@@ -107,4 +78,30 @@ export default class RibbonCommands {
); );
}); });
} }
private addCommandForDatabase(dbDetails: DatabaseDetails) {
// Example logic - adjust based on your specific requirements
let commandId = `share-to-${dbDetails.abName}`;
let commandName = `Share to ${dbDetails.abName}`; // or use a translated name
let editorCallback: (editor: Editor, view: MarkdownView) => Promise<void>;
if (dbDetails.format === 'next') {
editorCallback = async (editor, view) => {
await uploadCommandNext(this.plugin, this.plugin.settings, dbDetails, this.plugin.app);
};
} else if (dbDetails.format === 'general') {
editorCallback = async (editor, view) => {
await uploadCommandGeneral(this.plugin, this.plugin.settings, dbDetails, this.plugin.app);
};
}
// else if (dbDetails.format === 'custom') {
// editorCallback = async (editor, view) => {
// await uploadCommandGeneral(this.plugin, dbDetails, this.plugin.app);
// };
// }
this.Ncommand.push({ id: commandId, name: commandName, editorCallback });
}
} }

View File

@@ -4,7 +4,7 @@ import { Upload2NotionGeneral } from "src/upload/upload_general/Upload2NotionGen
import { Upload2NotionNext } from "src/upload/upload_next/Upload2NotionNext"; import { Upload2NotionNext } from "src/upload/upload_next/Upload2NotionNext";
import { i18nConfig } from "src/lang/I18n"; import { i18nConfig } from "src/lang/I18n";
import ribbonCommands from "src/commands/NotionCommands"; import ribbonCommands from "src/commands/NotionCommands";
import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS } from "src/ui/settingTabs"; import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS, DatabaseDetails } from "src/ui/settingTabs";
// Remember to rename these classes and interfaces! // Remember to rename these classes and interfaces!
@@ -55,6 +55,15 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
await this.saveData(this.settings); await this.saveData(this.settings);
} }
async addDatabaseDetails(dbDetails: DatabaseDetails) {
this.settings.databaseDetails = {
...this.settings.databaseDetails,
[dbDetails.abName]: dbDetails,
};
await this.saveSettings();
}
} }

View File

@@ -7,29 +7,46 @@ import {
import { i18nConfig } from "../lang/I18n"; import { i18nConfig } from "../lang/I18n";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
import {ObsidianSettingTab} from "./settingTabs"; import {DatabaseDetails, ObsidianSettingTab} from "./settingTabs";
import {SettingNextTabs} from "./settingNextTabs"; import {SettingNextTabs} from "./settingNextTabs";
import {SettingGeneralTabs} from "./settingGeneralTabs"; import {SettingGeneralTabs} from "./settingGeneralTabs";
export class SettingModal extends Modal { export class SettingModal extends Modal {
databaseFormat: string = 'none'; data: Record<string, any> = {
databaseAbbreviateName: string = ''; databaseFormat: 'none',
notionAPINext: string = ''; databaseAbbreviateName: '',
databaseIDNext: string = ''; notionAPI: '',
GeneralButton: boolean = false; databaseID: '',
tagButton: true,
customTitleButton: false,
customTitleName: '',
// customValues: '',
saved: false,
};
plugin: ObsidianSyncNotionPlugin; plugin: ObsidianSyncNotionPlugin;
settingTab: ObsidianSettingTab; settingTab: ObsidianSettingTab;
constructor(app: App, plugin: ObsidianSyncNotionPlugin, settingTab: ObsidianSettingTab) { constructor(app: App, plugin: ObsidianSyncNotionPlugin, settingTab: ObsidianSettingTab, dbDetails?: DatabaseDetails) {
super(app); super(app);
this.plugin = plugin; this.plugin = plugin;
this.settingTab = settingTab; this.settingTab = settingTab;
if (dbDetails) {
this.data.databaseFormat = dbDetails.format;
this.data.databaseAbbreviateName = dbDetails.abName;
this.data.notionAPI = dbDetails.notionAPI;
this.data.databaseID = dbDetails.databaseID;
this.data.tagButton = dbDetails.tagButton;
this.data.customTitleButton = dbDetails.customTitleButton;
this.data.customTitleName = dbDetails.customTitleName;
// this.data.customValues = dbDetails.customValues;
}
} }
display(): void { display(): void {
this.containerEl.addClass("settings-modal"); this.containerEl.addClass("settings-modal");
this.titleEl.setText('Add new database');
// create the dropdown button to select the database format // create the dropdown button to select the database format
let { contentEl } = this; let { contentEl } = this;
@@ -48,15 +65,41 @@ export class SettingModal extends Modal {
.addOption('general', i18nConfig.databaseGeneral) .addOption('general', i18nConfig.databaseGeneral)
.addOption('next', i18nConfig.databaseNext) .addOption('next', i18nConfig.databaseNext)
.addOption('custom', i18nConfig.databaseCustom) .addOption('custom', i18nConfig.databaseCustom)
.setValue(this.databaseFormat) .setValue(this.data.databaseFormat)
.onChange(async (value) => { .onChange(async (value) => {
this.databaseFormat = value; this.data.databaseFormat = value;
nextTabs.empty();
this.updateContentBasedOnSelection(value, nextTabs); this.updateContentBasedOnSelection(value, nextTabs);
}); });
// Initialize content based on the current dropdown value // Initialize content based on the current dropdown value
this.updateContentBasedOnSelection(this.plugin.settings.databaseFormat, nextTabs); this.updateContentBasedOnSelection(this.plugin.settings.databaseFormat, nextTabs);
}); });
// add save button
let footerEl = contentEl.createDiv('save-button');
let saveButton = new Setting(footerEl)
saveButton.addButton((button: ButtonComponent) => {
return button
.setTooltip('Save')
.setIcon('checkmark')
.onClick(async () => {
this.data.saved = true;
this.close();
});
}
);
saveButton.addExtraButton((button) => {
return button
.setTooltip('Cancel')
.setIcon('cross')
.onClick(() => {
this.data.saved = false;
this.close();
});
}
);
} }
updateContentBasedOnSelection(value: string, nextTabs: HTMLElement): void { updateContentBasedOnSelection(value: string, nextTabs: HTMLElement): void {
@@ -68,134 +111,92 @@ export class SettingModal extends Modal {
nextTabs.createEl('h3', { text: i18nConfig.NotionGeneralSettingHeader }); nextTabs.createEl('h3', { text: i18nConfig.NotionGeneralSettingHeader });
// add abbreviate name // add abbreviate name
new Setting(nextTabs) this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'databaseAbbreviateName')
.setName(i18nConfig.databaseAbbreviateName)
.setDesc(i18nConfig.databaseAbbreviateNameDesc) // tag button
.addText((text) => this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.data.tagButton, 'tagButton')
text
.setPlaceholder(i18nConfig.databaseAbbreviateNameText)
.setValue(this.databaseAbbreviateName)
.onChange(async (value) => {
this.databaseAbbreviateName = value;
})
);
new Setting(nextTabs) // add api key
.setName(i18nConfig.NotionGeneralButton) this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'notionAPI')
.setDesc(i18nConfig.NotionGeneralButtonDesc)
.addToggle((toggle) =>
toggle
.setValue(this.GeneralButton)
.onChange(async (value) => {
this.GeneralButton = value;
this.updateSettingEl(notionAPIGeneralEl, value)
this.updateSettingEl(databaseIDGeneralEl, value)
})
);
const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton);
new Setting(notionAPIGeneralEl)
.setName(i18nConfig.NotionAPI)
.setDesc(i18nConfig.NotionAPIDesc)
.addText((text) => {
text.inputEl.type = 'password';
return text
.setPlaceholder(i18nConfig.NotionAPIText)
.setValue(this.notionAPINext)
.onChange(async (value) => {
this.notionAPINext = value; // Update the plugin settings directly
})
});
const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton);
new Setting(databaseIDGeneralEl)
.setName(i18nConfig.DatabaseID)
.setDesc(i18nConfig.NotionAPIDesc)
.addText((text) => {
text.inputEl.type = 'password';
return text
.setPlaceholder(i18nConfig.DatabaseIDText)
.setValue(this.databaseIDNext)
.onChange(async (value) => {
this.databaseIDNext = value; // Update the plugin settings directly
})
});
// add database id
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'databaseID')
} else if (value === 'next') { } else if (value === 'next') {
nextTabs.createEl('h3', { text: i18nConfig.NotionNextSettingHeader }); nextTabs.createEl('h3', { text: i18nConfig.NotionNextSettingHeader });
// add abbreviate name // add abbreviate name
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.databaseAbbreviateName) this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'databaseAbbreviateName')
// add api key
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'notionAPI')
// add database id
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'databaseID')
} else if (value === 'custom') {
nextTabs.createEl('h3', { text: i18nConfig.NotionCustomSettingHeader});
// add abbreviate name
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'databaseAbbreviateName')
// tag button
this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.data.tagButton, 'tagButton')
// add custom title button
new Setting(nextTabs) new Setting(nextTabs)
.setName(i18nConfig.databaseAbbreviateName) .setName(i18nConfig.NotionCustomTitle)
.setDesc(i18nConfig.databaseAbbreviateNameDesc) .setDesc(i18nConfig.NotionCustomTitleDesc)
.addText((text) => .addToggle((toggle) =>
text toggle
.setPlaceholder(i18nConfig.databaseAbbreviateNameText) .setValue(this.data.CustomTitleButton)
.setValue(this.databaseAbbreviateName)
.onChange(async (value) => { .onChange(async (value) => {
this.databaseAbbreviateName = value; this.data.CustomTitleButton = value;
this.updateSettingEl(CustomNameEl, value)
// this.updateSettingEl(CustomValuesEl, value)
await this.plugin.saveSettings();
await this.plugin.commands.updateCommand();
}) })
); );
// add api key
const notionAPINextEl = this.createStyleDiv('api-next', this.plugin.settings.NextButton)
new Setting(notionAPINextEl) // add custom title name
.setName(i18nConfig.NotionAPI) const CustomNameEl = this.createStyleDiv('custom-name', (this.data.CustomTitleButton), nextTabs);
.setDesc(i18nConfig.NotionAPIDesc) this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.data.CustomTitleName, 'CustomTitleName')
.addText((text) => {
text.inputEl.type = 'password'; // // add custom values
return text // const CustomValuesEl = this.createStyleDiv('custom-values', (this.data.CustomTitleButton), nextTabs);
.setPlaceholder(i18nConfig.NotionAPIText) // new Setting(CustomValuesEl)
.setValue(this.notionAPINext) // .setName(i18nConfig.NotionCustomValues)
.onChange(async (value) => { // .setDesc(i18nConfig.NotionCustomValuesDesc)
this.notionAPINext = value; // Update the plugin settings directly // .addTextArea((text) => {
}) // return text
}); // .setPlaceholder(i18nConfig.NotionCustomValuesText)
// .setValue(this.data.CustomValues)
// .onChange(async (value) => {
// this.data.CustomValues = value;
// await this.plugin.saveSettings();
// });
// });
// add api key
const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton, nextTabs);
this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'notionAPI')
// add database id // add database id
const databaseIDNextEl = this.createStyleDiv('databaseID-next', this.plugin.settings.NextButton) const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton, nextTabs);
this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'databaseID')
new Setting(databaseIDNextEl)
.setName(i18nConfig.DatabaseID)
.setDesc(i18nConfig.NotionAPIDesc)
.addText((text) => {
text.inputEl.type = 'password';
return text
.setPlaceholder(i18nConfig.DatabaseIDText)
.setValue(this.databaseIDNext)
.onChange(async (value) => {
this.databaseIDNext = value; // Update the plugin settings directly
})
});
// // test button
// new Setting(nextTabs)
// .setName(i18nConfig.NotionNextButton)
// .setDesc(i18nConfig.NotionNextButtonDesc)
// .addToggle((toggle) =>
// toggle
// .setValue(this.plugin.settings.NextButton)
// .onChange(async (value) => {
// this.plugin.settings.NextButton = value;
// })
// );
} else if (value === 'custom') {
} }
// Implement for 'custom' if needed
} }
@@ -208,8 +209,8 @@ export class SettingModal extends Modal {
// create a function to create a div with a style for pop over elements // create a function to create a div with a style for pop over elements
public createStyleDiv(className: string, commandValue: boolean = false) { public createStyleDiv(className: string, commandValue: boolean = false,parentEl: HTMLElement ) {
return this.contentEl.createDiv(className, (div) => { return parentEl.createDiv(className, (div) => {
this.updateSettingEl(div, commandValue); this.updateSettingEl(div, commandValue);
}); });
} }
@@ -222,7 +223,7 @@ export class SettingModal extends Modal {
} }
// function to add one setting element in the setting tab. // function to add one setting element in the setting tab.
public createSettingEl(contentEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any) { public createSettingEl(contentEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any,settingsKey: string) {
if (type === 'password') { if (type === 'password') {
return new Setting(contentEl) return new Setting(contentEl)
.setName(name) .setName(name)
@@ -233,8 +234,7 @@ export class SettingModal extends Modal {
.setPlaceholder(placeholder) .setPlaceholder(placeholder)
.setValue(holderValue) .setValue(holderValue)
.onChange(async (value) => { .onChange(async (value) => {
holderValue = value; // Update the plugin settings directly this.data[settingsKey] = value; // Update the settings dictionary await this.plugin.saveSettings();
await this.plugin.saveSettings();
}) })
}); });
} else if (type === 'toggle') { } else if (type === 'toggle') {
@@ -245,8 +245,7 @@ export class SettingModal extends Modal {
toggle toggle
.setValue(holderValue) .setValue(holderValue)
.onChange(async (value) => { .onChange(async (value) => {
holderValue = value; // Update the plugin settings directly this.data[settingsKey] = value; // Update the settings dictionary await this.plugin.saveSettings();
await this.plugin.saveSettings();
}) })
); );
} else if (type === 'text') { } else if (type === 'text') {
@@ -258,8 +257,7 @@ export class SettingModal extends Modal {
.setPlaceholder(placeholder) .setPlaceholder(placeholder)
.setValue(holderValue) .setValue(holderValue)
.onChange(async (value) => { .onChange(async (value) => {
holderValue = value; // Update the plugin settings directly this.data[settingsKey] = value; // Update the settings dictionary await this.plugin.saveSettings();
await this.plugin.saveSettings();
}) })
); );
} }

View File

@@ -40,10 +40,10 @@ export class SettingNextTabs extends PluginSettingTab {
const notionAPINextEl = this.settingModal.createStyleDiv('api-next', this.plugin.settings.NextButton) const notionAPINextEl = this.settingModal.createStyleDiv('api-next', this.plugin.settings.NextButton)
this.settingModal.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext, 'notionAPINext') this.settingModal.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext)
const databaseIDNextEl = this.settingModal.createStyleDiv('databaseID-next', this.plugin.settings.NextButton) const databaseIDNextEl = this.settingModal.createStyleDiv('databaseID-next', this.plugin.settings.NextButton)
this.settingModal.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext, 'databaseIDNext') this.settingModal.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext)
} }
} }

View File

@@ -23,6 +23,18 @@ export interface PluginSettings {
notionAPICustom: string; notionAPICustom: string;
databaseIDCustom: string; databaseIDCustom: string;
[key: string]: any; [key: string]: any;
databaseDetails: Record<string, DatabaseDetails>
}
export interface DatabaseDetails {
format: string;
abName: string;
notionAPI: string;
databaseID: string;
tagButton: boolean;
customTitleButton: boolean;
customTitleName: string;
// customValues: string;
} }
export const DEFAULT_SETTINGS: PluginSettings = { export const DEFAULT_SETTINGS: PluginSettings = {
@@ -42,6 +54,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
CustomValues: "", CustomValues: "",
notionAPICustom: "", notionAPICustom: "",
databaseIDCustom: "", databaseIDCustom: "",
databaseDetails: {},
}; };
@@ -80,16 +93,24 @@ export class ObsidianSettingTab extends PluginSettingTab {
let modal = new SettingModal(this.app, this.plugin, this); let modal = new SettingModal(this.app, this.plugin, this);
modal.onClose = () => { modal.onClose = () => {
// if (modal.saved) { if (modal.data.saved) {
// const database = { const dbDetails = {
// format: modal.data.databaseFormat,
// } abName: modal.data.databaseAbbreviateName,
// this.plugin.addDatabase(database); notionAPI: modal.data.notionAPI,
// databaseID: modal.data.databaseID,
// this.plugin.calloutManager.addDatabase(database); tagButton: modal.data.tagButton,
// customTitleButton: modal.data.customTitleButton,
// this.display(); customTitleName: modal.data.customTitleName,
// } // customValues: modal.data.customValues,
}
this.plugin.addDatabaseDetails(dbDetails);
this.plugin.commands.updateCommand();
this.display()
}
} }
modal.open(); modal.open();
@@ -97,6 +118,9 @@ export class ObsidianSettingTab extends PluginSettingTab {
}); });
// list all created database
// // notion next database settings // // notion next database settings
// //

View File

@@ -3,7 +3,7 @@ import { App, Notice } from "obsidian";
import { Upload2NotionNext } from "./upload_next/Upload2NotionNext"; import { Upload2NotionNext } from "./upload_next/Upload2NotionNext";
import { Upload2NotionGeneral } from "./upload_general/Upload2NotionGeneral"; import { Upload2NotionGeneral } from "./upload_general/Upload2NotionGeneral";
import { Upload2NotionCustom } from "./upoload_custom/Upload2NotionCustom"; import { Upload2NotionCustom } from "./upoload_custom/Upload2NotionCustom";
import { PluginSettings } from "../ui/settingTabs"; import {DatabaseDetails, PluginSettings} from "../ui/settingTabs";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
import { getNowFileMarkdownContentNext } from "./upload_next/getMarkdownNext"; import { getNowFileMarkdownContentNext } from "./upload_next/getMarkdownNext";
import { getNowFileMarkdownContentGeneral } from "./upload_general/getMarkdownGeneral"; import { getNowFileMarkdownContentGeneral } from "./upload_general/getMarkdownGeneral";
@@ -12,10 +12,11 @@ import {getNowFileMarkdownContentCustom} from "./upoload_custom/getMarkdownCusto
export async function uploadCommandNext( export async function uploadCommandNext(
plugin: ObsidianSyncNotionPlugin, plugin: ObsidianSyncNotionPlugin,
settings: PluginSettings, settings: PluginSettings,
dbDetails: DatabaseDetails,
app: App, app: App,
) { ) {
const { notionAPINext, databaseIDNext } = settings; const { notionAPI, databaseID } = dbDetails;
// Check if NNon exists // Check if NNon exists
// if (NNon === undefined) { // if (NNon === undefined) {
@@ -25,7 +26,7 @@ export async function uploadCommandNext(
// } // }
// Check if the user has set up the Notion API and database ID // Check if the user has set up the Notion API and database ID
if (notionAPINext === "" || databaseIDNext === "") { if (notionAPI === "" || databaseID === "") {
const setAPIMessage = i18nConfig["set-api-id"]; const setAPIMessage = i18nConfig["set-api-id"];
new Notice(setAPIMessage); new Notice(setAPIMessage);
return; return;
@@ -35,7 +36,7 @@ export async function uploadCommandNext(
if (markDownData) { if (markDownData) {
const { basename } = nowFile; const { basename } = nowFile;
const upload = new Upload2NotionNext(plugin); const upload = new Upload2NotionNext(plugin, dbDetails);
const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app); const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app);
if (res.status === 200) { if (res.status === 200) {
@@ -52,13 +53,14 @@ export async function uploadCommandNext(
export async function uploadCommandGeneral( export async function uploadCommandGeneral(
plugin: ObsidianSyncNotionPlugin, plugin: ObsidianSyncNotionPlugin,
settings: PluginSettings, settings: PluginSettings,
dbDetails: DatabaseDetails,
app: App, app: App,
) { ) {
const { notionAPIGeneral, databaseIDGeneral } = settings; const { notionAPI, databaseID } = settings;
// Check if the user has set up the Notion API and database ID // Check if the user has set up the Notion API and database ID
if (notionAPIGeneral === "" || databaseIDGeneral === "") { if (notionAPI === "" || databaseID === "") {
const setAPIMessage = i18nConfig["set-api-id"]; const setAPIMessage = i18nConfig["set-api-id"];
new Notice(setAPIMessage); new Notice(setAPIMessage);
return; return;
@@ -69,7 +71,7 @@ export async function uploadCommandGeneral(
if (markDownData) { if (markDownData) {
const { basename } = nowFile; const { basename } = nowFile;
const upload = new Upload2NotionGeneral(plugin); const upload = new Upload2NotionGeneral(plugin, dbDetails);
const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app); const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app);
if (res.status === 200) { if (res.status === 200) {

View File

@@ -4,14 +4,15 @@ import { markdownToBlocks } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import { PluginSettings } from "../../ui/settingTabs"; import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
import { UploadBaseGeneral } from "./BaseUpload2NotionGeneral"; import { UploadBaseGeneral } from "./BaseUpload2NotionGeneral";
import { updateYamlInfo } from "../updateYaml"; import { updateYamlInfo } from "../updateYaml";
export class Upload2NotionGeneral extends UploadBaseGeneral { export class Upload2NotionGeneral extends UploadBaseGeneral {
settings: PluginSettings; settings: PluginSettings;
dbDetails: DatabaseDetails;
constructor(plugin: MyPlugin) { constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
super(plugin); super(plugin);
} }
@@ -26,8 +27,9 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
) { ) {
await this.deletePage(notionID); await this.deletePage(notionID);
const { databaseID } = this.dbDetails;
const databasecover = await this.getDataBase( const databasecover = await this.getDataBase(
this.plugin.settings.databaseIDGeneral, databaseID,
); );
if (cover == null) { if (cover == null) {
@@ -125,7 +127,10 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
const file2Block = markdownToBlocks(__content, options); const file2Block = markdownToBlocks(__content, options);
const frontmasster = const frontmasster =
app.metadataCache.getFileCache(nowFile)?.frontmatter; app.metadataCache.getFileCache(nowFile)?.frontmatter;
const notionID = frontmasster ? frontmasster.notionID : null; const {abName} = this.dbDetails
const notionIDKey = `${abName}-NotionID`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
if (notionID) { if (notionID) {
res = await this.updatePage( res = await this.updatePage(

View File

@@ -5,14 +5,15 @@ import { markdownToBlocks, } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import { PluginSettings } from "../../ui/settingTabs"; import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
import { updateYamlInfo } from "../updateYaml"; import { updateYamlInfo } from "../updateYaml";
import {LIMITS, paragraph} from "@tryfabric/martian/src/notion"; import {LIMITS, paragraph} from "@tryfabric/martian/src/notion";
export class Upload2NotionNext extends UploadBaseNext { export class Upload2NotionNext extends UploadBaseNext {
settings: PluginSettings; settings: PluginSettings;
dbDetails: DatabaseDetails
constructor(plugin: MyPlugin) { constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
super(plugin); super(plugin);
} }
@@ -36,7 +37,9 @@ export class Upload2NotionNext extends UploadBaseNext {
) { ) {
await this.deletePage(notionID) await this.deletePage(notionID)
const databasecover = await this.getDataBase(this.plugin.settings.databaseIDNext) const { databaseID} = this.dbDetails
const databasecover = await this.getDataBase(databaseID)
if (cover == null) { if (cover == null) {
cover = databasecover cover = databasecover
@@ -216,7 +219,10 @@ export class Upload2NotionNext extends UploadBaseNext {
const __content = yamlContent.__content const __content = yamlContent.__content
const file2Block = markdownToBlocks(__content, options); const file2Block = markdownToBlocks(__content, options);
const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter
const notionID = frontmasster ? frontmasster.notionID : null const {abName} = this.dbDetails
const notionIDKey = `${abName}-NotionID`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
// increase the limits // increase the limits
// Motivated by https://github.com/tryfabric/martian/issues/51 // Motivated by https://github.com/tryfabric/martian/issues/51